From b7cad3cee80a49161220368388146875d9ead9fc Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Thu, 7 Mar 2024 16:00:57 +0800 Subject: [PATCH 01/32] =?UTF-8?q?=E5=BA=97=E9=93=BA=E7=94=B3=E8=AF=B7?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E5=BA=97=E9=93=BA=E8=B5=84=E8=B4=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/merchant/MerchantIntentionRepository.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/common/repositories/system/merchant/MerchantIntentionRepository.php b/app/common/repositories/system/merchant/MerchantIntentionRepository.php index 8b9ed3c1..446fd16e 100755 --- a/app/common/repositories/system/merchant/MerchantIntentionRepository.php +++ b/app/common/repositories/system/merchant/MerchantIntentionRepository.php @@ -16,6 +16,7 @@ use app\common\model\system\merchant\Merchant; use app\common\model\system\merchant\MerchantCategory; use app\common\model\system\merchant\MerchantIntention; use app\common\repositories\BaseRepository; +use app\common\repositories\system\config\ConfigValueRepository; use crmeb\jobs\SendSmsJob; use crmeb\services\SmsService; use FormBuilder\Factory\Elm; @@ -182,6 +183,9 @@ class MerchantIntentionRepository extends BaseRepository if ($data['status'] == 1) { if ($create) { $merchant = app()->make(MerchantRepository::class)->createMerchant($merData); + app()->make(ConfigValueRepository::class)->setFormData([ + 'mer_certificate' => $data['mer_certificate'] + ], $merchant->mer_id); $data['mer_id'] = $merchant->mer_id; $data['uid'] = $intention['uid']; $data['reg_admin_id'] = $autoCreate ? 0: $merchant['merchant_admin']['merchant_admin_id']; From d865bf4fdb07bbfbbaa2ba3e020d2640d3b7a189 Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Thu, 7 Mar 2024 16:10:05 +0800 Subject: [PATCH 02/32] =?UTF-8?q?=E5=BA=97=E9=93=BA=E7=94=B3=E8=AF=B7?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E5=BA=97=E9=93=BA=E8=B5=84=E8=B4=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/merchant/MerchantIntentionRepository.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/common/repositories/system/merchant/MerchantIntentionRepository.php b/app/common/repositories/system/merchant/MerchantIntentionRepository.php index 446fd16e..81816797 100755 --- a/app/common/repositories/system/merchant/MerchantIntentionRepository.php +++ b/app/common/repositories/system/merchant/MerchantIntentionRepository.php @@ -183,9 +183,11 @@ class MerchantIntentionRepository extends BaseRepository if ($data['status'] == 1) { if ($create) { $merchant = app()->make(MerchantRepository::class)->createMerchant($merData); - app()->make(ConfigValueRepository::class)->setFormData([ - 'mer_certificate' => $data['mer_certificate'] - ], $merchant->mer_id); + if (!empty($intention['images'])) { + app()->make(ConfigValueRepository::class)->setFormData([ + 'mer_certificate' => $intention['images'] + ], $merchant->mer_id); + } $data['mer_id'] = $merchant->mer_id; $data['uid'] = $intention['uid']; $data['reg_admin_id'] = $autoCreate ? 0: $merchant['merchant_admin']['merchant_admin_id']; From 0771bef93a8e12f81d76654e49c79e8882f4d2cb Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Thu, 7 Mar 2024 16:26:13 +0800 Subject: [PATCH 03/32] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=98=A5=E8=80=95?= =?UTF-8?q?=E8=A1=A5=E8=B4=B4=E6=BF=80=E6=B4=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crmeb/listens/ActivateConsumptionListen.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crmeb/listens/ActivateConsumptionListen.php b/crmeb/listens/ActivateConsumptionListen.php index a4f22625..d496b22b 100644 --- a/crmeb/listens/ActivateConsumptionListen.php +++ b/crmeb/listens/ActivateConsumptionListen.php @@ -20,23 +20,28 @@ class ActivateConsumptionListen extends TimerService implements ListenerInterfac { $this->tick(1000 * 60, function () { Log::info('定时任务:激活商户补贴'); + $count = 0; $couponId = StoreConsumption::where('type', StoreConsumption::TYPE_RECHARGE)->value('coupon_id'); if (empty($couponId)) { return; } + $buyCouponId = StoreConsumption::where('type', StoreConsumption::TYPE_PULL_CONSUMPTION)->value('coupon_id'); $storeConsumptionUser = StoreConsumptionUser::where('coupon_id', $couponId) ->where('status', StoreConsumptionUser::STATUS_REPEAL) ->select(); foreach ($storeConsumptionUser as $item) { $saleTotal = Merchant::where('uid', $item['uid'])->value('sale_amount'); - if ($saleTotal >= $item['order_amount'] && $item['balance'] <= 0) { + $balance = StoreConsumptionUser::where('coupon_id', $buyCouponId)->where('uid', $item['uid'])->value('balance'); + if ($saleTotal >= $item['order_amount'] && $balance <= 0) { $item->status = StoreConsumptionUser::STATUS_UNUSED; $item->start_time = date('Y-m-d H:i:s'); $item->end_time = date('Y-m-d H:i:s', strtotime('+1 year')); $item->save(); UserBill::where('link_id', $item['coupon_user_id'])->where('type', 'red_pack_2')->update(['status', 1]); + $count++; } } + Log::info('定时任务:激活商户补贴,执行数量:' . $count); }); } From cf4d51574183821df861de2a1ef80aa054e4db0b Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Thu, 7 Mar 2024 16:36:42 +0800 Subject: [PATCH 04/32] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=98=A5=E8=80=95?= =?UTF-8?q?=E8=A1=A5=E8=B4=B4=E6=BF=80=E6=B4=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crmeb/listens/ActivateConsumptionListen.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crmeb/listens/ActivateConsumptionListen.php b/crmeb/listens/ActivateConsumptionListen.php index d496b22b..d498406d 100644 --- a/crmeb/listens/ActivateConsumptionListen.php +++ b/crmeb/listens/ActivateConsumptionListen.php @@ -37,7 +37,7 @@ class ActivateConsumptionListen extends TimerService implements ListenerInterfac $item->start_time = date('Y-m-d H:i:s'); $item->end_time = date('Y-m-d H:i:s', strtotime('+1 year')); $item->save(); - UserBill::where('link_id', $item['coupon_user_id'])->where('type', 'red_pack_2')->update(['status', 1]); + UserBill::where('link_id', $item['coupon_user_id'])->where('type', 'red_pack_2')->update(['status' => 1]); $count++; } } From 891ab45bdf19c689fafe0cc516006701b9275148 Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Thu, 7 Mar 2024 16:49:29 +0800 Subject: [PATCH 05/32] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=95=86=E6=88=B7?= =?UTF-8?q?=E6=9C=80=E4=BD=8E=E6=8F=90=E7=8E=B0=E9=87=91=E9=A2=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/user/User.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controller/api/user/User.php b/app/controller/api/user/User.php index a20c44c6..903daa1c 100755 --- a/app/controller/api/user/User.php +++ b/app/controller/api/user/User.php @@ -98,6 +98,7 @@ class User extends BaseController 'now_money' => $user->now_money, 'broken_day' => (int)systemConfig('lock_brokerage_timer'), 'user_extract_min' => (int)systemConfig('user_extract_min'), + 'mer_extract_min' => (int)systemConfig('extract_minimum_num'), ]; return app('json')->success($data); } From 54bf58b197e6bcc774fa84c6ee3e50103e699f95 Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Thu, 7 Mar 2024 17:41:49 +0800 Subject: [PATCH 06/32] =?UTF-8?q?=E8=B0=83=E8=AF=95=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E6=8E=88=E6=9D=83=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/Auth.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/controller/api/Auth.php b/app/controller/api/Auth.php index f0f7bb8b..06267ba7 100755 --- a/app/controller/api/Auth.php +++ b/app/controller/api/Auth.php @@ -874,9 +874,10 @@ class Auth extends BaseController throw new ValidateException('授权失败[003]'); return $user; } else if ($auth['type'] === 'app_wechat') { - $oauth = WechatService::create()->getApplication()->oauth; + $oauth = WechatService::create(true)->getApplication()->oauth; + $accessToken = $oauth->getAccessToken($data['code']); try { - $wechatInfo = $oauth->user(new AccessToken(['access_token' => $data['code'], 'openid' => $data['openid']]))->getOriginal(); + $wechatInfo = $oauth->user($accessToken)->getOriginal(); } catch (Exception $e) { throw new ValidateException('授权失败[001]' . $e->getMessage()); } From 50248f1c2bc5bd0015824682c55d4e8b3335787e Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Fri, 8 Mar 2024 11:05:36 +0800 Subject: [PATCH 07/32] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=95=86=E6=88=B7?= =?UTF-8?q?=E5=86=BB=E7=BB=93=E9=87=91=E9=A2=9D=E8=A7=A3=E5=86=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../listens/AutoUnlockMerchantMoneyListen.php | 41 +++++++++++++------ 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/crmeb/listens/AutoUnlockMerchantMoneyListen.php b/crmeb/listens/AutoUnlockMerchantMoneyListen.php index 612b2080..a58f2248 100755 --- a/crmeb/listens/AutoUnlockMerchantMoneyListen.php +++ b/crmeb/listens/AutoUnlockMerchantMoneyListen.php @@ -18,24 +18,39 @@ use app\common\repositories\user\UserBillRepository; use crmeb\interfaces\ListenerInterface; use crmeb\services\TimerService; use think\facade\Db; +use think\facade\Log; class AutoUnlockMerchantMoneyListen extends TimerService implements ListenerInterface { public function handle($event): void { - $this->tick(1000 * 60 * 20, function () { - request()->clearCache(); - $userBill = app()->make(UserBillRepository::class); - $timer = ((int)systemConfig('mer_lock_time')); - $time = date('Y-m-d H:i:s', $timer ? strtotime("- $timer day") : time()); - $bills = $userBill->getTimeoutMerchantMoneyBill($time); - $merchant = app()->make(MerchantRepository::class); - foreach ($bills as $bill) { - Db::transaction(function () use ($bill, $merchant) { - $merchant->addMoney($bill->mer_id, $bill->number); - $bill->status = 1; - $bill->save(); - }); + $this->tick(1000 * 60 * 60, function () { + if (time() >= strtotime('today 18:00:00') && time() >= strtotime('today 20:00:00')) { + request()->clearCache(); + /** @var UserBillRepository $userBill */ + $userBill = app()->make(UserBillRepository::class); +// $timer = ((int)systemConfig('mer_lock_time')); +// $time = date('Y-m-d H:i:s', $timer ? strtotime("- $timer day") : time()); + $time = date('Y-m-d 00:00:00'); + $bills = $userBill->getTimeoutMerchantMoneyBill($time); + $merchant = app()->make(MerchantRepository::class); + $count = 0; + foreach ($bills as $bill) { + Db::startTrans(); + try { + $merchant->addMoney($bill->mer_id, $bill->number); + $bill->status = 1; + $bill->save(); + Db::commit(); + $count++; + } catch (\Throwable $e) { + Db::rollback(); + Log::error('商户冻结金额解冻出错:' . $e->getMessage()); + } + } + if ($count > 0) { + Log::info('商户冻结金额解冻成功:' . $count); + } } }); } From bc4afc83b2c5a18010f14f2da7721eed72aa1d6d Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Fri, 8 Mar 2024 14:07:10 +0800 Subject: [PATCH 08/32] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=BD=AC=E8=B4=A6?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/admin/system/financial/Financial.php | 4 +++- crmeb/services/ExcelService.php | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/controller/admin/system/financial/Financial.php b/app/controller/admin/system/financial/Financial.php index 6ad046cd..5bf2500a 100755 --- a/app/controller/admin/system/financial/Financial.php +++ b/app/controller/admin/system/financial/Financial.php @@ -149,7 +149,9 @@ class Financial extends BaseController { $where = $this->request->params(['date', 'status', 'financial_type', 'financial_status', 'keyword', 'is_trader', 'mer_id']); [$page, $limit] = $this->getPage(); - $data = app()->make(ExcelService::class)->financialLog($where,$page,$limit); + /** @var ExcelService $make */ + $make = app()->make(ExcelService::class); + $data = $make->financialLog($where,$page,$limit); return app('json')->success($data); } diff --git a/crmeb/services/ExcelService.php b/crmeb/services/ExcelService.php index ce520590..2fac4fd4 100755 --- a/crmeb/services/ExcelService.php +++ b/crmeb/services/ExcelService.php @@ -678,6 +678,10 @@ class ExcelService $list = $query->page($page, $limit)->select(); foreach ($list as $item) { if ($item->financial_type == 1) { + if (empty($item->financial_account->bank)) { + $acount = ''; + continue; + } $acount = '姓名:' . $item->financial_account->name . PHP_EOL; $acount .= '银行名称:' . $item->financial_account->bank . PHP_EOL; $acount .= '银行卡号:' . $item->financial_account->bank_code; From d4ab5146d84b8ae1c7cd74596c93be353c99de72 Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Fri, 8 Mar 2024 15:56:34 +0800 Subject: [PATCH 09/32] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=B4=A6=E5=8F=B7?= =?UTF-8?q?=E5=90=88=E5=B9=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/store/order/StoreOrderOther.php | 2 +- app/controller/api/Auth.php | 10 +- app/controller/api/user/User.php | 106 ++++++++++++++++++ route/api.php | 2 + 4 files changed, 116 insertions(+), 4 deletions(-) diff --git a/app/common/model/store/order/StoreOrderOther.php b/app/common/model/store/order/StoreOrderOther.php index 084c1cfe..b113e5a0 100755 --- a/app/common/model/store/order/StoreOrderOther.php +++ b/app/common/model/store/order/StoreOrderOther.php @@ -52,7 +52,7 @@ class StoreOrderOther extends BaseModel public function refundOrder() { - return $this->hasMany(StoreRefundOrder::class,'order_id','order_id'); + return $this->hasMany(StoreRefundOrderOther::class,'order_id','order_id'); } public function orderStatus() diff --git a/app/controller/api/Auth.php b/app/controller/api/Auth.php index 06267ba7..a4070cba 100755 --- a/app/controller/api/Auth.php +++ b/app/controller/api/Auth.php @@ -122,7 +122,7 @@ class Auth extends BaseController $destination = public_path('uploads').'img/' . $filename; // 目标路径 $pict_url= $url.'/uploads/img/'.$filename; file_put_contents($destination, file_get_contents($res->pict_url)); - + if($resp && isset($resp->small_images) && isset($resp->small_images->string)){ foreach($resp->small_images->string as $k=>$v){ $filename = basename($v); // 获取文件名 @@ -197,13 +197,13 @@ class Auth extends BaseController function convertUrlQuery($query) { $queryParts = explode('&', $query); - + $params = array(); foreach ($queryParts as $param) { $item = explode('=', $param); $params[$item[0]] = $item[1]; } - + return $params; } public function dotest() @@ -914,6 +914,7 @@ class Auth extends BaseController if (!$users) return app('json')->fail('授权失败'); $authInfo = $users[0]; + /** @var UserRepository $userRepository */ $userRepository = app()->make(UserRepository::class); $user = $users[1] ?? $userRepository->wechatUserIdBytUser($authInfo['wechat_user_id']); $code = (int)($auth['auth']['spread_code']['id'] ?? $auth['auth']['spread_code'] ?? ''); @@ -931,6 +932,9 @@ class Auth extends BaseController if ($auth['auth']['spread'] ?? 0) { $userRepository->bindSpread($user, (int)($auth['auth']['spread'])); } + if (!empty($user['account'])) { + $user = $userRepository->accountByUser($user['account']); + } $tokenInfo = $userRepository->createToken($user); $userRepository->loginAfter($user); return app('json')->status(200, $userRepository->returnToken($user, $tokenInfo)); diff --git a/app/controller/api/user/User.php b/app/controller/api/user/User.php index 903daa1c..9e6d8c28 100755 --- a/app/controller/api/user/User.php +++ b/app/controller/api/user/User.php @@ -15,8 +15,16 @@ namespace app\controller\api\user; use app\common\dao\store\order\StoreOrderDao; +use app\common\model\store\consumption\StoreConsumptionDetail; +use app\common\model\store\consumption\StoreConsumptionUser; +use app\common\model\store\order\StoreGroupOrder; +use app\common\model\store\order\StoreOrder; use app\common\model\store\order\StoreOrderOther; +use app\common\model\store\order\StoreOrderProduct; +use app\common\model\store\order\StoreOrderStatus; +use app\common\model\store\order\StoreRefundOrder; use app\common\model\system\merchant\Merchant; +use app\common\model\user\UserBill; use app\common\repositories\store\IntegralRepository; use app\common\repositories\store\order\PresellOrderRepository; use app\common\repositories\store\service\StoreServiceRepository; @@ -26,6 +34,7 @@ use app\common\repositories\user\UserBillRepository; use app\common\repositories\user\UserBrokerageRepository; use app\common\repositories\user\UserRepository; use app\common\repositories\user\UserVisitRepository; +use app\common\model\system\merchant\FinancialRecord; use app\validate\api\UserBaseInfoValidate; use crmeb\basic\BaseController; use crmeb\services\MiniProgramService; @@ -36,6 +45,10 @@ use think\db\exception\DbException; use think\db\exception\ModelNotFoundException; use app\controller\api\Common; use app\common\model\user\User as UserModel; +use app\common\model\user\UserAddress; +use app\common\model\user\UserRecharge; +use think\db\Query; +use think\facade\Db; class User extends BaseController { @@ -594,4 +607,97 @@ class User extends BaseController return app('json')->success(['count' => count($userIds), 'list' => $result]); } + /** + * 合并账号 + * @param UserRepository $repository + * @return mixed + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + */ + public function merge(UserRepository $repository) + { + $user = $this->request->userInfo(); + $data = $this->request->params(['phone', 'sms_code'] ); + if ($user['account'] == $data['phone']) { + return app('json')->fail('绑定的账号不能相同'); + } + if (!empty($user['account'])) { + return app('json')->fail('已绑定手机号'); + } + $sms_code = app()->make(SmsService::class)->checkSmsCode($data['phone'], $data['sms_code'], 'login'); + if (!$sms_code && !env('APP_DEBUG')) { + return app('json')->fail('验证码不正确'); + } + $targetUser = $repository->accountByUser($data['phone']); + if (empty($targetUser)) { + $user->account = $data['phone']; + $user->phone = $data['phone']; + $user->save(); + $tokenInfo = $repository->createToken($user); + return app('json')->success($repository->returnToken($user, $tokenInfo)); + } else { + Db::startTrans(); + try { + StoreGroupOrder::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); + StoreOrder::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); + StoreOrderProduct::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); + UserBill::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); + FinancialRecord::where('user_id', $user['uid'])->update(['user_id' => $targetUser['uid']]); + UserAddress::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); + StoreConsumptionUser::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); + StoreConsumptionDetail::where('user_id', $user['uid'])->update(['user_id' => $targetUser['uid']]); + StoreRefundOrder::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); + UserRecharge::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); + StoreOrderStatus::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); + if ($user->now_money > 0) { + $targetUser->now_money = bcadd($targetUser->now_money, $user->now_money, 2); + $targetUser->save(); + } + $merchant = Merchant::where('uid', $targetUser['uid'])->find(); + if (!empty($merchant)) { + $orders = StoreOrder::with(['refundOrder' => function(Query $query) { + $query->where('status', '<>', -1)->field('order_id,refund_price'); + }])->where('uid', $user['uid']) + ->whereIn('status', [0, 1, 2, 3, 9, 10]) + ->field('order_id,uid,total_price') + ->select()->toArray(); + $otherOrders = StoreOrderOther::with(['refundOrder' => function(Query $query) { + $query->where('status', '<>', -1)->field('order_id,refund_price'); + }])->where('uid', $user['uid']) + ->whereIn('status', [0, 1, 2, 3, 9, 10]) + ->field('order_id,uid,total_price') + ->select()->toArray(); + $purchaseAmount = 0; + foreach ($orders as $order) { + $purchaseAmount = bcadd($purchaseAmount, $order['total_price'], 2); + foreach ($order['refundOrder']as $refundOrder) { + $purchaseAmount = bcsub($purchaseAmount, $refundOrder['refund_price'], 2); + } + } + unset($refundOrder, $order); + foreach ($otherOrders as $otherOrder) { + $purchaseAmount = bcadd($purchaseAmount, $otherOrder['total_price'], 2); + foreach ($otherOrder['refundOrder']as $refundOrder) { + $purchaseAmount = bcsub($purchaseAmount, $refundOrder['refund_price'], 2); + } + } + unset($refundOrder, $otherOrder); + if ($purchaseAmount > 0) { + $merchant->purchase_amount = bcadd($merchant->purchase_amount, $purchaseAmount, 2); + $merchant->save(); + } + $user->account = $data['phone']; + $user->phone = $data['phone']; + $user->save(); + } + Db::commit(); + } catch (\Throwable $e) { + Db::rollback(); + } + $tokenInfo = $repository->createToken($targetUser); + return app('json')->success($repository->returnToken($targetUser, $tokenInfo)); + } + } + } diff --git a/route/api.php b/route/api.php index 5eb990c1..b6648122 100755 --- a/route/api.php +++ b/route/api.php @@ -173,6 +173,8 @@ Route::group('api/', function () { //切换账号 Route::get('account', 'User/account'); Route::post('switch', 'User/switchUser'); + //合并账号 + Route::post('merge', 'User/merge'); //修改信息 Route::post('change/phone', 'User/changePhone'); Route::post('change/info', 'User/updateBaseInfo'); From 6b759c4be4061761dd774c52989ff2fd88844185 Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Fri, 8 Mar 2024 16:09:29 +0800 Subject: [PATCH 10/32] =?UTF-8?q?=E5=A4=84=E7=90=86=E6=8E=A8=E5=B9=BF?= =?UTF-8?q?=E4=BD=A3=E9=87=91=E5=88=B0=E8=B4=A6=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/repositories/store/order/StoreOrderRepository.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/common/repositories/store/order/StoreOrderRepository.php b/app/common/repositories/store/order/StoreOrderRepository.php index 4c335251..3049228d 100755 --- a/app/common/repositories/store/order/StoreOrderRepository.php +++ b/app/common/repositories/store/order/StoreOrderRepository.php @@ -794,8 +794,9 @@ class StoreOrderRepository extends BaseRepository } $promoterCommission = FinancialRecord::where('order_id', $order['order_id']) - ->where('financial_type', 'promoter_commission') - ->column('user_id,number'); + ->where('financial_type', 'commission_to_promoter') + ->field('user_id,number') + ->find(); if (!empty($promoterCommission)) { $userBillRepository->incBill($promoterCommission['user_id'], 'brokerage', 'order_one', [ 'link_id' => $order['order_id'], From 5bd918891d709faf5bef67e6111745fafedead8a Mon Sep 17 00:00:00 2001 From: liu <1873441552@qq.com> Date: Fri, 8 Mar 2024 17:28:48 +0800 Subject: [PATCH 11/32] =?UTF-8?q?=E6=96=B0=E5=A2=9Eexcel=E9=93=B6=E8=A1=8C?= =?UTF-8?q?=E5=8D=A1=E8=B4=A6=E5=8D=95=E5=AF=BC=E5=87=BA=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/system/financial/Financial.php | 11 ++++ crmeb/services/ExcelService.php | 54 +++++++++++++++++++ route/admin/accounts.php | 5 ++ 3 files changed, 70 insertions(+) diff --git a/app/controller/admin/system/financial/Financial.php b/app/controller/admin/system/financial/Financial.php index 5bf2500a..aaae17ba 100755 --- a/app/controller/admin/system/financial/Financial.php +++ b/app/controller/admin/system/financial/Financial.php @@ -156,4 +156,15 @@ class Financial extends BaseController } + public function billExport() + { + $where = $this->request->params(['date', 'status', 'financial_type', 'financial_status', 'keyword', 'is_trader', 'mer_id']); + [$page, $limit] = $this->getPage(); + $data = app()->make(ExcelService::class)->withdrawalBill($where,$page,$limit); + return app('json')->success($data); + + } + + + } diff --git a/crmeb/services/ExcelService.php b/crmeb/services/ExcelService.php index 2fac4fd4..881af72f 100755 --- a/crmeb/services/ExcelService.php +++ b/crmeb/services/ExcelService.php @@ -676,6 +676,7 @@ class ExcelService $query = app()->make(FinancialRepository::class)->search($where)->with('merchant'); $count = $query->count(); $list = $query->page($page, $limit)->select(); + foreach ($list as $item) { if ($item->financial_type == 1) { if (empty($item->financial_account->bank)) { @@ -711,6 +712,59 @@ class ExcelService return compact('count', 'header', 'title', 'export', 'foot', 'filename'); } + /** + * 提现银行账单导出 + * @param array $where + * @param int $page + * @param int $limit + * @return array + */ + public function withdrawalBill(array $where, int $page, int $limit) + { + $title = [ + '转账记录', + '生成时间:' . date('Y-m-d H:i:s', time()) + ]; + $header = ['编号', '收款方账号', '收款方户名', '是否农业银行', '开户银行(行别)', '开户行大额行号', '开户行支行名称', '金额','用途(附言)']; + $filename = '转账记录_' . time(); + $export = []; + $where['type'] = 0; //申请类型默认为余额 + + $query = app()->make(FinancialRepository::class)->search($where)->with('merchant'); + + $count = $query->count(); + $list = $query->page($page, $limit)->select(); + foreach ($list as $item) { + $checkRes = ""; + if (!empty($item->financial_account) && isset($item->financial_account->bank)) { + $bankName = $item->financial_account->bank; + if (preg_match("/农业银行/i", $bankName)) { + $checkRes = "是"; + } else { + $checkRes = "否"; + } + }else{ + //测试数据有未存在的数据 + $bankName=''; + } + + $export[] = [ + $item->financial_sn, + $item->financial_account->bank_code??'', + $bankName, + $checkRes, + '',//'开户银行(行别) + '',//'开户行大额行号' + $item->financial_account->bank_branch??'', + $item->extract_money, + $item->mark + ]; + } + $foot = ''; + return compact('count', 'header', 'title', 'export', 'foot', 'filename'); + } + + /** * TODO 用户提现申请 * @param array $where diff --git a/route/admin/accounts.php b/route/admin/accounts.php index 15b82f4f..4f886934 100755 --- a/route/admin/accounts.php +++ b/route/admin/accounts.php @@ -279,6 +279,11 @@ Route::group(function () { Route::get('export', 'Financial/export')->name('systemFinancialExport')->option([ '_alias' => '导出', ]); + + Route::get('bill', 'Financial/billExport')->name('systemFinancialBillExport')->option([ + '_alias' => '账单导出', + ]); + })->prefix('admin.system.financial.')->option([ '_path' => '/accounts/transferRecord', '_auth' => true, From 03f99316bfdbed75dd706a51aef04c41be68f20b Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Fri, 8 Mar 2024 17:38:51 +0800 Subject: [PATCH 12/32] =?UTF-8?q?=E8=B0=83=E6=95=B4=E8=B4=A6=E5=8F=B7?= =?UTF-8?q?=E5=90=88=E5=B9=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/user/User.php | 149 ++++++++++++++++--------------- 1 file changed, 79 insertions(+), 70 deletions(-) diff --git a/app/controller/api/user/User.php b/app/controller/api/user/User.php index 9e6d8c28..4736d5d6 100755 --- a/app/controller/api/user/User.php +++ b/app/controller/api/user/User.php @@ -48,6 +48,7 @@ use app\common\model\user\User as UserModel; use app\common\model\user\UserAddress; use app\common\model\user\UserRecharge; use think\db\Query; +use think\facade\Cache; use think\facade\Db; class User extends BaseController @@ -617,87 +618,95 @@ class User extends BaseController */ public function merge(UserRepository $repository) { - $user = $this->request->userInfo(); - $data = $this->request->params(['phone', 'sms_code'] ); - if ($user['account'] == $data['phone']) { - return app('json')->fail('绑定的账号不能相同'); - } - if (!empty($user['account'])) { - return app('json')->fail('已绑定手机号'); - } + $data = $this->request->params(['phone', 'sms_code', 'spread', 'pwd', 'auth_token', ['user_type', 'h5']]); $sms_code = app()->make(SmsService::class)->checkSmsCode($data['phone'], $data['sms_code'], 'login'); if (!$sms_code && !env('APP_DEBUG')) { return app('json')->fail('验证码不正确'); } + $auth = Cache::get('u_try' . $data['auth_token']); +// $auth && Cache::delete('u_try' . $data['auth_token']); + $user = $repository->wechatUserIdBytUser($auth['id']); + if (!empty($user['account'])) { + return app('json')->fail('已绑定手机号'); + } $targetUser = $repository->accountByUser($data['phone']); - if (empty($targetUser)) { + if (!empty($user) && empty($targetUser)) { $user->account = $data['phone']; $user->phone = $data['phone']; $user->save(); $tokenInfo = $repository->createToken($user); return app('json')->success($repository->returnToken($user, $tokenInfo)); - } else { - Db::startTrans(); - try { - StoreGroupOrder::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); - StoreOrder::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); - StoreOrderProduct::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); - UserBill::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); - FinancialRecord::where('user_id', $user['uid'])->update(['user_id' => $targetUser['uid']]); - UserAddress::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); - StoreConsumptionUser::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); - StoreConsumptionDetail::where('user_id', $user['uid'])->update(['user_id' => $targetUser['uid']]); - StoreRefundOrder::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); - UserRecharge::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); - StoreOrderStatus::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); - if ($user->now_money > 0) { - $targetUser->now_money = bcadd($targetUser->now_money, $user->now_money, 2); - $targetUser->save(); - } - $merchant = Merchant::where('uid', $targetUser['uid'])->find(); - if (!empty($merchant)) { - $orders = StoreOrder::with(['refundOrder' => function(Query $query) { - $query->where('status', '<>', -1)->field('order_id,refund_price'); - }])->where('uid', $user['uid']) - ->whereIn('status', [0, 1, 2, 3, 9, 10]) - ->field('order_id,uid,total_price') - ->select()->toArray(); - $otherOrders = StoreOrderOther::with(['refundOrder' => function(Query $query) { - $query->where('status', '<>', -1)->field('order_id,refund_price'); - }])->where('uid', $user['uid']) - ->whereIn('status', [0, 1, 2, 3, 9, 10]) - ->field('order_id,uid,total_price') - ->select()->toArray(); - $purchaseAmount = 0; - foreach ($orders as $order) { - $purchaseAmount = bcadd($purchaseAmount, $order['total_price'], 2); - foreach ($order['refundOrder']as $refundOrder) { - $purchaseAmount = bcsub($purchaseAmount, $refundOrder['refund_price'], 2); - } - } - unset($refundOrder, $order); - foreach ($otherOrders as $otherOrder) { - $purchaseAmount = bcadd($purchaseAmount, $otherOrder['total_price'], 2); - foreach ($otherOrder['refundOrder']as $refundOrder) { - $purchaseAmount = bcsub($purchaseAmount, $refundOrder['refund_price'], 2); - } - } - unset($refundOrder, $otherOrder); - if ($purchaseAmount > 0) { - $merchant->purchase_amount = bcadd($merchant->purchase_amount, $purchaseAmount, 2); - $merchant->save(); - } - $user->account = $data['phone']; - $user->phone = $data['phone']; - $user->save(); - } - Db::commit(); - } catch (\Throwable $e) { - Db::rollback(); - } - $tokenInfo = $repository->createToken($targetUser); - return app('json')->success($repository->returnToken($targetUser, $tokenInfo)); } + if (empty($targetUser) && empty($user)) { + $targetUser = $repository->registr($data['phone'], $data['pwd'], $data['user_type']); + } + if ($auth) { + $repository->syncBaseAuth($auth, $targetUser); + } + $targetUser = $repository->mainUser($targetUser); + $repository->bindSpread($targetUser, intval($data['spread'])); + Db::startTrans(); + try { + StoreGroupOrder::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); + StoreOrder::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); + StoreOrderProduct::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); + UserBill::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); + FinancialRecord::where('user_id', $user['uid'])->update(['user_id' => $targetUser['uid']]); + UserAddress::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); + StoreConsumptionUser::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); + StoreConsumptionDetail::where('user_id', $user['uid'])->update(['user_id' => $targetUser['uid']]); + StoreRefundOrder::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); + UserRecharge::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); + StoreOrderStatus::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); + if ($user->now_money > 0) { + $user->now_money = 0; + $targetUser->now_money = bcadd($targetUser->now_money, $user->now_money, 2); + $targetUser->save(); + } + $merchant = Merchant::where('uid', $targetUser['uid'])->find(); + if (!empty($merchant)) { + $orders = StoreOrder::with(['refundOrder' => function(Query $query) { + $query->where('status', '<>', -1)->field('order_id,refund_price'); + }])->where('uid', $user['uid']) + ->whereIn('status', [0, 1, 2, 3, 9, 10]) + ->field('order_id,uid,total_price') + ->select()->toArray(); + $otherOrders = StoreOrderOther::with(['refundOrder' => function(Query $query) { + $query->where('status', '<>', -1)->field('order_id,refund_price'); + }])->where('uid', $user['uid']) + ->whereIn('status', [0, 1, 2, 3, 9, 10]) + ->field('order_id,uid,total_price') + ->select()->toArray(); + $purchaseAmount = 0; + foreach ($orders as $order) { + $purchaseAmount = bcadd($purchaseAmount, $order['total_price'], 2); + foreach ($order['refundOrder']as $refundOrder) { + $purchaseAmount = bcsub($purchaseAmount, $refundOrder['refund_price'], 2); + } + } + unset($refundOrder, $order); + foreach ($otherOrders as $otherOrder) { + $purchaseAmount = bcadd($purchaseAmount, $otherOrder['total_price'], 2); + foreach ($otherOrder['refundOrder']as $refundOrder) { + $purchaseAmount = bcsub($purchaseAmount, $refundOrder['refund_price'], 2); + } + } + unset($refundOrder, $otherOrder); + if ($purchaseAmount > 0) { + $merchant->purchase_amount = bcadd($merchant->purchase_amount, $purchaseAmount, 2); + $merchant->save(); + } + } + if (!empty($user)) { + $user->wechat_user_id = 0; + $user->save(); + } + Db::commit(); + } catch (\Throwable $e) { + Db::rollback(); + } + $tokenInfo = $repository->createToken($targetUser); + return app('json')->success($repository->returnToken($targetUser, $tokenInfo)); } } From 34187247aadbd3ae2db865ac4dc060afdf0292db Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Fri, 8 Mar 2024 17:59:25 +0800 Subject: [PATCH 13/32] =?UTF-8?q?=E8=B0=83=E6=95=B4=E8=B4=A6=E5=8F=B7?= =?UTF-8?q?=E5=90=88=E5=B9=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/user/User.php | 37 +++++++++++++++++--------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/app/controller/api/user/User.php b/app/controller/api/user/User.php index 4736d5d6..6a266a4a 100755 --- a/app/controller/api/user/User.php +++ b/app/controller/api/user/User.php @@ -48,6 +48,7 @@ use app\common\model\user\User as UserModel; use app\common\model\user\UserAddress; use app\common\model\user\UserRecharge; use think\db\Query; +use think\exception\ValidateException; use think\facade\Cache; use think\facade\Db; @@ -624,27 +625,28 @@ class User extends BaseController return app('json')->fail('验证码不正确'); } $auth = Cache::get('u_try' . $data['auth_token']); -// $auth && Cache::delete('u_try' . $data['auth_token']); + $auth && Cache::delete('u_try' . $data['auth_token']); + if (empty($auth)) { + return app('json')->fail('授权已过期,请重新登录'); + } $user = $repository->wechatUserIdBytUser($auth['id']); if (!empty($user['account'])) { return app('json')->fail('已绑定手机号'); } $targetUser = $repository->accountByUser($data['phone']); - if (!empty($user) && empty($targetUser)) { - $user->account = $data['phone']; - $user->phone = $data['phone']; - $user->save(); - $tokenInfo = $repository->createToken($user); - return app('json')->success($repository->returnToken($user, $tokenInfo)); + if (empty($targetUser) && !empty($user)) { + if (!empty($user)) { + $user->account = $data['phone']; + $user->phone = $data['phone']; + $user->save(); + $tokenInfo = $repository->createToken($user); + return app('json')->success($repository->returnToken($user, $tokenInfo)); + } else { + $targetUser = $repository->registr($data['phone'], $data['pwd'], $data['user_type']); + $repository->bindSpread($targetUser, intval($data['spread'])); + } } - if (empty($targetUser) && empty($user)) { - $targetUser = $repository->registr($data['phone'], $data['pwd'], $data['user_type']); - } - if ($auth) { - $repository->syncBaseAuth($auth, $targetUser); - } - $targetUser = $repository->mainUser($targetUser); - $repository->bindSpread($targetUser, intval($data['spread'])); + $repository->syncBaseAuth($auth, $targetUser); Db::startTrans(); try { StoreGroupOrder::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); @@ -702,11 +704,12 @@ class User extends BaseController $user->save(); } Db::commit(); + $tokenInfo = $repository->createToken($targetUser); + return app('json')->success($repository->returnToken($targetUser, $tokenInfo)); } catch (\Throwable $e) { Db::rollback(); + throw new ValidateException('绑定出错'); } - $tokenInfo = $repository->createToken($targetUser); - return app('json')->success($repository->returnToken($targetUser, $tokenInfo)); } } From 7048613cd1994d3dfc08db8879ed157f86b12e8a Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Sat, 9 Mar 2024 09:39:52 +0800 Subject: [PATCH 14/32] =?UTF-8?q?=E5=A4=84=E7=90=86=E6=8E=A8=E5=B9=BF?= =?UTF-8?q?=E4=BD=A3=E9=87=91=E5=8F=91=E6=94=BE=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/model/system/merchant/Merchant.php | 2 +- app/common/repositories/store/order/StoreOrderRepository.php | 2 ++ .../repositories/store/order/StoreOtherOrderRepository.php | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/common/model/system/merchant/Merchant.php b/app/common/model/system/merchant/Merchant.php index d11a256c..a1fa913e 100755 --- a/app/common/model/system/merchant/Merchant.php +++ b/app/common/model/system/merchant/Merchant.php @@ -319,7 +319,7 @@ class Merchant extends BaseModel public function promoter() { - return User::where('uid', $this->uid)->value('spread_uid'); + return User::where('uid', $this->uid)->field('spread_uid,nickname')->find(); } } diff --git a/app/common/repositories/store/order/StoreOrderRepository.php b/app/common/repositories/store/order/StoreOrderRepository.php index 3049228d..bd241375 100755 --- a/app/common/repositories/store/order/StoreOrderRepository.php +++ b/app/common/repositories/store/order/StoreOrderRepository.php @@ -360,10 +360,12 @@ class StoreOrderRepository extends BaseRepository $promoter = $order->merchant->promoter(); $promoterCommission = bcmul($orderValidAmount, 0.003, 2); if (!empty($promoter) && $promoterCommission > 0) { + $financeDao->user = $promoter; $financeDao->platformOut($promoterCommission, 'commission_to_promoter'); } // 平台收入手续费 + $financeDao->user = $groupOrder->user; $commission_rate = bcdiv((string)$order['commission_rate'],'100',6); $platformCommission = bcmul($orderValidAmount, (string)$commission_rate, 2); if ($commission_rate > 0 && $platformCommission > 0) { diff --git a/app/common/repositories/store/order/StoreOtherOrderRepository.php b/app/common/repositories/store/order/StoreOtherOrderRepository.php index c3f808ff..cfe75943 100755 --- a/app/common/repositories/store/order/StoreOtherOrderRepository.php +++ b/app/common/repositories/store/order/StoreOtherOrderRepository.php @@ -237,10 +237,12 @@ class StoreOtherOrderRepository extends BaseRepository $promoter = $order->merchant->promoter(); $promoterCommission = bcmul($orderValidAmount, 0.003, 2); if (!empty($promoter) && $promoterCommission > 0) { + $financeDao->user = $promoter; $financeDao->platformOut($promoterCommission, 'commission_to_promoter'); } // 平台收入手续费 + $financeDao->user = $groupOrder->user; $commission_rate = bcdiv((string)$order['commission_rate'],'100',6); $platformCommission = bcmul($orderValidAmount, (string)$commission_rate, 2); if ($commission_rate > 0 && $platformCommission > 0) { From 2790700d0b91a988534839ebbee06d96086cb708 Mon Sep 17 00:00:00 2001 From: liu <1873441552@qq.com> Date: Sat, 9 Mar 2024 09:47:53 +0800 Subject: [PATCH 15/32] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E5=B1=95=E7=A4=BA?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crmeb/services/ExcelService.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crmeb/services/ExcelService.php b/crmeb/services/ExcelService.php index 881af72f..8e4d3e82 100755 --- a/crmeb/services/ExcelService.php +++ b/crmeb/services/ExcelService.php @@ -751,9 +751,9 @@ class ExcelService $export[] = [ $item->financial_sn, $item->financial_account->bank_code??'', - $bankName, + $item->financial_account->name??'',//收款方户名 $checkRes, - '',//'开户银行(行别) + $bankName,//'开户银行(行别) '',//'开户行大额行号' $item->financial_account->bank_branch??'', $item->extract_money, From c54991b591fd6876f4c8c6fb98890c8ab90a88df Mon Sep 17 00:00:00 2001 From: liu <1873441552@qq.com> Date: Sat, 9 Mar 2024 09:59:30 +0800 Subject: [PATCH 16/32] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=B1=95=E7=A4=BA?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crmeb/services/ExcelService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crmeb/services/ExcelService.php b/crmeb/services/ExcelService.php index 8e4d3e82..5a153e7d 100755 --- a/crmeb/services/ExcelService.php +++ b/crmeb/services/ExcelService.php @@ -751,7 +751,7 @@ class ExcelService $export[] = [ $item->financial_sn, $item->financial_account->bank_code??'', - $item->financial_account->name??'',//收款方户名 + $item->financial_account->name??'',//收款方户名1 $checkRes, $bankName,//'开户银行(行别) '',//'开户行大额行号' From acd937ab81fb3d4a273a597f9529610fbe4e655a Mon Sep 17 00:00:00 2001 From: liu <1873441552@qq.com> Date: Sat, 9 Mar 2024 10:02:35 +0800 Subject: [PATCH 17/32] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E5=B1=95=E7=A4=BA?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store/order/StoreOrderRepository.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/common/repositories/store/order/StoreOrderRepository.php b/app/common/repositories/store/order/StoreOrderRepository.php index 3049228d..cdf74ff7 100755 --- a/app/common/repositories/store/order/StoreOrderRepository.php +++ b/app/common/repositories/store/order/StoreOrderRepository.php @@ -260,14 +260,14 @@ class StoreOrderRepository extends BaseRepository $groupOrder->append(['orderList.orderProduct']); $flag = true; $profitsharing = []; - $userMerchantRepository = app()->make(UserMerchantRepository::class); - $storeOrderProfitsharingRepository = app()->make(StoreOrderProfitsharingRepository::class); + $userMerchantRepository = app()->make(UserMerchantRepository::class);//商户用户表 + $storeOrderProfitsharingRepository = app()->make(StoreOrderProfitsharingRepository::class);//分账 $uid = $groupOrder->uid; // $isVipCoupon = app()->make(StoreGroupOrderRepository::class)->isVipCoupon($groupOrder); //订单记录 - $storeOrderStatusRepository = app()->make(StoreOrderStatusRepository::class); + $storeOrderStatusRepository = app()->make(StoreOrderStatusRepository::class);//订单操作 $svipDiscount = 0; - $financeDao = new FinancialDao(); + $financeDao = new FinancialDao(); //商户财务申请提现 foreach ($groupOrder->orderList as $_k => $order) { $isPickupCard = $order->source == 999; (new StoreActivityDao())->saveOrderProduct(2, $order); @@ -280,7 +280,7 @@ class StoreOrderRepository extends BaseRepository $presell = false; //todo 等待付尾款 if ($order->activity_type == 2) { - $_make = app()->make(ProductPresellSkuRepository::class); + $_make = app()->make(ProductPresellSkuRepository::class);//库存 if ($order->orderProduct[0]['cart_info']['productPresell']['presell_type'] == 2) { $order->status = 10; $presell = true; @@ -291,7 +291,7 @@ class StoreOrderRepository extends BaseRepository } else if ($order->activity_type == 4) { $order->status = 9; $order->save(); - $group_buying_id = app()->make(ProductGroupBuyingRepository::class)->create( + $group_buying_id = app()->make(ProductGroupBuyingRepository::class)->create( //平团 $groupOrder->user, $order->orderProduct[0]['cart_info']['activeSku']['product_group_id'], $order->orderProduct[0]['activity_id'], @@ -333,7 +333,7 @@ class StoreOrderRepository extends BaseRepository foreach ($order->orderProduct as $product) { if ($flag && $product['cart_info']['product']['is_gift_bag']) { - app()->make(UserRepository::class)->promoter($order->uid); + app()->make(UserRepository::class)->promoter($order->uid); //推广 $flag = false; } } @@ -376,7 +376,7 @@ class StoreOrderRepository extends BaseRepository if ($orderValidAmount > 0) { /** @var MerchantRepository $merchantRepo */ - $merchantRepo = app()->make(MerchantRepository::class); + $merchantRepo = app()->make(MerchantRepository::class);//商户 $merchantRepo->merId = $order['mer_id']; $merchantRepo->forceMargin = false; [$orderValidAmount, $financeDao] = $merchantRepo->deductDeposit($orderValidAmount, $order, $financeDao); From cef1d6580420c00dc8a69f63d189847c57c09da5 Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Sat, 9 Mar 2024 10:43:42 +0800 Subject: [PATCH 18/32] =?UTF-8?q?=E4=BF=AE=E6=94=B9APP=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E6=8E=88=E6=9D=83=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/model/system/merchant/Merchant.php | 2 +- app/controller/api/Auth.php | 125 +++++++++++++++++- app/controller/api/user/User.php | 120 ----------------- route/api.php | 4 +- 4 files changed, 127 insertions(+), 124 deletions(-) diff --git a/app/common/model/system/merchant/Merchant.php b/app/common/model/system/merchant/Merchant.php index a1fa913e..b6aae8fe 100755 --- a/app/common/model/system/merchant/Merchant.php +++ b/app/common/model/system/merchant/Merchant.php @@ -319,7 +319,7 @@ class Merchant extends BaseModel public function promoter() { - return User::where('uid', $this->uid)->field('spread_uid,nickname')->find(); + return User::where('uid', $this->uid)->field('spread_uid as uid,nickname')->find(); } } diff --git a/app/controller/api/Auth.php b/app/controller/api/Auth.php index a4070cba..992f3155 100755 --- a/app/controller/api/Auth.php +++ b/app/controller/api/Auth.php @@ -14,6 +14,18 @@ namespace app\controller\api; +use app\common\model\store\consumption\StoreConsumptionDetail; +use app\common\model\store\consumption\StoreConsumptionUser; +use app\common\model\store\order\StoreGroupOrder; +use app\common\model\store\order\StoreOrder; +use app\common\model\store\order\StoreOrderOther; +use app\common\model\store\order\StoreOrderProduct; +use app\common\model\store\order\StoreOrderStatus; +use app\common\model\store\order\StoreRefundOrder; +use app\common\model\system\merchant\FinancialRecord; +use app\common\model\user\UserAddress; +use app\common\model\user\UserBill; +use app\common\model\user\UserRecharge; use app\common\repositories\store\order\StoreOrderRepository; use app\common\repositories\store\order\StoreRefundOrderRepository; use app\common\repositories\system\notice\SystemNoticeConfigRepository; @@ -41,6 +53,7 @@ use Symfony\Component\HttpFoundation\Request; use think\db\exception\DataNotFoundException; use think\db\exception\DbException; use think\db\exception\ModelNotFoundException; +use think\db\Query; use think\exception\ValidateException; use think\facade\Cache; use think\facade\Db; @@ -910,7 +923,11 @@ class Auth extends BaseController public function authLogin() { $auth = $this->request->param('auth'); - $users = $this->authInfo($auth, systemConfig('is_phone_login') !== '1'); + $createUser = true; + if ($auth['type'] == 'app_wechat' || systemConfig('is_phone_login') == '1') { + $createUser = false; + } + $users = $this->authInfo($auth, $createUser); if (!$users) return app('json')->fail('授权失败'); $authInfo = $users[0]; @@ -1656,4 +1673,110 @@ class Auth extends BaseController $data = $repository->getResult($type); return app('json')->success($data); } + + /** + * 合并账号 + * @param UserRepository $repository + * @return mixed + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + */ + public function merge(UserRepository $repository) + { + $data = $this->request->params(['phone', 'sms_code', 'spread', 'pwd', 'auth_token', ['user_type', 'h5']]); + $sms_code = app()->make(SmsService::class)->checkSmsCode($data['phone'], $data['sms_code'], 'login'); + if (!$sms_code && !env('APP_DEBUG')) { + return app('json')->fail('验证码不正确'); + } + $auth = Cache::get('u_try' . $data['auth_token']); +// $auth && Cache::delete('u_try' . $data['auth_token']); + if (empty($auth)) { + return app('json')->fail('授权已过期,请重新登录'); + } + $user = $repository->wechatUserIdBytUser($auth['id']); + if (!empty($user['account'])) { + return app('json')->fail('已绑定手机号'); + } + $targetUser = $repository->accountByUser($data['phone']); + if (empty($targetUser)) { + if (!empty($user)) { + $user->account = $data['phone']; + $user->phone = $data['phone']; + $user->save(); + $tokenInfo = $repository->createToken($user); + return app('json')->success($repository->returnToken($user, $tokenInfo)); + } else { + $targetUser = $repository->registr($data['phone'], $data['pwd'], $data['user_type']); + $repository->bindSpread($targetUser, intval($data['spread'])); + } + } + $repository->syncBaseAuth($auth, $targetUser); + if (!empty($user)) { + Db::startTrans(); + try { + StoreGroupOrder::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); + StoreOrder::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); + StoreOrderProduct::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); + UserBill::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); + FinancialRecord::where('user_id', $user['uid'])->update(['user_id' => $targetUser['uid']]); + UserAddress::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); + StoreConsumptionUser::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); + StoreConsumptionDetail::where('user_id', $user['uid'])->update(['user_id' => $targetUser['uid']]); + StoreRefundOrder::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); + UserRecharge::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); + StoreOrderStatus::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); + if ($user->now_money > 0) { + $user->now_money = 0; + $targetUser->now_money = bcadd($targetUser->now_money, $user->now_money, 2); + $targetUser->save(); + } + $merchant = Merchant::where('uid', $targetUser['uid'])->find(); + if (!empty($merchant)) { + $orders = StoreOrder::with(['refundOrder' => function(Query $query) { + $query->where('status', '<>', -1)->field('order_id,refund_price'); + }])->where('uid', $user['uid']) + ->whereIn('status', [0, 1, 2, 3, 9, 10]) + ->field('order_id,uid,total_price') + ->select()->toArray(); + $otherOrders = StoreOrderOther::with(['refundOrder' => function(Query $query) { + $query->where('status', '<>', -1)->field('order_id,refund_price'); + }])->where('uid', $user['uid']) + ->whereIn('status', [0, 1, 2, 3, 9, 10]) + ->field('order_id,uid,total_price') + ->select()->toArray(); + $purchaseAmount = 0; + foreach ($orders as $order) { + $purchaseAmount = bcadd($purchaseAmount, $order['total_price'], 2); + foreach ($order['refundOrder']as $refundOrder) { + $purchaseAmount = bcsub($purchaseAmount, $refundOrder['refund_price'], 2); + } + } + unset($refundOrder, $order); + foreach ($otherOrders as $otherOrder) { + $purchaseAmount = bcadd($purchaseAmount, $otherOrder['total_price'], 2); + foreach ($otherOrder['refundOrder']as $refundOrder) { + $purchaseAmount = bcsub($purchaseAmount, $refundOrder['refund_price'], 2); + } + } + unset($refundOrder, $otherOrder); + if ($purchaseAmount > 0) { + $merchant->purchase_amount = bcadd($merchant->purchase_amount, $purchaseAmount, 2); + $merchant->save(); + } + } + if (!empty($user)) { + $user->wechat_user_id = 0; + $user->save(); + } + Db::commit(); + } catch (\Throwable $e) { + Db::rollback(); + throw new ValidateException('绑定出错'); + } + } + $tokenInfo = $repository->createToken($targetUser); + return app('json')->success($repository->returnToken($targetUser, $tokenInfo)); + } + } diff --git a/app/controller/api/user/User.php b/app/controller/api/user/User.php index 6a266a4a..8f6db4a2 100755 --- a/app/controller/api/user/User.php +++ b/app/controller/api/user/User.php @@ -10,21 +10,11 @@ // | Author: CRMEB Team // +---------------------------------------------------------------------- - namespace app\controller\api\user; - use app\common\dao\store\order\StoreOrderDao; -use app\common\model\store\consumption\StoreConsumptionDetail; -use app\common\model\store\consumption\StoreConsumptionUser; -use app\common\model\store\order\StoreGroupOrder; -use app\common\model\store\order\StoreOrder; use app\common\model\store\order\StoreOrderOther; -use app\common\model\store\order\StoreOrderProduct; -use app\common\model\store\order\StoreOrderStatus; -use app\common\model\store\order\StoreRefundOrder; use app\common\model\system\merchant\Merchant; -use app\common\model\user\UserBill; use app\common\repositories\store\IntegralRepository; use app\common\repositories\store\order\PresellOrderRepository; use app\common\repositories\store\service\StoreServiceRepository; @@ -34,7 +24,6 @@ use app\common\repositories\user\UserBillRepository; use app\common\repositories\user\UserBrokerageRepository; use app\common\repositories\user\UserRepository; use app\common\repositories\user\UserVisitRepository; -use app\common\model\system\merchant\FinancialRecord; use app\validate\api\UserBaseInfoValidate; use crmeb\basic\BaseController; use crmeb\services\MiniProgramService; @@ -45,12 +34,6 @@ use think\db\exception\DbException; use think\db\exception\ModelNotFoundException; use app\controller\api\Common; use app\common\model\user\User as UserModel; -use app\common\model\user\UserAddress; -use app\common\model\user\UserRecharge; -use think\db\Query; -use think\exception\ValidateException; -use think\facade\Cache; -use think\facade\Db; class User extends BaseController { @@ -609,107 +592,4 @@ class User extends BaseController return app('json')->success(['count' => count($userIds), 'list' => $result]); } - /** - * 合并账号 - * @param UserRepository $repository - * @return mixed - * @throws DataNotFoundException - * @throws DbException - * @throws ModelNotFoundException - */ - public function merge(UserRepository $repository) - { - $data = $this->request->params(['phone', 'sms_code', 'spread', 'pwd', 'auth_token', ['user_type', 'h5']]); - $sms_code = app()->make(SmsService::class)->checkSmsCode($data['phone'], $data['sms_code'], 'login'); - if (!$sms_code && !env('APP_DEBUG')) { - return app('json')->fail('验证码不正确'); - } - $auth = Cache::get('u_try' . $data['auth_token']); - $auth && Cache::delete('u_try' . $data['auth_token']); - if (empty($auth)) { - return app('json')->fail('授权已过期,请重新登录'); - } - $user = $repository->wechatUserIdBytUser($auth['id']); - if (!empty($user['account'])) { - return app('json')->fail('已绑定手机号'); - } - $targetUser = $repository->accountByUser($data['phone']); - if (empty($targetUser) && !empty($user)) { - if (!empty($user)) { - $user->account = $data['phone']; - $user->phone = $data['phone']; - $user->save(); - $tokenInfo = $repository->createToken($user); - return app('json')->success($repository->returnToken($user, $tokenInfo)); - } else { - $targetUser = $repository->registr($data['phone'], $data['pwd'], $data['user_type']); - $repository->bindSpread($targetUser, intval($data['spread'])); - } - } - $repository->syncBaseAuth($auth, $targetUser); - Db::startTrans(); - try { - StoreGroupOrder::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); - StoreOrder::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); - StoreOrderProduct::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); - UserBill::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); - FinancialRecord::where('user_id', $user['uid'])->update(['user_id' => $targetUser['uid']]); - UserAddress::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); - StoreConsumptionUser::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); - StoreConsumptionDetail::where('user_id', $user['uid'])->update(['user_id' => $targetUser['uid']]); - StoreRefundOrder::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); - UserRecharge::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); - StoreOrderStatus::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); - if ($user->now_money > 0) { - $user->now_money = 0; - $targetUser->now_money = bcadd($targetUser->now_money, $user->now_money, 2); - $targetUser->save(); - } - $merchant = Merchant::where('uid', $targetUser['uid'])->find(); - if (!empty($merchant)) { - $orders = StoreOrder::with(['refundOrder' => function(Query $query) { - $query->where('status', '<>', -1)->field('order_id,refund_price'); - }])->where('uid', $user['uid']) - ->whereIn('status', [0, 1, 2, 3, 9, 10]) - ->field('order_id,uid,total_price') - ->select()->toArray(); - $otherOrders = StoreOrderOther::with(['refundOrder' => function(Query $query) { - $query->where('status', '<>', -1)->field('order_id,refund_price'); - }])->where('uid', $user['uid']) - ->whereIn('status', [0, 1, 2, 3, 9, 10]) - ->field('order_id,uid,total_price') - ->select()->toArray(); - $purchaseAmount = 0; - foreach ($orders as $order) { - $purchaseAmount = bcadd($purchaseAmount, $order['total_price'], 2); - foreach ($order['refundOrder']as $refundOrder) { - $purchaseAmount = bcsub($purchaseAmount, $refundOrder['refund_price'], 2); - } - } - unset($refundOrder, $order); - foreach ($otherOrders as $otherOrder) { - $purchaseAmount = bcadd($purchaseAmount, $otherOrder['total_price'], 2); - foreach ($otherOrder['refundOrder']as $refundOrder) { - $purchaseAmount = bcsub($purchaseAmount, $refundOrder['refund_price'], 2); - } - } - unset($refundOrder, $otherOrder); - if ($purchaseAmount > 0) { - $merchant->purchase_amount = bcadd($merchant->purchase_amount, $purchaseAmount, 2); - $merchant->save(); - } - } - if (!empty($user)) { - $user->wechat_user_id = 0; - $user->save(); - } - Db::commit(); - $tokenInfo = $repository->createToken($targetUser); - return app('json')->success($repository->returnToken($targetUser, $tokenInfo)); - } catch (\Throwable $e) { - Db::rollback(); - throw new ValidateException('绑定出错'); - } - } - } diff --git a/route/api.php b/route/api.php index b6648122..e5ed425a 100755 --- a/route/api.php +++ b/route/api.php @@ -173,8 +173,6 @@ Route::group('api/', function () { //切换账号 Route::get('account', 'User/account'); Route::post('switch', 'User/switchUser'); - //合并账号 - Route::post('merge', 'User/merge'); //修改信息 Route::post('change/phone', 'User/changePhone'); Route::post('change/info', 'User/updateBaseInfo'); @@ -741,6 +739,8 @@ Route::group('api/', function () { Route::post('auth/apple', 'api.Auth/appleAuth'); //修改密码 Route::post('user/change_pwd', 'api.Auth/changePassword'); + //合并账号 + Route::post('user/merge', 'api.auth/merge'); //验证码 Route::post('auth/verify', 'api.Auth/verify'); Route::post('auth/verifyCode', 'api.Auth/verifyCode'); From 6679124abffa3e05b5bed034d5e32224598053d4 Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Sat, 9 Mar 2024 11:12:03 +0800 Subject: [PATCH 19/32] =?UTF-8?q?=E5=A4=84=E7=90=86=E6=8E=A8=E5=B9=BF?= =?UTF-8?q?=E4=BD=A3=E9=87=91=E5=8F=91=E6=94=BE=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repositories/store/order/StoreOrderRepository.php | 7 ++++--- app/controller/api/Auth.php | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/common/repositories/store/order/StoreOrderRepository.php b/app/common/repositories/store/order/StoreOrderRepository.php index 05324e42..df05f969 100755 --- a/app/common/repositories/store/order/StoreOrderRepository.php +++ b/app/common/repositories/store/order/StoreOrderRepository.php @@ -802,15 +802,16 @@ class StoreOrderRepository extends BaseRepository if (!empty($promoterCommission)) { $userBillRepository->incBill($promoterCommission['user_id'], 'brokerage', 'order_one', [ 'link_id' => $order['order_id'], - 'status' => 0, + 'status' => 1, 'title' => '获得推广佣金', 'number' => $promoterCommission['number'], 'mark' => $order->merchant['mer_name'] . '成功销售' . floatval($order['pay_price']) . '元,奖励推广佣金' . floatval($promoterCommission['number']), 'balance' => 0 ]); - $balance = bcadd($user->now_money, $promoterCommission['number'], 2); - $user->save(['now_money' => $balance]); + $promoter = User::where('uid', $promoterCommission['user_id'])->find(); + $balance = bcadd($promoter->now_money, $promoterCommission['number'], 2); + $promoter->save(['now_money' => $balance]); } } diff --git a/app/controller/api/Auth.php b/app/controller/api/Auth.php index 992f3155..2522acea 100755 --- a/app/controller/api/Auth.php +++ b/app/controller/api/Auth.php @@ -1690,7 +1690,7 @@ class Auth extends BaseController return app('json')->fail('验证码不正确'); } $auth = Cache::get('u_try' . $data['auth_token']); -// $auth && Cache::delete('u_try' . $data['auth_token']); + $auth && Cache::delete('u_try' . $data['auth_token']); if (empty($auth)) { return app('json')->fail('授权已过期,请重新登录'); } From ea7a01ecf499c45884e90381d11276abfbf269d0 Mon Sep 17 00:00:00 2001 From: liu <1873441552@qq.com> Date: Sat, 9 Mar 2024 11:50:23 +0800 Subject: [PATCH 20/32] =?UTF-8?q?=E5=87=8F=E5=B0=91=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E6=80=BB=E6=95=B0=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/dao/store/product/SpuDao.php | 11 ++++++++--- .../repositories/store/product/SpuRepository.php | 15 ++++++++++++++- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/app/common/dao/store/product/SpuDao.php b/app/common/dao/store/product/SpuDao.php index 1ce6bac7..e47d20b6 100755 --- a/app/common/dao/store/product/SpuDao.php +++ b/app/common/dao/store/product/SpuDao.php @@ -55,6 +55,11 @@ class SpuDao extends BaseDao if(isset($where['order']) && $where['order'] === 'none'){ $order = ''; } + + if(isset($where['order_remark']) && $where['order_remark'] === 'none'){ + $order = ''; + } + $query = Spu::getDB()->alias('S')->join('StoreProduct P','S.product_id = P.product_id', 'left'); $query->when(isset($where['is_del']) && $where['is_del'] !== '',function($query)use($where){ $query->where('P.is_del',$where['is_del']); @@ -90,9 +95,9 @@ class SpuDao extends BaseDao ->when(isset($where['is_trader']) && $where['is_trader'] !== '',function($query)use($where){ $merId = app()->make(MerchantRepository::class)->search([ 'is_trader' => $where['is_trader'], - 'status' => 1, - 'mer_state' => 1, - 'is_del' => 1, + 'status' => 1,//状态正常 + 'mer_state' => 1,//商户开启 + 'is_del' => 1,// ])->column('mer_id'); $query->whereIn('P.mer_id',$merId); diff --git a/app/common/repositories/store/product/SpuRepository.php b/app/common/repositories/store/product/SpuRepository.php index e9f8860c..5c9368e3 100755 --- a/app/common/repositories/store/product/SpuRepository.php +++ b/app/common/repositories/store/product/SpuRepository.php @@ -154,6 +154,19 @@ class SpuRepository extends BaseRepository if (!empty($this->orderField)) { $this->dao->orderField = $this->orderField; } + //取消数量排序 + $where['order_remark'] = "none"; + $queryCount = $this->dao->search($where); +// $queryCount->with([ +// 'merchant' => function ($queryCount) { +// $queryCount->field($this->merchantFiled)->with(['type_names', 'street_names']); +// }, +// 'issetCoupon', +// 'product.attrValue', +// ]); + unset($where['order_remark']); + $count = $queryCount->count(); + $query = $this->dao->search($where); $query->with([ @@ -164,7 +177,7 @@ class SpuRepository extends BaseRepository 'product.attrValue', ]); $productMake = app()->make(ProductRepository::class); - $count = $query->count(); +// $count = $query->count(); if ($limit == 0) { $list = $query->setOption('field', [])->field($this->productFiled)->select() ->each(function ($item) use ($is_sku, $productMake, $userInfo,$where) { From 1ef145cb81b368999cd36a0ac58b467d041679fe Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Sat, 9 Mar 2024 14:24:16 +0800 Subject: [PATCH 21/32] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/Auth.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/controller/api/Auth.php b/app/controller/api/Auth.php index 2522acea..ffc7301d 100755 --- a/app/controller/api/Auth.php +++ b/app/controller/api/Auth.php @@ -391,8 +391,9 @@ class Auth extends BaseController }else{ $data['mer_info'] =$mer_arr; } - $typCode = Db::name('merchant_type')->where('mer_type_id', $mer_arr['type_id'] ?? 0)->value('type_code'); - $data['mer_info']['type_code'] = $typCode; + $merType = Db::name('merchant_type')->where('mer_type_id', $mer_arr['type_id'] ?? 0)->field('type_code,type_name')->find(); + $data['mer_info']['type_code'] = $merType['type_code']; + $data['mer_info']['type_name'] = $merType['type_name']; $data['mer_info']['setting_status'] = 0; if (($mer_arr['update_time'] ?? '') > ($mer_arr['create_time'] ?? '')) { $data['mer_info']['setting_status'] = 1; From c4c62d64cb9e97c095682b8e133566f015c747fc Mon Sep 17 00:00:00 2001 From: liu <1873441552@qq.com> Date: Sat, 9 Mar 2024 16:05:20 +0800 Subject: [PATCH 22/32] =?UTF-8?q?=E8=B4=A6=E5=8D=95=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E6=97=A5=E8=B4=A6=E5=8D=95=E6=9F=A5=E8=AF=A2=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../merchant/FinancialRecordRepository.php | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/app/common/repositories/system/merchant/FinancialRecordRepository.php b/app/common/repositories/system/merchant/FinancialRecordRepository.php index 196e4130..c395677e 100755 --- a/app/common/repositories/system/merchant/FinancialRecordRepository.php +++ b/app/common/repositories/system/merchant/FinancialRecordRepository.php @@ -37,6 +37,13 @@ class FinancialRecordRepository extends BaseRepository ,'commission_to_cloud_warehouse','commission_to_cloud_warehouse_refund', 'commission_to_store', 'commission_to_courier', 'commission_to_promoter', 'commission_to_store_refund', 'commission_to_courier_refund', 'commission_to_promoter_refund', 'auto_margin', 'auto_margin_refund', 'supply_chain', 'supply_chain_refund', 'platform_consumption', 'platform_consumption_refund', 'merchant_order', 'merchant_order_refund' ]; + public $commonFinancialMixType = [ + 'order', 'order_presell', 'order_refund', 'brokerage_one', 'brokerage_two', 'refund_brokerage_one', 'refund_brokerage_two', 'refund_order','order_platform_coupon', + 'order_svip_coupon','commission_to_service_team','commission_to_service_team_refund','commission_to_platform','commission_to_platform_refund','commission_to_village','commission_to_village_refund','commission_to_town','commission_to_town_refund' + ,'commission_to_entry_merchant','commission_to_entry_merchant_refund' + ,'commission_to_cloud_warehouse','commission_to_cloud_warehouse_refund', 'commission_to_courier', 'commission_to_store_refund', 'commission_to_courier_refund', 'commission_to_promoter_refund', 'auto_margin','supply_chain', 'supply_chain_refund', 'platform_consumption', 'platform_consumption_refund', 'merchant_order', 'merchant_order_refund' + ]; + const TYPE_CN_MAP = [ 'order' => '订单支付', 'order_presell' => '预售订单(定金)', @@ -414,7 +421,8 @@ class FinancialRecordRepository extends BaseRepository //日 if ($where['type'] == 1) { $field = Db::raw('from_unixtime(unix_timestamp(create_time),\'%Y-%m-%d\') as time'); - } else { + } + else { //月 if (!empty($where['date'])) { list($startTime, $endTime) = explode('-', $where['date']); @@ -425,12 +433,13 @@ class FinancialRecordRepository extends BaseRepository } $field = Db::raw('from_unixtime(unix_timestamp(create_time),\'%Y-%m\') as time'); } - $make = app()->make(UserBillRepository::class); +// $make = app()->make(UserBillRepository::class); $query = $this->dao->search($where)->field($field)->group("time")->order('create_time DESC'); $count = $query->count(); $list = $query->page($page, $limit)->select()->each(function ($item) use ($where, $merchant) { $key = $where['is_mer'] ? $where['is_mer'] . '_financial_record_list_' . $item['time'] : 'sys_financial_record_list_' . $item['time']; + if (($where['type'] == 1 && ($item['time'] == date('Y-m-d', time()))) || ($where['type'] == 2 && ($item['time'] == date('Y-m', time())))) { $income = ($this->countIncome($where['type'], $where, $item['time'],$merchant))['number']; $expend = ($this->countExpend($where['type'], $where, $item['time'],$merchant))['number']; @@ -440,7 +449,7 @@ class FinancialRecordRepository extends BaseRepository 'charge' => bcsub($income, $expend, 2), ]; } else { - if (!$ret = Cache::get($key)) { + if (empty(Cache::get($key))) { $income = ($this->countIncome($where['type'], $where, $item['time'],$merchant))['number']; $expend = ($this->countExpend($where['type'], $where, $item['time'],$merchant))['number']; $ret = [ @@ -449,6 +458,8 @@ class FinancialRecordRepository extends BaseRepository 'charge' => bcsub($income, $expend, 2), ]; Cache::tag('system')->set($key, $ret, 24 * 3600); + } else{ + $ret = Cache::get($key); } } $item['income'] = $ret['income']; @@ -613,7 +624,7 @@ class FinancialRecordRepository extends BaseRepository 'commission_to_courier_refund', 'supply_chain_refund', 'auto_margin', 'platform_consumption_refund']; } if ($merchant){ - switch ($merchant['type_id']) { + switch ($merchant['type_id']) {//21? case 16: $financialType1 = ['commission_to_town']; break; @@ -633,7 +644,9 @@ class FinancialRecordRepository extends BaseRepository $financialType1 = []; } - $financialType = array_merge($financialType, $financialType1); + + + $financialType = array_merge($financialType, $financialType1,$this->commonFinancialMixType); } [$data['count_order'], $data['number_order']] = $this->dao->getDataByType($type, $where, $date, $financialType); if (!empty($financialType1)){ From e687dd5709761833fcb2487525d0386aa6dfe742 Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Sat, 9 Mar 2024 16:20:45 +0800 Subject: [PATCH 23/32] =?UTF-8?q?=E5=A4=84=E7=90=86=E9=82=80=E8=AF=B7?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/user/User.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controller/api/user/User.php b/app/controller/api/user/User.php index 8f6db4a2..7bc26e61 100755 --- a/app/controller/api/user/User.php +++ b/app/controller/api/user/User.php @@ -563,7 +563,7 @@ class User extends BaseController public function merchantRecord() { [$page, $limit] = $this->getPage(); - $userIds = UserModel::where('spread_uid', $this->user->uid)->column('uid'); + $userIds = UserModel::where('spread_uid', $this->user->uid)->page($page, $limit)->column('uid'); $query = Merchant::whereIn('uid', $userIds)->where('is_del', 0); $merchants = $query->page($page, $limit) ->field('mer_id,mer_name,uid,real_name') From 14168f2fd8edcee04eafeb9c1f87acaa7ad1717d Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Sat, 9 Mar 2024 16:26:49 +0800 Subject: [PATCH 24/32] =?UTF-8?q?=E8=B0=83=E8=AF=95=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E6=8E=88=E6=9D=83=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/Auth.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controller/api/Auth.php b/app/controller/api/Auth.php index ffc7301d..dba5fdad 100755 --- a/app/controller/api/Auth.php +++ b/app/controller/api/Auth.php @@ -940,7 +940,7 @@ class Auth extends BaseController if ($code && ($info = app()->make(RoutineQrcodeRepository::class)->getRoutineQrcodeFindType($code))) { $auth['auth']['spread'] = $info['third_id']; } - if (!$user) { + if (!$user || empty($user['account']) { $uni = uniqid(true, false) . random_int(1, 100000000); $key = 'U' . md5(time() . $uni); Cache::set('u_try' . $key, ['id' => $authInfo['wechat_user_id'], 'type' => $authInfo['user_type'], 'spread' => $auth['auth']['spread'] ?? 0], 3600); From dfa7e6e2c98cc67a98d42698e7ff90efd3060c69 Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Sat, 9 Mar 2024 16:27:36 +0800 Subject: [PATCH 25/32] =?UTF-8?q?=E8=B0=83=E8=AF=95=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E6=8E=88=E6=9D=83=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/Auth.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controller/api/Auth.php b/app/controller/api/Auth.php index dba5fdad..a8a74493 100755 --- a/app/controller/api/Auth.php +++ b/app/controller/api/Auth.php @@ -940,7 +940,7 @@ class Auth extends BaseController if ($code && ($info = app()->make(RoutineQrcodeRepository::class)->getRoutineQrcodeFindType($code))) { $auth['auth']['spread'] = $info['third_id']; } - if (!$user || empty($user['account']) { + if (!$user || empty($user['account'])) { $uni = uniqid(true, false) . random_int(1, 100000000); $key = 'U' . md5(time() . $uni); Cache::set('u_try' . $key, ['id' => $authInfo['wechat_user_id'], 'type' => $authInfo['user_type'], 'spread' => $auth['auth']['spread'] ?? 0], 3600); From 60221e78e4c156fdff1d082a01eb3866de5a6ccf Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Sat, 9 Mar 2024 16:33:35 +0800 Subject: [PATCH 26/32] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=82=80=E8=AF=B7?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=20=E9=87=87=E8=B4=AD=E9=87=91=E9=A2=9D?= =?UTF-8?q?=E5=92=8C=E9=94=80=E5=94=AE=E9=87=91=E9=A2=9D=E7=9A=84=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/user/User.php | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/app/controller/api/user/User.php b/app/controller/api/user/User.php index 7bc26e61..83ecab35 100755 --- a/app/controller/api/user/User.php +++ b/app/controller/api/user/User.php @@ -566,23 +566,13 @@ class User extends BaseController $userIds = UserModel::where('spread_uid', $this->user->uid)->page($page, $limit)->column('uid'); $query = Merchant::whereIn('uid', $userIds)->where('is_del', 0); $merchants = $query->page($page, $limit) - ->field('mer_id,mer_name,uid,real_name') + ->field('mer_id,mer_name,uid,real_name,sale_amount,purchase_amount as buy_amount') ->select()->toArray(); - $dao = new StoreOrderDao(); - /** @var PresellOrderRepository $preSellDao */ - $preSellRepo = app()->make(PresellOrderRepository::class); $merchants = reset_index($merchants, 'uid'); $result = []; foreach ($userIds as $userId) { if (isset($merchants[$userId])) { $merchant = $merchants[$userId]; - $saleOrderQuery = $dao->search(['mer_id' => $merchant['mer_id']])->whereIn('StoreOrder.status', [0, 1, 2, 3, 9, 10])->where('paid', 1); - $saleOrderIds = $saleOrderQuery->column('order_id'); - $saleAmount1 = $saleOrderQuery->sum('StoreOrder.pay_price'); - $saleAmount2 = $preSellRepo->search(['paid' => 1, 'order_ids' => $saleOrderIds])->sum('pay_price'); - $merchant['sale_amount'] = bcadd($saleAmount1, $saleAmount2, 2); - $merchant['buy_amount'] = StoreOrderOther::where('uid', $merchant['uid'])->whereIn('status', [0, 1, 2, 3, 9, 10])->where('paid', 1)->sum('pay_price'); - $merchant['buy_amount'] = bcadd($merchant['buy_amount'], 0, 2); $merchant['status'] = 1; $result[] = $merchant; } else { From 4fe3f45e7a571646915819003fc99bc06a24b3dd Mon Sep 17 00:00:00 2001 From: liu <1873441552@qq.com> Date: Sat, 9 Mar 2024 16:34:12 +0800 Subject: [PATCH 27/32] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=B4=A6=E5=8D=95?= =?UTF-8?q?=E5=95=86=E5=AE=B6=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repositories/store/order/StoreOtherOrderRepository.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/common/repositories/store/order/StoreOtherOrderRepository.php b/app/common/repositories/store/order/StoreOtherOrderRepository.php index cfe75943..0cbb3a1b 100755 --- a/app/common/repositories/store/order/StoreOtherOrderRepository.php +++ b/app/common/repositories/store/order/StoreOtherOrderRepository.php @@ -1084,6 +1084,9 @@ class StoreOtherOrderRepository extends BaseRepository 'spread' => function ($query) { $query->field('uid,nickname,avatar'); }, + 'merchant' => function ($query) { + $query->field('mer_id,mer_name'); + }, ] ); if (!$res) throw new ValidateException('数据不存在'); From 879e56c3a5485dea443ed97b0de4b8b51538b2a9 Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Sat, 9 Mar 2024 16:39:38 +0800 Subject: [PATCH 28/32] =?UTF-8?q?=E8=B0=83=E8=AF=95=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E6=8E=88=E6=9D=83=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/Auth.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controller/api/Auth.php b/app/controller/api/Auth.php index a8a74493..e1c0407f 100755 --- a/app/controller/api/Auth.php +++ b/app/controller/api/Auth.php @@ -940,7 +940,7 @@ class Auth extends BaseController if ($code && ($info = app()->make(RoutineQrcodeRepository::class)->getRoutineQrcodeFindType($code))) { $auth['auth']['spread'] = $info['third_id']; } - if (!$user || empty($user['account'])) { + if (!$user || empty($user['account']) || empty($user['phone'])) { $uni = uniqid(true, false) . random_int(1, 100000000); $key = 'U' . md5(time() . $uni); Cache::set('u_try' . $key, ['id' => $authInfo['wechat_user_id'], 'type' => $authInfo['user_type'], 'spread' => $auth['auth']['spread'] ?? 0], 3600); From fc78d3af34c53f5d9b02764bedde924d34532e31 Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Sat, 9 Mar 2024 16:47:06 +0800 Subject: [PATCH 29/32] =?UTF-8?q?=E8=B0=83=E8=AF=95=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E6=8E=88=E6=9D=83=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/Auth.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controller/api/Auth.php b/app/controller/api/Auth.php index e1c0407f..a6494276 100755 --- a/app/controller/api/Auth.php +++ b/app/controller/api/Auth.php @@ -1696,7 +1696,7 @@ class Auth extends BaseController return app('json')->fail('授权已过期,请重新登录'); } $user = $repository->wechatUserIdBytUser($auth['id']); - if (!empty($user['account'])) { + if (!empty($user['account']) && !empty($user['phone'])) { return app('json')->fail('已绑定手机号'); } $targetUser = $repository->accountByUser($data['phone']); From ca00b1ab27a1eaec170687bc4cf3472e8f1e6bd1 Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Sat, 9 Mar 2024 16:50:09 +0800 Subject: [PATCH 30/32] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=95=86=E6=88=B7?= =?UTF-8?q?=E6=8A=BC=E9=87=91=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/server/StoreOrder.php | 6 +++--- app/controller/api/store/merchant/Merchant.php | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/controller/api/server/StoreOrder.php b/app/controller/api/server/StoreOrder.php index 571d5182..7feaef9f 100755 --- a/app/controller/api/server/StoreOrder.php +++ b/app/controller/api/server/StoreOrder.php @@ -405,14 +405,14 @@ class StoreOrder extends BaseController return app('json')->success($list); } - + /** * 获取商户押金列表 */ public function getOrderAutoMarginList($merId){ [$page, $limit] = $this->getPage(); - $select= Db::name('financial_record')->where('mer_id',$merId)->where('type',1) - ->where('financial_type','auto_margin')->where('financial_pm',0) + $select= Db::name('financial_record')->where('mer_id',$merId) + ->where('financial_type','auto_margin') ->page($page)->limit($limit)->order('financial_record_id','desc')->select(); return app('json')->success($select); diff --git a/app/controller/api/store/merchant/Merchant.php b/app/controller/api/store/merchant/Merchant.php index a0b046a4..fe71060d 100755 --- a/app/controller/api/store/merchant/Merchant.php +++ b/app/controller/api/store/merchant/Merchant.php @@ -301,10 +301,10 @@ class Merchant extends BaseController if (empty($merchantInfo)) { return app('json')->fail('参数错误'); } - $margin = Db::name('MerchantType')->where('mer_type_id', $merchantInfo['type_id'])->value('margin'); - $merchantInfo['unpaid_margin'] = bcsub($margin, $merchantInfo['paid_margin'], 2); - if ($merchantInfo['margin'] == 0) { - $merchantInfo['margin'] = $merchantInfo['unpaid_margin']; + $merchantInfo['unpaid_margin'] = bcsub($merchantInfo['margin'], $merchantInfo['paid_margin'], 2); + if ($merchantInfo['margin'] <= 0) { + $merchantInfo['unpaid_margin'] = 0; + $merchantInfo['paid_margin'] = 0; } return app('json')->success($merchantInfo); } From dd5bfd7f1154ddf20829b8a98449296c61e5b2e9 Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Sat, 9 Mar 2024 17:51:51 +0800 Subject: [PATCH 31/32] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=95=86=E6=88=B7?= =?UTF-8?q?=E5=86=BB=E7=BB=93=E9=87=91=E9=A2=9D=E8=A7=A3=E5=86=BB=E6=97=B6?= =?UTF-8?q?=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crmeb/listens/AutoUnlockMerchantMoneyListen.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crmeb/listens/AutoUnlockMerchantMoneyListen.php b/crmeb/listens/AutoUnlockMerchantMoneyListen.php index a58f2248..68ce5969 100755 --- a/crmeb/listens/AutoUnlockMerchantMoneyListen.php +++ b/crmeb/listens/AutoUnlockMerchantMoneyListen.php @@ -25,7 +25,7 @@ class AutoUnlockMerchantMoneyListen extends TimerService implements ListenerInte public function handle($event): void { $this->tick(1000 * 60 * 60, function () { - if (time() >= strtotime('today 18:00:00') && time() >= strtotime('today 20:00:00')) { + if (time() >= strtotime('today 18:00:00') && time() <= strtotime('today 20:00:00')) { request()->clearCache(); /** @var UserBillRepository $userBill */ $userBill = app()->make(UserBillRepository::class); From 657849f2cf76f56d802a649149f152765476557c Mon Sep 17 00:00:00 2001 From: liu <1873441552@qq.com> Date: Sat, 9 Mar 2024 17:52:56 +0800 Subject: [PATCH 32/32] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/repositories/store/product/ProductRepository.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index 7d157bdc..16c77d7d 100755 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -417,6 +417,8 @@ class ProductRepository extends BaseRepository $data['cost'] = $settleParams['data']['cost']; $data['stock'] = $settleParams['data']['stock']; $data['svip_price'] = $settleParams['data']['svip_price']; + + $data['update_time'] = date('Y-m-d H:i:s',time()); } $res = $this->dao->update($id, $data);