From 804ed52d81aa5ac80ca85b976c6f08071a192bce Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Mon, 15 Jul 2024 20:41:52 +0800 Subject: [PATCH 01/69] 1 --- app/api/controller/Article.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/api/controller/Article.php b/app/api/controller/Article.php index 0c8fc9ab..359a7d8b 100644 --- a/app/api/controller/Article.php +++ b/app/api/controller/Article.php @@ -38,6 +38,8 @@ class Article extends Controller $model = new ArticleModel; $title = (string)$this->request->param('title'); $list = $model->getList($categoryId, 15, $title); + + return $this->renderSuccess(compact('list')); } From 54bd83ecfc9bac51fa1d442d39d7a69ee216d024 Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Mon, 15 Jul 2024 20:42:11 +0800 Subject: [PATCH 02/69] 1 --- app/api/controller/Article.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/api/controller/Article.php b/app/api/controller/Article.php index 359a7d8b..0c8fc9ab 100644 --- a/app/api/controller/Article.php +++ b/app/api/controller/Article.php @@ -38,8 +38,6 @@ class Article extends Controller $model = new ArticleModel; $title = (string)$this->request->param('title'); $list = $model->getList($categoryId, 15, $title); - - return $this->renderSuccess(compact('list')); } From 0e60d91ba8cc2c7baae81481a4eda62f03b29a3c Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Mon, 15 Jul 2024 20:50:58 +0800 Subject: [PATCH 03/69] 1 --- app/common/enum/user/UserTypeEnum.php | 61 ++++++++++++++------------- 1 file changed, 31 insertions(+), 30 deletions(-) diff --git a/app/common/enum/user/UserTypeEnum.php b/app/common/enum/user/UserTypeEnum.php index 116fe575..0443cb5b 100644 --- a/app/common/enum/user/UserTypeEnum.php +++ b/app/common/enum/user/UserTypeEnum.php @@ -30,17 +30,17 @@ class UserTypeEnum extends EnumBasics 'value' => self::NORMAL, ], self::MEMBER => [ - 'name' => '会员', + 'name' => '采购商', 'value' => self::MEMBER, ], self::DEALER => [ - 'name' => '分销商', + 'name' => '服务商', 'value' => self::DEALER, ], - self::STORE => [ - 'name' => '店长', - 'value' => self::STORE, - ] +// self::STORE => [ +// 'name' => '店长', +// 'value' => self::STORE, +// ] ]; } @@ -55,32 +55,33 @@ class UserTypeEnum extends EnumBasics } - - public static function homeLocation(string $mobile){ + public static function homeLocation(string $mobile): string + { $datatype = 'txt'; - $url = 'https://api.ip138.com/mobile/?mobile='.$mobile.'&datatype='.$datatype; + $url = 'https://api.ip138.com/mobile/?mobile=' . $mobile . '&datatype=' . $datatype; $header = array('token:00d5cb1fac5dc5cbfe2ff218292a2dfd33'); - return self::getName($url,$header ); + return self::getName($url, $header); } - public function getData($url,$header){ - - $curl = curl_init(); - - curl_setopt($curl,CURLOPT_URL,$url); - - curl_setopt($curl,CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_1); - - curl_setopt($curl,CURLOPT_HTTPHEADER,$header); - - curl_setopt($curl,CURLOPT_RETURNTRANSFER,1); - - curl_setopt($curl,CURLOPT_CONNECTTIMEOUT,3); - - $handles = curl_exec($curl); - - curl_close($curl); - - return $handles; - } + public function getData($url, $header) + { + + $curl = curl_init(); + + curl_setopt($curl, CURLOPT_URL, $url); + + curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); + + curl_setopt($curl, CURLOPT_HTTPHEADER, $header); + + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); + + curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 3); + + $handles = curl_exec($curl); + + curl_close($curl); + + return $handles; + } } \ No newline at end of file From 2d7ca2b1542ccf698fcb28c9b8e13ba3fc89aa9f Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Tue, 16 Jul 2024 19:17:20 +0800 Subject: [PATCH 04/69] 1 --- app/store/model/dealer/Apply.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/store/model/dealer/Apply.php b/app/store/model/dealer/Apply.php index 159c934a..9366d699 100644 --- a/app/store/model/dealer/Apply.php +++ b/app/store/model/dealer/Apply.php @@ -97,9 +97,10 @@ class Apply extends ApplyModel $info = UserModel::detail(['user_id' => $this['user_id']]); if (!empty($info)) { $info = $info->toArray(); - if ($info['effective_time'] && strtotime($info['effective_time']) > time() && $info['user_type'] == UserTypeEnum::MEMBER) { + if ($info['user_type'] == UserTypeEnum::NORMAL) { $up['user_type'] = UserTypeEnum::DEALER; - $up['fx_effective_time'] = $info['effective_time']; + $current_date = date('Y-m-d'); // 获取当前日期 + $up['fx_effective_time'] = date('Y-m-d', strtotime('+1 year', strtotime($current_date))); $userModel->where(['user_id' => $info['user_id']])->save($up); } } From 27427d388360416f5ca4b3156482fa64a50dc107 Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Tue, 16 Jul 2024 19:20:27 +0800 Subject: [PATCH 05/69] 1 --- app/store/model/dealer/Apply.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/store/model/dealer/Apply.php b/app/store/model/dealer/Apply.php index 9366d699..0d7950f0 100644 --- a/app/store/model/dealer/Apply.php +++ b/app/store/model/dealer/Apply.php @@ -99,6 +99,9 @@ class Apply extends ApplyModel $info = $info->toArray(); if ($info['user_type'] == UserTypeEnum::NORMAL) { $up['user_type'] = UserTypeEnum::DEALER; + if ($info['effective_time']) { + $up['effective_time'] = null; + } $current_date = date('Y-m-d'); // 获取当前日期 $up['fx_effective_time'] = date('Y-m-d', strtotime('+1 year', strtotime($current_date))); $userModel->where(['user_id' => $info['user_id']])->save($up); From 1313d44a304841ac99ef4aba217a7262cf541120 Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Tue, 16 Jul 2024 20:08:48 +0800 Subject: [PATCH 06/69] 1 --- app/api/model/dealer/Order.php | 36 ++++++++++++++++++++++++++--- app/common/model/dealer/Referee.php | 14 +++++++++++ app/common/model/dealer/User.php | 14 +++++++++++ 3 files changed, 61 insertions(+), 3 deletions(-) diff --git a/app/api/model/dealer/Order.php b/app/api/model/dealer/Order.php index 2f0d1a92..625b722a 100644 --- a/app/api/model/dealer/Order.php +++ b/app/api/model/dealer/Order.php @@ -23,6 +23,7 @@ use app\common\model\dealer\Order as DealerOrderModel; use app\common\model\Order as OrderModel; use app\common\model\UserAddress as UserAddessModel; use cores\exception\BaseException; +use think\facade\Db; /** @@ -115,6 +116,8 @@ class Order extends DealerOrderModel $model = new static; // 分销商基本设置 $setting = Setting::getItem('basic'); + Db::table('yoshop_wx_server')->insertGetId(['content' => "分销商设置", 'created_at' => date('Y-m-d H:i:s')]); + Db::table('yoshop_wx_server')->insertGetId(['content' => json_encode($setting), 'created_at' => date('Y-m-d H:i:s')]); // 是否开启分销功能 if (!$setting['is_open']) { return false; @@ -125,6 +128,7 @@ class Order extends DealerOrderModel if (!$dealerUser['first_user_id']) { return false; } + Db::table('yoshop_wx_server')->insertGetId(['content' => "买家上级服务商ID" . $dealerUser['first_user_id'], 'created_at' => date('Y-m-d H:i:s')]); //如果上级已经不是分销商 if (!User::isDealerUser($dealerUser['first_user_id'])) { return false; @@ -153,6 +157,32 @@ class Order extends DealerOrderModel ]); } + /** + * 获取当前买家的所有上级分销商用户ID + * @param int $userId 用户ID + * @param int $level 推荐等级 + * @param bool $selfBuy 分销商自购 + * @return array + */ +// private function getDealerUserId(int $userId, int $level, bool $selfBuy): array +// { +// $dealerUser = [ +// 'first_user_id' => $level >= 1 ? Referee::getRefereeUserId($userId, 1, true) : 0, +// 'second_user_id' => $level >= 2 ? Referee::getRefereeUserId($userId, 2, true) : 0, +// 'third_user_id' => $level == 3 ? Referee::getRefereeUserId($userId, 3, true) : 0 +// ]; +// // 分销商自购 +// if ($selfBuy && User::isDealerUser($userId)) { +// return [ +// 'first_user_id' => $userId, +// 'second_user_id' => $dealerUser['first_user_id'], +// 'third_user_id' => $dealerUser['second_user_id'], +// ]; +// } +// return $dealerUser; +// } +// + /** * 获取当前买家的所有上级分销商用户ID * @param int $userId 用户ID @@ -163,9 +193,9 @@ class Order extends DealerOrderModel private function getDealerUserId(int $userId, int $level, bool $selfBuy): array { $dealerUser = [ - 'first_user_id' => $level >= 1 ? Referee::getRefereeUserId($userId, 1, true) : 0, - 'second_user_id' => $level >= 2 ? Referee::getRefereeUserId($userId, 2, true) : 0, - 'third_user_id' => $level == 3 ? Referee::getRefereeUserId($userId, 3, true) : 0 + 'first_user_id' => $level >= 1 ? Referee::getRefereeBuyUser($userId, 1, true) : 0, + 'second_user_id' => $level >= 2 ? Referee::getRefereeBuyUser($userId, 2, true) : 0, + 'third_user_id' => $level == 3 ? Referee::getRefereeBuyUser($userId, 3, true) : 0 ]; // 分销商自购 if ($selfBuy && User::isDealerUser($userId)) { diff --git a/app/common/model/dealer/Referee.php b/app/common/model/dealer/Referee.php index 476d71e1..4bf6ca7a 100644 --- a/app/common/model/dealer/Referee.php +++ b/app/common/model/dealer/Referee.php @@ -63,6 +63,20 @@ class Referee extends BaseModel return $isDealer ? (User::isDealerUser($dealerId) ? $dealerId : 0) : $dealerId; } + /** + * 获取上级用户id + * @param int $userId + * @param int $level + * @param bool $isBuyer 必须是采购商 + * @return bool|mixed + */ + public static function getRefereeBuyUser(int $userId, int $level, bool $isBuyer = false) + { + $dealerId = (new self)->where(['user_id' => $userId, 'level' => $level])->value('dealer_id'); + if (!$dealerId) return 0; + return $isBuyer ? (User::isBuyer($userId) ? $dealerId : 0) : $dealerId; + } + /** * 获取我的团队列表 * @param int $dealerId 分销商ID diff --git a/app/common/model/dealer/User.php b/app/common/model/dealer/User.php index 250f065c..ff047fb1 100644 --- a/app/common/model/dealer/User.php +++ b/app/common/model/dealer/User.php @@ -13,6 +13,7 @@ declare (strict_types=1); namespace app\common\model\dealer; use app\common\enum\dealer\DealerUserEnum; +use app\common\enum\user\UserTypeEnum; use app\common\library\helper; use cores\BaseModel; use think\Collection; @@ -106,6 +107,19 @@ class User extends BaseModel return self::get($userId, $with); } + /** + * @notes:是否为采购商 + * @param int $userId + * @return mixed + * @author: wanghousheng + */ + public static function isBuyer(int $userId) + { + return (new \app\common\model\User())->where('user_id', '=', $userId) + ->where('user_type', '=', UserTypeEnum::MEMBER) + ->value('user_id'); + } + /** * 是否为分销商 * @param int $userId From 73098adac0faecca66ec39e6fac5d112c66d5389 Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Tue, 16 Jul 2024 21:41:44 +0800 Subject: [PATCH 07/69] 1 --- app/timer/controller/dealer/Order.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/timer/controller/dealer/Order.php b/app/timer/controller/dealer/Order.php index ef11d261..2f1bc7ef 100644 --- a/app/timer/controller/dealer/Order.php +++ b/app/timer/controller/dealer/Order.php @@ -26,7 +26,7 @@ class Order extends Controller private string $taskKey = 'DealerOrder'; // 任务执行间隔时长 (单位:秒) - protected int $taskExpire = 60 * 30; + protected int $taskExpire = 10; // 当前商城ID private int $storeId; From 5e4ca027569b414d1239cbacecbc77ab52974fa9 Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Tue, 16 Jul 2024 21:45:33 +0800 Subject: [PATCH 08/69] 1 --- app/timer/controller/dealer/Order.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/timer/controller/dealer/Order.php b/app/timer/controller/dealer/Order.php index 2f1bc7ef..bcd9bfba 100644 --- a/app/timer/controller/dealer/Order.php +++ b/app/timer/controller/dealer/Order.php @@ -26,7 +26,7 @@ class Order extends Controller private string $taskKey = 'DealerOrder'; // 任务执行间隔时长 (单位:秒) - protected int $taskExpire = 10; + protected int $taskExpire = 5; // 当前商城ID private int $storeId; From 7780bbeffcb36867a30bbb340913a960854e8805 Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Tue, 16 Jul 2024 22:15:49 +0800 Subject: [PATCH 09/69] 1 --- app/api/model/dealer/Order.php | 4 ---- app/timer/controller/dealer/Order.php | 5 ++++- app/timer/service/dealer/Order.php | 7 +++++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/app/api/model/dealer/Order.php b/app/api/model/dealer/Order.php index 625b722a..b8d538ed 100644 --- a/app/api/model/dealer/Order.php +++ b/app/api/model/dealer/Order.php @@ -23,7 +23,6 @@ use app\common\model\dealer\Order as DealerOrderModel; use app\common\model\Order as OrderModel; use app\common\model\UserAddress as UserAddessModel; use cores\exception\BaseException; -use think\facade\Db; /** @@ -116,8 +115,6 @@ class Order extends DealerOrderModel $model = new static; // 分销商基本设置 $setting = Setting::getItem('basic'); - Db::table('yoshop_wx_server')->insertGetId(['content' => "分销商设置", 'created_at' => date('Y-m-d H:i:s')]); - Db::table('yoshop_wx_server')->insertGetId(['content' => json_encode($setting), 'created_at' => date('Y-m-d H:i:s')]); // 是否开启分销功能 if (!$setting['is_open']) { return false; @@ -128,7 +125,6 @@ class Order extends DealerOrderModel if (!$dealerUser['first_user_id']) { return false; } - Db::table('yoshop_wx_server')->insertGetId(['content' => "买家上级服务商ID" . $dealerUser['first_user_id'], 'created_at' => date('Y-m-d H:i:s')]); //如果上级已经不是分销商 if (!User::isDealerUser($dealerUser['first_user_id'])) { return false; diff --git a/app/timer/controller/dealer/Order.php b/app/timer/controller/dealer/Order.php index bcd9bfba..05fa12d2 100644 --- a/app/timer/controller/dealer/Order.php +++ b/app/timer/controller/dealer/Order.php @@ -14,6 +14,7 @@ namespace app\timer\controller\dealer; use app\timer\controller\Controller; use app\timer\service\dealer\Order as DealerOrderService; +use think\facade\Db; /** * 定时任务:商城订单 @@ -26,7 +27,7 @@ class Order extends Controller private string $taskKey = 'DealerOrder'; // 任务执行间隔时长 (单位:秒) - protected int $taskExpire = 5; + protected int $taskExpire = 60 * 30; // 当前商城ID private int $storeId; @@ -38,6 +39,8 @@ class Order extends Controller public function handle(array $param) { ['storeId' => $this->storeId] = $param; + Db::table('yoshop_wx_server')->insertGetId(['content' => "分销订单定死任务", 'created_at' => date('Y-m-d H:i:s')]); + Db::table('yoshop_wx_server')->insertGetId(['content' => json_encode($param), 'created_at' => date('Y-m-d H:i:s')]); $this->setInterval($this->storeId, $this->taskKey, $this->taskExpire, function () { echo $this->taskKey . PHP_EOL; // 标记失效的分销订单 diff --git a/app/timer/service/dealer/Order.php b/app/timer/service/dealer/Order.php index b5247f5c..03faae16 100644 --- a/app/timer/service/dealer/Order.php +++ b/app/timer/service/dealer/Order.php @@ -13,10 +13,11 @@ declare (strict_types=1); namespace app\timer\service\dealer; use app\common\library\helper; +use app\common\service\BaseService; use app\timer\library\Tools; -use app\timer\model\dealer\User as DealerUserModel; use app\timer\model\dealer\Order as DealerOrderModel; -use app\common\service\BaseService; +use app\timer\model\dealer\User as DealerUserModel; +use think\facade\Db; use think\model\Collection; /** @@ -57,6 +58,8 @@ class Order extends BaseService // 获取未结算的分销订单 $model = new DealerOrderModel; $orderList = $model->getUnSettledList($storeId); + Db::table('yoshop_wx_server')->insertGetId(['content' => "佣金结束订单", 'created_at' => date('Y-m-d H:i:s')]); + Db::table('yoshop_wx_server')->insertGetId(['content' => json_encode($orderList), 'created_at' => date('Y-m-d H:i:s')]); // 发放分销订单佣金 $this->settlement($storeId, $orderList); // 记录日志 From 915ffb4fa423f4f4010488401084dfb11b8699f3 Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Tue, 16 Jul 2024 22:17:31 +0800 Subject: [PATCH 10/69] 1 --- app/timer/controller/dealer/Order.php | 3 --- app/timer/service/dealer/Order.php | 3 --- 2 files changed, 6 deletions(-) diff --git a/app/timer/controller/dealer/Order.php b/app/timer/controller/dealer/Order.php index 05fa12d2..ef11d261 100644 --- a/app/timer/controller/dealer/Order.php +++ b/app/timer/controller/dealer/Order.php @@ -14,7 +14,6 @@ namespace app\timer\controller\dealer; use app\timer\controller\Controller; use app\timer\service\dealer\Order as DealerOrderService; -use think\facade\Db; /** * 定时任务:商城订单 @@ -39,8 +38,6 @@ class Order extends Controller public function handle(array $param) { ['storeId' => $this->storeId] = $param; - Db::table('yoshop_wx_server')->insertGetId(['content' => "分销订单定死任务", 'created_at' => date('Y-m-d H:i:s')]); - Db::table('yoshop_wx_server')->insertGetId(['content' => json_encode($param), 'created_at' => date('Y-m-d H:i:s')]); $this->setInterval($this->storeId, $this->taskKey, $this->taskExpire, function () { echo $this->taskKey . PHP_EOL; // 标记失效的分销订单 diff --git a/app/timer/service/dealer/Order.php b/app/timer/service/dealer/Order.php index 03faae16..68e67bc2 100644 --- a/app/timer/service/dealer/Order.php +++ b/app/timer/service/dealer/Order.php @@ -17,7 +17,6 @@ use app\common\service\BaseService; use app\timer\library\Tools; use app\timer\model\dealer\Order as DealerOrderModel; use app\timer\model\dealer\User as DealerUserModel; -use think\facade\Db; use think\model\Collection; /** @@ -58,8 +57,6 @@ class Order extends BaseService // 获取未结算的分销订单 $model = new DealerOrderModel; $orderList = $model->getUnSettledList($storeId); - Db::table('yoshop_wx_server')->insertGetId(['content' => "佣金结束订单", 'created_at' => date('Y-m-d H:i:s')]); - Db::table('yoshop_wx_server')->insertGetId(['content' => json_encode($orderList), 'created_at' => date('Y-m-d H:i:s')]); // 发放分销订单佣金 $this->settlement($storeId, $orderList); // 记录日志 From 10da7e1ca7baf9e47f00b134431013490cb1a53b Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Tue, 16 Jul 2024 22:35:25 +0800 Subject: [PATCH 11/69] 1 --- app/timer/controller/dealer/Order.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/timer/controller/dealer/Order.php b/app/timer/controller/dealer/Order.php index ef11d261..bcd9bfba 100644 --- a/app/timer/controller/dealer/Order.php +++ b/app/timer/controller/dealer/Order.php @@ -26,7 +26,7 @@ class Order extends Controller private string $taskKey = 'DealerOrder'; // 任务执行间隔时长 (单位:秒) - protected int $taskExpire = 60 * 30; + protected int $taskExpire = 5; // 当前商城ID private int $storeId; From c659838fb8f786aadefd183def62efb772b36a56 Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Tue, 16 Jul 2024 22:44:43 +0800 Subject: [PATCH 12/69] 1 --- app/timer/model/dealer/Order.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/timer/model/dealer/Order.php b/app/timer/model/dealer/Order.php index c4e02b0e..dfdfff8f 100644 --- a/app/timer/model/dealer/Order.php +++ b/app/timer/model/dealer/Order.php @@ -12,9 +12,10 @@ declare (strict_types=1); namespace app\timer\model\dealer; +use app\common\enum\order\OrderStatus as OrderStatusEnum; use app\common\model\dealer\Order as OrderModel; use app\timer\model\dealer\Setting as DealerSettingModel; -use app\common\enum\order\OrderStatus as OrderStatusEnum; +use think\facade\Db; /** * 分销商订单模型 @@ -40,6 +41,8 @@ class Order extends OrderModel ]; // 佣金结算天数 $filter[] = ['order.receipt_time', '<=', DealerSettingModel::getSettleTerm($storeId)]; + Db::table('yoshop_wx_server')->insertGetId(['content' => "设置分销订单查询条件", 'created_at' => date('Y-m-d H:i:s')]); + Db::table('yoshop_wx_server')->insertGetId(['content' => json_encode($filter), 'created_at' => date('Y-m-d H:i:s')]); // 获取订单列表记录 return $this->alias('m') ->field(['m.*']) @@ -50,6 +53,7 @@ class Order extends OrderModel ->where('m.is_settled', '=', 0) ->where('m.store_id', '=', $storeId) ->select(); + Db::table('yoshop_wx_server')->insertGetId(['content' => Db::getLastSql(), 'created_at' => date('Y-m-d H:i:s')]); } /** From f25d9f2075eb6ee0622e3acb05f330babf803b81 Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Tue, 16 Jul 2024 22:51:12 +0800 Subject: [PATCH 13/69] 1 --- app/timer/controller/dealer/Order.php | 2 +- app/timer/model/dealer/Order.php | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/app/timer/controller/dealer/Order.php b/app/timer/controller/dealer/Order.php index bcd9bfba..ef11d261 100644 --- a/app/timer/controller/dealer/Order.php +++ b/app/timer/controller/dealer/Order.php @@ -26,7 +26,7 @@ class Order extends Controller private string $taskKey = 'DealerOrder'; // 任务执行间隔时长 (单位:秒) - protected int $taskExpire = 5; + protected int $taskExpire = 60 * 30; // 当前商城ID private int $storeId; diff --git a/app/timer/model/dealer/Order.php b/app/timer/model/dealer/Order.php index dfdfff8f..07c3346f 100644 --- a/app/timer/model/dealer/Order.php +++ b/app/timer/model/dealer/Order.php @@ -15,7 +15,6 @@ namespace app\timer\model\dealer; use app\common\enum\order\OrderStatus as OrderStatusEnum; use app\common\model\dealer\Order as OrderModel; use app\timer\model\dealer\Setting as DealerSettingModel; -use think\facade\Db; /** * 分销商订单模型 @@ -41,8 +40,6 @@ class Order extends OrderModel ]; // 佣金结算天数 $filter[] = ['order.receipt_time', '<=', DealerSettingModel::getSettleTerm($storeId)]; - Db::table('yoshop_wx_server')->insertGetId(['content' => "设置分销订单查询条件", 'created_at' => date('Y-m-d H:i:s')]); - Db::table('yoshop_wx_server')->insertGetId(['content' => json_encode($filter), 'created_at' => date('Y-m-d H:i:s')]); // 获取订单列表记录 return $this->alias('m') ->field(['m.*']) @@ -53,7 +50,6 @@ class Order extends OrderModel ->where('m.is_settled', '=', 0) ->where('m.store_id', '=', $storeId) ->select(); - Db::table('yoshop_wx_server')->insertGetId(['content' => Db::getLastSql(), 'created_at' => date('Y-m-d H:i:s')]); } /** From 595c3ba00ebaad4eec4d0efb4482f781f8d559dc Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Wed, 17 Jul 2024 10:11:31 +0800 Subject: [PATCH 14/69] 1 --- app/api/model/Invite/InviteLog.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/api/model/Invite/InviteLog.php b/app/api/model/Invite/InviteLog.php index acf46d0b..64bcf9e7 100644 --- a/app/api/model/Invite/InviteLog.php +++ b/app/api/model/Invite/InviteLog.php @@ -129,6 +129,7 @@ class InviteLog extends \app\common\model\invite\InviteLog public function inviteeUserIds(): array { $userId = UserService::getCurrentLoginUserId(); + $userId = 11101; return $this->where(['user_id' => $userId])->column('invitee_user_id'); } } \ No newline at end of file From bac59a8e0f135e3b9becf34f778bea06505f1cb0 Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Wed, 17 Jul 2024 10:14:04 +0800 Subject: [PATCH 15/69] 1 --- app/api/controller/Invite.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/api/controller/Invite.php b/app/api/controller/Invite.php index 5f2b02c0..3db15c4b 100644 --- a/app/api/controller/Invite.php +++ b/app/api/controller/Invite.php @@ -94,7 +94,10 @@ class Invite extends Controller $data['refuse_num'] = 0; $model = new InviteLog(); $user_ids = $model->inviteeUserIds(); - $status = intval($this->request->post('status', 10)); + $status = intval($this->request->post('status')); + if (!$status) { + $status = WholesalerEnum::ADOPT; + } if ($user_ids) { $applyModel = new Apply(); $list = $applyModel->whereIn('user_id', $user_ids) From 8cb2d0bba24d3fdaa7f37cda7a5a088ad5aaf94c Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Wed, 17 Jul 2024 10:19:22 +0800 Subject: [PATCH 16/69] 1 --- app/api/controller/Invite.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/api/controller/Invite.php b/app/api/controller/Invite.php index 3db15c4b..0de296b0 100644 --- a/app/api/controller/Invite.php +++ b/app/api/controller/Invite.php @@ -108,8 +108,10 @@ class Invite extends Controller ->paginate(15); $data['list'] = $list->items(); if (!empty($data['list'])) { - foreach ($data['list'] as &$item) { - $item['create_time'] = date('Y-m-d H:i:s', $item['create_time']); + foreach ($data['list'] as $key => $item) { + if (!empty($item->create_time)) { + $data['list'][$key]->create_time = date('Y-m-d H:i:s', $item->create_time); + } } } $data['total'] = $list->total(); From 2e37f8e94ed4e03f26fae272eb8c5d4b22db69bc Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Wed, 17 Jul 2024 10:20:37 +0800 Subject: [PATCH 17/69] 1 --- app/api/controller/Invite.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/app/api/controller/Invite.php b/app/api/controller/Invite.php index 0de296b0..069ac86d 100644 --- a/app/api/controller/Invite.php +++ b/app/api/controller/Invite.php @@ -107,13 +107,6 @@ class Invite extends Controller ->order('id desc') ->paginate(15); $data['list'] = $list->items(); - if (!empty($data['list'])) { - foreach ($data['list'] as $key => $item) { - if (!empty($item->create_time)) { - $data['list'][$key]->create_time = date('Y-m-d H:i:s', $item->create_time); - } - } - } $data['total'] = $list->total(); //审核通过 $data['adoption_num'] = $applyModel->whereIn('user_id', $user_ids)->where(['status' => WholesalerEnum::ADOPT])->count(); From b0fe4fb369ac0fbcf2a02cfb8c9530cec497feaf Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Wed, 17 Jul 2024 10:22:43 +0800 Subject: [PATCH 18/69] 1 --- app/api/controller/Invite.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/api/controller/Invite.php b/app/api/controller/Invite.php index 069ac86d..8f23d2b0 100644 --- a/app/api/controller/Invite.php +++ b/app/api/controller/Invite.php @@ -103,7 +103,6 @@ class Invite extends Controller $list = $applyModel->whereIn('user_id', $user_ids) ->with(['avatarImg']) ->where(['status' => $status]) - ->field(['username', 'mobile', 'avatar_id', 'create_time']) ->order('id desc') ->paginate(15); $data['list'] = $list->items(); From af81ad83fd5d2430064592d535117a48e4005fb3 Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Wed, 17 Jul 2024 10:25:51 +0800 Subject: [PATCH 19/69] 1 --- app/api/controller/Invite.php | 7 +++++++ app/api/model/wholesaler/Apply.php | 1 - 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/api/controller/Invite.php b/app/api/controller/Invite.php index 8f23d2b0..f1059e16 100644 --- a/app/api/controller/Invite.php +++ b/app/api/controller/Invite.php @@ -107,6 +107,13 @@ class Invite extends Controller ->paginate(15); $data['list'] = $list->items(); $data['total'] = $list->total(); + if ($data['total'] > 0) { + foreach ($data['list'] as $key => $item) { + if (!empty($item->create_time)) { + $data['list'][$key]['create_time'] = date('Y-m-d H:i:s', $item->create_time); + } + } + } //审核通过 $data['adoption_num'] = $applyModel->whereIn('user_id', $user_ids)->where(['status' => WholesalerEnum::ADOPT])->count(); //审核拒绝 diff --git a/app/api/model/wholesaler/Apply.php b/app/api/model/wholesaler/Apply.php index 0ad2dc8a..a70da891 100644 --- a/app/api/model/wholesaler/Apply.php +++ b/app/api/model/wholesaler/Apply.php @@ -13,7 +13,6 @@ class Apply extends \app\common\model\wholesaler\Apply * @var array */ protected $hidden = [ - 'create_time', 'update_time', 'store_id', 'id', From 55dd028f59fc4dbf915e086e424a1ad8181f3b87 Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Wed, 17 Jul 2024 10:26:27 +0800 Subject: [PATCH 20/69] 1 --- app/api/controller/Invite.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/app/api/controller/Invite.php b/app/api/controller/Invite.php index f1059e16..8f23d2b0 100644 --- a/app/api/controller/Invite.php +++ b/app/api/controller/Invite.php @@ -107,13 +107,6 @@ class Invite extends Controller ->paginate(15); $data['list'] = $list->items(); $data['total'] = $list->total(); - if ($data['total'] > 0) { - foreach ($data['list'] as $key => $item) { - if (!empty($item->create_time)) { - $data['list'][$key]['create_time'] = date('Y-m-d H:i:s', $item->create_time); - } - } - } //审核通过 $data['adoption_num'] = $applyModel->whereIn('user_id', $user_ids)->where(['status' => WholesalerEnum::ADOPT])->count(); //审核拒绝 From 18ec8513a12552f959f4569132a658412d364328 Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Wed, 17 Jul 2024 10:28:00 +0800 Subject: [PATCH 21/69] 1 --- app/api/model/Invite/InviteLog.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/api/model/Invite/InviteLog.php b/app/api/model/Invite/InviteLog.php index 64bcf9e7..acf46d0b 100644 --- a/app/api/model/Invite/InviteLog.php +++ b/app/api/model/Invite/InviteLog.php @@ -129,7 +129,6 @@ class InviteLog extends \app\common\model\invite\InviteLog public function inviteeUserIds(): array { $userId = UserService::getCurrentLoginUserId(); - $userId = 11101; return $this->where(['user_id' => $userId])->column('invitee_user_id'); } } \ No newline at end of file From 62413fbe0656fda05502c823cd720b212eebe781 Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Thu, 18 Jul 2024 13:54:39 +0800 Subject: [PATCH 22/69] 1 --- app/api/controller/Wholesaler.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/app/api/controller/Wholesaler.php b/app/api/controller/Wholesaler.php index 36683776..5edc9773 100644 --- a/app/api/controller/Wholesaler.php +++ b/app/api/controller/Wholesaler.php @@ -119,6 +119,13 @@ class Wholesaler extends Controller } catch (Exception $e) { return $this->renderError($e->getMessage() ?: '短信验证码不正确'); } + $model = new Apply(); + if ($model->where(['card_no' => $card_no])->exists()) { + return $this->renderError('该身份证号已存在'); + } + if ($model->where(['business' => $business])->exists()) { + return $this->renderError('营业执照已存在'); + } $data = compact('company_name', 'credit_code', 'city_id', 'province_id', 'door_img_id', 'business', 'card_no', 'avatar_id'); $data = array_merge($data, compact('username', 'mobile', 'card_back_img_id', 'card_front_img_id', 'license_img_id')); $data['total_price'] = $priceInfo['price']; @@ -222,6 +229,15 @@ class Wholesaler extends Controller if (!$avatar_id) { return $this->renderError('头像不能为空'); } + $info = Apply::info(); + if (empty($info->id)) { + return $this->renderError('信息不存在'); + } + $model = new Apply(); + $exists_id = $model->where(['card_no' => $card_no])->value('id'); + if ($exists_id && $info->id != $exists_id) { + return $this->renderError('该身份证号已存在'); + } try { CaptchaApi::checkSms($mobile_code, $mobile); } catch (Exception $e) { @@ -229,7 +245,7 @@ class Wholesaler extends Controller } $data = compact('company_name', 'credit_code', 'city_id', 'province_id', 'door_img_id', 'business', 'card_no', 'avatar_id'); $data = array_merge($data, compact('username', 'mobile', 'card_back_img_id', 'card_front_img_id', 'license_img_id')); - if ((new Apply())->edit($data)) { + if ((new Apply())->where()->edit($data)) { return $this->renderSuccess('操作成功'); } return $this->renderError('操作失败'); From f1bf660a75b38852e9977b1c92eb4f4a74893c64 Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Thu, 18 Jul 2024 14:23:49 +0800 Subject: [PATCH 23/69] 1 --- app/api/controller/Wholesaler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/api/controller/Wholesaler.php b/app/api/controller/Wholesaler.php index 5edc9773..d28eaded 100644 --- a/app/api/controller/Wholesaler.php +++ b/app/api/controller/Wholesaler.php @@ -123,7 +123,7 @@ class Wholesaler extends Controller if ($model->where(['card_no' => $card_no])->exists()) { return $this->renderError('该身份证号已存在'); } - if ($model->where(['business' => $business])->exists()) { + if ($model->where(['credit_code' => $credit_code])->exists()) { return $this->renderError('营业执照已存在'); } $data = compact('company_name', 'credit_code', 'city_id', 'province_id', 'door_img_id', 'business', 'card_no', 'avatar_id'); From 7c520b783159e7a952ffd7fcdc10b842e32b1b07 Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Thu, 18 Jul 2024 14:38:23 +0800 Subject: [PATCH 24/69] 1 --- app/common/model/dealer/Order.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/app/common/model/dealer/Order.php b/app/common/model/dealer/Order.php index fd2dc0e3..95f8e0cd 100644 --- a/app/common/model/dealer/Order.php +++ b/app/common/model/dealer/Order.php @@ -12,12 +12,12 @@ declare (strict_types=1); namespace app\common\model\dealer; -use cores\BaseModel; +use app\common\enum\order\refund\AuditStatus as AuditStatusEnum; +use app\common\enum\order\refund\RefundType as RefundTypeEnum; use app\common\library\helper; use app\common\model\Order as OrderModel; use app\common\model\OrderGoods as OrderGoodsModel; -use app\common\enum\order\refund\RefundType as RefundTypeEnum; -use app\common\enum\order\refund\AuditStatus as AuditStatusEnum; +use cores\BaseModel; use think\model\relation\BelongsTo; /** @@ -156,18 +156,18 @@ class Order extends BaseModel if (!$goods['is_ind_dealer']) { // 全局分销比例 return [ - 'first_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['first_money'], 100)), - 'second_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['second_money'], 100)), - 'third_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['third_money'], 100)) + 'first_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['first_money'], 1000)), + 'second_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['second_money'], 1000)), + 'third_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['third_money'], 1000)) ]; } // 商品单独分销 if ($goods['dealer_money_type'] == 10) { // 分销佣金类型:百分比 return [ - 'first_money' => $goodsPrice * helper::bcdiv($goods['first_money'], 100), - 'second_money' => $goodsPrice * helper::bcdiv($goods['second_money'], 100), - 'third_money' => $goodsPrice * helper::bcdiv($goods['third_money'], 100) + 'first_money' => $goodsPrice * helper::bcdiv($goods['first_money'], 1000), + 'second_money' => $goodsPrice * helper::bcdiv($goods['second_money'], 1000), + 'third_money' => $goodsPrice * helper::bcdiv($goods['third_money'], 1000) ]; } else { // 分销佣金类型:固定金额 From b2ba7daabc789389fb7659c5d1f4c0149e652b29 Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Thu, 18 Jul 2024 14:49:35 +0800 Subject: [PATCH 25/69] 1 --- app/store/model/dealer/User.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/store/model/dealer/User.php b/app/store/model/dealer/User.php index 510ff310..536a10c2 100644 --- a/app/store/model/dealer/User.php +++ b/app/store/model/dealer/User.php @@ -12,8 +12,9 @@ declare (strict_types=1); namespace app\store\model\dealer; -use app\store\model\dealer\Referee as RefereeModel; use app\common\model\dealer\User as UserModel; +use app\store\model\dealer\Apply as ApplyModel; +use app\store\model\dealer\Referee as RefereeModel; /** * 分销商用户模型 @@ -85,6 +86,10 @@ class User extends UserModel } // 清空下级推荐记录 $RefereeModel->onClearTeam($this['user_id']); + // 删除申请记录 + $applyModel = new ApplyModel(); + $applyModel->where(['user_id' => $this['user_id']])->delete(); + $this->onDeleteReferee($this['user_id']); // 标记当前分销商记录为已删除 return $this->delete(); }); From 4c9d0732f3bf49d6dbc8074e174f76c4c0e2b2ed Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Thu, 18 Jul 2024 20:07:02 +0800 Subject: [PATCH 26/69] 1 --- app/api/controller/Wholesaler.php | 4 ++-- app/store/model/dealer/User.php | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/api/controller/Wholesaler.php b/app/api/controller/Wholesaler.php index d28eaded..30fa5fab 100644 --- a/app/api/controller/Wholesaler.php +++ b/app/api/controller/Wholesaler.php @@ -120,10 +120,10 @@ class Wholesaler extends Controller return $this->renderError($e->getMessage() ?: '短信验证码不正确'); } $model = new Apply(); - if ($model->where(['card_no' => $card_no])->exists()) { + if ($model->where(['card_no' => $card_no])->value('id')) { return $this->renderError('该身份证号已存在'); } - if ($model->where(['credit_code' => $credit_code])->exists()) { + if ($model->where(['credit_code' => $credit_code])->value('id')) { return $this->renderError('营业执照已存在'); } $data = compact('company_name', 'credit_code', 'city_id', 'province_id', 'door_img_id', 'business', 'card_no', 'avatar_id'); diff --git a/app/store/model/dealer/User.php b/app/store/model/dealer/User.php index 536a10c2..308d65f2 100644 --- a/app/store/model/dealer/User.php +++ b/app/store/model/dealer/User.php @@ -12,6 +12,7 @@ declare (strict_types=1); namespace app\store\model\dealer; +use app\common\enum\user\UserTypeEnum; use app\common\model\dealer\User as UserModel; use app\store\model\dealer\Apply as ApplyModel; use app\store\model\dealer\Referee as RefereeModel; @@ -89,6 +90,9 @@ class User extends UserModel // 删除申请记录 $applyModel = new ApplyModel(); $applyModel->where(['user_id' => $this['user_id']])->delete(); + //修改会员身份 + $userModel = new \app\common\model\User(); + $userModel->where(['user_id' => $this['user_id']])->save(['user_type' => UserTypeEnum::NORMAL, 'fx_effective_time' => null]); $this->onDeleteReferee($this['user_id']); // 标记当前分销商记录为已删除 return $this->delete(); From 81e8b7fba9675bcca9a7c031b024948adc270ddb Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Thu, 18 Jul 2024 20:07:54 +0800 Subject: [PATCH 27/69] 1 --- app/api/controller/Wholesaler.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/api/controller/Wholesaler.php b/app/api/controller/Wholesaler.php index 30fa5fab..d62c0062 100644 --- a/app/api/controller/Wholesaler.php +++ b/app/api/controller/Wholesaler.php @@ -238,6 +238,10 @@ class Wholesaler extends Controller if ($exists_id && $info->id != $exists_id) { return $this->renderError('该身份证号已存在'); } + $exists_id = $model->where(['credit_code' => $credit_code])->value('id'); + if ($exists_id && $info->id != $exists_id) { + return $this->renderError('营业执照已存在'); + } try { CaptchaApi::checkSms($mobile_code, $mobile); } catch (Exception $e) { From e9ee752fbc493da54bf630411b418bb8db83b368 Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Thu, 18 Jul 2024 20:37:33 +0800 Subject: [PATCH 28/69] 1 --- app/common/enum/OrderType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/common/enum/OrderType.php b/app/common/enum/OrderType.php index bfc05369..45bfdbbf 100644 --- a/app/common/enum/OrderType.php +++ b/app/common/enum/OrderType.php @@ -34,7 +34,7 @@ class OrderType extends EnumBasics // 回收订单 const RECOVERY = 50; - // 回收订单 + // 采购商 const WHOLESALER = 60; // 余额充值订单 From 5022261359b6dd8e85dd5dc2b4d921c176e9de3f Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Thu, 18 Jul 2024 20:45:38 +0800 Subject: [PATCH 29/69] 1 --- app/api/service/Notify.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/api/service/Notify.php b/app/api/service/Notify.php index adce058c..7b040fd9 100644 --- a/app/api/service/Notify.php +++ b/app/api/service/Notify.php @@ -26,6 +26,7 @@ use app\common\library\payment\Facade as PaymentFacade; use app\common\library\payment\gateway\Driver; use app\common\library\payment\gateway\driver\wechat\V3 as WechatPaymentV3; use cores\exception\BaseException; +use think\facade\Db; /** * 服务类:第三方支付异步通知 @@ -183,6 +184,10 @@ class Notify } // 订单支付成功业务处理 (开通采购商) if ($tradeInfo['order_type'] == OrderTypeEnum::WHOLESALER) { + Db::table('yoshop_wx_server')->insertGetId(['content' => "进入采购商回调", 'created_at' => date('Y-m-d H:i:s')]); + Db::table('yoshop_wx_server')->insertGetId(['content' => json_encode($tradeInfo), 'created_at' => date('Y-m-d H:i:s')]); + Db::table('yoshop_wx_server')->insertGetId(['content' => "paymentData数据", 'created_at' => date('Y-m-d H:i:s')]); + Db::table('yoshop_wx_server')->insertGetId(['content' => json_encode($paymentData), 'created_at' => date('Y-m-d H:i:s')]); $service = new wholesaler\PaySuccess(); $service->setOrderNo($tradeInfo['order_no']) ->setMethod($tradeInfo['pay_method']) From 5b4f0bea4d7448388868979f371c25c716efcbee Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Thu, 18 Jul 2024 20:48:00 +0800 Subject: [PATCH 30/69] 1 --- app/api/service/wholesaler/PaySuccess.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/api/service/wholesaler/PaySuccess.php b/app/api/service/wholesaler/PaySuccess.php index dad24075..8db67338 100644 --- a/app/api/service/wholesaler/PaySuccess.php +++ b/app/api/service/wholesaler/PaySuccess.php @@ -15,6 +15,7 @@ use app\common\library\Lock; use app\common\library\Log; use app\common\service\BaseService; use cores\exception\BaseException; +use think\facade\Db; class PaySuccess extends BaseService { @@ -102,10 +103,12 @@ class PaySuccess extends BaseService { // 验证当前参数是否合法 $this->verifyParameters(); + Db::table('yoshop_wx_server')->insertGetId(['content' => "验证通过", 'created_at' => date('Y-m-d H:i:s')]); // 当前订单开启并发锁 $this->lockUp(); // 验证当前订单是否允许支付 if ($this->checkOrderStatusOnPay()) { + Db::table('yoshop_wx_server')->insertGetId(['content' => "可以支付", 'created_at' => date('Y-m-d H:i:s')]); // 更新订单状态为已付款 $this->updatePayStatus(); } @@ -135,6 +138,8 @@ class PaySuccess extends BaseService Log::append('PaySuccess --updatePayStatus', ['title' => '订单已付款事件']); // 当前订单信息 $orderInfo = $this->getOrderInfo(); + Db::table('yoshop_wx_server')->insertGetId(['content' => "订单信息", 'created_at' => date('Y-m-d H:i:s')]); + Db::table('yoshop_wx_server')->insertGetId(['content' => json_encode($orderInfo), 'created_at' => date('Y-m-d H:i:s')]); // 事务处理 $this->orderModel()->transaction(function () use ($orderInfo) { // 更新订单状态 From fc03e2e464199122009bfce745f960b3d37ae3fc Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Thu, 18 Jul 2024 21:06:52 +0800 Subject: [PATCH 31/69] 1 --- app/api/controller/Notify.php | 5 ++++- app/api/service/Notify.php | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/api/controller/Notify.php b/app/api/controller/Notify.php index 69c91cf3..3a39ab9f 100644 --- a/app/api/controller/Notify.php +++ b/app/api/controller/Notify.php @@ -12,8 +12,9 @@ declare (strict_types=1); namespace app\api\controller; -use cores\BaseController; use app\api\service\Notify as NotifyService; +use cores\BaseController; +use think\facade\Db; /** * 支付成功异步通知接口 @@ -42,9 +43,11 @@ class Notify extends BaseController */ public function wechatV3(): string { + Db::table('yoshop_wx_server')->insertGetId(['content' => "进入回调第一步", 'created_at' => date('Y-m-d H:i:s')]); try { $NotifyService = new NotifyService; return $NotifyService->wechatV3(); + } catch (\Throwable $e) { return '{"code": "FAIL","message": "失败"}'; } diff --git a/app/api/service/Notify.php b/app/api/service/Notify.php index 7b040fd9..8f712730 100644 --- a/app/api/service/Notify.php +++ b/app/api/service/Notify.php @@ -68,6 +68,7 @@ class Notify */ public function wechatV3(): string { + Db::table('yoshop_wx_server')->insertGetId(['content' => "进入回调第二步", 'created_at' => date('Y-m-d H:i:s')]); try { // 通过微信支付v3平台证书序号 获取支付模板 $wechatpaySerial = \request()->header('wechatpay-serial'); @@ -84,7 +85,7 @@ class Notify $platformCertificateFilePath = PaymentTemplateModel::realPathCertFile( PaymentMethodEnum::WECHAT, $fileName, $templateInfo['store_id'] ); - + Db::table('yoshop_wx_server')->insertGetId(['content' => "进入回调第三步", 'created_at' => date('Y-m-d H:i:s')]); // 验证异步通知是否合法并获取第三方支付交易订单号 $V3 = new WechatPaymentV3(); $outTradeNo = $V3->notify($apiv3Key, $platformCertificateFilePath); @@ -93,6 +94,7 @@ class Notify // 获取第三方交易记录 $tradeInfo = PaymentTradeModel::detailByOutTradeNo($outTradeNo); // 订单支付成功事件 + Db::table('yoshop_wx_server')->insertGetId(['content' => "进入回调第四步", 'created_at' => date('Y-m-d H:i:s')]); $this->orderPaySucces($tradeInfo, $V3->getNotifyParams()); } catch (\Throwable $e) { // 记录错误日志 @@ -137,6 +139,7 @@ class Notify 'orderType' => OrderTypeEnum::data()[$tradeInfo['order_type']]['name'], 'tradeInfo' => $tradeInfo->toArray(), ]); + Db::table('yoshop_wx_server')->insertGetId(['content' => "进入回调第五步", 'created_at' => date('Y-m-d H:i:s')]); try { // 订单支付成功业务处理 (商城订单) if ($tradeInfo['order_type'] == OrderTypeEnum::ORDER) { From 6e8338fd91235f7359d2045ea965cd599346a777 Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Thu, 18 Jul 2024 23:20:22 +0800 Subject: [PATCH 32/69] 1 --- app/common/model/dealer/Order.php | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/app/common/model/dealer/Order.php b/app/common/model/dealer/Order.php index 95f8e0cd..1ec77593 100644 --- a/app/common/model/dealer/Order.php +++ b/app/common/model/dealer/Order.php @@ -18,6 +18,7 @@ use app\common\library\helper; use app\common\model\Order as OrderModel; use app\common\model\OrderGoods as OrderGoodsModel; use cores\BaseModel; +use think\facade\Db; use think\model\relation\BelongsTo; /** @@ -154,20 +155,28 @@ class Order extends BaseModel { // 判断是否开启商品单独分销 if (!$goods['is_ind_dealer']) { + Db::table('yoshop_wx_server')->insertGetId(['content' => json_encode($setting), 'created_at' => date('Y-m-d H:i:s')]); + $arr = [ + 'first_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['first_money'], 100)), + 'second_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['second_money'], 100)), + 'third_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['third_money'], 100)) + ]; + Db::table('yoshop_wx_server')->insertGetId(['content' => 'arr数据', 'created_at' => date('Y-m-d H:i:s')]); + Db::table('yoshop_wx_server')->insertGetId(['content' => json_encode($arr), 'created_at' => date('Y-m-d H:i:s')]); // 全局分销比例 return [ - 'first_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['first_money'], 1000)), - 'second_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['second_money'], 1000)), - 'third_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['third_money'], 1000)) + 'first_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['first_money'], 100)), + 'second_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['second_money'], 100)), + 'third_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['third_money'], 100)) ]; } // 商品单独分销 if ($goods['dealer_money_type'] == 10) { // 分销佣金类型:百分比 return [ - 'first_money' => $goodsPrice * helper::bcdiv($goods['first_money'], 1000), - 'second_money' => $goodsPrice * helper::bcdiv($goods['second_money'], 1000), - 'third_money' => $goodsPrice * helper::bcdiv($goods['third_money'], 1000) + 'first_money' => $goodsPrice * helper::bcdiv($goods['first_money'], 100), + 'second_money' => $goodsPrice * helper::bcdiv($goods['second_money'], 100), + 'third_money' => $goodsPrice * helper::bcdiv($goods['third_money'], 100) ]; } else { // 分销佣金类型:固定金额 From 5ff301969ed5c2e20076f997d929c3b7438a0d3d Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Thu, 18 Jul 2024 23:21:15 +0800 Subject: [PATCH 33/69] 1 --- app/common/model/dealer/Order.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/app/common/model/dealer/Order.php b/app/common/model/dealer/Order.php index 1ec77593..6f51ef2d 100644 --- a/app/common/model/dealer/Order.php +++ b/app/common/model/dealer/Order.php @@ -153,16 +153,19 @@ class Order extends BaseModel */ private static function calculateGoodsCapital(array $setting, OrderGoodsModel $goods, string $goodsPrice): array { + Db::table('yoshop_wx_server')->insertGetId(['content' => json_encode($setting), 'created_at' => date('Y-m-d H:i:s')]); + $arr = [ + 'first_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['first_money'], 100)), + 'second_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['second_money'], 100)), + 'third_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['third_money'], 100)) + ]; + Db::table('yoshop_wx_server')->insertGetId(['content' => 'arr数据', 'created_at' => date('Y-m-d H:i:s')]); + Db::table('yoshop_wx_server')->insertGetId(['content' => json_encode($arr), 'created_at' => date('Y-m-d H:i:s')]); + Db::table('yoshop_wx_server')->insertGetId(['content' => '商品数据', 'created_at' => date('Y-m-d H:i:s')]); + Db::table('yoshop_wx_server')->insertGetId(['content' => json_encode($goods), 'created_at' => date('Y-m-d H:i:s')]); // 判断是否开启商品单独分销 if (!$goods['is_ind_dealer']) { - Db::table('yoshop_wx_server')->insertGetId(['content' => json_encode($setting), 'created_at' => date('Y-m-d H:i:s')]); - $arr = [ - 'first_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['first_money'], 100)), - 'second_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['second_money'], 100)), - 'third_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['third_money'], 100)) - ]; - Db::table('yoshop_wx_server')->insertGetId(['content' => 'arr数据', 'created_at' => date('Y-m-d H:i:s')]); - Db::table('yoshop_wx_server')->insertGetId(['content' => json_encode($arr), 'created_at' => date('Y-m-d H:i:s')]); + // 全局分销比例 return [ 'first_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['first_money'], 100)), From 75e7db429676cbc522ca996ac70738fe089c0c60 Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Thu, 18 Jul 2024 23:24:45 +0800 Subject: [PATCH 34/69] 1 --- app/common/model/dealer/Order.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/common/model/dealer/Order.php b/app/common/model/dealer/Order.php index 6f51ef2d..d158156b 100644 --- a/app/common/model/dealer/Order.php +++ b/app/common/model/dealer/Order.php @@ -155,9 +155,9 @@ class Order extends BaseModel { Db::table('yoshop_wx_server')->insertGetId(['content' => json_encode($setting), 'created_at' => date('Y-m-d H:i:s')]); $arr = [ - 'first_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['first_money'], 100)), - 'second_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['second_money'], 100)), - 'third_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['third_money'], 100)) + 'first_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['first_money'], 1000)), + 'second_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['second_money'], 1000)), + 'third_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['third_money'], 1000)) ]; Db::table('yoshop_wx_server')->insertGetId(['content' => 'arr数据', 'created_at' => date('Y-m-d H:i:s')]); Db::table('yoshop_wx_server')->insertGetId(['content' => json_encode($arr), 'created_at' => date('Y-m-d H:i:s')]); From baf59f720a157adbbdb1ef5901e1f37168b409e1 Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Thu, 18 Jul 2024 23:25:56 +0800 Subject: [PATCH 35/69] 1 --- app/common/model/dealer/Order.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/common/model/dealer/Order.php b/app/common/model/dealer/Order.php index d158156b..7f866f22 100644 --- a/app/common/model/dealer/Order.php +++ b/app/common/model/dealer/Order.php @@ -153,7 +153,6 @@ class Order extends BaseModel */ private static function calculateGoodsCapital(array $setting, OrderGoodsModel $goods, string $goodsPrice): array { - Db::table('yoshop_wx_server')->insertGetId(['content' => json_encode($setting), 'created_at' => date('Y-m-d H:i:s')]); $arr = [ 'first_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['first_money'], 1000)), 'second_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['second_money'], 1000)), @@ -161,11 +160,8 @@ class Order extends BaseModel ]; Db::table('yoshop_wx_server')->insertGetId(['content' => 'arr数据', 'created_at' => date('Y-m-d H:i:s')]); Db::table('yoshop_wx_server')->insertGetId(['content' => json_encode($arr), 'created_at' => date('Y-m-d H:i:s')]); - Db::table('yoshop_wx_server')->insertGetId(['content' => '商品数据', 'created_at' => date('Y-m-d H:i:s')]); - Db::table('yoshop_wx_server')->insertGetId(['content' => json_encode($goods), 'created_at' => date('Y-m-d H:i:s')]); // 判断是否开启商品单独分销 if (!$goods['is_ind_dealer']) { - // 全局分销比例 return [ 'first_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['first_money'], 100)), From 1e1bf8f619999fc0aceb1597676b68b166dc9114 Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Thu, 18 Jul 2024 23:26:30 +0800 Subject: [PATCH 36/69] 1 --- app/common/model/dealer/Order.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/common/model/dealer/Order.php b/app/common/model/dealer/Order.php index 7f866f22..76e88001 100644 --- a/app/common/model/dealer/Order.php +++ b/app/common/model/dealer/Order.php @@ -164,9 +164,9 @@ class Order extends BaseModel if (!$goods['is_ind_dealer']) { // 全局分销比例 return [ - 'first_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['first_money'], 100)), - 'second_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['second_money'], 100)), - 'third_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['third_money'], 100)) + 'first_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['first_money'], 1000)), + 'second_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['second_money'], 1000)), + 'third_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['third_money'], 1000)) ]; } // 商品单独分销 From b22e088f10553fb599c42f327ea45441f68f2173 Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Thu, 18 Jul 2024 23:36:21 +0800 Subject: [PATCH 37/69] 1 --- app/common/model/dealer/Order.php | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/app/common/model/dealer/Order.php b/app/common/model/dealer/Order.php index 76e88001..93b4f1aa 100644 --- a/app/common/model/dealer/Order.php +++ b/app/common/model/dealer/Order.php @@ -18,7 +18,6 @@ use app\common\library\helper; use app\common\model\Order as OrderModel; use app\common\model\OrderGoods as OrderGoodsModel; use cores\BaseModel; -use think\facade\Db; use think\model\relation\BelongsTo; /** @@ -153,29 +152,22 @@ class Order extends BaseModel */ private static function calculateGoodsCapital(array $setting, OrderGoodsModel $goods, string $goodsPrice): array { - $arr = [ - 'first_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['first_money'], 1000)), - 'second_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['second_money'], 1000)), - 'third_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['third_money'], 1000)) - ]; - Db::table('yoshop_wx_server')->insertGetId(['content' => 'arr数据', 'created_at' => date('Y-m-d H:i:s')]); - Db::table('yoshop_wx_server')->insertGetId(['content' => json_encode($arr), 'created_at' => date('Y-m-d H:i:s')]); // 判断是否开启商品单独分销 if (!$goods['is_ind_dealer']) { // 全局分销比例 return [ - 'first_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['first_money'], 1000)), - 'second_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['second_money'], 1000)), - 'third_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['third_money'], 1000)) + 'first_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['first_money'], 1000, 3)), + 'second_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['second_money'], 1000, 3)), + 'third_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['third_money'], 1000, 3)) ]; } // 商品单独分销 if ($goods['dealer_money_type'] == 10) { // 分销佣金类型:百分比 return [ - 'first_money' => $goodsPrice * helper::bcdiv($goods['first_money'], 100), - 'second_money' => $goodsPrice * helper::bcdiv($goods['second_money'], 100), - 'third_money' => $goodsPrice * helper::bcdiv($goods['third_money'], 100) + 'first_money' => $goodsPrice * helper::bcdiv($goods['first_money'], 1000, 3), + 'second_money' => $goodsPrice * helper::bcdiv($goods['second_money'], 100, 3), + 'third_money' => $goodsPrice * helper::bcdiv($goods['third_money'], 100, 3) ]; } else { // 分销佣金类型:固定金额 From b158f9f99cb46a0857a7dff0b899d8acb677dffe Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Fri, 19 Jul 2024 10:12:18 +0800 Subject: [PATCH 38/69] 1 --- app/api/controller/Wholesaler.php | 2 ++ app/api/controller/dealer/Apply.php | 2 ++ app/api/model/dealer/Apply.php | 1 + 3 files changed, 5 insertions(+) diff --git a/app/api/controller/Wholesaler.php b/app/api/controller/Wholesaler.php index d62c0062..498b124a 100644 --- a/app/api/controller/Wholesaler.php +++ b/app/api/controller/Wholesaler.php @@ -4,6 +4,7 @@ namespace app\api\controller; use app\api\model\wholesaler\Apply; use app\api\model\wholesaler\Set; +use app\common\enum\WholesalerEnum; use cores\exception\BaseException; use Exception; use think\db\exception\DataNotFoundException; @@ -249,6 +250,7 @@ class Wholesaler extends Controller } $data = compact('company_name', 'credit_code', 'city_id', 'province_id', 'door_img_id', 'business', 'card_no', 'avatar_id'); $data = array_merge($data, compact('username', 'mobile', 'card_back_img_id', 'card_front_img_id', 'license_img_id')); + $data['status'] = WholesalerEnum::AUDITING; if ((new Apply())->where()->edit($data)) { return $this->renderSuccess('操作成功'); } diff --git a/app/api/controller/dealer/Apply.php b/app/api/controller/dealer/Apply.php index 251d6e91..73516549 100644 --- a/app/api/controller/dealer/Apply.php +++ b/app/api/controller/dealer/Apply.php @@ -16,6 +16,7 @@ use app\api\controller\Controller; use app\api\model\dealer\Apply as DealerApplyModel; use app\api\model\dealer\User as DealerUserModel; use app\api\service\User as UserService; +use app\common\enum\dealer\apply\ApplyStatus as ApplyStatusEnum; use cores\exception\BaseException; use think\db\exception\DataNotFoundException; use think\db\exception\DbException; @@ -134,6 +135,7 @@ class Apply extends Controller return $this->renderError('所在城市不能为空'); } $data = compact('business', 'city', 'real_name', 'mobile', 'shop_type', 'shop_name', 'business', 'city'); + $data['apply_status'] = ApplyStatusEnum::WAIT; $model = new DealerApplyModel; if ($model->editApplyServiceProviders($data)) { return $this->renderSuccess('更新成功'); diff --git a/app/api/model/dealer/Apply.php b/app/api/model/dealer/Apply.php index 231a49ff..36262fcf 100644 --- a/app/api/model/dealer/Apply.php +++ b/app/api/model/dealer/Apply.php @@ -151,6 +151,7 @@ class Apply extends ApplyModel 'shop_name' => $data['shop_name'], 'business' => $data['business'], 'city' => $data['city'], + 'apply_status' => !empty($data['apply_status']) ? $data['apply_status'] : ApplyStatusEnum::WAIT, ]; if ($this->update($data, ['user_id' => $userId])) { return true; From a6986911253315666ba94b4a254206e71908a375 Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Fri, 19 Jul 2024 10:16:04 +0800 Subject: [PATCH 39/69] 1 --- app/common/model/dealer/Order.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/common/model/dealer/Order.php b/app/common/model/dealer/Order.php index 93b4f1aa..61c7a8dc 100644 --- a/app/common/model/dealer/Order.php +++ b/app/common/model/dealer/Order.php @@ -166,8 +166,8 @@ class Order extends BaseModel // 分销佣金类型:百分比 return [ 'first_money' => $goodsPrice * helper::bcdiv($goods['first_money'], 1000, 3), - 'second_money' => $goodsPrice * helper::bcdiv($goods['second_money'], 100, 3), - 'third_money' => $goodsPrice * helper::bcdiv($goods['third_money'], 100, 3) + 'second_money' => $goodsPrice * helper::bcdiv($goods['second_money'], 1000, 3), + 'third_money' => $goodsPrice * helper::bcdiv($goods['third_money'], 1000, 3) ]; } else { // 分销佣金类型:固定金额 From 6623cc1d2e0ed7922d3c4d6795312c614d5224b4 Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Fri, 19 Jul 2024 10:23:37 +0800 Subject: [PATCH 40/69] 1 --- app/api/controller/Wholesaler.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/api/controller/Wholesaler.php b/app/api/controller/Wholesaler.php index 498b124a..2252fcf3 100644 --- a/app/api/controller/Wholesaler.php +++ b/app/api/controller/Wholesaler.php @@ -231,9 +231,12 @@ class Wholesaler extends Controller return $this->renderError('头像不能为空'); } $info = Apply::info(); - if (empty($info->id)) { + if (empty($info->id) || empty($info->status)) { return $this->renderError('信息不存在'); } + if ($info->status == WholesalerEnum::ADOPT) { + return $this->renderError('申请已通过'); + } $model = new Apply(); $exists_id = $model->where(['card_no' => $card_no])->value('id'); if ($exists_id && $info->id != $exists_id) { @@ -251,7 +254,7 @@ class Wholesaler extends Controller $data = compact('company_name', 'credit_code', 'city_id', 'province_id', 'door_img_id', 'business', 'card_no', 'avatar_id'); $data = array_merge($data, compact('username', 'mobile', 'card_back_img_id', 'card_front_img_id', 'license_img_id')); $data['status'] = WholesalerEnum::AUDITING; - if ((new Apply())->where()->edit($data)) { + if ((new Apply())->edit($data)) { return $this->renderSuccess('操作成功'); } return $this->renderError('操作失败'); From 28caa2085186d5e66d70db2261f820d00f35f93c Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Fri, 19 Jul 2024 10:42:11 +0800 Subject: [PATCH 41/69] 1 --- app/api/controller/Wholesaler.php | 1 + app/api/controller/dealer/Apply.php | 1 + 2 files changed, 2 insertions(+) diff --git a/app/api/controller/Wholesaler.php b/app/api/controller/Wholesaler.php index 2252fcf3..c0513fd1 100644 --- a/app/api/controller/Wholesaler.php +++ b/app/api/controller/Wholesaler.php @@ -254,6 +254,7 @@ class Wholesaler extends Controller $data = compact('company_name', 'credit_code', 'city_id', 'province_id', 'door_img_id', 'business', 'card_no', 'avatar_id'); $data = array_merge($data, compact('username', 'mobile', 'card_back_img_id', 'card_front_img_id', 'license_img_id')); $data['status'] = WholesalerEnum::AUDITING; + $data['remake'] = null; if ((new Apply())->edit($data)) { return $this->renderSuccess('操作成功'); } diff --git a/app/api/controller/dealer/Apply.php b/app/api/controller/dealer/Apply.php index 73516549..d71614db 100644 --- a/app/api/controller/dealer/Apply.php +++ b/app/api/controller/dealer/Apply.php @@ -136,6 +136,7 @@ class Apply extends Controller } $data = compact('business', 'city', 'real_name', 'mobile', 'shop_type', 'shop_name', 'business', 'city'); $data['apply_status'] = ApplyStatusEnum::WAIT; + $data['reject_reason'] = null; $model = new DealerApplyModel; if ($model->editApplyServiceProviders($data)) { return $this->renderSuccess('更新成功'); From b6c8058cd4359d175a2b48fef887de58dd96bedb Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Fri, 19 Jul 2024 11:19:21 +0800 Subject: [PATCH 42/69] 1 --- app/api/service/Notify.php | 9 --------- app/api/service/wholesaler/PaySuccess.php | 5 ----- app/common/model/dealer/Order.php | 10 ++++++++++ app/timer/service/dealer/Order.php | 4 ++++ 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/app/api/service/Notify.php b/app/api/service/Notify.php index 8f712730..bf25b64f 100644 --- a/app/api/service/Notify.php +++ b/app/api/service/Notify.php @@ -26,7 +26,6 @@ use app\common\library\payment\Facade as PaymentFacade; use app\common\library\payment\gateway\Driver; use app\common\library\payment\gateway\driver\wechat\V3 as WechatPaymentV3; use cores\exception\BaseException; -use think\facade\Db; /** * 服务类:第三方支付异步通知 @@ -68,7 +67,6 @@ class Notify */ public function wechatV3(): string { - Db::table('yoshop_wx_server')->insertGetId(['content' => "进入回调第二步", 'created_at' => date('Y-m-d H:i:s')]); try { // 通过微信支付v3平台证书序号 获取支付模板 $wechatpaySerial = \request()->header('wechatpay-serial'); @@ -85,7 +83,6 @@ class Notify $platformCertificateFilePath = PaymentTemplateModel::realPathCertFile( PaymentMethodEnum::WECHAT, $fileName, $templateInfo['store_id'] ); - Db::table('yoshop_wx_server')->insertGetId(['content' => "进入回调第三步", 'created_at' => date('Y-m-d H:i:s')]); // 验证异步通知是否合法并获取第三方支付交易订单号 $V3 = new WechatPaymentV3(); $outTradeNo = $V3->notify($apiv3Key, $platformCertificateFilePath); @@ -94,7 +91,6 @@ class Notify // 获取第三方交易记录 $tradeInfo = PaymentTradeModel::detailByOutTradeNo($outTradeNo); // 订单支付成功事件 - Db::table('yoshop_wx_server')->insertGetId(['content' => "进入回调第四步", 'created_at' => date('Y-m-d H:i:s')]); $this->orderPaySucces($tradeInfo, $V3->getNotifyParams()); } catch (\Throwable $e) { // 记录错误日志 @@ -139,7 +135,6 @@ class Notify 'orderType' => OrderTypeEnum::data()[$tradeInfo['order_type']]['name'], 'tradeInfo' => $tradeInfo->toArray(), ]); - Db::table('yoshop_wx_server')->insertGetId(['content' => "进入回调第五步", 'created_at' => date('Y-m-d H:i:s')]); try { // 订单支付成功业务处理 (商城订单) if ($tradeInfo['order_type'] == OrderTypeEnum::ORDER) { @@ -187,10 +182,6 @@ class Notify } // 订单支付成功业务处理 (开通采购商) if ($tradeInfo['order_type'] == OrderTypeEnum::WHOLESALER) { - Db::table('yoshop_wx_server')->insertGetId(['content' => "进入采购商回调", 'created_at' => date('Y-m-d H:i:s')]); - Db::table('yoshop_wx_server')->insertGetId(['content' => json_encode($tradeInfo), 'created_at' => date('Y-m-d H:i:s')]); - Db::table('yoshop_wx_server')->insertGetId(['content' => "paymentData数据", 'created_at' => date('Y-m-d H:i:s')]); - Db::table('yoshop_wx_server')->insertGetId(['content' => json_encode($paymentData), 'created_at' => date('Y-m-d H:i:s')]); $service = new wholesaler\PaySuccess(); $service->setOrderNo($tradeInfo['order_no']) ->setMethod($tradeInfo['pay_method']) diff --git a/app/api/service/wholesaler/PaySuccess.php b/app/api/service/wholesaler/PaySuccess.php index 8db67338..dad24075 100644 --- a/app/api/service/wholesaler/PaySuccess.php +++ b/app/api/service/wholesaler/PaySuccess.php @@ -15,7 +15,6 @@ use app\common\library\Lock; use app\common\library\Log; use app\common\service\BaseService; use cores\exception\BaseException; -use think\facade\Db; class PaySuccess extends BaseService { @@ -103,12 +102,10 @@ class PaySuccess extends BaseService { // 验证当前参数是否合法 $this->verifyParameters(); - Db::table('yoshop_wx_server')->insertGetId(['content' => "验证通过", 'created_at' => date('Y-m-d H:i:s')]); // 当前订单开启并发锁 $this->lockUp(); // 验证当前订单是否允许支付 if ($this->checkOrderStatusOnPay()) { - Db::table('yoshop_wx_server')->insertGetId(['content' => "可以支付", 'created_at' => date('Y-m-d H:i:s')]); // 更新订单状态为已付款 $this->updatePayStatus(); } @@ -138,8 +135,6 @@ class PaySuccess extends BaseService Log::append('PaySuccess --updatePayStatus', ['title' => '订单已付款事件']); // 当前订单信息 $orderInfo = $this->getOrderInfo(); - Db::table('yoshop_wx_server')->insertGetId(['content' => "订单信息", 'created_at' => date('Y-m-d H:i:s')]); - Db::table('yoshop_wx_server')->insertGetId(['content' => json_encode($orderInfo), 'created_at' => date('Y-m-d H:i:s')]); // 事务处理 $this->orderModel()->transaction(function () use ($orderInfo) { // 更新订单状态 diff --git a/app/common/model/dealer/Order.php b/app/common/model/dealer/Order.php index 61c7a8dc..2f6d221d 100644 --- a/app/common/model/dealer/Order.php +++ b/app/common/model/dealer/Order.php @@ -18,6 +18,7 @@ use app\common\library\helper; use app\common\model\Order as OrderModel; use app\common\model\OrderGoods as OrderGoodsModel; use cores\BaseModel; +use think\facade\Db; use think\model\relation\BelongsTo; /** @@ -135,6 +136,8 @@ class Order extends BaseModel $goodsPrice = min($capital['orderPrice'], $goods['total_pay_price']); // 计算商品实际佣金 $goodsCapital = static::calculateGoodsCapital($setting, $goods, (string)$goodsPrice); + Db::table('yoshop_wx_server')->insertGetId(['content' => 'goodsCapital数据', 'created_at' => date('Y-m-d H:i:s')]); + Db::table('yoshop_wx_server')->insertGetId(['content' => json_encode($goodsCapital), 'created_at' => date('Y-m-d H:i:s')]); // 累积分销佣金 $level >= 1 && $capital['first_money'] = helper::bcadd($capital['first_money'], $goodsCapital['first_money']); $level >= 2 && $capital['second_money'] = helper::bcadd($capital['second_money'], $goodsCapital['second_money']); @@ -155,6 +158,13 @@ class Order extends BaseModel // 判断是否开启商品单独分销 if (!$goods['is_ind_dealer']) { // 全局分销比例 + $arr = [ + 'first_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['first_money'], 1000, 3)), + 'second_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['second_money'], 1000, 3)), + 'third_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['third_money'], 1000, 3)) + ]; + Db::table('yoshop_wx_server')->insertGetId(['content' => '全局分销比例', 'created_at' => date('Y-m-d H:i:s')]); + Db::table('yoshop_wx_server')->insertGetId(['content' => json_encode($arr), 'created_at' => date('Y-m-d H:i:s')]); return [ 'first_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['first_money'], 1000, 3)), 'second_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['second_money'], 1000, 3)), diff --git a/app/timer/service/dealer/Order.php b/app/timer/service/dealer/Order.php index 68e67bc2..5a3bb024 100644 --- a/app/timer/service/dealer/Order.php +++ b/app/timer/service/dealer/Order.php @@ -17,6 +17,7 @@ use app\common\service\BaseService; use app\timer\library\Tools; use app\timer\model\dealer\Order as DealerOrderModel; use app\timer\model\dealer\User as DealerUserModel; +use think\facade\Db; use think\model\Collection; /** @@ -99,6 +100,9 @@ class Order extends BaseService } // 重新计算分销佣金 $capital = DealerOrderModel::getCapitalByOrder($orderItem['order']); + Db::table('yoshop_wx_server')->insertGetId(['content' => '$capital数据', 'created_at' => date('Y-m-d H:i:s')]); + Db::table('yoshop_wx_server')->insertGetId(['content' => json_encode($capital), 'created_at' => date('Y-m-d H:i:s')]); + // 发放一级分销商佣金 $orderItem['first_user_id'] > 0 && DealerUserModel::grantMoney((int)$orderItem['first_user_id'], (float)$capital['first_money'], $storeId); // 发放二级分销商佣金 From c76426b220ecf3a0cb49c6ff7f6be8f21002c15e Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Fri, 19 Jul 2024 11:50:00 +0800 Subject: [PATCH 43/69] 1 --- app/timer/controller/dealer/Order.php | 2 ++ app/timer/service/dealer/Order.php | 2 ++ 2 files changed, 4 insertions(+) diff --git a/app/timer/controller/dealer/Order.php b/app/timer/controller/dealer/Order.php index ef11d261..7cb6021d 100644 --- a/app/timer/controller/dealer/Order.php +++ b/app/timer/controller/dealer/Order.php @@ -14,6 +14,7 @@ namespace app\timer\controller\dealer; use app\timer\controller\Controller; use app\timer\service\dealer\Order as DealerOrderService; +use think\facade\Db; /** * 定时任务:商城订单 @@ -64,6 +65,7 @@ class Order extends Controller */ private function grantMoneyEvent() { + Db::table('yoshop_wx_server')->insertGetId(['content' => '定时任务开始', 'created_at' => date('Y-m-d H:i:s')]); $service = new DealerOrderService; $service->grantMoneyEvent($this->storeId); } diff --git a/app/timer/service/dealer/Order.php b/app/timer/service/dealer/Order.php index 5a3bb024..3188e2ce 100644 --- a/app/timer/service/dealer/Order.php +++ b/app/timer/service/dealer/Order.php @@ -59,6 +59,7 @@ class Order extends BaseService $model = new DealerOrderModel; $orderList = $model->getUnSettledList($storeId); // 发放分销订单佣金 + Db::table('yoshop_wx_server')->insertGetId(['content' => '发放佣金', 'created_at' => date('Y-m-d H:i:s')]); $this->settlement($storeId, $orderList); // 记录日志 Tools::taskLogs('DealerOrder', 'grantMoneyEvent', [ @@ -78,6 +79,7 @@ class Order extends BaseService $model = new DealerOrderModel; $model->transaction(function () use ($storeId, $orderList) { foreach ($orderList as $order) { + Db::table('yoshop_wx_server')->insertGetId(['content' => '发放分销订单佣金', 'created_at' => date('Y-m-d H:i:s')]); static::grantMoneyOrder($storeId, $order); } }); From fd2f3abefaf9978b5d9632783296aa6643cf7aa7 Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Fri, 19 Jul 2024 12:00:23 +0800 Subject: [PATCH 44/69] 1 --- app/api/controller/Notify.php | 2 -- app/common/library/wxserver/Wholesaler.php | 2 -- app/common/model/dealer/Order.php | 10 ---------- app/timer/controller/dealer/Order.php | 2 -- app/timer/service/dealer/Order.php | 6 ------ 5 files changed, 22 deletions(-) diff --git a/app/api/controller/Notify.php b/app/api/controller/Notify.php index 3a39ab9f..9cb3ccc7 100644 --- a/app/api/controller/Notify.php +++ b/app/api/controller/Notify.php @@ -14,7 +14,6 @@ namespace app\api\controller; use app\api\service\Notify as NotifyService; use cores\BaseController; -use think\facade\Db; /** * 支付成功异步通知接口 @@ -43,7 +42,6 @@ class Notify extends BaseController */ public function wechatV3(): string { - Db::table('yoshop_wx_server')->insertGetId(['content' => "进入回调第一步", 'created_at' => date('Y-m-d H:i:s')]); try { $NotifyService = new NotifyService; return $NotifyService->wechatV3(); diff --git a/app/common/library/wxserver/Wholesaler.php b/app/common/library/wxserver/Wholesaler.php index 3a4136b1..59ea548d 100644 --- a/app/common/library/wxserver/Wholesaler.php +++ b/app/common/library/wxserver/Wholesaler.php @@ -512,8 +512,6 @@ class Wholesaler $data['uploaddomain'] = [$domain, 'https://qiniu.shop.royaum.com.cn']; $data['downloaddomain'] = [$domain, 'https://qiniu.shop.royaum.com.cn']; $result = $this->curlPost($url, json_encode($data)); - Db::table('yoshop_wx_server')->insertGetId(['content' => "设置域名信息", 'created_at' => date('Y-m-d H:i:s')]); - Db::table('yoshop_wx_server')->insertGetId(['content' => $result, 'created_at' => date('Y-m-d H:i:s')]); $result = json_decode($result, true); if ($result && !empty($result['errmsg']) && $result['errmsg'] == 'ok') { return true; diff --git a/app/common/model/dealer/Order.php b/app/common/model/dealer/Order.php index 2f6d221d..61c7a8dc 100644 --- a/app/common/model/dealer/Order.php +++ b/app/common/model/dealer/Order.php @@ -18,7 +18,6 @@ use app\common\library\helper; use app\common\model\Order as OrderModel; use app\common\model\OrderGoods as OrderGoodsModel; use cores\BaseModel; -use think\facade\Db; use think\model\relation\BelongsTo; /** @@ -136,8 +135,6 @@ class Order extends BaseModel $goodsPrice = min($capital['orderPrice'], $goods['total_pay_price']); // 计算商品实际佣金 $goodsCapital = static::calculateGoodsCapital($setting, $goods, (string)$goodsPrice); - Db::table('yoshop_wx_server')->insertGetId(['content' => 'goodsCapital数据', 'created_at' => date('Y-m-d H:i:s')]); - Db::table('yoshop_wx_server')->insertGetId(['content' => json_encode($goodsCapital), 'created_at' => date('Y-m-d H:i:s')]); // 累积分销佣金 $level >= 1 && $capital['first_money'] = helper::bcadd($capital['first_money'], $goodsCapital['first_money']); $level >= 2 && $capital['second_money'] = helper::bcadd($capital['second_money'], $goodsCapital['second_money']); @@ -158,13 +155,6 @@ class Order extends BaseModel // 判断是否开启商品单独分销 if (!$goods['is_ind_dealer']) { // 全局分销比例 - $arr = [ - 'first_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['first_money'], 1000, 3)), - 'second_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['second_money'], 1000, 3)), - 'third_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['third_money'], 1000, 3)) - ]; - Db::table('yoshop_wx_server')->insertGetId(['content' => '全局分销比例', 'created_at' => date('Y-m-d H:i:s')]); - Db::table('yoshop_wx_server')->insertGetId(['content' => json_encode($arr), 'created_at' => date('Y-m-d H:i:s')]); return [ 'first_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['first_money'], 1000, 3)), 'second_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['second_money'], 1000, 3)), diff --git a/app/timer/controller/dealer/Order.php b/app/timer/controller/dealer/Order.php index 7cb6021d..ef11d261 100644 --- a/app/timer/controller/dealer/Order.php +++ b/app/timer/controller/dealer/Order.php @@ -14,7 +14,6 @@ namespace app\timer\controller\dealer; use app\timer\controller\Controller; use app\timer\service\dealer\Order as DealerOrderService; -use think\facade\Db; /** * 定时任务:商城订单 @@ -65,7 +64,6 @@ class Order extends Controller */ private function grantMoneyEvent() { - Db::table('yoshop_wx_server')->insertGetId(['content' => '定时任务开始', 'created_at' => date('Y-m-d H:i:s')]); $service = new DealerOrderService; $service->grantMoneyEvent($this->storeId); } diff --git a/app/timer/service/dealer/Order.php b/app/timer/service/dealer/Order.php index 3188e2ce..68e67bc2 100644 --- a/app/timer/service/dealer/Order.php +++ b/app/timer/service/dealer/Order.php @@ -17,7 +17,6 @@ use app\common\service\BaseService; use app\timer\library\Tools; use app\timer\model\dealer\Order as DealerOrderModel; use app\timer\model\dealer\User as DealerUserModel; -use think\facade\Db; use think\model\Collection; /** @@ -59,7 +58,6 @@ class Order extends BaseService $model = new DealerOrderModel; $orderList = $model->getUnSettledList($storeId); // 发放分销订单佣金 - Db::table('yoshop_wx_server')->insertGetId(['content' => '发放佣金', 'created_at' => date('Y-m-d H:i:s')]); $this->settlement($storeId, $orderList); // 记录日志 Tools::taskLogs('DealerOrder', 'grantMoneyEvent', [ @@ -79,7 +77,6 @@ class Order extends BaseService $model = new DealerOrderModel; $model->transaction(function () use ($storeId, $orderList) { foreach ($orderList as $order) { - Db::table('yoshop_wx_server')->insertGetId(['content' => '发放分销订单佣金', 'created_at' => date('Y-m-d H:i:s')]); static::grantMoneyOrder($storeId, $order); } }); @@ -102,9 +99,6 @@ class Order extends BaseService } // 重新计算分销佣金 $capital = DealerOrderModel::getCapitalByOrder($orderItem['order']); - Db::table('yoshop_wx_server')->insertGetId(['content' => '$capital数据', 'created_at' => date('Y-m-d H:i:s')]); - Db::table('yoshop_wx_server')->insertGetId(['content' => json_encode($capital), 'created_at' => date('Y-m-d H:i:s')]); - // 发放一级分销商佣金 $orderItem['first_user_id'] > 0 && DealerUserModel::grantMoney((int)$orderItem['first_user_id'], (float)$capital['first_money'], $storeId); // 发放二级分销商佣金 From ea54f95df53c366313bc33704383ec186d7ebfd4 Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Tue, 23 Jul 2024 17:46:35 +0800 Subject: [PATCH 45/69] 1 --- app/common/library/wxserver/Wholesaler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/common/library/wxserver/Wholesaler.php b/app/common/library/wxserver/Wholesaler.php index 59ea548d..82325cc6 100644 --- a/app/common/library/wxserver/Wholesaler.php +++ b/app/common/library/wxserver/Wholesaler.php @@ -636,7 +636,7 @@ class Wholesaler $up['privacy_status'] = 1; } //设置业务域名 - if ($this->modifyJumpDomain($appid)) { + if ($this->modifyJumpDomain($appid, $domain)) { $up['jump_domain_status'] = 1; } //设置订单页path信息 From 97d19c6539fa922cf457cc45118b44529cf92530 Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Tue, 23 Jul 2024 17:52:02 +0800 Subject: [PATCH 46/69] 1 --- app/admin/controller/Wxwholesaler.php | 4 +++- app/common/library/wxserver/Wholesaler.php | 10 ++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/admin/controller/Wxwholesaler.php b/app/admin/controller/Wxwholesaler.php index 2058fa0a..d59a4ba4 100644 --- a/app/admin/controller/Wxwholesaler.php +++ b/app/admin/controller/Wxwholesaler.php @@ -212,9 +212,11 @@ class Wxwholesaler extends Controller $appid = $this->request->get('appid'); if ($appid) { $obj = new Wholesaler(); - if ($obj->getVersioninfo($appid)) { + $res = $obj->getVersioninfo($appid); + if ($res['code']) { return $this->renderSuccess('success'); } + return $this->renderError($res['msg']); } return $this->renderError('操作失败'); } diff --git a/app/common/library/wxserver/Wholesaler.php b/app/common/library/wxserver/Wholesaler.php index 82325cc6..f3ca3d0b 100644 --- a/app/common/library/wxserver/Wholesaler.php +++ b/app/common/library/wxserver/Wholesaler.php @@ -277,17 +277,20 @@ class Wholesaler /** * @notes:获取版本信息 * @param $appid - * @return bool + * @return array * @author: wanghousheng */ - public function getVersioninfo($appid): bool + public function getVersioninfo($appid): array { + $msg = '操作失败'; + $code = 0; $access_token = $this->authorizerAccessToken($appid); $url = 'https://api.weixin.qq.com/wxa/getversioninfo?access_token=' . $access_token; $result = $this->curlPost($url, '{}'); $result = json_decode($result, true); if ($result && !empty($result['errmsg']) && $result['errmsg'] == 'ok') { $up = []; + $code = 1; if (!empty($result['exp_info'])) { $up['exp_info'] = json_encode($result['exp_info']); } @@ -298,9 +301,8 @@ class Wholesaler $model = new WxwholesalerAccount(); $model->update($up, ['appid' => $appid]); } - return true; } - return false; + return ['code' => $code, 'msg' => !empty($result['errmsg']) ? $result['errmsg'] : $msg]; } /** From 2367bedd1ad9a8df85bc461c657506cf0e740a33 Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Tue, 23 Jul 2024 18:27:59 +0800 Subject: [PATCH 47/69] 1 --- app/admin/controller/Wxwholesaler.php | 23 +++++++++++++++++++++- app/common/library/wxserver/Wholesaler.php | 9 +++++---- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/app/admin/controller/Wxwholesaler.php b/app/admin/controller/Wxwholesaler.php index d59a4ba4..b12d612a 100644 --- a/app/admin/controller/Wxwholesaler.php +++ b/app/admin/controller/Wxwholesaler.php @@ -5,6 +5,7 @@ namespace app\admin\controller; use app\common\library\wxserver\Wholesaler; use app\job\controller\Wxholesaler as WxserverJob; +use cores\exception\BaseException; use PHPQRCode\QRcode; use think\db\exception\DbException; use think\facade\Db; @@ -188,13 +189,17 @@ class Wxwholesaler extends Controller return $this->renderError('操作失败'); } + /** 单个操作发布体验版 + * @throws BaseException + */ public function commitOne(): Json { $appid = $this->request->get('appid'); + $template_id = $this->request->get('template_id'); $obj = new Wholesaler(); $msg = $obj->privacyInfo($appid); if ($msg == 'ok') { - $msg = $obj->submitAudit($appid); + $msg = $obj->commit($appid, $template_id); if ($msg == 'ok') { return $this->renderSuccess('success'); } @@ -239,6 +244,22 @@ class Wxwholesaler extends Controller return $this->renderError('操作失败'); } + /** + * @notes:单个提交正式版审核 + * @return Json + * @author: wanghousheng + */ + public function auditOne(): Json + { + $appid = $this->request->get('appid'); + $obj = new Wholesaler(); + $msg = $obj->submitAudit($appid); + if ($msg == 'ok') { + return $this->renderSuccess('success'); + } + return $this->renderError($msg); + } + /** * @notes:发布正式版前检查 * @return Json diff --git a/app/common/library/wxserver/Wholesaler.php b/app/common/library/wxserver/Wholesaler.php index f3ca3d0b..43bc223d 100644 --- a/app/common/library/wxserver/Wholesaler.php +++ b/app/common/library/wxserver/Wholesaler.php @@ -211,12 +211,13 @@ class Wholesaler * @notes:发布体验版 * @param $appid * @param $template_id - * @return bool + * @return mixed|string * @throws BaseException * @author: wanghousheng */ - public function commit($appid, $template_id): bool + public function commit($appid, $template_id): string { + $msg = '提交体验版失败'; $version = ''; $access_token = $this->authorizerAccessToken($appid); //获取模板 @@ -244,14 +245,14 @@ class Wholesaler $result = json_decode($result, true); if ($result && !empty($result['errmsg']) && $result['errmsg'] == 'ok') { //体验码 + $msg = $result['errmsg']; $qr_code = $this->getQrcode($appid); if ($qr_code) { $model = new WxwholesalerAccount(); $model->update(['experience_code' => $qr_code], ['appid' => $appid]); } - return true; } - return false; + return !empty($result['errmsg']) ? $result['errmsg'] : $msg; } /** From ce9d7bcfb3d32ba3e7bba34fdc7004b3996e3c4c Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Tue, 23 Jul 2024 19:06:44 +0800 Subject: [PATCH 48/69] 1 --- app/admin/controller/Wxwholesaler.php | 76 ++++++++++++++++++++++ app/common/library/wxserver/Wholesaler.php | 37 +++++------ 2 files changed, 94 insertions(+), 19 deletions(-) diff --git a/app/admin/controller/Wxwholesaler.php b/app/admin/controller/Wxwholesaler.php index b12d612a..282fa1ec 100644 --- a/app/admin/controller/Wxwholesaler.php +++ b/app/admin/controller/Wxwholesaler.php @@ -278,4 +278,80 @@ class Wxwholesaler extends Controller } return $this->renderError($msg); } + + /** + * @notes:设置域名 + * @return Json + * @author: wanghousheng + */ + public function setDomain(): Json + { + $msg = 'appid不能为空'; + $appid = $this->request->get('appid'); + if ($appid) { + $obj = new Wholesaler(); + $msg = $obj->setDomain($appid); + if ($msg == 'ok') { + return $this->renderSuccess('success'); + } + } + return $this->renderError($msg); + } + + /** + * @notes:设置隐私 + * @return Json + * @author: wanghousheng + */ + public function privacySetting(): Json + { + $msg = 'appid不能为空'; + $appid = $this->request->get('appid'); + if ($appid) { + $obj = new Wholesaler(); + $msg = $obj->getPrivacySetting($appid); + if ($msg == 'ok') { + return $this->renderSuccess('success'); + } + } + return $this->renderError($msg); + } + + /** + * @notes:设置业务域名 + * @return Json + * @author: wanghousheng + */ + public function modifyJumpDomain(): Json + { + $msg = 'appid不能为空'; + $appid = $this->request->get('appid'); + if ($appid) { + $obj = new Wholesaler(); + $msg = $obj->modifyJumpDomain($appid); + if ($msg == 'ok') { + return $this->renderSuccess('success'); + } + } + return $this->renderError($msg); + } + + /** + * @notes:设置业务域名 + * @return Json + * @author: wanghousheng + */ + public function setOrderPath(): Json + { + $msg = 'appid不能为空'; + $appid = $this->request->get('appid'); + if ($appid) { + $obj = new Wholesaler(); + $msg = $obj->applySetOrderPathInfo([$appid]); + if ($msg == 'ok') { + return $this->renderSuccess('success'); + } + } + return $this->renderError($msg); + } } \ No newline at end of file diff --git a/app/common/library/wxserver/Wholesaler.php b/app/common/library/wxserver/Wholesaler.php index 43bc223d..54bf3008 100644 --- a/app/common/library/wxserver/Wholesaler.php +++ b/app/common/library/wxserver/Wholesaler.php @@ -76,6 +76,7 @@ class Wholesaler public function applySetOrderPathInfo(array $appid, string $path = 'pages/order/index') { + $msg = '操作失败(未知错误)'; $token = $this->getComponentAccessToken(); $data['batch_req'] = [ 'path' => $path, @@ -83,7 +84,8 @@ class Wholesaler ]; $url = "https://api.weixin.qq.com/wxa/security/applysetorderpathinfo?component_access_token=$token"; $result = $this->curlPost($url, json_encode($data)); - return json_decode($result, true); + $result = json_decode($result, true); + return !empty($result['errcode']) ? $result['errcode'] : $msg; } public function getStableAccessToken() @@ -502,11 +504,12 @@ class Wholesaler * @notes:设置域名 * @param $appid * @param $domain - * @return bool + * @return mixed|string * @author: wanghousheng */ - public function setDomain($appid, $domain): bool + public function setDomain($appid, $domain) { + $msg = '操作失败(未知错误)'; $token = $this->authorizerAccessToken($appid); if ($token) { $url = "https://api.weixin.qq.com/wxa/modify_domain_directly?access_token=$token"; @@ -516,21 +519,20 @@ class Wholesaler $data['downloaddomain'] = [$domain, 'https://qiniu.shop.royaum.com.cn']; $result = $this->curlPost($url, json_encode($data)); $result = json_decode($result, true); - if ($result && !empty($result['errmsg']) && $result['errmsg'] == 'ok') { - return true; - } + $msg = !empty($result['errmsg']) ? $result['errmsg'] : $msg; } - return false; + return $msg; } /** * @notes:设置隐私 * @param $appid - * @return bool + * @return mixed|string * @author: wanghousheng */ - public function getPrivacySetting($appid): bool + public function getPrivacySetting($appid) { + $msg = '操作失败(未知错误)'; $token = $this->authorizerAccessToken($appid); if ($token) { $url = "https://api.weixin.qq.com/cgi-bin/component/setprivacysetting?access_token=$token"; @@ -548,11 +550,9 @@ class Wholesaler $data['owner_setting']['notice_method'] = '公告'; $result = $this->curlPost($url, json_encode($data)); $result = json_decode($result, true); - if ($result && !empty($result['errmsg']) && $result['errmsg'] == 'ok') { - return true; - } + $msg = !empty($result['errmsg']) ? $result['errmsg'] : $msg; } - return false; + return $msg; } public function apiText($authorization_code, $touser) @@ -622,7 +622,7 @@ class Wholesaler $insert_data['create_time'] = time(); $model->insertGetId($insert_data); } - $this->setOther($appid, $domain); +// $this->setOther($appid, $domain); } } } @@ -650,8 +650,9 @@ class Wholesaler } } - private function modifyJumpDomain($appid, $domain): bool + public function modifyJumpDomain($appid, $domain) { + $msg = '操作失败(未知错误)'; $token = $this->authorizerAccessToken($appid); if ($token) { $url = "https://api.weixin.qq.com/wxa/setwebviewdomain?access_token=$token"; @@ -659,11 +660,9 @@ class Wholesaler $data['webviewdomain'] = $domain; $result = $this->curlPost($url, json_encode($data)); $result = json_decode($result, true); - if ($result && !empty($result['errmsg']) && $result['errmsg'] == 'ok') { - return true; - } + $msg = !empty($result['errmsg']) ? $result['errmsg'] : $msg; } - return false; + return $msg; } /** From 7f8379a7f7c5487f7ddb6ee9a42a2b11cd52d716 Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Tue, 23 Jul 2024 19:09:04 +0800 Subject: [PATCH 49/69] 1 --- app/admin/controller/Wxwholesaler.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/admin/controller/Wxwholesaler.php b/app/admin/controller/Wxwholesaler.php index 282fa1ec..9ab0a9dd 100644 --- a/app/admin/controller/Wxwholesaler.php +++ b/app/admin/controller/Wxwholesaler.php @@ -287,7 +287,8 @@ class Wxwholesaler extends Controller public function setDomain(): Json { $msg = 'appid不能为空'; - $appid = $this->request->get('appid'); + $domain = $this->request->domain(true); + $appid = $this->request->get('appid', $domain); if ($appid) { $obj = new Wholesaler(); $msg = $obj->setDomain($appid); From 798a103e5ef0f6613215067b4bc74eacbbf1f151 Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Tue, 23 Jul 2024 19:09:52 +0800 Subject: [PATCH 50/69] 1 --- app/admin/controller/Wxwholesaler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/admin/controller/Wxwholesaler.php b/app/admin/controller/Wxwholesaler.php index 9ab0a9dd..2de225fd 100644 --- a/app/admin/controller/Wxwholesaler.php +++ b/app/admin/controller/Wxwholesaler.php @@ -291,7 +291,7 @@ class Wxwholesaler extends Controller $appid = $this->request->get('appid', $domain); if ($appid) { $obj = new Wholesaler(); - $msg = $obj->setDomain($appid); + $msg = $obj->setDomain($appid, $domain); if ($msg == 'ok') { return $this->renderSuccess('success'); } From 5dd2e2dd0e42a4da2d29fc0e53b3aba5c1c070ee Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Tue, 23 Jul 2024 19:11:10 +0800 Subject: [PATCH 51/69] 1 --- app/admin/controller/Wxwholesaler.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/admin/controller/Wxwholesaler.php b/app/admin/controller/Wxwholesaler.php index 2de225fd..9d0e8fff 100644 --- a/app/admin/controller/Wxwholesaler.php +++ b/app/admin/controller/Wxwholesaler.php @@ -326,10 +326,11 @@ class Wxwholesaler extends Controller public function modifyJumpDomain(): Json { $msg = 'appid不能为空'; + $domain = $this->request->domain(true); $appid = $this->request->get('appid'); if ($appid) { $obj = new Wholesaler(); - $msg = $obj->modifyJumpDomain($appid); + $msg = $obj->modifyJumpDomain($appid, $domain); if ($msg == 'ok') { return $this->renderSuccess('success'); } @@ -338,7 +339,7 @@ class Wxwholesaler extends Controller } /** - * @notes:设置业务域名 + * @notes:设置订单页 * @return Json * @author: wanghousheng */ From af3e05cf769c4026b0f1cf81db05f564d62379ed Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Tue, 23 Jul 2024 19:13:07 +0800 Subject: [PATCH 52/69] 1 --- app/common/library/wxserver/Wholesaler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/common/library/wxserver/Wholesaler.php b/app/common/library/wxserver/Wholesaler.php index 54bf3008..f7b9d872 100644 --- a/app/common/library/wxserver/Wholesaler.php +++ b/app/common/library/wxserver/Wholesaler.php @@ -85,7 +85,7 @@ class Wholesaler $url = "https://api.weixin.qq.com/wxa/security/applysetorderpathinfo?component_access_token=$token"; $result = $this->curlPost($url, json_encode($data)); $result = json_decode($result, true); - return !empty($result['errcode']) ? $result['errcode'] : $msg; + return !empty($result['errmsg']) ? $result['errmsg'] : $msg; } public function getStableAccessToken() From 09169eb76e046e2f801b6b0970e229f9f4991173 Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Tue, 23 Jul 2024 19:15:20 +0800 Subject: [PATCH 53/69] 1 --- app/admin/controller/Wxwholesaler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/admin/controller/Wxwholesaler.php b/app/admin/controller/Wxwholesaler.php index 9d0e8fff..088e9b84 100644 --- a/app/admin/controller/Wxwholesaler.php +++ b/app/admin/controller/Wxwholesaler.php @@ -335,7 +335,7 @@ class Wxwholesaler extends Controller return $this->renderSuccess('success'); } } - return $this->renderError($msg); + return $this->renderError($domain); } /** From b832ced56ddc68bbdeb087233e3a99f9cf1b16e0 Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Tue, 23 Jul 2024 19:17:46 +0800 Subject: [PATCH 54/69] 1 --- app/admin/controller/Wxwholesaler.php | 2 +- app/common/library/wxserver/Wholesaler.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/admin/controller/Wxwholesaler.php b/app/admin/controller/Wxwholesaler.php index 088e9b84..9d0e8fff 100644 --- a/app/admin/controller/Wxwholesaler.php +++ b/app/admin/controller/Wxwholesaler.php @@ -335,7 +335,7 @@ class Wxwholesaler extends Controller return $this->renderSuccess('success'); } } - return $this->renderError($domain); + return $this->renderError($msg); } /** diff --git a/app/common/library/wxserver/Wholesaler.php b/app/common/library/wxserver/Wholesaler.php index f7b9d872..0d8096a0 100644 --- a/app/common/library/wxserver/Wholesaler.php +++ b/app/common/library/wxserver/Wholesaler.php @@ -656,7 +656,7 @@ class Wholesaler $token = $this->authorizerAccessToken($appid); if ($token) { $url = "https://api.weixin.qq.com/wxa/setwebviewdomain?access_token=$token"; - $data['action'] = 'set'; + $data['action'] = 'add'; $data['webviewdomain'] = $domain; $result = $this->curlPost($url, json_encode($data)); $result = json_decode($result, true); From 352e6238b7a0f569934d5f9013d6ae97b8ff5a14 Mon Sep 17 00:00:00 2001 From: lqmac Date: Tue, 23 Jul 2024 22:39:46 +0800 Subject: [PATCH 55/69] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=95=86=E5=9F=8E?= =?UTF-8?q?=E7=9A=84=E9=98=9F=E5=88=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/queue.php | 2 +- dump.rdb | Bin 0 -> 1554 bytes 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 dump.rdb diff --git a/config/queue.php b/config/queue.php index 52900d43..e505184c 100644 --- a/config/queue.php +++ b/config/queue.php @@ -27,7 +27,7 @@ return [ 'host' => env('redis.hostname', '127.0.0.1'), 'port' => env('redis.hostport', '6379'), 'password' => env('redis.password', ''), - 'select' => 1,//env('redis.select', '0'), + 'select' => 3,//env('redis.select', '0'), 'timeout' => 0, 'persistent' => false, 'retry_after' => 60, // 队列任务无响应时(例如die exit)重试的间隔时间, 默认60秒 diff --git a/dump.rdb b/dump.rdb new file mode 100644 index 0000000000000000000000000000000000000000..38caa2985039ac8126071aa45738d3489d019f97 GIT binary patch literal 1554 zcmZ8eJB$-o6uo1!7%-8MHfRegnm22rEmq6=KP)cx8GnZH`m63H+6(nU~%<;*BJW%xJb4xyMotzmO&BmJE z)SqKv5l+sCz1Er}8qGQU1Mi#!TrdV=tF>$A!O+-^1S0eQ*81$Eg!*85@Ij~`!<{WLU9#4=u->67>r?EQR+9-1cCN8}^1GJ6LPd zowa7MJ=Bx?1--Tp3F`eRU7OT`*14~!yG~wD8_O=(pq5UJrQk^W`YBA%5lB>Gz8H_e z$Rd2NA>{52dbRFwztuh1zaC%pXez&_v`QnI?Pd-oraF5Hx#j89V-ZiR(~liWX5+PE zX>KlWxvwaNuA#{KhQU{F#~?>-&OCoW=wdW0rX%!zHxiAuBas9X;h8$yjUSy#2O3Np z-Gv?Dr88fS8_4N0bIJH9o2+1$4Ha{oO|saH76ljhXD;U?n=GP5qBuh9U?LNFAU9hP zT*%`n8hPwpNT!Tjc@I008#9nXULrNIA?+CDCdfr3Swuqd0QwjOstsZ|&wJ1kIb$(}9o086RBK6_;IKR!1kY(WLBi1*R=kiy6FLi`DOg>K;0sRz5M zn6QrAkh6e9CA@CW9jD&TNvLBIamXVu@l}Z5Isyf+iz<3JC*#bN{CpD?1QLQ4L4qt4 zkPPOsYfe%}v(4pqkQ05^+_P^5k6=#sp4}8&!ivvLRLo}{dv-tGogRxX1$s)NV{~&y z3xA?@+lNN??IpcJ_vf@g+Pw1g$Jg+JDA%zQuTUhUp1*<7l!V;eiyltxzn^(6pyQ7O znsU#)pw4JWE#DEmFhcjIUMN$K@LzX6AcH85(Kq-p_;2}$eB;swVkBR>0}^tkV&_?% zSNIOE7Lrvp>suo8Tz!ydilIWuALbdpo#iT%Tt^Pqxr|mw=Ejg~9ud_rbI*}0%gaZE z97KO#>!n{_IwpHcgBt{D!A!dz9B7hWR9eN$y)|iT+}KVe0WH9f_(+Dd&p eGaSUTI}s*-cpz<;{HffBd%u16(+{_!j(-77e&f~v literal 0 HcmV?d00001 From 8b260737e2db4882ee186678958104dac7433f08 Mon Sep 17 00:00:00 2001 From: lqmac Date: Wed, 24 Jul 2024 01:08:08 +0800 Subject: [PATCH 56/69] 1 --- app/command/SyncCategoryAdmin.php | 329 ++++++++++++++ app/command/SyncStoreBasicData.php | 8 +- app/command/SyncStoreBasicDataAdmin.php | 565 ++++++++++++++++++++++++ config/database.php | 38 ++ 4 files changed, 936 insertions(+), 4 deletions(-) create mode 100644 app/command/SyncCategoryAdmin.php create mode 100644 app/command/SyncStoreBasicDataAdmin.php diff --git a/app/command/SyncCategoryAdmin.php b/app/command/SyncCategoryAdmin.php new file mode 100644 index 00000000..f963579c --- /dev/null +++ b/app/command/SyncCategoryAdmin.php @@ -0,0 +1,329 @@ +setName('SyncCategory')->setDescription('同步商品数据到ES'); + $this->addArgument("store_id"); + $this->addArgument("is_update_image"); + } + + + protected function execute(Input $input, Output $output) + { + // $store_id = $input->getArgument("store_id"); + $is_update_image = $input->getArgument("is_update_image"); + // $where[] = ['is_sync_cate','=', 1]; + // $where[] = ['is_delete','=', 0]; + // $where[] = ['is_recycle','=', 0]; + // $where[] = ['status','=', 1]; + + // if ($store_id) { + // $where[] = ['store_id','=', $store_id]; + // } else { + // $where[] = ['store_id', '<>', self::DEFAULT_STORE_ID]; + // } + // $stores = Store::where($where)->field('store_id,is_sync,is_recycle,status,is_delete')->select()->toArray(); + // if (!$stores) { + // echo "没有要同步的商城了"; + // return; + // } + // foreach ($stores as $store) { + $this->copyCategory(0, $is_update_image); + //} + } + + public function copyCategory(int $new_store_id, $is_update_image = 0){ + $store_id = 0; + $model = new CategoryModel; + $list = Db::connect("shopMysql")->name('yoshop_category')->where('store_id', 0)->order(['sort', 'create_time'])->select(); + $list = $this->getTreeData($list); + //$list = $model->getList(['store_id' => self::DEFAULT_STORE_ID]); + // var_dump($list); + // exit(); + if (!$list) { + return; + } + foreach ($list as $value) { + //$value = $value->toArray(); + if ($value['status'] != 1) { + continue; + } + $category = CategoryModel::where('original_category_id', $value['category_id'])->where('store_id', $new_store_id)->find(); + if ($category) { + //更新分类 + //父类id + if ($value['parent_id']) { + $p_category = CategoryModel::where('original_category_id', $value['parent_id'])->where('store_id', $new_store_id)->find(); + } + $upData = [ + 'name' => $value['name'], + 'level' => $value['level'], + 'sort' => $value['sort'], + 'parent_id' => $p_category['category_id'] ?? 0, + ]; + if ($is_update_image) { + $upData['image_id'] = $value['image_id'] ? $this->copyImage($value['image_id'], $new_store_id) : 0; + $upData['rank_image_id'] = $value['rank_image_id'] ? $this->copyImage($value['rank_image_id'], $new_store_id) : 0; + } + // var_dump($upData); + // exit(); + $ret = CategoryModel::where('category_id', $category->category_id)->update($upData); + echo "更新成功".PHP_EOL; + var_dump($ret); + $firstid = $category->category_id; + } else { + //新增一个分类 + $value['store_id'] = $new_store_id; + $value['create_time'] = time(); + $value['update_time'] = time(); + $value['image_id'] = $value['image_id'] ? $this->copyImage($value['image_id'], $new_store_id) : 0; + $value['rank_image_id'] = $value['rank_image_id'] ? $this->copyImage($value['rank_image_id'], $new_store_id) : 0; + $value['original_category_id'] = $value['category_id']; + $temp = $value; + unset($temp['children']); + unset($temp['rankimage']); + unset($temp['image']); + unset($temp['category_id']); + $firstid = Db::table('yoshop_category')->insertGetId($temp); + } + + if (!isset($value['children']) || !$value['children']) { + continue; + } + foreach ($value['children'] as $value1) { + //$value1 = $value1->toArray(); + if ($value1['status'] != 1) { + continue; + } + $category1 = CategoryModel::where('original_category_id', $value1['category_id'])->where('store_id', $new_store_id)->find(); + //var_dump($category1->toArray()); + if ($category1) { + //更新分类 + //父类id + $p_category1 = CategoryModel::where('original_category_id', $value1['parent_id'])->where('store_id', $new_store_id)->find(); + // var_dump($p_category1); + // exit(); + $upData1 = [ + 'name' => $value1['name'], + 'level' => $value1['level'], + 'sort' => $value1['sort'], + 'parent_id' => $p_category1['category_id'] ?? 0, + ]; + if ($is_update_image) { + $upData1['image_id'] = $value1['image_id'] ? $this->copyImage($value1['image_id'], $new_store_id) : 0; + $upData1['rank_image_id'] = $value1['rank_image_id'] ? $this->copyImage($value1['rank_image_id'], $new_store_id) : 0; + } + $ret = CategoryModel::where('category_id', $category1->category_id)->update($upData1); + echo "更新成功".PHP_EOL; + var_dump($ret); + $secondid = $category1->category_id; + } else { + //新增一个分类 + $value1['parent_id'] = $firstid; + $value1['store_id'] = $new_store_id; + $value1['create_time'] = time(); + $value1['update_time'] = time(); + $value1['image_id'] = $value1['image_id'] ? $this->copyImage($value1['image_id'], $new_store_id) : 0; + $value1['rank_image_id'] = $value1['rank_image_id'] ? $this->copyImage($value1['rank_image_id'], $new_store_id) : 0; + $value1['original_category_id'] = $value1['category_id']; + $temp1 = $value1; + unset($temp1['children']); + unset($temp1['image']); + unset($temp1['rankimage']); + unset($temp1['category_id']); + + $secondid = Db::table('yoshop_category')->insertGetId($temp1); + } + + if (!isset($value1['children']) || !$value1['children']) { + continue; + } + foreach ($value1['children'] as $value2) { + //$value2 = $value2->toArray(); + if ($value2['status'] != 1) { + continue; + } + $category2 = CategoryModel::where('original_category_id', $value2['category_id'])->where('store_id', $new_store_id)->find(); + if ($category2) { + //更新分类 + //父类id + $p_category2 = CategoryModel::where('original_category_id', $value2['parent_id'])->where('store_id', $new_store_id)->find(); + $upData2 = [ + 'name' => $value2['name'], + 'level' => $value2['level'], + 'sort' => $value2['sort'], + 'parent_id' => $p_category2['category_id'] ?? 0, + ]; + if ($is_update_image) { + $upData2['image_id'] = $value2['image_id'] ? $this->copyImage($value2['image_id'], $new_store_id) : 0; + $upData2['rank_image_id'] = $value2['rank_image_id'] ? $this->copyImage($value2['rank_image_id'], $new_store_id) : 0; + } + $ret = CategoryModel::where('category_id', $category2->category_id)->update($upData2); + echo "更新成功".PHP_EOL; + var_dump($ret); + $thirdid = $category2->category_id; + } else { + //新增一个分类 + $value2['parent_id'] = $secondid; + $value2['store_id'] = $new_store_id; + $value2['create_time'] = time(); + $value2['update_time'] = time(); + $value2['image_id'] = $value2['image_id'] ? $this->copyImage($value2['image_id'], $new_store_id) : 0; + $value2['rank_image_id'] = $value2['rank_image_id'] ? $this->copyImage($value2['rank_image_id'], $new_store_id) : 0; + $value2['original_category_id'] = $value2['category_id']; + $temp2 = $value2; + unset($temp2['children']); + unset($temp2['image']); + unset($temp2['rankimage']); + unset($temp2['category_id']); + + $thirdid = Db::table('yoshop_category')->insertGetId($temp2); + } + + if (!isset($value2['children']) || !$value2['children']) { + continue; + } + foreach ($value2['children'] as $value3) { + //$value3 = $value3->toArray(); + if ($value3['status'] != 1) { + continue; + } + + $category3 = CategoryModel::where('original_category_id', $value3['category_id'])->where('store_id', $new_store_id)->find(); + if ($category3) { + //更新分类 + //父类id + $p_category3 = CategoryModel::where('original_category_id', $value3['parent_id'])->where('store_id', $new_store_id)->find(); + $upData3 = [ + 'name' => $value3['name'], + 'level' => $value3['level'], + 'sort' => $value3['sort'], + 'parent_id' => $p_category3['category_id'] ?? 0, + ]; + if ($is_update_image) { + $upData3['image_id'] = $value3['image_id'] ? $this->copyImage($value3['image_id'], $new_store_id) : 0; + $upData3['rank_image_id'] = $value3['rank_image_id'] ? $this->copyImage($value3['rank_image_id'], $new_store_id) : 0; + } + $ret = CategoryModel::where('category_id', $category3->category_id)->update($upData3); + echo "更新成功".PHP_EOL; + var_dump($ret); + $fourthid = $category3->category_id; + } else { + $value3['parent_id'] = $thirdid; + $value3['store_id'] = $new_store_id; + $value3['create_time'] = time(); + $value3['update_time'] = time(); + $value3['image_id'] = $value3['image_id'] ? $this->copyImage($value3['image_id'], $new_store_id) : 0; + $value3['rank_image_id'] = $value3['rank_image_id'] ? $this->copyImage($value3['rank_image_id'], $new_store_id) : 0; + $value3['original_category_id'] = $value3['category_id']; + $temp3 = $value3; + unset($temp3['children']); + unset($temp3['image']); + unset($temp3['rankimage']); + unset($temp3['category_id']); + + $fourthid = Db::table('yoshop_category')->insertGetId($temp3); + } + + + if (!isset($value3['children']) || !$value3['children']) { + continue; + } + foreach ($value3['children'] as $value4) { + //$value4 = $value4->toArray(); + if ($value4['status'] != 1) { + continue; + } + + $category4 = CategoryModel::where('original_category_id', $value4['category_id'])->where('store_id', $new_store_id)->find(); + if ($category4) { + //更新分类 + //父类id + $p_category4 = CategoryModel::where('original_category_id', $value4['parent_id'])->where('store_id', $new_store_id)->find(); + $upData4 = [ + 'name' => $value4['name'], + 'level' => $value4['level'], + 'sort' => $value4['sort'], + 'parent_id' => $p_category4['category_id'] ?? 0, + ]; + if ($is_update_image) { + $upData4['image_id'] = $value4['image_id'] ? $this->copyImage($value4['image_id'], $new_store_id) : 0; + $upData4['rank_image_id'] = $value4['rank_image_id'] ? $this->copyImage($value4['rank_image_id'], $new_store_id) : 0; + } + $ret = CategoryModel::where('category_id', $category4->category_id)->update($upData4); + echo "更新成功".PHP_EOL; + var_dump($ret); + } else { + $value4['parent_id'] = $fourthid; + $value4['store_id'] = $new_store_id; + $value4['create_time'] = time(); + $value4['update_time'] = time(); + $value4['image_id'] = $value4['image_id'] ? $this->copyImage($value4['image_id'], $new_store_id) : 0; + $value4['rank_image_id'] = $value4['rank_image_id'] ? $this->copyImage($value4['rank_image_id'], $new_store_id) : 0; + $value4['original_category_id'] = $value4['category_id']; + $temp4 = $value4; + unset($temp4['children']); + unset($temp4['image']); + unset($temp4['rankimage']); + unset($temp4['category_id']); + + Db::table('yoshop_category')->insertGetId($temp4); + } + + + } + } + } + } + } + } + + public function copyImage($image_id, $store_id){ + $upload_file = Db::connect("shopMysql")->name('yoshop_upload_file')->where('file_id', $image_id)->find(); + if (!$upload_file) { + return 0; + } + $upload_file['store_id'] = $store_id; + $upload_file['create_time'] = time(); + unset($upload_file['file_id']); + $new_image_id = DB::table("yoshop_upload_file")->insertGetId($upload_file); + return $new_image_id; + } + + /** + * 获取树状列表 + * @param $list + * @param int $parentId + * @return array + */ + private function getTreeData($list, int $parentId = 0): array + { + $data = []; + foreach ($list as $key => $item) { + if ($item['parent_id'] == $parentId) { + $children = $this->getTreeData($list, $item['category_id']); + !empty($children) && $item['children'] = $children; + $data[] = $item; + unset($list[$key]); + } + } + return $data; + } + +} \ No newline at end of file diff --git a/app/command/SyncStoreBasicData.php b/app/command/SyncStoreBasicData.php index 3d2df4bb..7b3f83f8 100644 --- a/app/command/SyncStoreBasicData.php +++ b/app/command/SyncStoreBasicData.php @@ -26,7 +26,7 @@ use app\store\model\Setting; // /www/server/php/74/bin/php /server/wwwroot/yanzong/think test class SyncStoreBasicData extends Command { - const DEFAULT_STORE_ID = 10048; + const DEFAULT_STORE_ID = 10063; protected function configure() { @@ -86,9 +86,9 @@ class SyncStoreBasicData extends Command if ($isSyncRecoveryData) { $this->syncRecoveryData($store); } - if ($isSyncServerData) { - $this->syncServerData($store); - } + // if ($isSyncServerData) { + // $this->syncServerData($store); + // } if ($isSyncBannerData) { $this->syncBannerData($store); } diff --git a/app/command/SyncStoreBasicDataAdmin.php b/app/command/SyncStoreBasicDataAdmin.php new file mode 100644 index 00000000..d77ddc86 --- /dev/null +++ b/app/command/SyncStoreBasicDataAdmin.php @@ -0,0 +1,565 @@ +setName('SyncStoreBasicData')->setDescription('同步商城基础数据'); + $this->addArgument("store_id"); + $this->addArgument("isSyncMaintenanceData"); + $this->addArgument("isSyncHelpData"); + $this->addArgument("isSyncRichTextData"); + $this->addArgument("isSyncRecoveryData"); + $this->addArgument("isSyncServerData"); + $this->addArgument("isSyncBannerData"); + $this->addArgument("isSyncStoreSettingData"); + $this->addArgument("isSyncStoreExpressData"); + } + + protected function execute(Input $input, Output $output) + { + $store_id = $input->getArgument("store_id"); + $isSyncMaintenanceData = $input->getArgument("isSyncMaintenanceData"); + $isSyncHelpData = $input->getArgument("isSyncHelpData"); + $isSyncRichTextData = $input->getArgument("isSyncRichTextData"); + $isSyncRecoveryData = $input->getArgument("isSyncRecoveryData"); + $isSyncServerData = $input->getArgument("isSyncServerData"); + $isSyncBannerData = $input->getArgument("isSyncBannerData"); + $isSyncStoreSettingData = $input->getArgument("isSyncStoreSettingData"); + $isSyncStoreExpressData = $input->getArgument("isSyncStoreExpressData"); + + $where[] = ['is_sync','=', 0]; + $where[] = ['is_delete','=', 0]; + $where[] = ['is_recycle','=', 0]; + $where[] = ['status','=', 1]; + + if ($store_id) { + $where[] = ['store_id','=', $store_id]; + } else { + $where[] = ['store_id', '<>', self::DEFAULT_STORE_ID]; + } + $stores = Store::where($where)->field('store_id,is_sync,is_recycle,status,is_delete')->select()->toArray(); + // echo "
";
+        // print_r($stores);
+        // exit();
+        if (!$stores) {
+            echo "没有要同步的商城了";
+            return;
+        }
+        foreach ($stores as $store) {
+            if ($isSyncMaintenanceData) {
+               $this->syncMaintenanceData($store);
+            }
+            if ($isSyncHelpData) {
+               $this->syncHelpData($store);
+            }
+            if ($isSyncRichTextData) {
+               $this->syncRichTextData($store);
+            }
+            if ($isSyncRecoveryData) {
+               $this->syncRecoveryData($store);
+            }
+            if ($isSyncServerData) {
+               $this->syncServerData($store);
+            }
+            if ($isSyncBannerData) {
+               $this->syncBannerData($store);
+            }
+            if ($isSyncStoreSettingData) {
+               $this->syncStoreSettingData($store);
+            }
+            if ($isSyncStoreExpressData) {
+               $this->syncStoreExpressData($store);
+            }
+            Store::where('store_id', $store['store_id'])->update(['is_sync' => 1]);
+        }
+        
+
+    }
+    /**
+     * 同步物流公司
+     * [syncStoreExpressData description]
+     * @param  [type] $store [description]
+     * @return [type]        [description]
+     */
+    private function syncStoreExpressData($store){
+        //维修分类数据同步
+        $expressList =  Db::connect("shopMysql")->name('yoshop_express')->where('store_id',self::DEFAULT_STORE_ID)->select()->toArray();
+        if ($expressList) {
+            foreach ($expressList as &$express) {
+                $info = Express::where('store_id', $store['store_id'])->where('kuaidi100_code', $express['kuaidi100_code'])->where('kdniao_code', $express['kdniao_code'])->find();
+                if ($info) {
+                    echo $express['express_id']."物流公司已存在".PHP_EOL;
+                    $ret = Express::where('store_id', $store['store_id'])->where('express_id', $info['express_id'])->update([
+                        'express_name' => $express['express_name'],
+                        'kuaidi100_code' => $express['kuaidi100_code'],
+                        'kdniao_code' => $express['kdniao_code'],
+                        'original_id' => $express['express_id'],
+                    ]);
+                    var_dump($ret);
+                    continue;
+                }
+                $express['create_time'] = time();
+                $express['update_time'] = time();
+                $express['original_id'] = $express['express_id'];
+                $express['store_id'] = $store['store_id'];
+                unset($express['express_id']);
+                $ret = Express::create($express);
+                var_dump($ret->express_id);
+            }
+            unset($express);
+        }
+    }
+    /**
+     * 同步基本信息,七牛云、快递100、99api的配置
+     * [syncSettingData description]
+     * @param  [type] $store [description]
+     * @return [type]        [description]
+     */
+    private function syncStoreSettingData($store){
+        //99api配置
+        // $collector = Setting::where('key','collector')->where('store_id', $store['store_id'])->find();
+
+        // if (!$collector) {
+        //     $collectorData = [
+        //         "key" => "collector",
+        //         "describe" => "商品采集设置",
+        //         "values" => json_decode('{"config":{"99api":{"apiKey":"9271DA7BF37C6F50BED49B7F0ADD49A2"}}}', true),
+        //         "store_id" => $store['store_id'],
+        //         "create_time" => time(),
+        //         "update_time" => time(),
+        //     ];
+        //     $ret = Setting::create($collectorData);
+        //     echo "99api配置新增成功";
+        //     var_dump($ret->key);
+        // }
+        //配送设置
+        $delivery = Setting::where('key','delivery')->where('store_id', $store['store_id'])->find();
+
+        if (!$delivery) {
+            $deliveryData = [
+                "key" => "delivery",
+                "describe" => "配送设置",
+                "values" => json_decode('{"traces":{"enable":1,"default":"kd100","providerConfig":{"kd100":{"customer":"F6CAEF5CEA6B5BF219149B9B42BECAA1","key":"pjVBLUai1633"},"aliyun":{"appCode":""}}},"delivery_type":[10,20,30]}', true),
+                "store_id" => $store['store_id'],
+                "create_time" => time(),
+                "update_time" => time(),
+            ];
+            $ret = Setting::create($deliveryData);
+            echo "配送设置新增成功";
+            var_dump($ret->key);
+        }
+        //上传设置
+        $storage = Setting::where('key','storage')->where('store_id', $store['store_id'])->find();
+        if (!$storage) {
+            $storageData = [
+                "key" => "storage",
+                "describe" => "上传设置",
+                "values" => json_decode('{"default":"qiniu","engine":{"qiniu":{"bucket":"saasyovo","access_key":"ehSHgkSkS9lGex8n0-vMf1-wkbgi56yv6fhEwsYS","secret_key":"jNXsuPmTnmfiRlNs-JoAmT833o0qusgXrXqeR3VK","domain":"https:\/\/qiniu.shop.royaum.com.cn"},"aliyun":{"bucket":"","access_key_id":"","access_key_secret":"","domain":"http:\/\/"},"qcloud":{"bucket":"","region":"","secret_id":"","secret_key":"","domain":"http:\/\/"}}}', true),
+                "store_id" => $store['store_id'],
+                "create_time" => time(),
+                "update_time" => time(),
+            ];
+            $ret = Setting::create($storageData);
+            echo "上传设置新增成功";
+            var_dump($ret->key);
+        }
+    }
+    /**
+     * 同步富文本数据
+     * [syncHelpData description]
+     * @param  [type] $store [description]
+     * @return [type]        [description]
+     */
+    private function syncRichTextData($store){
+        //维修分类数据同步
+        $agreementList =  Db::connect("shopMysql")->name('yoshop_agreement')->where('store_id',self::DEFAULT_STORE_ID)->select()->toArray();
+        if ($agreementList) {
+            foreach ($agreementList as &$agreement) {
+                $info = Agreement::where('store_id', $store['store_id'])->where('original_id', $agreement['id'])->find();
+                if ($info) {
+                    echo $agreement['id']."富文本已存在".PHP_EOL;
+                    continue;
+                }
+                $agreement['create_time'] = time();
+                $agreement['update_time'] = time();
+                $agreement['original_id'] = $agreement['id'];
+                $agreement['store_id'] = $store['store_id'];
+                unset($agreement['id']);
+                $ret = Agreement::create($agreement);
+                var_dump($ret->id);
+            }
+            unset($agreement);
+        }
+    }
+    /**
+     * 同步帮助中心数据
+     * [syncHelpData description]
+     * @param  [type] $store [description]
+     * @return [type]        [description]
+     */
+    private function syncHelpData($store){
+        //维修分类数据同步
+        $articleCategoryList =  Db::connect("shopMysql")->name('yoshop_article_category')->where('store_id',self::DEFAULT_STORE_ID)->where('status', 1)->select()->toArray();
+        if ($articleCategoryList) {
+            foreach ($articleCategoryList as &$articleCategory) {
+                $info = Category::where('store_id', $store['store_id'])->where('original_id', $articleCategory['category_id'])->find();
+                if ($info) {
+                    echo $articleCategory['category_id']."帮助分类已存在".PHP_EOL;
+                    continue;
+                }
+                $articleCategory['create_time'] = time();
+                $articleCategory['update_time'] = time();
+                $articleCategory['original_id'] = $articleCategory['category_id'];
+                $articleCategory['store_id'] = $store['store_id'];
+                unset($articleCategory['category_id']);
+
+                //复制图片
+                $upload_file = Db::connect("shopMysql")->name('yoshop_upload_file')->where('file_id', $articleCategory['img_id'])->find();
+                if ($upload_file) {
+                    $upload_file['store_id'] = $store['store_id'];
+                    $upload_file['create_time'] = time();
+                    unset($upload_file['file_id']);
+                    $image_id = Db::name('upload_file')->insertGetId($upload_file);
+                }
+                //写入维修数据
+                $articleCategory['img_id'] = $image_id ?? 0;
+                $ret = Category::create($articleCategory);
+                var_dump($ret->id);
+            }
+            unset($articleCategory);
+        }
+        
+        //维修数据同步
+        $articleList =  Db::connect("shopMysql")->name('yoshop_article')->where('store_id',self::DEFAULT_STORE_ID)->where('is_delete', 0)->where('status', 1)->select()->toArray();
+        if ($articleList) {
+            foreach ($articleList as &$article) {
+                $info = Article::where('store_id', $store['store_id'])->where('original_id', $article['article_id'])->find();
+                if ($info) {
+                    echo $article['article_id']."帮助已存在".PHP_EOL;
+                    continue;
+                }
+                //查询分类id
+                $articleCategory = Category::where('original_id', $article['category_id'])->where('store_id', $store['store_id'])->find();
+                if (!$articleCategory) {
+                    continue;
+                }
+                $article['create_time'] = time();
+                $article['update_time'] = time();
+                $article['original_id'] = $article['article_id'];
+                $article['category_id'] = $articleCategory['category_id'];
+                $article['store_id'] = $store['store_id'];
+                unset($article['article_id']);
+                //复制图片
+                $upload_file = Db::connect("shopMysql")->name('yoshop_upload_file')->where('file_id', $article['image_id'])->find();
+                if ($upload_file) {
+                    $upload_file['store_id'] = $store['store_id'];
+                    $upload_file['create_time'] = time();
+                    unset($upload_file['file_id']);
+                    $image_id = Db::name('upload_file')->insertGetId($upload_file);
+                }
+                //写入维修数据
+                $article['image_id'] = $image_id;
+                $ret = Article::create($article);
+                //写入图片id
+                var_dump($ret->id);
+            }
+            unset($article);
+        }
+    }
+    /**
+     * 同步维修数据
+     * [syncMaintenanceData description]
+     * @param  [type] $store [description]
+     * @return [type]        [description]
+     */
+    private function syncMaintenanceData($store){
+        //维修分类数据同步
+        $maintenanceCategoryList =  Db::connect("shopMysql")->name('yoshop_maintenance_category')->where('store_id',self::DEFAULT_STORE_ID)->where('status', 1)->select()->toArray();
+       
+        if ($maintenanceCategoryList) {
+            foreach ($maintenanceCategoryList as &$maintenanceCategory) {
+                $info = MaintenanceCategory::where('store_id', $store['store_id'])->where('original_id', $maintenanceCategory['id'])->find();
+                if ($info) {
+                    echo $maintenanceCategory['id']."维修分类已存在".PHP_EOL;
+                    continue;
+                }
+                $maintenanceCategory['create_time'] = time();
+                $maintenanceCategory['update_time'] = time();
+                $maintenanceCategory['original_id'] = $maintenanceCategory['id'];
+                $maintenanceCategory['store_id'] = $store['store_id'];
+                unset($maintenanceCategory['id']);
+                // echo "
";
+                // print_r($maintenanceCategory);
+                // exit();
+                $ret = MaintenanceCategory::create($maintenanceCategory);
+                var_dump($ret->id);
+            }
+            unset($maintenanceCategory);
+        }
+        
+        //维修数据同步
+        $maintenanceList =  Db::connect("shopMysql")->name('yoshop_maintenance')->where('store_id',self::DEFAULT_STORE_ID)->where('is_delete', 0)->select()->toArray();
+        
+        if ($maintenanceList) {
+            foreach ($maintenanceList as &$maintenance) {
+                $info = Maintenance::where('store_id', $store['store_id'])->where('original_id', $maintenance['id'])->find();
+                if ($info) {
+                    echo $maintenance['id']."维修已存在".PHP_EOL;
+                    continue;
+                }
+                // echo "
";
+                // print_r($info);
+                // exit();
+                //查询分类id
+                $maintenanceCategory = MaintenanceCategory::where('original_id', $maintenance['category_id'])->where('store_id', $store['store_id'])->find();
+                if (!$maintenanceCategory) {
+                    continue;
+                }
+                $maintenance['create_time'] = time();
+                $maintenance['update_time'] = time();
+                $maintenance['original_id'] = $maintenance['id'];
+                $maintenance['category_id'] = $maintenanceCategory['id'];
+                $maintenance['store_id'] = $store['store_id'];
+                unset($maintenance['id']);
+                //复制图片
+                $upload_file = Db::connect("shopMysql")->name('yoshop_upload_file')->where('file_id', $maintenance['img_id'])->find();
+                if ($upload_file) {
+                    $upload_file['store_id'] = $store['store_id'];
+                    $upload_file['create_time'] = time();
+                    unset($upload_file['file_id']);
+                    // echo "
";
+                    // print_r($upload_file);
+                    // exit();
+                    $image_id = Db::name('upload_file')->insertGetId($upload_file);
+                }
+                
+                //写入维修数据
+                $maintenance['img_id'] = $image_id ?? 0;
+                $ret = Maintenance::create($maintenance);
+                //写入图片id
+                var_dump($ret->id);
+            }
+            unset($maintenance);
+        }
+    }
+
+     /**
+     * 同步回收数据
+     * [syncHelpData description]
+     * @param  [type] $store [description]
+     * @return [type]        [description]
+     */
+    private function syncRecoveryData($store){
+        //维修分类数据同步
+        $articleCategoryList =  Db::connect("shopMysql")->name('yoshop_server_recovery_category')->where('store_id',self::DEFAULT_STORE_ID)->where('status', 1)->select()->toArray();
+        if ($articleCategoryList) {
+            foreach ($articleCategoryList as &$articleCategory) {
+                $info = RecoveryCategory::where('store_id', $store['store_id'])->where('original_id', $articleCategory['category_id'])->find();
+                if ($info) {
+                    echo $articleCategory['category_id']."回收已存在".PHP_EOL;
+                    continue;
+                }
+                $articleCategory['create_time'] = time();
+                $articleCategory['update_time'] = time();
+                $articleCategory['original_id'] = $articleCategory['category_id'];
+                $articleCategory['store_id'] = $store['store_id'];
+                unset($articleCategory['category_id']);
+
+                //复制图片
+                $upload_file = Db::connect("shopMysql")->name('yoshop_upload_file')->where('file_id', $articleCategory['image_id'])->find();
+                if ($upload_file) {
+                    $upload_file['store_id'] = $store['store_id'];
+                    $upload_file['create_time'] = time();
+                    unset($upload_file['file_id']);
+                    $image_id = Db::name('upload_file')->insertGetId($upload_file);
+                }
+                //写入维修数据
+                $articleCategory['image_id'] = $image_id ?? 0;
+                $ret = RecoveryCategory::create($articleCategory);
+                var_dump($ret->category_id);
+            }
+            unset($articleCategory);
+        }
+        
+        //维修数据同步
+        $articleList =  Db::connect("shopMysql")->name('yoshop_server_recovery')->where('store_id',self::DEFAULT_STORE_ID)->where('status', 1)->select()->toArray();
+        if ($articleList) {
+            foreach ($articleList as &$article) {
+                $info = ServerRecovery::where('store_id', $store['store_id'])->where('original_id', $article['recovery_id'])->find();
+                if ($info) {
+                    echo $article['recovery_id']."回收已存在".PHP_EOL;
+                    continue;
+                }
+                //查询分类id
+                $articleCategory = RecoveryCategory::where('original_id', $article['category_id'])->where('store_id', $store['store_id'])->find();
+                if (!$articleCategory) {
+                    continue;
+                }
+                $article['create_time'] = time();
+                $article['update_time'] = time();
+                $article['original_id'] = $article['recovery_id'];
+                $article['category_id'] = $articleCategory['category_id'];
+                $article['store_id'] = $store['store_id'];
+                unset($article['recovery_id']);
+                //复制图片
+                $upload_file = Db::connect("shopMysql")->name('yoshop_upload_file')->where('file_id', $article['image_id'])->find();
+                if ($upload_file) {
+                    $upload_file['store_id'] = $store['store_id'];
+                    $upload_file['create_time'] = time();
+                    unset($upload_file['file_id']);
+                    $image_id = Db::name('upload_file')->insertGetId($upload_file);
+                }
+                //写入维修数据
+                $article['image_id'] = $image_id;
+                $ret = ServerRecovery::create($article);
+                //写入图片id
+                var_dump($ret->recovery_id);
+            }
+            unset($article);
+        }
+    }
+
+     /**
+     * 同步服务数据
+     * [syncHelpData description]
+     * @param  [type] $store [description]
+     * @return [type]        [description]
+     */
+    private function syncServerData($store){
+        //服务分类数据同步
+        $articleCategoryList =  Db::connect("shopMysql")->name('yoshop_server_category')->where('store_id',self::DEFAULT_STORE_ID)->where('status', 1)->select()->toArray();
+        if ($articleCategoryList) {
+            foreach ($articleCategoryList as &$articleCategory) {
+                $info = ServerCategory::where('store_id', $store['store_id'])->where('original_id', $articleCategory['category_id'])->find();
+                if ($info) {
+                    echo $articleCategory['category_id']."服务分类已存在".PHP_EOL;
+                    continue;
+                }
+                $articleCategory['create_time'] = time();
+                $articleCategory['update_time'] = time();
+                $articleCategory['original_id'] = $articleCategory['category_id'];
+                $articleCategory['store_id'] = $store['store_id'];
+                unset($articleCategory['category_id']);
+
+                //复制图片
+                $upload_file = Db::connect("shopMysql")->name('yoshop_upload_file')->where('file_id', $articleCategory['image_id'])->find();
+                if ($upload_file) {
+                    $upload_file['store_id'] = $store['store_id'];
+                    $upload_file['create_time'] = time();
+                    unset($upload_file['file_id']);
+                    $image_id = Db::name('upload_file')->insertGetId($upload_file);
+                }
+                //写入维修数据
+                $articleCategory['image_id'] = $image_id ?? 0;
+                $ret = ServerCategory::create($articleCategory);
+                var_dump($ret->category_id);
+            }
+            unset($articleCategory);
+        }
+        
+        //服务数据同步
+        $articleList =  Db::connect("shopMysql")->name('yoshop_server')->where('store_id',self::DEFAULT_STORE_ID)->where('status', 1)->select()->toArray();
+        if ($articleList) {
+            foreach ($articleList as &$article) {
+                $info = Server::where('store_id', $store['store_id'])->where('original_id', $article['server_id'])->find();
+                if ($info) {
+                    echo $article['server_id']."服务已存在".PHP_EOL;
+                    continue;
+                }
+                //查询分类id
+                $articleCategory = ServerCategory::where('original_id', $article['category_id'])->where('store_id', $store['store_id'])->find();
+                if (!$articleCategory) {
+                    continue;
+                }
+                $article['create_time'] = time();
+                $article['update_time'] = time();
+                $article['original_id'] = $article['server_id'];
+                $article['category_id'] = $articleCategory['category_id'];
+                $article['store_id'] = $store['store_id'];
+                unset($article['server_id']);
+                //复制图片
+                $upload_file = Db::connect("shopMysql")->name('yoshop_upload_file')->where('file_id', $article['image_id'])->find();
+                if ($upload_file) {
+                    $upload_file['store_id'] = $store['store_id'];
+                    $upload_file['create_time'] = time();
+                    unset($upload_file['file_id']);
+                    $image_id = Db::name('upload_file')->insertGetId($upload_file);
+                }
+                //写入维修数据
+                $article['image_id'] = $image_id;
+                $ret = Server::create($article);
+                //写入图片id
+                var_dump($ret->server_id);
+            }
+            unset($article);
+        }
+    }
+    /**
+     * 同步轮播图数据
+     * [syncHelpData description]
+     * @param  [type] $store [description]
+     * @return [type]        [description]
+     */
+    private function syncBannerData($store){
+        //服务分类数据同步
+        $articleCategoryList =  Db::connect("shopMysql")->name('yoshop_banner')->where('store_id',self::DEFAULT_STORE_ID)->where('status', 10)->select()->toArray();
+        if ($articleCategoryList) {
+            foreach ($articleCategoryList as &$articleCategory) {
+                $info = Banner::where('store_id', $store['store_id'])->where('original_id', $articleCategory['id'])->find();
+                if ($info) {
+                    echo $articleCategory['id']."轮播图已存在".PHP_EOL;
+                    continue;
+                }
+                $articleCategory['create_time'] = time();
+                $articleCategory['update_time'] = time();
+                $articleCategory['original_id'] = $articleCategory['id'];
+                $articleCategory['store_id'] = $store['store_id'];
+                unset($articleCategory['id']);
+                unset($articleCategory['redirect_url']);
+
+                //复制图片
+                $upload_file = Db::connect("shopMysql")->name('yoshop_upload_file')->where('file_id', $articleCategory['image_id'])->find();
+                if ($upload_file) {
+                    $upload_file['store_id'] = $store['store_id'];
+                    $upload_file['create_time'] = time();
+                    unset($upload_file['file_id']);
+                    $image_id = Db::name('upload_file')->insertGetId($upload_file);
+                }
+                //写入维修数据
+                $articleCategory['image_id'] = $image_id ?? 0;
+                $ret = Banner::create($articleCategory);
+                var_dump($ret->id);
+            }
+            unset($articleCategory);
+        }
+        
+    }
+}
diff --git a/config/database.php b/config/database.php
index cf68d182..bab4bb65 100644
--- a/config/database.php
+++ b/config/database.php
@@ -111,7 +111,45 @@ return [
             // 字段缓存路径
             'schema_cache_path' => app()->getRuntimePath() . 'schema' . DIRECTORY_SEPARATOR,
         ],
+        'shopMysql' => [
+            // 数据库类型
+            'type' => env('sdatabase.type', 'mysql'),
+            // 服务器地址
+            'hostname' => env('sdatabase.hostname', $config['host']),
+            // 数据库名
+            'database' => env('sdatabase.database', $config['database']),
+            // 用户名
+            'username' => env('sdatabase.username', $config['username']),
+            // 密码
+            'password' => env('sdatabase.password', $config['password']),
+            // 端口
+            'hostport' => env('sdatabase.hostport', $config['hostport']),
+            // 数据库连接参数
+            'params' => [],
+            // 数据库编码默认采用utf8
+            'charset' => env('sdatabase.charset', 'utf8'),
+            // 数据库表前缀
+            'prefix' => "",
 
+            // 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器)
+            'deploy' => 0,
+            // 数据库读写是否分离 主从式有效
+            'rw_separate' => false,
+            // 读写分离后 主服务器数量
+            'master_num' => 1,
+            // 指定从服务器序号
+            'slave_no' => '',
+            // 是否严格检查字段是否存在
+            'fields_strict' => true,
+            // 是否需要断线重连
+            'break_reconnect' => false,
+            // 监听SQL
+            'trigger_sql' => true,
+            // 开启字段缓存
+            'fields_cache' => false,
+            // 字段缓存路径
+            'schema_cache_path' => app()->getRuntimePath() . 'schema' . DIRECTORY_SEPARATOR,
+        ],
         // 更多的数据库配置信息
     ],
     

From df548667ad92c0400694faae941253cb1595d635 Mon Sep 17 00:00:00 2001
From: lqmac 
Date: Thu, 25 Jul 2024 00:27:14 +0800
Subject: [PATCH 57/69] 1

---
 app/command/SyncStoreBasicData.php |   6 +++---
 dump.rdb                           | Bin 1554 -> 0 bytes
 2 files changed, 3 insertions(+), 3 deletions(-)
 delete mode 100644 dump.rdb

diff --git a/app/command/SyncStoreBasicData.php b/app/command/SyncStoreBasicData.php
index 7b3f83f8..272caacb 100644
--- a/app/command/SyncStoreBasicData.php
+++ b/app/command/SyncStoreBasicData.php
@@ -74,9 +74,9 @@ class SyncStoreBasicData extends Command
             return;
         }
         foreach ($stores as $store) {
-            if ($isSyncMaintenanceData) {
-               $this->syncMaintenanceData($store);
-            }
+            // if ($isSyncMaintenanceData) {
+            //    $this->syncMaintenanceData($store);
+            // }
             if ($isSyncHelpData) {
                $this->syncHelpData($store);
             }
diff --git a/dump.rdb b/dump.rdb
deleted file mode 100644
index 38caa2985039ac8126071aa45738d3489d019f97..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001

literal 1554
zcmZ8eJB$-o6uo1!7%-8MHfRegnm22rEmq6=KP)cx8GnZH`m63H+6(nU~%<;*BJW%xJb4xyMotzmO&BmJE
z)SqKv5l+sCz1Er}8qGQU1Mi#!TrdV=tF>$A!O+-^1S0eQ*81$Eg!*85@Ij~`!<{WLU9#4=u->67>r?EQR+9-1cCN8}^1GJ6LPd
zowa7MJ=Bx?1--Tp3F`eRU7OT`*14~!yG~wD8_O=(pq5UJrQk^W`YBA%5lB>Gz8H_e
z$Rd2NA>{52dbRFwztuh1zaC%pXez&_v`QnI?Pd-oraF5Hx#j89V-ZiR(~liWX5+PE
zX>KlWxvwaNuA#{KhQU{F#~?>-&OCoW=wdW0rX%!zHxiAuBas9X;h8$yjUSy#2O3Np
z-Gv?Dr88fS8_4N0bIJH9o2+1$4Ha{oO|saH76ljhXD;U?n=GP5qBuh9U?LNFAU9hP
zT*%`n8hPwpNT!Tjc@I008#9nXULrNIA?+CDCdfr3Swuqd0QwjOstsZ|&wJ1kIb$(}9o086RBK6_;IKR!1kY(WLBi1*R=kiy6FLi`DOg>K;0sRz5M
zn6QrAkh6e9CA@CW9jD&TNvLBIamXVu@l}Z5Isyf+iz<3JC*#bN{CpD?1QLQ4L4qt4
zkPPOsYfe%}v(4pqkQ05^+_P^5k6=#sp4}8&!ivvLRLo}{dv-tGogRxX1$s)NV{~&y
z3xA?@+lNN??IpcJ_vf@g+Pw1g$Jg+JDA%zQuTUhUp1*<7l!V;eiyltxzn^(6pyQ7O
znsU#)pw4JWE#DEmFhcjIUMN$K@LzX6AcH85(Kq-p_;2}$eB;swVkBR>0}^tkV&_?%
zSNIOE7Lrvp>suo8Tz!ydilIWuALbdpo#iT%Tt^Pqxr|mw=Ejg~9ud_rbI*}0%gaZE
z97KO#>!n{_IwpHcgBt{D!A!dz9B7hWR9eN$y)|iT+}KVe0WH9f_(+Dd&p
eGaSUTI}s*-cpz<;{HffBd%u16(+{_!j(-77e&f~v


From 5d03fcb26fa66035405cb18c0fe8f0eabda529af Mon Sep 17 00:00:00 2001
From: lqmac 
Date: Fri, 2 Aug 2024 15:16:34 +0800
Subject: [PATCH 58/69] =?UTF-8?q?=E9=93=B6=E8=81=94=E6=94=AF=E4=BB=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 app/admin/controller/Goods.php                |   7 +-
 app/api/controller/Notify.php                 |  10 +
 app/api/service/Notify.php                    |  27 +-
 app/api/service/Server/PaySuccess.php         |   2 +-
 app/api/service/Server/ServerPayment.php      |   6 +-
 app/api/service/cashier/Payment.php           |  10 +-
 app/api/service/identity/PaySuccess.php       |   2 +-
 app/api/service/identity/Payment.php          |   4 +-
 app/api/service/order/PaySuccess.php          |   2 +-
 app/api/service/recharge/PaySuccess.php       |   2 +-
 app/api/service/recharge/Payment.php          |   6 +-
 app/api/service/wholesaler/PaySuccess.php     |   2 +-
 app/api/service/wholesaler/Payment.php        |   4 +-
 app/common.php                                |   4 +-
 app/common/enum/payment/Method.php            |   2 +-
 .../library/payment/gateway/driver/Huifu.php  | 344 +++++++++---------
 app/common/model/Goods.php                    |   2 +-
 app/common/model/Payment.php                  |   2 +-
 app/common/service/order/Refund.php           |  14 +-
 app/store/controller/Goods.php                |   3 +
 public/huifuNotice.php                        |  23 ++
 21 files changed, 266 insertions(+), 212 deletions(-)
 create mode 100644 public/huifuNotice.php

diff --git a/app/admin/controller/Goods.php b/app/admin/controller/Goods.php
index 2494cbfd..8b412ceb 100644
--- a/app/admin/controller/Goods.php
+++ b/app/admin/controller/Goods.php
@@ -353,6 +353,7 @@ class Goods extends Controller
             ['delivery_time'=>'发货时效(0:24小时 1:48小时 2:72小时 3:7天内 4:15天内 5:30天内 6:45天内 填写其中一项)'],
             ['is_check'=>'是否审单(是填1 否填0)'],
             ['is_use_jd_stock'=>'是否使用京东库存(是填1 否填0)'],
+            ['video_id'=>'是否覆盖商品(是填1 否填0)'],
         ];
         
         downLoadExcel('导出数据-'.date('Y-m-d', time()),$titles,$data['data']);
@@ -510,9 +511,9 @@ class Goods extends Controller
      */
     public function collector(string $sku): Json{
         $res = getJdGoodsBySku([$sku]);
-        // $collector = new \app\job\service\goods\Collector;
-        // $url = "https://item.jd.com/{$sku}.html";
-        // $res1 = $collector->collector($url, 10048);
+        if (!$res) {
+            return $this->renderError('数据抓取失败');
+        }
         
         return $this->renderSuccess($res[$sku] ?? []);
     }
diff --git a/app/api/controller/Notify.php b/app/api/controller/Notify.php
index 9cb3ccc7..2b96c89b 100644
--- a/app/api/controller/Notify.php
+++ b/app/api/controller/Notify.php
@@ -60,4 +60,14 @@ class Notify extends BaseController
         $NotifyService = new NotifyService;
         return $NotifyService->alipay();
     }
+
+    /**
+     * 支付成功异步通知 (支付宝)
+     * @return string
+     */
+    public function huifu(): string
+    {
+        $NotifyService = new NotifyService;
+        return $NotifyService->huifu();
+    }
 }
diff --git a/app/api/service/Notify.php b/app/api/service/Notify.php
index bf25b64f..49452cd3 100644
--- a/app/api/service/Notify.php
+++ b/app/api/service/Notify.php
@@ -122,7 +122,29 @@ class Notify
         }
         return isset($Payment) ? $Payment->getNotifyResponse() : 'FAIL';
     }
-
+    /**
+     * 支付成功异步通知 (银联)
+     * @return string
+     */
+    public function huifu(): string
+    {
+        try {
+            // 获取第三方交易记录
+            $tradeInfo = $this->getTradeInfo(PaymentMethodEnum::HUIFU);
+            // 构建支付模块
+            $Payment = $this->getPayment($tradeInfo);
+            // 验证异步通知参数是否合法
+            if (!$Payment->notify()) {
+                throwError($Payment->getError() ?: '异步通知验证未通过');
+            }
+            // 订单支付成功事件
+            $this->orderPaySucces($tradeInfo, $Payment->getNotifyParams());
+        } catch (\Throwable $e) {
+            // 记录错误日志
+            Log::append('Notify-银联', ['errMessage' => $e->getMessage()]);
+        }
+        return isset($Payment) ? $Payment->getNotifyResponse() : 'FAIL';
+    }
     /**
      * 订单支付成功事件
      * @param PaymentTradeModel $tradeInfo
@@ -217,6 +239,9 @@ class Notify
         if ($method === PaymentMethodEnum::ALIPAY) {
             return \request()->post('out_trade_no');
         }
+        if ($method === PaymentMethodEnum::HUIFU) {
+            return \request()->post('merOrderId');
+        }
         return null;
     }
 
diff --git a/app/api/service/Server/PaySuccess.php b/app/api/service/Server/PaySuccess.php
index 4e8c8ace..6467536c 100644
--- a/app/api/service/Server/PaySuccess.php
+++ b/app/api/service/Server/PaySuccess.php
@@ -187,7 +187,7 @@ class PaySuccess extends BaseService
             ], ['order_no' => $orderInfo['order_no']]);
         }
         // 将第三方交易记录更新为已支付状态
-        if (in_array($this->method, [PaymentMethodEnum::WECHAT, PaymentMethodEnum::ALIPAY])) {
+        if (in_array($this->method, [PaymentMethodEnum::WECHAT, PaymentMethodEnum::ALIPAY, PaymentMethodEnum::HUIFU])) {
             $this->updateTradeRecord();
         }
     }
diff --git a/app/api/service/Server/ServerPayment.php b/app/api/service/Server/ServerPayment.php
index b060ae4b..66104de0 100644
--- a/app/api/service/Server/ServerPayment.php
+++ b/app/api/service/Server/ServerPayment.php
@@ -185,7 +185,7 @@ class ServerPayment extends BaseService
     private function extraAsUnify(array $extra = []): array
     {
         // 微信支付时需要的附加数据
-        if ($this->method === PaymentMethodEnum::WECHAT) {
+        if ($this->method === PaymentMethodEnum::WECHAT || $this->method === PaymentMethodEnum::HUIFU) {
             // 微信小程序端和微信公众号端需要openid
             if (in_array($this->client, [ClientEnum::WXOFFICIAL, ClientEnum::MP_WEIXIN])) {
                 $extra['openid'] = $this->getWechatOpenid();
@@ -234,7 +234,7 @@ class ServerPayment extends BaseService
     public function tradeQuery(string $outTradeNo): bool
     {
         // 判断支付方式是否合法
-        if (!in_array($this->method, [PaymentMethodEnum::WECHAT, PaymentMethodEnum::ALIPAY])) {
+        if (!in_array($this->method, [PaymentMethodEnum::WECHAT, PaymentMethodEnum::ALIPAY, PaymentMethodEnum::HUIFU])) {
             return false;
         }
         // 获取支付方式的配置信息
@@ -267,7 +267,7 @@ class ServerPayment extends BaseService
     private function unifiedorder(array $extra = []): array
     {
         // 判断支付方式是否合法
-        if (!in_array($this->method, [PaymentMethodEnum::WECHAT, PaymentMethodEnum::ALIPAY])) {
+        if (!in_array($this->method, [PaymentMethodEnum::WECHAT, PaymentMethodEnum::ALIPAY, PaymentMethodEnum::HUIFU])) {
             return [];
         }
         // 生成第三方交易订单号 (并非主订单号)
diff --git a/app/api/service/cashier/Payment.php b/app/api/service/cashier/Payment.php
index de3cfff2..b6d897a3 100644
--- a/app/api/service/cashier/Payment.php
+++ b/app/api/service/cashier/Payment.php
@@ -154,7 +154,7 @@ class Payment extends BaseService
     public function tradeQuery(string $outTradeNo): bool
     {
         // 判断支付方式是否合法
-        if (!in_array($this->method, [PaymentMethodEnum::WECHAT, PaymentMethodEnum::ALIPAY])) {
+        if (!in_array($this->method, [PaymentMethodEnum::WECHAT, PaymentMethodEnum::ALIPAY, PaymentMethodEnum::HUIFU])) {
             return false;
         }
         //新增获取商户的支付配置问题
@@ -286,7 +286,7 @@ class Payment extends BaseService
     private function extraAsUnify(array $extra = []): array
     {
         // 微信支付时需要的附加数据
-        if ($this->method === PaymentMethodEnum::WECHAT) {
+        if ($this->method === PaymentMethodEnum::WECHAT || $this->method == PaymentMethodEnum::HUIFU) {
             // 微信小程序端和微信公众号端需要openid
             if (in_array($this->client, [ClientEnum::WXOFFICIAL, ClientEnum::MP_WEIXIN])) {
                 $extra['openid'] = $this->getWechatOpenid();
@@ -299,12 +299,6 @@ class Payment extends BaseService
                 $extra['buyerId'] = $this->getAlipayBuyerId();
             }
         }
-        if ($this->method === PaymentMethodEnum::HUIFU) {
-            // 微信小程序端和微信公众号端需要openid
-            if (in_array($this->client, [ClientEnum::WXOFFICIAL, ClientEnum::MP_WEIXIN])) {
-                $extra['openid'] = $this->getWechatOpenid();
-            }
-        }
         return $extra;
     }
 
diff --git a/app/api/service/identity/PaySuccess.php b/app/api/service/identity/PaySuccess.php
index 76cd928f..76c878e9 100644
--- a/app/api/service/identity/PaySuccess.php
+++ b/app/api/service/identity/PaySuccess.php
@@ -221,7 +221,7 @@ class PaySuccess extends BaseService
             ], ['order_no' => $orderInfo['order_no']]);
         }
         // 将第三方交易记录更新为已支付状态
-        if (in_array($this->method, [PaymentMethodEnum::WECHAT, PaymentMethodEnum::ALIPAY])) {
+        if (in_array($this->method, [PaymentMethodEnum::WECHAT, PaymentMethodEnum::ALIPAY,  PaymentMethodEnum::HUIFU])) {
             $this->updateTradeRecord();
         }
     }
diff --git a/app/api/service/identity/Payment.php b/app/api/service/identity/Payment.php
index 15746759..dfb8b7dc 100644
--- a/app/api/service/identity/Payment.php
+++ b/app/api/service/identity/Payment.php
@@ -243,7 +243,7 @@ class Payment extends BaseService
     private function unifiedorder(array $extra = []): array
     {
         // 判断支付方式是否合法
-        if (!in_array($this->method, [PaymentMethodEnum::WECHAT, PaymentMethodEnum::ALIPAY])) {
+        if (!in_array($this->method, [PaymentMethodEnum::WECHAT, PaymentMethodEnum::ALIPAY, PaymentMethodEnum::HUIFU])) {
             return [];
         }
         // 生成第三方交易订单号 (并非主订单号)
@@ -286,7 +286,7 @@ class Payment extends BaseService
     private function extraAsUnify(array $extra = []): array
     {
         // 微信支付时需要的附加数据
-        if ($this->method === PaymentMethodEnum::WECHAT) {
+        if ($this->method === PaymentMethodEnum::WECHAT || $this->method ==  PaymentMethodEnum::HUIFU) {
             // 微信小程序端和微信公众号端需要openid
             if (in_array($this->client, [ClientEnum::WXOFFICIAL, ClientEnum::MP_WEIXIN])) {
                 $extra['openid'] = $this->getWechatOpenid();
diff --git a/app/api/service/order/PaySuccess.php b/app/api/service/order/PaySuccess.php
index 3e1dbf9b..2a1ed9bb 100644
--- a/app/api/service/order/PaySuccess.php
+++ b/app/api/service/order/PaySuccess.php
@@ -367,7 +367,7 @@ class PaySuccess extends BaseService
             // merchantModel::setIncTotal($orderInfo['merchant_id'], $precentPrice);
         }
         // 将第三方交易记录更新为已支付状态
-        if (in_array($this->method, [PaymentMethodEnum::WECHAT, PaymentMethodEnum::ALIPAY])) {
+        if (in_array($this->method, [PaymentMethodEnum::WECHAT, PaymentMethodEnum::ALIPAY,  PaymentMethodEnum::HUIFU])) {
             $this->updateTradeRecord();
         }
     }
diff --git a/app/api/service/recharge/PaySuccess.php b/app/api/service/recharge/PaySuccess.php
index 43430e57..8b3997df 100644
--- a/app/api/service/recharge/PaySuccess.php
+++ b/app/api/service/recharge/PaySuccess.php
@@ -195,7 +195,7 @@ class PaySuccess extends BaseService
                 'store_id' => empty($orderInfo['store_id'])?$this->getStoreId():$orderInfo['store_id'],
             ], ['order_no' => $orderInfo['order_no']],$orderInfo['store_id']);
             // 将第三方交易记录更新为已支付状态
-            if (in_array($this->method, [PaymentMethodEnum::WECHAT, PaymentMethodEnum::ALIPAY])) {
+            if (in_array($this->method, [PaymentMethodEnum::WECHAT, PaymentMethodEnum::ALIPAY, PaymentMethodEnum::HUIFU])) {
                 $this->updateTradeRecord();
             }
             // 提交事务处理
diff --git a/app/api/service/recharge/Payment.php b/app/api/service/recharge/Payment.php
index e5002114..1e50c59d 100644
--- a/app/api/service/recharge/Payment.php
+++ b/app/api/service/recharge/Payment.php
@@ -121,7 +121,7 @@ class Payment extends BaseService
     public function tradeQuery(string $outTradeNo): bool
     {
         // 判断支付方式是否合法
-        if (!in_array($this->method, [PaymentMethodEnum::WECHAT, PaymentMethodEnum::ALIPAY])) {
+        if (!in_array($this->method, [PaymentMethodEnum::WECHAT, PaymentMethodEnum::ALIPAY,  PaymentMethodEnum::HUIFU])) {
             return false;
         }
         // 获取支付方式的配置信息
@@ -183,7 +183,7 @@ class Payment extends BaseService
     private function unifiedorder(array $extra = []): array
     {
         // 判断支付方式是否合法
-        if (!in_array($this->method, [PaymentMethodEnum::WECHAT, PaymentMethodEnum::ALIPAY])) {
+        if (!in_array($this->method, [PaymentMethodEnum::WECHAT, PaymentMethodEnum::ALIPAY,  PaymentMethodEnum::HUIFU])) {
             return [];
         }
         // 生成第三方交易订单号 (并非主订单号)
@@ -226,7 +226,7 @@ class Payment extends BaseService
     private function extraAsUnify(array $extra = []): array
     {
         // 微信支付时需要的附加数据
-        if ($this->method === PaymentMethodEnum::WECHAT) {
+        if ($this->method === PaymentMethodEnum::WECHAT || $this->method === PaymentMethodEnum::HUIFU) {
             // 微信小程序端和微信公众号端需要openid
             if (in_array($this->client, [ClientEnum::WXOFFICIAL, ClientEnum::MP_WEIXIN])) {
                 $extra['openid'] = $this->getWechatOpenid();
diff --git a/app/api/service/wholesaler/PaySuccess.php b/app/api/service/wholesaler/PaySuccess.php
index dad24075..9818b057 100644
--- a/app/api/service/wholesaler/PaySuccess.php
+++ b/app/api/service/wholesaler/PaySuccess.php
@@ -167,7 +167,7 @@ class PaySuccess extends BaseService
             ], ['order_no' => $orderInfo['order_no']]);
         }
         // 将第三方交易记录更新为已支付状态
-        if (in_array($this->method, [PaymentMethodEnum::WECHAT, PaymentMethodEnum::ALIPAY])) {
+        if (in_array($this->method, [PaymentMethodEnum::WECHAT, PaymentMethodEnum::ALIPAY, PaymentMethodEnum::HUIFU])) {
             $this->updateTradeRecord();
         }
     }
diff --git a/app/api/service/wholesaler/Payment.php b/app/api/service/wholesaler/Payment.php
index 932744ad..927ea359 100644
--- a/app/api/service/wholesaler/Payment.php
+++ b/app/api/service/wholesaler/Payment.php
@@ -134,7 +134,7 @@ class Payment extends BaseService
     private function unifiedorder(array $extra = []): array
     {
         // 判断支付方式是否合法
-        if (!in_array($this->method, [PaymentMethodEnum::WECHAT, PaymentMethodEnum::ALIPAY])) {
+        if (!in_array($this->method, [PaymentMethodEnum::WECHAT, PaymentMethodEnum::ALIPAY, PaymentMethodEnum::HUIFU])) {
             return [];
         }
         // 生成第三方交易订单号 (并非主订单号)
@@ -162,7 +162,7 @@ class Payment extends BaseService
     private function extraAsUnify(array $extra = []): array
     {
         // 微信支付时需要的附加数据
-        if ($this->method === PaymentMethodEnum::WECHAT) {
+        if ($this->method === PaymentMethodEnum::WECHAT || $this->method === PaymentMethodEnum::HUIFU) {
             // 微信小程序端和微信公众号端需要openid
             if (in_array($this->client, [ClientEnum::WXOFFICIAL, ClientEnum::MP_WEIXIN])) {
                 $extra['openid'] = $this->getWechatOpenid();
diff --git a/app/common.php b/app/common.php
index d5b786ea..1d910457 100644
--- a/app/common.php
+++ b/app/common.php
@@ -625,8 +625,8 @@ function getJdGoodsBySku($skus){
     $url = "http://8.130.98.31:8811/api/skus/info?skus=".$sku;
     $data = httpRequest($url, "GET", null, [], false, 30);
     
-    if ($data['code'] != 0 || !$data['data']) {
-        return [];
+    if (!isset($data['code']) || $data['code'] != 0 || !$data['data']) {
+        return false;
     }
     $data = $data['data'];
     foreach ($data as &$item) {
diff --git a/app/common/enum/payment/Method.php b/app/common/enum/payment/Method.php
index f28368c3..94acf3cb 100644
--- a/app/common/enum/payment/Method.php
+++ b/app/common/enum/payment/Method.php
@@ -47,7 +47,7 @@ class Method extends EnumBasics
                 'name' => '支付宝',
                 'value' => self::ALIPAY,
             ],
-            self::ALIPAY => [
+            self::HUIFU => [
                 'name' => '汇支付',
                 'value' => self::HUIFU,
             ],
diff --git a/app/common/library/payment/gateway/driver/Huifu.php b/app/common/library/payment/gateway/driver/Huifu.php
index cc3397fe..5cf3db8d 100644
--- a/app/common/library/payment/gateway/driver/Huifu.php
+++ b/app/common/library/payment/gateway/driver/Huifu.php
@@ -1,41 +1,22 @@
 
-// +----------------------------------------------------------------------
 declare (strict_types=1);
 
 namespace app\common\library\payment\gateway\driver;
 
 use app\common\library\payment\gateway\Driver;
 use cores\exception\BaseException;
-
-# 加载 SDK 初始化文件
-require_once  root_path() . "/vendor/huifurepo/dg-php-sdk/BsPaySdk/init.php";
-require_once  root_path() . "/vendor/huifurepo/dg-php-sdk/BsPaySdk/request/V2TradePaymentJspayRequest.php";
-require_once  root_path() . "/vendor/huifurepo/dg-php-sdk/BsPaySdk/request/V2MerchantBusiOpenRequest.php";
-
-use BsPaySdk\core\BsPay;
-use BsPaySdk\core\BsPayClient;
-use BsPaySdk\request\V2TradePaymentJspayRequest;
-use BsPaySdk\request\V2MerchantBusiOpenRequest;
-use BsPaySdk\config\MerConfig;
 use app\common\library\Log;
 use app\common\enum\Client as ClientEnum;
-
 /**
- * 微信支付驱动
+ * 全民付移动支付驱动
  * Class Wechat
  * @package app\common\library\payment\gateway\driver
  */
 class Huifu extends Driver
 {
-     /**
+    private $domain = "https://api-mop.chinaums.com";
+    private $result;
+    /**
      * 设置支付宝配置信息(全局只需设置一次)
      * @param array $options 支付宝配置信息
      * @param string $client 下单客户端
@@ -44,25 +25,28 @@ class Huifu extends Driver
     public function setOptions(array $options, string $client): ?Driver
     {
         $this->client = $client ?: null;
-        $this->options = $options;
         if ($options['mchType'] === 'provider') {
             $config = [
-                'sys_id' => $options['provider']['sys_id'],
-                'product_id' => $options['provider']['product_id'],
-                'rsa_merch_private_key' => $options['provider']['rsa_merch_private_key'],
-                'rsa_huifu_public_key' => $options['provider']['rsa_huifu_public_key'],
+                'appid' => $options['provider']['appid'],
+                'appkey' => $options['provider']['appkey'],
+                'msgSrcId' => $options['provider']['msgSrcId'],
+                'msgSrc' => $options['provider']['msgSrc'],
+                'md5Secret' => $options['provider']['md5Secret'],
+                'mid' => $options['provider']['mid'],
+                'tid' => $options['provider']['tid'],
             ];
         } else {
             $config = [
-                'sys_id' => $options['normal']['sys_id'],
-                'product_id' => $options['normal']['product_id'],
-                'rsa_merch_private_key' => $options['normal']['rsa_merch_private_key'],
-                'rsa_huifu_public_key' => $options['normal']['rsa_huifu_public_key'],
+                'appid' => $options['normal']['appid'],
+                'appkey' => $options['normal']['appkey'],
+                'msgSrcId' => $options['normal']['msgSrcId'],
+                'msgSrc' => $options['normal']['msgSrc'],
+                'md5Secret' => $options['normal']['md5Secret'],
+                'mid' => $options['normal']['mid'],
+                'tid' => $options['normal']['tid'],
             ];
         }
-        $this->merChantKey = $options['normal']['sys_id'].$options['normal']['product_id'];
-        BsPay::init($config, true, $this->merChantKey);
-
+        $this->config = $config;
         return $this;
     }
    
@@ -108,47 +92,87 @@ class Huifu extends Driver
             // 发起API调用 微信小程序端
             if ($this->client === ClientEnum::MP_WEIXIN) {
 
-                // 2.组装请求参数
-                $request = new V2TradePaymentJspayRequest();
-                // 请求日期
-                $request->setReqDate(date("Ymd"));
-                // 请求流水号
-                $request->setReqSeqId($outTradeNo);
-
-                $merConfig = BsPay::getConfig($this->merChantKey);
-                // 商户号
-                $request->setHuifuId($merConfig->sys_id);
-                // 交易类型
-                $request->setTradeType("T_MINIAPP");
-                // 交易金额
-                $request->setTransAmt(sprintf("%.2f", $totalFee));
-                // 商品描述
-                $request->setGoodsDesc($extra['title'] ?? "商品支付");
-
-                // 设置非必填字段
-                $extendInfoMap = $this->getExtendInfos($extra);
-                $request->setExtendInfo($extendInfoMap);
-
-                // 3. 发起API调用
-                $client = new BsPayClient($this->merChantKey);
-                $result = $client->postRequest($request);
-                var_dump($result);
-                exit();
-                Log::append('Alipay-unify', ['client' => $this->client, 'result' => $result]);
-                if (!$result || $result->isError()) {
+                //$outTradeNo = date("YmdHis").mt_rand(1000,9999);
+                $order_url = $this->domain . "/v1/netpay/wx/mini-pre-order";
+                //$order_url = $this->domain . "/v1/netpay/wx/unified-order";
+                $params = [
+                    "requestTimestamp" => date("Y-m-d H:i:s"),
+                    "merOrderId" => $this->config['msgSrcId'].$outTradeNo,
+                    "mid" => $this->config['mid'],
+                    "tid" => $this->config['tid'],
+                    "subAppId" => $this->config['appid'],
+                    "subOpenId" => $extra['openid'],
+                    "tradeType" => "MINI",
+                    "notifyUrl" => $this->notifyUrl(),
+                    "orderDesc" => "商品支付",
+                    "totalAmount" => bcmul($totalFee, "100"),
+                    "divisionFlag" => false,//分账标记
+                    //"platformAmount" => false,//平台商户分 账金额
+                    // "subOrders" => [
+                    //     [
+                    //         "mid" => "111",
+                    //         "totalAmount" => 1,
+                    //     ]
+                        
+                    // ],
+                ];
+                $authorization = $this->getAuthorization($params);
+                $headers = ["Authorization:".$authorization];
+                
+                $data = httpRequest($order_url, "POST", json_encode($params), $headers, false);
+                if ($data['errCode'] != "SUCCESS") {
+                    Log::append('银联-unify', ['client' => $this->client, 'result' => $data]);
                     return false;
                 }
-                $data = $result->getRspDatas()['data'];
-                if (isset($data['resp_code']) && $data['resp_code'] == "00000100") {
-                    return $data;
-                }
+                $this->result = $data;
+                return true;
+            }
+        } catch (\Throwable $e) {
+            $this->throwError('银联API下单失败:' . $e->getMessage(), true, 'unify');
+        }
+        return false;
+    }
+    /**
+     * 交易查询 (主动查询订单支付状态)
+     * @param string $outTradeNo 交易订单号
+     * @return array|null
+     * @throws BaseException
+     */
+    public function tradeQuery(string $outTradeNo): ?array
+    {
+        try {
+             $tradeQuery_url = $this->domain . "/v1/netpay/wx/mini-pre-query";
+            $params = [
+                "requestTimestamp" => date("Y-m-d H:i:s"),
+                "merOrderId" => $outTradeNo,//date("YmdHis").mt_rand(1000,9999),
+                "mid" => $this->config['mid'],
+                "tid" => $this->config['tid'],
+            ];
+            $authorization = $this->getAuthorization($params);
+            $headers = ["Authorization:".$authorization];
+            
+            $data = httpRequest($tradeQuery_url, "POST", json_encode($params), $headers, false);
+            // echo "
";
+            // print_r($data);
+            // exit();
+            if ($data['errCode'] != "SUCCESS") {
+                Log::append('huifu-tradeQuery', ['client' => $this->client, 'result' => $data]);
                 return false;
             }
+            return [
+                // 支付状态: true成功 false失败
+                'paySuccess' => isset($data['status']) && $data['status'] === 'TRADE_SUCCESS',
+                // 第三方交易流水号
+                'tradeNo' => $data['targetOrderId'] ?? ""
+            ];
+            return $data;
         } catch (\Throwable $e) {
-            $this->throwError('支付宝API下单失败:' . $e->getMessage(), true, 'unify');
+            $this->throwError('银联API交易查询失败:' . $e->getMessage(), true, 'tradeQuery');
         }
         return false;
+       
     }
+
     /**
      * 输出错误信息
      * @param string $errMessage 错误信息
@@ -159,95 +183,11 @@ class Huifu extends Driver
     private function throwError(string $errMessage, bool $isLog = false, string $action = '')
     {
         $this->error = $errMessage;
-        $isLog && Log::append("Alipay-{$action}", ['errMessage' => $errMessage]);
+        $isLog && Log::append("银联-{$action}", ['errMessage' => $errMessage]);
         throwError($errMessage);
     }
-    public function getExtendInfos($params) {
-        // 设置非必填字段
-        $extendInfoMap = array();
-        // 交易有效期
-        $extendInfoMap["time_expire"]= date("YmdHis", time() + 86400);
-        // 禁用信用卡标记
-        $extendInfoMap["limit_pay_type"]= "NO_CREDIT";
-        // 是否延迟交易
-        $extendInfoMap["delay_acct_flag"]= "N";
-        // 渠道号
-        $extendInfoMap["channel_no"]= "";
-        // 手续费扣款标志
-        // $extendInfoMap["fee_flag"]= "";
-        // 补贴支付信息
-        // $extendInfoMap["combinedpay_data"]= $this->getCombinedpayData();
-        // 场景类型
-        $extendInfoMap["pay_scene"]= "02";
-        // 安全信息
-        //$extendInfoMap["risk_check_data"]= $this->getRiskCheckData();
-        // 设备信息
-        //$extendInfoMap["terminal_device_data"]= $this->getTerminalDeviceData();
-        // 分账对象
-        //$extendInfoMap["acct_split_bunch"]= $this->getAcctSplitBunch();
-        // 传入分帐遇到优惠的处理规则
-        $extendInfoMap["term_div_coupon_type"]= "0";
-        // 聚合正扫微信拓展参数集合
-        $extendInfoMap["wx_data"]= $this->getWxData($params);
-        // 支付宝扩展参数集合
-        //$extendInfoMap["alipay_data"]= $this->getAlipayData();
-        // 银联参数集合
-        // $extendInfoMap["unionpay_data"]= getUnionpayData();
-        // 数字人民币参数集合
-        // $extendInfoMap["dc_data"]= getDcData();
-        // 商户贴息标记
-        $extendInfoMap["fq_mer_discount_flag"]= "N";
-        // 异步通知地址
-        $extendInfoMap["notify_url"]= $this->notifyUrl();
-        // 备注
-        $extendInfoMap["remark"] = $params['title'] ?? "商品支付";
-        // 账户号
-        // $extendInfoMap["acct_id"]= "";
-        return $extendInfoMap;
-    }
-    public function getWxData($params) {
-        $dto = array();
-        // 子商户公众账号id
-        $dto["sub_appid"] = "wxa3127ed5c3542a28";
-        // 用户标识
-        $dto["openid"] = $params['openid'];
-        // 子商户用户标识
-        $dto["sub_openid"] = "";
-        // 附加数据
-        // $dto["attach"] = "";
-        // 商品描述
-        // $dto["body"] = "";
-        // 商品详情
-        // $dto["detail"] = getDetail();
-        // 设备号
-        // $dto["device_info"] = "";
-        // 订单优惠标记
-        // $dto["goods_tag"] = "";
-        // 实名支付
-        // $dto["identity"] = "";
-        // 开发票入口开放标识
-        // $dto["receipt"] = "";
-        // 场景信息
-        // $dto["scene_info"] = getSceneInfo();
-        // 终端ip
-        // $dto["spbill_create_ip"] = "";
-        // 单品优惠标识
-        // $dto["promotion_flag"] = "";
-        // 新增商品ID
-        // $dto["product_id"] = "";
-
-        return json_encode($dto,JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
-    }
-    /**
-     * 交易查询 (主动查询订单支付状态)
-     * @param string $outTradeNo 交易订单号
-     * @return array|null
-     * @throws BaseException
-     */
-    public function tradeQuery(string $outTradeNo): ?array
-    {
-        return $this->getApp()->tradeQuery($outTradeNo);
-    }
+    
+    
 
     /**
      * 支付成功后的异步通知
@@ -256,11 +196,30 @@ class Huifu extends Driver
      */
     public function notify(): bool
     {
-        if (!$this->getApp()->notify()) {
-            $this->setError($this->getApp()->getError());
-            return false;
+       // 接收表单数据
+        $this->notifyParams = request()->filter([])->post();
+
+        $notifyParams = $this->notifyParams;
+        $sign = $notifyParams['sign'];
+        unset($notifyParams['sign']);
+        ksort($notifyParams);
+        $str = http_build_query($notifyParams);
+        $verifyNotify = false;
+        if ($sign != md5($str)) {
+            $verifyNotify = true;
         }
-        return true;
+        
+        // 判断交易单状态必须是支付成功
+        $this->notifyResult = $verifyNotify && $this->notifyParams['status'] === 'TRADE_SUCCESS';
+        // 记录日志
+        Log::append('银联-notify', [
+            'params' => $this->notifyParams,
+            'verifyNotify' => $verifyNotify,
+            'response' => $this->getNotifyResponse(),
+            'result' => $this->notifyResult,
+            'message' => '银联异步回调验证' . ($this->notifyResult ? '成功' : '失败')
+        ]);
+        return $this->notifyResult;
     }
 
     /**
@@ -273,11 +232,32 @@ class Huifu extends Driver
      */
     public function refund(string $outTradeNo, string $refundAmount, array $extra = []): bool
     {
-        if (!$this->getApp()->refund($outTradeNo, $refundAmount, $extra)) {
-            $this->setError($this->getApp()->getError());
-            return false;
+
+        try {
+            $refund_url = $this->domain . "/v1/netpay/refund";
+            $params = [
+                "requestTimestamp" => date("Y-m-d H:i:s"),
+                "merOrderId" => $outTradeNo,
+                "mid" => $this->config['mid'],
+                "tid" => $this->config['tid'],
+                "targetOrderId" => $extra['trade_no'],
+                "refundAmount" => bcmul($refundAmount, "100"),
+                "refundOrderId" => $this->config['msgSrcId'].date("YmdHis").mt_rand(1000, 9999),
+                "refundDesc" => "订单退款",
+            ];
+            $authorization = $this->getAuthorization($params);
+            $headers = ["Authorization:".$authorization];
+            
+            $data = httpRequest($refund_url, "POST", json_encode($params), $headers, false);
+            if ($data['errCode'] != "SUCCESS") {
+                $this->throwError($data['errMsg']);
+            }
+            // 请求成功
+            return true;
+         } catch (\Throwable $e) {
+            $this->throwError('银联API退款请求:' . $e->getMessage(), true, 'refund');
         }
-        return true;
+        return false;
     }
 
     /**
@@ -303,17 +283,19 @@ class Huifu extends Driver
      */
     public function getNotifyParams(): array
     {
-        return $this->getApp()->getNotifyParams();
+        return [
+            // 第三方交易流水号
+            'tradeNo' => $this->notifyParams['targetOrderId']
+        ];
     }
 
     /**
      * 返回异步通知结果的输出内容
      * @return string
-     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
      */
     public function getNotifyResponse(): string
     {
-        return $this->getApp()->getNotifyResponse();
+        return $this->notifyResult ? 'SUCCESS' : 'FAILED';
     }
 
     /**
@@ -323,7 +305,31 @@ class Huifu extends Driver
      */
     public function getUnifyResult(): array
     {
-        return $this->getApp()->getUnifyResult();
+        if (empty($this->result)) {
+            $this->throwError('当前没有unify结果', true, 'getUnifyResult');
+        }
+        $this->result['out_trade_no'] =  $this->result['merOrderId'];//str_replace($this->config['msgSrcId'], "", $this->result['merOrderId']);
+        return $this->result;
+    }
+    /**
+     * 生成授权码
+     * [getAuthorization description]
+     * @param  [type] $data [description]
+     * @return [type]       [description]
+     */
+    private function getAuthorization($data){
+        $appid = $this->config['appid'];
+        $appkey = $this->config['appkey'];
+
+        $timestamp = date("YmdHis",time());
+        $nonce = md5(uniqid((string)microtime(true),true));
+        $body = json_encode($data);
+        //echo $body;
+        $str = bin2hex(hash('sha256', $body, true));
+        $signature = base64_encode(hash_hmac('sha256', "$appid$timestamp$nonce$str", $appkey, true));
+        $authorization = 'OPEN-BODY-SIG AppId="'.$appid.'", Timestamp="'.$timestamp.'", Nonce="'.$nonce.'", Signature="'.$signature.'"';
+
+        return $authorization;
     }
     /**
      * 异步回调地址
@@ -332,6 +338,6 @@ class Huifu extends Driver
     private function notifyUrl(): string
     {
         // 例如:https://www.xxxx.com/alipayNotice.php
-        return base_url() . 'alipayNotice.php';
+        return base_url() . 'huifuNotice.php';
     }
-}
\ No newline at end of file
+}
diff --git a/app/common/model/Goods.php b/app/common/model/Goods.php
index 1aaf0293..c9a3728c 100644
--- a/app/common/model/Goods.php
+++ b/app/common/model/Goods.php
@@ -209,7 +209,7 @@ class Goods extends BaseModel
         // 执行查询
         $list = $query
             ->alias($this->name)
-            ->field(['goods.goods_id', 'goods.goods_name', 'cmmdty_model', 'remark', 'cost_price_min', 'stock_total', 'is_check', 'goods_price_min','goods_no','goods_source','delivery_time','delivery_id','status','link','link_other','channel','is_use_jd_stock'])
+            ->field(['goods.goods_id', 'goods.goods_name', 'cmmdty_model', 'remark', 'cost_price_min', 'stock_total', 'is_check', 'goods_price_min','goods_no','goods_source','delivery_time','delivery_id','status','link','link_other','channel','is_use_jd_stock','video_id'])
             ->where('is_delete', '=', 0)
             ->order($sort)
             ->paginate($listRows);
diff --git a/app/common/model/Payment.php b/app/common/model/Payment.php
index fb86f391..79fe95ca 100644
--- a/app/common/model/Payment.php
+++ b/app/common/model/Payment.php
@@ -193,8 +193,8 @@ class Payment extends BaseModel
     {
         $data = [
             ClientEnum::MP_WEIXIN => $this->defaultGroup(ClientEnum::MP_WEIXIN, [
-                PaymentMethodEnum::WECHAT,
                 PaymentMethodEnum::HUIFU,
+                PaymentMethodEnum::WECHAT,
                 PaymentMethodEnum::BALANCE,
                 
             ]),
diff --git a/app/common/service/order/Refund.php b/app/common/service/order/Refund.php
index a8727a01..cf794364 100644
--- a/app/common/service/order/Refund.php
+++ b/app/common/service/order/Refund.php
@@ -1,13 +1,5 @@
 
-// +----------------------------------------------------------------------
+
 declare (strict_types=1);
 
 namespace app\common\service\order;
@@ -51,7 +43,7 @@ class Refund extends BaseService
             return $this->balance($order, $money);
         }
         // 第三方支付退款
-        if (in_array($order['pay_method'], [PaymentMethodEnum::WECHAT, PaymentMethodEnum::ALIPAY])) {
+        if (in_array($order['pay_method'], [PaymentMethodEnum::WECHAT, PaymentMethodEnum::ALIPAY, PaymentMethodEnum::HUIFU])) {
             return $this->payment($order, $money);
         }
         return false;
@@ -94,7 +86,7 @@ class Refund extends BaseService
         // 构建支付模块
         $Payment = PaymentFacade::store($order['pay_method'])->setOptions($options, $order['platform']);
         // 执行第三方支付下单API
-        if (!$Payment->refund($tradeInfo['out_trade_no'], $money, ['totalFee' => (string)$order['pay_price']])) {
+        if (!$Payment->refund($tradeInfo['out_trade_no'], $money, ['totalFee' => (string)$order['pay_price'], 'trade_no' => $tradeInfo['trade_no']])) {
             throwError($Payment->getError() ?: '第三方支付退款API调用失败');
         }
         // 将第三方交易记录更新为已退款状态
diff --git a/app/store/controller/Goods.php b/app/store/controller/Goods.php
index 5322a0f0..80c38775 100644
--- a/app/store/controller/Goods.php
+++ b/app/store/controller/Goods.php
@@ -371,6 +371,9 @@ class Goods extends Controller
      */
     public function collector(string $sku): Json{
         $res = getJdGoodsBySku([$sku]);
+        if (!$res) {
+            return $this->renderError('数据抓取失败');
+        }
         // $collector = new \app\job\service\goods\Collector;
         // $url = "https://item.jd.com/{$sku}.html";
         // $res1 = $collector->collector($url, 10048);
diff --git a/public/huifuNotice.php b/public/huifuNotice.php
new file mode 100644
index 00000000..59047172
--- /dev/null
+++ b/public/huifuNotice.php
@@ -0,0 +1,23 @@
+ 7.1.0 !');
+
+// 加载核心文件
+require __DIR__ . '/../vendor/autoload.php';
+
+// 执行HTTP应用并响应
+$http = (new App())->http;
+
+// 手动指定设置路由
+$_SERVER['PATH_INFO'] = '/notify/huifu';
+
+// $http->name()用于设置当前入口文件绑定的应用
+$response = $http->name('api')->run();
+
+$response->send();
+
+$http->end($response);

From 814f229d32e573a4321c1920f6708f5897d2e978 Mon Sep 17 00:00:00 2001
From: zengyyh 
Date: Sun, 4 Aug 2024 11:03:47 +0800
Subject: [PATCH 59/69] pifa

---
 app/admin/controller/RetailDescribe.php       |  50 +++
 app/api/controller/Region copy.php            |  52 +++
 app/api/controller/Retail.php                 | 182 ++++++++
 app/api/controller/User.php                   |  12 +
 app/api/model/Retail.php                      | 118 +++++
 app/api/model/RetailOrder.php                 |  23 +
 app/api/model/user/Retail.php                 |  22 +
 app/api/model/user/RetailOrder.php            | 133 ++++++
 app/api/service/Retail.php                    | 142 ++++++
 app/api/service/Retail/PaySuccess.php         | 418 ++++++++++++++++++
 app/api/service/Retail/Payment.php            | 346 +++++++++++++++
 app/common/enum/RetailDescribeEnum.php        |  42 ++
 .../enum/user/balanceLog/RetailType.php       |  47 ++
 app/common/model/Retail.php                   |  46 ++
 app/common/model/RetailDescribe.php           |  34 ++
 app/common/model/RetailOrder.php              |  45 ++
 app/store/controller/Retail.php               | 109 +++++
 app/store/model/Retail.php                    |  74 ++++
 app/store/model/RetailDescribe.php            |  72 +++
 app/store/model/RetailOrder.php               |  78 ++++
 20 files changed, 2045 insertions(+)
 create mode 100644 app/admin/controller/RetailDescribe.php
 create mode 100644 app/api/controller/Region copy.php
 create mode 100644 app/api/controller/Retail.php
 create mode 100644 app/api/model/Retail.php
 create mode 100644 app/api/model/RetailOrder.php
 create mode 100644 app/api/model/user/Retail.php
 create mode 100644 app/api/model/user/RetailOrder.php
 create mode 100644 app/api/service/Retail.php
 create mode 100644 app/api/service/Retail/PaySuccess.php
 create mode 100644 app/api/service/Retail/Payment.php
 create mode 100644 app/common/enum/RetailDescribeEnum.php
 create mode 100644 app/common/enum/user/balanceLog/RetailType.php
 create mode 100644 app/common/model/Retail.php
 create mode 100644 app/common/model/RetailDescribe.php
 create mode 100644 app/common/model/RetailOrder.php
 create mode 100644 app/store/controller/Retail.php
 create mode 100644 app/store/model/Retail.php
 create mode 100644 app/store/model/RetailDescribe.php
 create mode 100644 app/store/model/RetailOrder.php

diff --git a/app/admin/controller/RetailDescribe.php b/app/admin/controller/RetailDescribe.php
new file mode 100644
index 00000000..7780931e
--- /dev/null
+++ b/app/admin/controller/RetailDescribe.php
@@ -0,0 +1,50 @@
+
+// +----------------------------------------------------------------------
+declare (strict_types=1);
+
+namespace app\admin\controller;
+use app\store\model\RetailDescribe as retDescribeModel;
+
+class RetailDescribe extends Controller
+{
+    public function index()
+    {
+        $model = new retDescribeModel;
+        $where = $this->request->get();
+        $list = $model->getList($where);
+        return $this->renderSuccess(compact('list'));
+    }
+
+    public function add(){
+        $model = new retDescribeModel;
+        if($model->add($this->postForm())){
+            return $this->renderSuccess('添加成功');
+        }
+        return $this->renderError($model->getError() ?: '添加失败');
+    }
+
+    public function edit(int $id){
+        $model = new retDescribeModel;
+        if($model->edit($id,$this->postForm())){
+            return $this->renderSuccess('编辑成功');
+        }
+        return $this->renderError($model->getError() ?: '编辑失败');
+    }
+
+    public function delete(array $id){
+        $model = new retDescribeModel;
+        if($model->del($id)){
+            return $this->renderSuccess('删除成功');
+        }
+        return $this->renderError($model->getError() ?: '删除失败');
+    }
+
+}
\ No newline at end of file
diff --git a/app/api/controller/Region copy.php b/app/api/controller/Region copy.php
new file mode 100644
index 00000000..2ea0c90a
--- /dev/null
+++ b/app/api/controller/Region copy.php	
@@ -0,0 +1,52 @@
+
+// +----------------------------------------------------------------------
+declare (strict_types=1);
+
+namespace app\api\controller;
+
+use app\api\model\Region as RegionModel;
+use think\response\Json;
+
+/**
+ * 地区管理
+ * Class Region
+ * @package app\api\controller
+ */
+class Region extends Controller
+{
+    /**
+     * 获取所有地区
+     * @return Json
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function all(): Json
+    {
+        $list = RegionModel::getCacheAll();
+        return $this->renderSuccess(compact('list'));
+    }
+
+    /**
+     * 获取所有地区(树状)
+     * @return Json
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function tree(): Json
+    {
+        $model = new RegionModel();
+        $list = $model->getNewTreeList();
+        //$list = array_values($list);
+        return $this->renderSuccess(compact('list'));
+    }
+}
diff --git a/app/api/controller/Retail.php b/app/api/controller/Retail.php
new file mode 100644
index 00000000..15190e16
--- /dev/null
+++ b/app/api/controller/Retail.php
@@ -0,0 +1,182 @@
+
+// +----------------------------------------------------------------------
+declare (strict_types=1);
+namespace app\api\controller;
+
+use think\response\Json;
+use app\api\model\Retail as RetailModel;
+use app\api\model\RetailOrder as RetailOrderModel;
+use app\api\model\Agreement as AgreementModel;
+use app\common\model\RetailDescribe as RetailDescribeModel;
+use app\api\service\order\Checkout as CheckoutService;
+use app\api\service\User as UserService;
+use app\common\enum\RetailDescribeEnum;
+
+class Retail extends Controller
+{
+
+    /**
+     * 获取零售批发会员列表
+     * @param int $retailType
+     * @return Json
+     */
+    public function list(int $retailType): Json
+    {        
+        $list = RetailModel::withoutGlobalScope()->where('retail_type',$retailType)->where('retail_status',10)->select();
+        return $this->renderSuccess(compact('list'));
+    }
+
+    /**
+     * 获取软件付费协议
+     * @return Json
+     */
+    public function getSoftAgreement(): Json
+    {
+        $params = $this->request->param();
+        if (empty($params['type'])) {
+            return $this->renderSuccess("参数错误");
+        }
+        $detail = AgreementModel::detail(['type' => $params['type']]);
+        if (!empty($detail->content)) {
+            $detail->content = str_ireplace('nowrap', 'inherit', $detail->content);
+        }
+        return $this->renderSuccess(compact('detail'));
+    }
+
+
+    /**
+     * 获取零售批发会员列表
+     * @param int $retailType
+     * @return Json
+     */
+    public function retailPayList(): Json
+    {   
+        $client = $this->request->post();
+        if (!$client['client']) {
+            return $this->renderError('客户端不能为空');
+        }
+        $model =new \app\api\service\Retail();
+        $list = $model->userCenter($client);
+        $list['retail'] = '

+ 1、客户直接在商城查看价格,快速比价、下单 +

+

+ 2、所有会员、分销数字化管理 +

+

+ 3、所有订单,调货记录,物流状态实时查询 +

+

+ 4、供应链资源快速对接 +

+

+ 5、商品数据快速上架,商城之间数据实时传输 +

+

+ 6、商品市场价实时自动更新 +

+

+ 7、货款到账时间支持当天或隔天,支付费率低     +

+

+    至千分之2.x +

+

+ 8、支持到店自提、同城闪送 +

+

+ 9、促进清洗、安装、维修、回收、租赁服务与产品销售一体化 +

+

+ 10、促进本地商家联盟数字化平台化发展 +

+

+
+

'; + $list['wholesale'] = '

+ 1、客户直接在商城查看价格,快速比价、下单 +

+

+ 2、所有会员、分销数字化管理 +

+

+ 3、所有订单,调货记录,物流状态实时查询 +

+

+ 4、供应链资源快速对接 +

+

+ 5、商品数据快速上架,商城之间数据实时传输 +

+

+ 6、商品市场价实时自动更新 +

+

+ 7、货款到账时间支持当天或隔天,支付费率低     +

+

+    至千分之2.x +

+

+ 8、支持到店自提、同城闪送 +

+

+ 9、促进清洗、安装、维修、回收、租赁服务与产品销售一体化 +

+

+ 10、促进本地商家联盟数字化平台化发展 +

+

+
+

'; + return $this->renderSuccess(compact('list')); + } + + public function submit(): Json + { + $method = $this->request->post('method'); + if (!$method) { + return $this->renderError('支付方式不能为空'); + } + $client = $this->request->post('client'); + if (!$client) { + return $this->renderError('客户端不能为空'); + } + $retailPriceId = intval($this->request->post('retail_price_id')); + if (!$retailPriceId) { + return $this->renderError('缺少必要参数'); + } + $service = new \app\api\service\Retail(); + $data = $service->setMethod($method) + ->setClient($client) + ->orderPay($retailPriceId); + return $this->renderSuccess($data, $service->getMessage() ?: '下单成功'); + } + + + /** + * 商厂权限 + */ + public function describe() + { + $type = $this->request->get('type')??10; + $list = RetailDescribeModel::withoutGlobalScope()->where(['description_status' =>10,'type' => $type])->select(); + $group = []; + foreach($list as $item){ + + $group[$item['plate_id']]['list'][] = $item; + $group[$item['plate_id']]['name'] = RetailDescribeEnum::$version[$item['plate_id']] ?? "" ; + } + return $this->renderSuccess(compact('group')); + } + + +} \ No newline at end of file diff --git a/app/api/controller/User.php b/app/api/controller/User.php index 58283d10..86a7e70c 100644 --- a/app/api/controller/User.php +++ b/app/api/controller/User.php @@ -19,6 +19,7 @@ use app\api\model\User as UserModel; use app\api\model\user\BalanceLog; use app\api\model\user\GoodSource as GoodsSourceModel; use app\api\model\user\InvoiceOrder; +use app\api\model\RetailOrder as RetailOrderModel; use app\api\model\user\UserCoupon; use app\api\model\user\UserInvoice; use app\api\model\UserCoupon as UserCouponModel; @@ -51,6 +52,7 @@ class User extends Controller { $user_id = UserService::getCurrentLoginUserId(); UserModel::where('user_id', $user_id)->update(['is_delete' => 1, 'update_time' => time()]); + return $this->renderSuccess('注销成功'); } /** @@ -80,6 +82,16 @@ class User extends Controller $userInfo['withdrawal_money'] = !empty($dealer_info->money) ? $dealer_info->money : 0; $userInfo['freeze_money'] = !empty($dealer_info->freeze_money) ? $dealer_info->freeze_money : 0; } + $retailOrderList = RetailOrderModel::getRetailOrder($userInfo['user_id']); + $userInfo['retail'] = 0; + if (empty($retailOrderList)) { + // 如果零售订单列表为空,设置用户信息中的零售状态为 1 + $userInfo['retail'] = 0; + } else { + // 如果零售订单列表不为空,设置用户信息中的零售状态为 0 + $userInfo['retail'] = 1; + } + return $this->renderSuccess(compact('userInfo')); } diff --git a/app/api/model/Retail.php b/app/api/model/Retail.php new file mode 100644 index 00000000..d40cc021 --- /dev/null +++ b/app/api/model/Retail.php @@ -0,0 +1,118 @@ + +// +---------------------------------------------------------------------- +declare (strict_types=1); + +namespace app\api\model; +use app\common\model\Retail as RetailModel; +use app\api\model\Payment as PaymentModel; +use app\api\service\identity\Payment; +use app\api\service\User as UserService; + +class Retail extends RetailModel +{ + // 提示信息 + private string $message = ''; + + // 支付方式 (微信支付、支付宝、余额) + private string $method; + + // 下单的客户端 + private string $client; + + //隐藏字段 + protected $hidden = [ + 'create_time', + 'update_time', + 'store_id', + ]; + + public function setMethod(string $method): Retail + { + $this->method = $method; + return $this; + } + public static function getRetailList() + { + return self::select(); + } + /** + * 设置下单的客户端 + * @param string $client 客户端 + * @return $this + */ + public function setClient(string $client): Retail + { + $this->client = $client; + return $this; + } + public function getList(array $where) + { + return $this->where($where)->order('sort', 'asc')->select(); + } + + /** + * 返回消息提示 + * @return string + */ + public function getMessage(): string + { + return $this->message; + } + + + // public static function detail(array $where = []) : array + // { + // $where = [ + // 'retail_price_id'=>$where['retail_price_id'], + // 'retail_status'=>10 + // ]; + + // return RetailModel::where($where)->select(); + // } + + + + private function cheapPrice($data): array + { + $one_data = $data[0]; + + foreach ($data as $key => $value) { + $data[$key]['cheap_price'] = 0; + if (!empty($one_data)) { + if ($key > 0) { + $price = $value['month'] * $one_data['price']; + $data[$key]['cheap_price'] = $price - $value['price']; + } + } + } + return $data; + } + + /** + * 确认订单支付事件 + * @param int $identityId + * @param array $extra 附加数据 + * @return array[] + * @throws BaseException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + */ + public function orderPay(int $identityId, array $extra = []): array + { + $PaymentService = new Payment(); + $result = $PaymentService->setMethod($this->method) + ->setClient($this->client) + ->orderPay($identityId, $extra); + $this->message = $PaymentService->getMessage(); + return $result; + } +} \ No newline at end of file diff --git a/app/api/model/RetailOrder.php b/app/api/model/RetailOrder.php new file mode 100644 index 00000000..0701e997 --- /dev/null +++ b/app/api/model/RetailOrder.php @@ -0,0 +1,23 @@ + +// +---------------------------------------------------------------------- +declare (strict_types=1); + +namespace app\api\model; +use app\common\model\RetailOrder as RetailOrderModel; + +class RetailOrder extends RetailOrderModel +{ + public static function getRetailOrder($user_id) + { + return self::where('user_id', $user_id)->where('pay_status',20)->select(); + } + +} \ No newline at end of file diff --git a/app/api/model/user/Retail.php b/app/api/model/user/Retail.php new file mode 100644 index 00000000..547fc337 --- /dev/null +++ b/app/api/model/user/Retail.php @@ -0,0 +1,22 @@ +1){ + $price= $identityInfo['retail_current_price'] * $identityInfo['year']-$identityInfo['retail_discounts'];//订单支付价格 + $preferentialPrice = $identityInfo['retail_discounts']; + }else { + $price = $identityInfo['retail_current_price'] * $identityInfo['year']; + $preferentialPrice = 0; + } + $data = [ + 'user_id' => UserService::getCurrentLoginUserId(),//用户id + 'order_no' => OrderService::createOrderNo(),//订单号 + 'retail_price_id' => $identityInfo['retail_price_id'],//会员id + 'order_type' => $identityInfo['retail_type'],//订单类型 + 'order_price' => $identityInfo['order_price'],//订单支付价格 + 'pay_price' => $price, + 'preferential_price' => $preferentialPrice,//优惠价格 + 'year' => $identityInfo['year'], + 'platform' => getPlatform(), + 'pay_method' => $method, + 'store_id' => self::$storeId, + + ]; + return $this->save($data); + } + + /** + * 获取订单详情 (待付款状态) + * @param string $orderNo 订单号 + * @return array|null|static + */ + public static function getPayDetail(string $orderNo) + { + return self::detail(['order_no' => $orderNo]); + } + + /** + * @notes:编辑 + * @param $data + * @return bool + * @author: wanghousheng + */ + public function edit($data): bool + { + return $this->save($data) !== false; + } + + public function identity(): HasOne + { + return $this->hasOne(Identity::class, 'identity_id', 'identity_id') + ->bind(['identity_name' => 'name']); + } + + /** + * @notes:开卡记录 + * @param array $where + * @return array + * @throws BaseException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + * @author: wanghousheng + */ + public function cardList(array $where = []): array + { + $userId = UserService::getCurrentLoginUserId(); + $params['user_id'] = $userId; + $params['pay_status'] = PayStatus::SUCCESS; + $where = array_merge($where, $params); + $list = $this->where($where) + ->with(['identity']) + ->order('pay_time', 'desc') + ->limit(20) + ->select(); + $data = []; + if (!empty($list)) { + foreach ($list as $value) { + $end_time = date("Y-m-d", strtotime("+{$value['month']} months", $value['pay_time'])); + $is_valid = false; + if (strtotime(date("Y-m-d")) < strtotime($end_time)) { + $is_valid = true; + } + $data[] = [ + 'start_time' => date("Y-m-d", $value['pay_time']), + 'end_time' => $end_time, + 'name' => $value['identity_name'], + 'month' => $value['month'], + 'is_valid' => $is_valid + ]; + } + } + return $data; + } +} \ No newline at end of file diff --git a/app/api/service/Retail.php b/app/api/service/Retail.php new file mode 100644 index 00000000..f10baaad --- /dev/null +++ b/app/api/service/Retail.php @@ -0,0 +1,142 @@ +method = $method; + return $this; + } + + /** + * 设置下单的客户端 + * @param string $client 客户端 + * @return $this + */ + public function setClient(string $client): Retail + { + $this->client = $client; + return $this; + } + + /** + * 开通会员页面数据 + * @param string $client 当前客户端 + * @return array + * @throws BaseException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + */ + public function userCenter(array $client): array + { + // 当期用户信息 + $userInfo = UserService::getCurrentLoginUser(true); +// //是否分销商 +// if (UserService::isDealerMember() || UserService::isStore()) { +// throwError('非法操作'); +// } + // 获取充值方案列表 + $model = new RetailModel(); + $planList = $model->getList(['retail_type' => $client['retail_type']]); + if (!$planList->isEmpty()) { + // $planList = $this->cheapPrice($planList->toArray()); + } + //计算优惠价格 + // 根据指定客户端获取可用的支付方式 + $PaymentModel = new PaymentModel; + $methods = $PaymentModel->getMethodsByClient($client['client']); + // 返回数据 + return [ + 'personal' => $userInfo, + 'list' => $planList, + 'paymentMethods' => $methods + ]; + } + + private function cheapPrice($data): array + { + $one_data = $data[0]; + foreach ($data as $key => $value) { + $data[$key]['cheap_price'] = 0; + if (!empty($one_data)) { + if ($key > 0) { + $price = $value['month'] * $one_data['price']; + $data[$key]['cheap_price'] = $price - $value['price']; + } + } + } + return $data; + } + + /** + * 确认订单支付事件 + * @param int $identityId + * @param array $extra 附加数据 + * @return array[] + * @throws BaseException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + */ + public function orderPay(int $identityId, array $extra = []): array + { + $PaymentService = new Payment(); + $result = $PaymentService->setMethod($this->method) + ->setClient($this->client) + ->orderPay($identityId); + $this->message = $PaymentService->getMessage(); + return $result; + } + + /** + * 交易查询 + * 查询第三方支付订单是否付款成功 + * @param string $outTradeNo 商户订单号 + * @return bool + * @throws BaseException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + */ + public function tradeQuery(string $outTradeNo): bool + { + $PaymentService = new Payment(); + return $PaymentService->setMethod($this->method)->setClient($this->client)->tradeQuery($outTradeNo); + } + + /** + * 返回消息提示 + * @return string + */ + public function getMessage(): string + { + return $this->message; + } +} \ No newline at end of file diff --git a/app/api/service/Retail/PaySuccess.php b/app/api/service/Retail/PaySuccess.php new file mode 100644 index 00000000..e402558b --- /dev/null +++ b/app/api/service/Retail/PaySuccess.php @@ -0,0 +1,418 @@ + +// +---------------------------------------------------------------------- +declare (strict_types=1); + +namespace app\api\service\Retail; + +use app\api\model\PaymentTrade as PaymentTradeModel; +use app\api\model\recharge\Order as OrderModel; +use app\api\model\User as UserModel; +use app\api\model\user\BalanceLog as BalanceLogModel; +use app\api\model\user\RetailOrder; +use app\common\enum\order\PayStatus; +use app\common\enum\payment\Method as PaymentMethodEnum; +use app\common\enum\recharge\order\PayStatus as PayStatusEnum; +use app\common\enum\user\balanceLog\Scene as SceneEnum; +use app\common\enum\user\IdentityEnum; +use app\common\enum\user\UserTypeEnum; +use app\common\library\Lock; +use app\common\library\Log; +use app\common\service\BaseService; +use app\store\model\dealer\User; +use app\common\enum\user\balanceLog\RetailType; +use cores\exception\BaseException; + +/** + * 余额充值订单支付成功服务类 + * Class PaySuccess + * @package app\api\service\order + */ +class PaySuccess extends BaseService +{ + // 当前订单信息 + public RetailOrder $orderInfo; + + // 当前用户信息 + private UserModel $userInfo; + + // 当前订单号 + private string $orderNo; + + // 当前订单ID + private int $orderId; + + // 订单支付方式 + private string $method; + + // 第三方交易记录ID + private ?int $tradeId = null; + + // 第三方支付成功返回的数据 + private array $paymentData = []; + + private int $type; + + /** + * 设置支付的订单ID + * @param int $orderId 订单ID + */ + public function setOrderId(int $orderId): PaySuccess + { + $this->orderId = $orderId; + return $this; + } + + public function setType($type): PaySuccess + { + $this->type = $type; + + return $this; + } + + /** + * 设置当前的订单号 + * @param string $orderNo + * @return $this + */ + public function setOrderNo(string $orderNo): PaySuccess + { + $this->orderNo = $orderNo; + return $this; + } + + /** + * 设置订单支付方式 + * @param string $method + * @return $this + */ + public function setMethod(string $method): PaySuccess + { + $this->method = $method; + return $this; + } + + /** + * 第三方支付交易记录ID + * @param int|null $tradeId + * @return $this + */ + public function setTradeId(?int $tradeId = null): PaySuccess + { + $this->tradeId = $tradeId; + return $this; + } + + /** + * 第三方支付成功返回的数据 + * @param array $paymentData + * @return $this + */ + public function setPaymentData(array $paymentData): PaySuccess + { + $this->paymentData = $paymentData; + return $this; + } + + // public function setOrderInfo(array $orderInfo): PaySuccess + // { + // $this->orderInfo = RetailOrder::detail(['order_no' => $this->orderNo]); + // return $this; + // } + + /** + * 订单支付成功业务处理 + * @return bool + * @throws BaseException + */ + public function handle(): bool + { + // 验证当前参数是否合法 + $this->verifyParameters(); + // 当前订单开启并发锁 + $this->lockUp(); + // 验证当前订单是否允许支付 + if ($this->checkOrderStatusOnPay()) { + // 更新订单状态为已付款 + $this->updatePayStatus(); + } + // 当前订单解除并发锁 + $this->unLock(); + return true; + } + + /** + * 验证当前参数是否合法 + * @throws BaseException + */ + private function verifyParameters() + { + if (empty($this->orderNo)) { + throwError('orderNo not found'); + } + if (empty($this->method)) { + throwError('method not found'); + } + if ($this->tradeId) { + empty($this->paymentData) && throwError('PaymentData not found'); + !isset($this->paymentData['tradeNo']) && throwError('PaymentData not found'); + } + // 记录日志 + Log::append('PaySuccess', [ + 'orderNo' => $this->orderNo, 'method' => $this->method, + 'tradeId' => $this->tradeId, 'paymentData' => $this->paymentData + ]); + } + + /** + * 订单模型 + * @return RetailOrder|null + * @throws BaseException + */ + private function orderModel(): ?RetailOrder + { + return $this->getOrderInfo(); + } + + /** + * 订单已付款事件 + * @return void + * @throws BaseException + */ + private function updatePayStatus(): void + { + // 记录日志 + Log::append('PaySuccess --updatePayStatus', ['title' => '订单已付款事件']); + // 当前订单信息 + $orderInfo = $this->getOrderInfo(); + // 事务处理 + $this->orderModel()->transaction(function () use ($orderInfo) { + // 更新订单状态 + $this->updateOrderStatus(); + // 累积用户总消费金额 + UserModel::setIncPayMoney($orderInfo['user_id'], (float)$orderInfo['pay_price']); + // 记录订单支付信息 + $this->updatePayInfo(); + //更改会员角色 + // $this->activate(); + }); + } + + + /** + * 记录订单支付的信息 + * @throws BaseException + */ + private function updatePayInfo() + { + // 当前订单信息 + $orderInfo = $this->getOrderInfo(); + // 余额支付 + if ($this->method == PaymentMethodEnum::BALANCE) { + // 更新用户余额 + UserModel::setDecBalance((int)$orderInfo['user_id'], (float)$orderInfo['pay_price']); + // 新增余额变动记录 + $type = SceneEnum::BUY_SHOP; + if ($this->type == IdentityEnum::DEALER) { + $type = SceneEnum::DEALER; + } + BalanceLogModel::add($type, [ + 'user_id' => (int)$orderInfo['user_id'], + 'money' => -$orderInfo['pay_price'], + ], ['order_no' => $orderInfo['order_no']]); + } + // 将第三方交易记录更新为已支付状态 + if (in_array($this->method, [PaymentMethodEnum::WECHAT, PaymentMethodEnum::ALIPAY, PaymentMethodEnum::HUIFU])) { + $this->updateTradeRecord(); + } + } + + /** + * 将第三方交易记录更新为已支付状态 + */ + private function updateTradeRecord() + { + if ($this->tradeId && !empty($this->paymentData)) { + PaymentTradeModel::updateToPaySuccess($this->tradeId, $this->paymentData['tradeNo']); + } + } + + /** + * 更新订单状态 + * @throws BaseException + */ + private function updateOrderStatus(): void + { + // 更新订单状态 + $this->orderModel()->save([ + 'pay_method' => $this->method, + 'pay_status' => PayStatus::SUCCESS, + 'pay_time' => time(), + 'trade_id' => $this->tradeId ?: 0, + ]); + + } + + /** + * 获取买家用户信息 + * @return UserModel|array|null + * @throws BaseException + */ + private function getUserInfo() + { + if (empty($this->userInfo)) { + $this->userInfo = UserModel::detail($this->getOrderInfo()['user_id']); + } + if (empty($this->userInfo)) { + throwError('未找到买家用户信息'); + } + return $this->userInfo; + } + + /** + * 验证当前订单是否允许支付 + * @return bool + * @throws BaseException + */ + private function checkOrderStatusOnPay(): bool + { + // 当前订单信息 + $orderInfo = $this->getOrderInfo(); + // 验证余额支付时用户余额是否满足 + if ($this->method == PaymentMethodEnum::BALANCE) { + if ($this->getUserInfo()['balance'] < $orderInfo['pay_price']) { + throwError('账户余额不足,无法使用余额支付'); + } + } + // 检查订单状态是否为已支付 + if ($orderInfo['pay_status'] == PayStatusEnum::SUCCESS) { + $this->onOrderPaid(); + return false; + } + return true; + } + + /** + * 处理订单已支付的情况 + * @throws BaseException + */ + private function onOrderPaid() + { + // 记录日志 + Log::append('PaySuccess --onOrderPaid', ['title' => '处理订单已支付的情况']); + // 当前订单信息 + $orderInfo = $this->getOrderInfo(); + // 余额支付直接返回错误信息 + if ($this->method == PaymentMethodEnum::BALANCE) { + throwError('当前订单已支付,无需重复支付'); + } + // 第三方支付判断是否为重复下单 (因异步回调可能存在网络延迟的原因,在并发的情况下会出现同时付款两次,这里需要容错) + // 如果订单记录中已存在tradeId并且和当前支付的tradeId不一致, 那么判断为重复的订单, 需进行退款处理 + if ($this->tradeId > 0 && $orderInfo['trade_id'] != $this->tradeId) { + // 执行原路退款 + throwError('当前订单异常'); + } + } + + + /** + * 获取当前订单的详情信息 + * @return OrderModel|null + * @throws BaseException + */ + private function getOrderInfo(): ?RetailOrder + { + // 获取订单详情 (待支付状态) + if (empty($this->orderInfo)) { + $this->orderInfo = RetailOrder::getPayDetail($this->orderNo); + } + // 判断订单是否存在 + if (empty($this->orderInfo)) { + throwError('未找到该订单信息'); + } + return $this->orderInfo; + } + + /** + * 订单锁:防止并发导致重复支付 + * @throws BaseException + */ + private function lockUp() + { + $orderInfo = $this->getOrderInfo(); + Lock::lockUp("RetailOrderPaySuccess_{$orderInfo['order_id']}"); + } + + /** + * 订单锁:防止并发导致重复支付 + * @throws BaseException + */ + private function unLock() + { + $orderInfo = $this->getOrderInfo(); + Lock::unLock("RetailOrderPaySuccess_{$orderInfo['order_id']}"); + } + + /** + * @notes:修改会员身份信息 + * @throws BaseException + * @author: wanghousheng + */ + private function activate(): void + { + $orderInfo = $this->getOrderInfo(); + $userInfo = $this->getUserInfo(); + //判断当前用户角色 + $orderType = $orderInfo['order_type']; + $userType = $userInfo['user_type']; + if ($userType == UserTypeEnum::STORE) { + return; + } + $userModel = new UserModel(); + $up = []; + $time = date('Y-m-d'); + //已经是会员或者未开通会员 + if ($orderType == IdentityEnum::MEMBER && $userType != UserTypeEnum::DEALER) { + $up['user_type'] = UserTypeEnum::MEMBER; + //已经是会员 + if ($userType == UserTypeEnum::MEMBER) { + //是否到期 + if (!empty($userInfo['effective_time']) && strtotime($userInfo['effective_time']) > strtotime(date('Y-m-d'))) { + $time = $userInfo['effective_time']; + } + } + $up['effective_time'] = date("Y-m-d", strtotime("+{$orderInfo['month']} months", strtotime($time))); + } else { + $up['user_type'] = UserTypeEnum::DEALER; + //已经是分销商 + if ($userType == UserTypeEnum::DEALER) { + //是否到期 + if (!empty($userInfo['fx_effective_time']) && strtotime($userInfo['fx_effective_time']) > strtotime(date('Y-m-d'))) { + $time = $userInfo['fx_effective_time']; + } + } + if (!User::isDealerUser($userInfo['user_id'])) { + // 新增分销商用户 + $model = new UserModel(); + $mobile = $model->where(['user_id' => $userInfo['user_id']])->value('mobile'); + User::add($userInfo['user_id'], [ + 'real_name' => $mobile, + 'mobile' => $mobile, + 'store_id' => $userInfo['store_id'] ?? 0, + ]); + } else { + //更新分销用户 + User::update(['is_delete' => 0], ['user_id' => $userInfo['user_id']]); + } + $up['fx_effective_time'] = date("Y-m-d", strtotime("+{$orderInfo['month']} months", strtotime($time))); + } + $userModel->where(['user_id' => $userInfo['user_id']])->save($up); + } +} \ No newline at end of file diff --git a/app/api/service/Retail/Payment.php b/app/api/service/Retail/Payment.php new file mode 100644 index 00000000..f53548d9 --- /dev/null +++ b/app/api/service/Retail/Payment.php @@ -0,0 +1,346 @@ + +// +---------------------------------------------------------------------- +declare (strict_types=1); + +namespace app\api\service\Retail; + +use app\api\model\Payment as PaymentModel; +use app\api\model\PaymentTrade as PaymentTradeModel; +use app\api\model\Retail as RetailModel; +use app\api\model\user\Retail; +use app\api\model\user\RetailOrder; +use app\api\service\Retail\PaySuccess as RetailPaySuccessService; +use app\api\service\Order as OrderService; +use app\api\service\User as UserService; +use app\common\enum\Client as ClientEnum; +use app\common\enum\OrderType as OrderTypeEnum; +use app\common\enum\payment\Method as PaymentMethodEnum; +use app\common\enum\user\IdentityEnum; +use app\common\library\payment\Facade as PaymentFacade; +use app\common\enum\user\balanceLog\RetailType; +use app\common\service\BaseService; +use cores\exception\BaseException; +use think\db\exception\DataNotFoundException; +use think\db\exception\DbException; +use think\db\exception\ModelNotFoundException; + +/** + * 开通会员/分销商订单付款服务类 + * Class Payment + * @package app\api\controller + */ +class Payment extends BaseService +{ + // 提示信息 + private string $message = ''; + + // 订单信息 + private RetailOrder $orderInfo; + + // 支付方式 (微信支付、支付宝,余额) + private string $method = ''; + + // 下单的客户端 + private string $client = ''; + + private int $type; + + /** + * 设置当前支付方式 + * @param string $method 支付方式 + * @return $this + */ + public function setMethod(string $method): Payment + { + $this->method = $method; + return $this; + } + + public function setType($type): Payment + { + $this->type = $type; + return $this; + } + + /** + * 设置下单的客户端 + * @param string $client 客户端 + * @return $this + */ + public function setClient(string $client): Payment + { + $this->client = $client; + return $this; + } + + /** + * 确认订单支付事件 + * @param int $retailPriceId + * @param array $extra 附加数据 + * @return array[] + * @throws BaseException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + */ + public function orderPay(int $retailPriceId, array $extra = []): array + { + // 创建订单信息 + $this->orderInfo = $this->createOrder($retailPriceId); + // 订单支付事件 + $this->orderPayEvent(); + // 构建第三方支付请求的参数 + $payment = $this->unifiedorder($extra); + // 记录第三方交易信息 + // $order_type = OrderTypeEnum::MEMBER;//开通会员 + // if ($this->orderInfo['order_type'] == IdentityEnum::DEALER) { + // $order_type = OrderTypeEnum::DEALER;//开通分销商 + // } + // $this->recordPaymentTrade($payment, $order_type); + // 返回结果 + return compact('payment'); + } + + /** + * 订单支付事件 + * @return void + * @throws BaseException + * @author: wanghousheng + */ + private function orderPayEvent(): void + { + // 余额支付 + if ($this->method == PaymentMethodEnum::BALANCE) { + $this->setType($this->orderInfo['order_type'])->orderPaySuccess($this->orderInfo['order_no']); + } + + } + + /** + * 订单支付成功事件 + * @param string $orderNo 当前订单号 + * @param int|null $tradeId + * @param array $paymentData + * @return void + * @throws BaseException + * @author: wanghousheng + */ + private function orderPaySuccess(string $orderNo, ?int $tradeId = null, array $paymentData = []): void + { + $service = new RetailPaySuccessService(); + // 订单支付成功业务处理 + $service->setOrderNo($orderNo) + ->setMethod($this->method) + ->setTradeId($tradeId) + ->setType($this->type) + ->setPaymentData($paymentData); + if (!$service->handle()) { + throwError($service->getError() ?: '订单支付失败'); + } + $this->message = '恭喜您,订单支付成功'; + } + + /** + * 创建订单 + * @param int $identityId + * @return RetailOrder + * @throws BaseException + */ + private function createOrder(int $retailPriceId ,array $extra = []): RetailOrder + { + $extra = $this->request->post('year'); + $model = new RetailOrder(); + $info = Retail::detail(['retail_price_id' => $retailPriceId]); + $info['year'] = $extra; + if ($info->isEmpty()) { + throwError('记录不存在'); + } + //店主不可操作 + if (UserService::isStore()) { + throwError('非法操作'); + } + // if (UserService::isDealerMember() && $info['type'] != IdentityEnum::DEALER) { + // throwError('非法操作'); + // } + if (!$model->createOrder($info->toArray(), $this->method)) { + throwError($model->getError() ?: '创建订单失败'); + } + $model['order_id'] = (int)$model['order_id']; + return $model; + } + + /** + * 查询订单是否支付成功 (仅限第三方支付订单) + * @param string $outTradeNo 商户订单号 + * @return bool + * @throws BaseException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + */ + public function tradeQuery(string $outTradeNo): bool + { + // 获取支付方式的配置信息 + $options = $this->getPaymentConfig(); + // 构建支付模块 + $Payment = PaymentFacade::store($this->method)->setOptions($options, $this->client); + // 执行第三方支付查询API + $result = $Payment->tradeQuery($outTradeNo); + // 订单支付成功事件 + if (!empty($result) && $result['paySuccess']) { + // 获取第三方交易记录信息 + $tradeInfo = PaymentTradeModel::detailByOutTradeNo($outTradeNo); + // 订单支付成功事件 + $this->orderPaySuccess($tradeInfo['order_no'], $tradeInfo['trade_id'], $result); + } + // 返回订单状态 + return $result ? $result['paySuccess'] : false; + } + + /** + * 记录第三方交易信息 + * @param array $payment 第三方支付数据 + * @throws BaseException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + */ + private function recordPaymentTrade(array $payment, int $orderType): void + { + if ($this->method != PaymentMethodEnum::BALANCE) { + PaymentTradeModel::record( + $this->orderInfo, + $this->method, + $this->client, + $orderType, + $payment + ); + } + } + + /** + * 返回消息提示 + * @return string + */ + public function getMessage(): string + { + return $this->message; + } + + /** + * 构建第三方支付请求的参数 + * @param array $extra 附加数据 + * @return array + * @throws BaseException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + */ + private function unifiedorder(array $extra = []): array + { + // 判断支付方式是否合法 + if (!in_array($this->method, [PaymentMethodEnum::WECHAT, PaymentMethodEnum::ALIPAY, PaymentMethodEnum::HUIFU])) { + return []; + } + // 生成第三方交易订单号 (并非主订单号) + $outTradeNo = OrderService::createOrderNo(); + // 获取支付方式的配置信息 + $options = $this->getPaymentConfig(); + // 整理下单接口所需的附加数据 + $extra = $this->extraAsUnify($extra); + // 构建支付模块 + $Payment = PaymentFacade::store($this->method)->setOptions($options, $this->client); + // 执行第三方支付下单API + if (!$Payment->unify($outTradeNo, (string)$this->orderInfo['pay_price'], $extra)) { + throwError('第三方支付下单API调用失败'); + } + // 返回客户端需要的支付参数 + return $Payment->getUnifyResult(); + } + + /** + * 获取支付方式的配置信息 + * @return mixed + * @throws BaseException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + */ + private function getPaymentConfig() + { + $PaymentModel = new PaymentModel; + $templateInfo = $PaymentModel->getPaymentInfo($this->method, $this->client, $this->getStoreId()); + return $templateInfo['template']['config'][$this->method]; + } + + /** + * 整理下单接口所需的附加数据 + * @param array $extra + * @return array + * @throws BaseException + */ + private function extraAsUnify(array $extra = []): array + { + // 微信支付时需要的附加数据 + if ($this->method === PaymentMethodEnum::WECHAT || $this->method === PaymentMethodEnum::HUIFU) { + // 微信小程序端和微信公众号端需要openid + if (in_array($this->client, [ClientEnum::WXOFFICIAL, ClientEnum::MP_WEIXIN])) { + $extra['openid'] = $this->getWechatOpenid(); + } + } + // 支付宝支付时需要的附加数据 + if ($this->method === PaymentMethodEnum::ALIPAY) { + // 支付宝小程序端需要buyerId + if ($this->client == ClientEnum::MP_ALIPAY) { + $extra['buyerId'] = $this->getAlipayBuyerId(); + } + } + return $extra; + } + + /** + * 获取微信端的用户openid(仅微信小程序和微信公众号) + * @return null + * @throws BaseException + */ + private function getWechatOpenid() + { + if (in_array($this->client, [ClientEnum::MP_WEIXIN, ClientEnum::WXOFFICIAL])) { + // 当前登录用户信息 + $useInfo = UserService::getCurrentLoginUser(true); + if (!$useInfo['currentOauth'] || empty($useInfo['currentOauth']['oauth_id'])) { + throwError('很抱歉,您当前不存在openid 无法发起微信支付'); + } + // 当前第三方用户标识 + return $useInfo['currentOauth']['oauth_id']; + } + return null; + } + + /** + * 获取支付宝端的用户buyerId(仅支付宝小程序端) + * @return null + * @throws BaseException + */ + private function getAlipayBuyerId() + { + if ($this->client == ClientEnum::MP_ALIPAY) { + // 当前登录用户信息 + $useInfo = UserService::getCurrentLoginUser(true); + if (!$useInfo['currentOauth'] || empty($useInfo['currentOauth']['oauth_id'])) { + throwError('很抱歉,您当前不存在buyerId 无法发起支付宝支付'); + } + // 当前第三方用户标识 + return $useInfo['currentOauth']['oauth_id']; + } + return null; + } +} \ No newline at end of file diff --git a/app/common/enum/RetailDescribeEnum.php b/app/common/enum/RetailDescribeEnum.php new file mode 100644 index 00000000..191246e1 --- /dev/null +++ b/app/common/enum/RetailDescribeEnum.php @@ -0,0 +1,42 @@ + "商品", + self::DATA => "数据", + self::PRODUCT_ORDER => "商品订单", + self::SERVICE_ORDER => "服务订单", + self::RECYCLE_ORDER => "回收订单", + self::PAYMENT => "支付", + self::FINANCE => "财务", + self::STORE_DISPLAY => "店铺展示", + self::ROLE => "角色", + self::MARKETING => "营销", + self::MULTI_MERCHANT => "多商户", + self::CONTENT_MANAGEMENT => "内容管理", + self::OTHER_FEATURES => "其他功能", + ]; + + private function __construct() { + + } // 防止实例化 + +} \ No newline at end of file diff --git a/app/common/enum/user/balanceLog/RetailType.php b/app/common/enum/user/balanceLog/RetailType.php new file mode 100644 index 00000000..23be70ac --- /dev/null +++ b/app/common/enum/user/balanceLog/RetailType.php @@ -0,0 +1,47 @@ + +// +---------------------------------------------------------------------- +declare (strict_types=1); + +namespace app\common\enum\user\balanceLog; + +use app\common\enum\EnumBasics; + +/** + * 余额变动场景枚举类 + * Class Scene + * @package app\common\enum\user\balanceLog + */ +class RetailType extends EnumBasics +{ + // 零售商城 + const RETAIL = 10; + + // 批发商城 + const WHOLESALE = 20; + + /** + * 获取订单类型值 + * @return array + */ + public static function data(): array + { + return [ + self::RETAIL => [ + 'name' => '零售商城', + 'value' => self::RETAIL, + ], + self::WHOLESALE => [ + 'name' => '批发商城', + 'value' => self::WHOLESALE, + ] + ]; + } +} \ No newline at end of file diff --git a/app/common/model/Retail.php b/app/common/model/Retail.php new file mode 100644 index 00000000..7bf12dfd --- /dev/null +++ b/app/common/model/Retail.php @@ -0,0 +1,46 @@ + +// +---------------------------------------------------------------------- +declare (strict_types=1); + +namespace app\common\model; + +use cores\BaseModel; + +class Retail extends BaseModel +{ + // 定义表名 + protected $name = 'retail_price'; + // 定义主键 + protected $pk = 'retail_price_id'; + + // 开启自动写入时间戳 + protected $autoWriteTimestamp = true; + + // 创建时间字段 + protected $createTime = 'create_time'; + + // 更新时间字段 + protected $updateTime = 'update_time'; + + + /** + * @notes:详情 + * @param $where + * @param array $with + * @return static|array|null + * @author: wanghousheng + */ + public static function detail($where, array $with = []) + { + return static::get($where, $with); + } + +} \ No newline at end of file diff --git a/app/common/model/RetailDescribe.php b/app/common/model/RetailDescribe.php new file mode 100644 index 00000000..da0813b1 --- /dev/null +++ b/app/common/model/RetailDescribe.php @@ -0,0 +1,34 @@ + +// +---------------------------------------------------------------------- +declare (strict_types=1); + +namespace app\common\model; + +use cores\BaseModel; +use think\model\relation\BelongsTo; + +class RetailDescribe extends BaseModel +{ + // 定义表名 + protected $name = 'retail_describe'; + // 定义主键 + protected $pk = 'id'; + + // 开启自动写入时间戳 + protected $autoWriteTimestamp = true; + + // 创建时间字段 + protected $createTime = 'create_time'; + + // 更新时间字段 + protected $updateTime = 'update_time'; + +} \ No newline at end of file diff --git a/app/common/model/RetailOrder.php b/app/common/model/RetailOrder.php new file mode 100644 index 00000000..387c9dce --- /dev/null +++ b/app/common/model/RetailOrder.php @@ -0,0 +1,45 @@ + +// +---------------------------------------------------------------------- +declare (strict_types=1); + +namespace app\common\model; + +use cores\BaseModel; +use think\model\relation\BelongsTo; + +class RetailOrder extends BaseModel +{ + // 定义表名 + protected $name = 'retail_order'; + // 定义主键 + protected $pk = 'order_id'; + + // 开启自动写入时间戳 + protected $autoWriteTimestamp = true; + + // 创建时间字段 + protected $createTime = 'create_time'; + + // 更新时间字段 + protected $updateTime = 'update_time'; + + public function user(): BelongsTo + { + $module = self::getCalledModule(); + return $this->belongsTo("app\\{$module}\\model\\User"); + } + + public static function detail($where) + { + return self::get($where); + } + +} \ No newline at end of file diff --git a/app/store/controller/Retail.php b/app/store/controller/Retail.php new file mode 100644 index 00000000..652e8756 --- /dev/null +++ b/app/store/controller/Retail.php @@ -0,0 +1,109 @@ + +// +---------------------------------------------------------------------- +declare (strict_types=1); + +namespace app\store\controller; + +use app\api\model\user\RetailOrder; +use think\response\Json; +use app\store\model\Retail as RetailModel; +use app\store\model\RetailOrder as RetailOrderModel; + +use function Symfony\Component\VarDumper\Dumper\esc; + +class Retail extends Controller +{ + + /** + * 查看所有会员售价 + * @return Json + */ + public function list(): Json + { + $where = []; + $type = $this->request->get('retailType'); + $pageSize = intval($this->request->get('pageSize')); + if ($type) { + $where['retail_type'] = $type; + } + $model = new RetailModel(); + // $list = $model->getList($where); + $list = $model->getList($where,$pageSize); + return $this->renderSuccess(compact('list')); + } + + /** + * @notes:新增 + * @return Json + * + */ + public function add(): Json + { + $data = $this->postForm(); + $id = $this->getStoreId(); + if (!$data) { + return $this->renderError('缺少必要参数'); + } + $model = new RetailModel(); + if ($model->add($data)) { + return $this->renderSuccess('添加成功'); + } + return $this->renderError($model->getError() ?: '添加失败'); + } + + /** + * @notes:编辑 + * @param int $retailPriceId + * @return Json + * @author: + */ + public function edit(int $retailPriceId): Json + { + $data = $this->postForm(); + if (!$data) { + return $this->renderError('缺少必要参数'); + } + $model = RetailModel::withoutGlobalScope()->where('retail_price_id', $retailPriceId)->find(); + if (!$model) { + return $this->renderError('找不到指定的数据'); + } + $data['update_time']=time(); + RetailModel::withoutGlobalScope()->where('retail_price_id', $retailPriceId)->update($data); + return $this->renderSuccess('编辑成功'); + + } + + /** + * @notes:删除 + * @param array $identityId + * @return Json + * @author: wanghousheng + */ + public function delete(array $retailPriceId): Json + { + $model = new RetailModel; + if ($model->remove($retailPriceId)) { + return $this->renderSuccess('删除成功'); + } + return $this->renderError('删除失败'); + } + + public function getRetailOrder(): Json{ + $model = new RetailOrderModel(); + $list = $model->getList($this->request->param()); + return $this->renderSuccess(compact('list')); + } + + + + + +} \ No newline at end of file diff --git a/app/store/model/Retail.php b/app/store/model/Retail.php new file mode 100644 index 00000000..b53a9963 --- /dev/null +++ b/app/store/model/Retail.php @@ -0,0 +1,74 @@ + +// +---------------------------------------------------------------------- +declare (strict_types=1); + +namespace app\store\model; + +use app\common\model\Retail as RetailModel; + +class Retail extends RetailModel +{ + + public function getList(array $where ,int $pageSize ): \think\Paginator + { + return $this->where($where)->order('sort', 'asc') + ->paginate($pageSize); + } + + /** + * @notes:新增 + * @param $data + * @return bool + */ + public function add($data): bool + { + $data['store_id'] = self::$storeId; + return $this->save($data); + } + + /** + * @notes:编辑 + * @param $data + * @return bool + */ + public function edit($data): bool + { + return $this->save($data) !== false; + } + + /** + * @notes:详情 + * @param $where + * @param array $with + * @return static|array|null + * @author: wanghousheng + */ + public static function detail($where, array $with = []) + { + return static::get($where, $with); + } + + /** + * @notes:删除 + * @param array $IdentityId + * @return bool + * @author: wanghousheng + */ + public function remove(array $retailPriceId): bool + { + if (static::whereIn('retail_price_id', $retailPriceId)->delete()) { + return true; + } + return false; + } + + +} \ No newline at end of file diff --git a/app/store/model/RetailDescribe.php b/app/store/model/RetailDescribe.php new file mode 100644 index 00000000..954bfc46 --- /dev/null +++ b/app/store/model/RetailDescribe.php @@ -0,0 +1,72 @@ + +// +---------------------------------------------------------------------- +declare (strict_types=1); + +namespace app\store\model; + +use app\common\model\RetailDescribe as retDescribeModel; + +class RetailDescribe extends RetDescribeModel +{ + + public function getList(array $param = []): \think\Paginator + { + // 设置查询条件 + $filter = $this->getFilter($param); + $list = $this->field('*') + ->where($filter) + ->order(['create_time' => 'asc','sort' => 'asc']) + ->paginate($param['pageSize'] ?? 15); + return $list; + } + + public function detail(int $id){ + return self::where('id',$id)->find(); + } + + public function add(array $data){ + return $this->save($data); + } + public function edit(int $id ,array $data){ + return $this->where('id' ,$id)->update($data); + } + + public function del(array $id){ + return $this->whereIn('id' ,$id)->delete(); + } + + /** + * 设置查询条件 + * @param array $param + * @return array + */ + private function getFilter(array $param): array + { + // 设置默认的检索数据 + $params = $this->setQueryDefaultValue($param, [ + 'plate_id' => 0, // 类型id + 'search' => '', // 查询内容 + 'type' => 0, // 商城类型 + 'description_status' => 0, // 状态 + ]); + // 检索查询条件 + $filter = []; + // 类型id + $params['plate_id'] > 0 && $filter[] = ['plate_id', '=', $params['plate_id']]; + // 用户昵称/订单号 + !empty($params['search']) && $filter[] = ['feature|function_description', 'like', "%{$params['search']}%"]; + // 批发商城类型 + $params['type'] > 0 && $filter[] = ['type', '=', (int)$params['type']]; + // 支付状态 + $params['description_status'] > 0 && $filter[] = ['description_status', '=', (int)$params['description_status']]; + return $filter; + } +} \ No newline at end of file diff --git a/app/store/model/RetailOrder.php b/app/store/model/RetailOrder.php new file mode 100644 index 00000000..c65ea63e --- /dev/null +++ b/app/store/model/RetailOrder.php @@ -0,0 +1,78 @@ + +// +---------------------------------------------------------------------- +declare (strict_types=1); + +namespace app\store\model; + +use app\common\model\RetailOrder as RetailOrderModel; + +class RetailOrder extends RetailOrderModel +{ + /** + * 获取订单列表 + * @param array $param + * @return \think\Paginator + */ + public function getList(array $param = []): \think\Paginator + { + // 设置查询条件 + $filter = $this->getFilter($param); + + // 获取列表数据 + $list = $this->alias('order') + ->field('order.*') + ->where($filter) + ->join('user', 'user.user_id = order.user_id') + ->order(['order.create_time' => 'desc']) + ->paginate($param['pageSize'] ?? 15); + // var_dump($list); + // exit(); + //return $list; + // 加载订单的关联数据 + return static::preload($list, ['user.avatar']); + } + + /** + * 设置查询条件 + * @param array $param + * @return array + */ + private function getFilter(array $param): array + { + // 设置默认的检索数据 + $params = $this->setQueryDefaultValue($param, [ + 'user_id' => 0, // 用户ID + 'search' => '', // 查询内容 + 'order_type' => 0, // 充值方式 + 'pay_method' => "", // 充值方式 + 'pay_status' => 0, // 支付状态 + 'betweenTime' => [] // 起止时间 + ]); + // 检索查询条件 + $filter = []; + // 用户ID + $params['user_id'] > 0 && $filter[] = ['order.user_id', '=', $params['user_id']]; + // 用户昵称/订单号 + !empty($params['search']) && $filter[] = ['order.order_no|user.nick_name', 'like', "%{$params['search']}%"]; + !empty($params['pay_method']) && $filter[] = ['order.pay_method', '=', $params['pay_method']]; + // 充值方式 + $params['order_type'] > 0 && $filter[] = ['order.order_type', '=', (int)$params['order_type']]; + // 支付状态 + $params['pay_status'] > 0 && $filter[] = ['order.pay_status', '=', (int)$params['pay_status']]; + // 起止时间 + if (!empty($params['pay_time'])) { + $times = between_time($params['pay_time']); + $filter[] = ['order.pay_time', '>=', $times['start_time']]; + $filter[] = ['order.pay_time', '<', $times['end_time'] + 86400]; + } + return $filter; + } +} \ No newline at end of file From 97775cbc96c726d432c72673c7bcbf0357f79388 Mon Sep 17 00:00:00 2001 From: lqmac Date: Sun, 4 Aug 2024 12:11:28 +0800 Subject: [PATCH 60/69] =?UTF-8?q?=E5=9F=BA=E7=A1=80=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/command/SyncStoreBasicData.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/command/SyncStoreBasicData.php b/app/command/SyncStoreBasicData.php index 272caacb..7b3f83f8 100644 --- a/app/command/SyncStoreBasicData.php +++ b/app/command/SyncStoreBasicData.php @@ -74,9 +74,9 @@ class SyncStoreBasicData extends Command return; } foreach ($stores as $store) { - // if ($isSyncMaintenanceData) { - // $this->syncMaintenanceData($store); - // } + if ($isSyncMaintenanceData) { + $this->syncMaintenanceData($store); + } if ($isSyncHelpData) { $this->syncHelpData($store); } From 4d2513a17ad898c1221d282070663edbac011dc1 Mon Sep 17 00:00:00 2001 From: lqmac Date: Sun, 4 Aug 2024 23:58:10 +0800 Subject: [PATCH 61/69] 1 --- app/store/controller/store/User.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/store/controller/store/User.php b/app/store/controller/store/User.php index a37d4969..d50ba77d 100644 --- a/app/store/controller/store/User.php +++ b/app/store/controller/store/User.php @@ -39,13 +39,13 @@ class User extends Controller $storeUserId = StoreUserService::getLoginUserId(); $roles = StoreRoleService::getLoginPermissions(); $modules = StoreModuleModel::getModules(); - if ($roles['isSuper'] == 1) { - $modules = array_flip($modules); - // var_dump($modules1); - // exit(); - unset($modules['apps-collector']); - $modules = array_keys($modules); - } + // if ($roles['isSuper'] == 1) { + // $modules = array_flip($modules); + // // var_dump($modules1); + // // exit(); + // unset($modules['apps-collector']); + // $modules = array_keys($modules); + // } return $this->renderSuccess([ // 用户信息 'userInfo' => StoreUserModel::detail($storeUserId), From 8ca65deade023dcc59050923f9a3c7b96d63169d Mon Sep 17 00:00:00 2001 From: zengyyh Date: Tue, 6 Aug 2024 11:41:48 +0800 Subject: [PATCH 62/69] pifa --- app/admin/controller/RetailDescribe.php | 6 ++ app/api/controller/Retail.php | 114 ++++++++++++---------- app/api/service/Notify.php | 12 +++ app/api/service/Retail/PaySuccess.php | 2 +- app/api/service/Retail/Payment.php | 10 +- app/api/service/Store.php | 4 +- app/common/enum/OrderType.php | 14 +++ app/common/enum/RetailDescribeEnum.php | 4 + app/common/enum/user/balanceLog/Scene.php | 8 ++ 9 files changed, 118 insertions(+), 56 deletions(-) diff --git a/app/admin/controller/RetailDescribe.php b/app/admin/controller/RetailDescribe.php index 7780931e..820e4989 100644 --- a/app/admin/controller/RetailDescribe.php +++ b/app/admin/controller/RetailDescribe.php @@ -12,6 +12,7 @@ declare (strict_types=1); namespace app\admin\controller; use app\store\model\RetailDescribe as retDescribeModel; +use app\common\enum\RetailDescribeEnum; class RetailDescribe extends Controller { @@ -47,4 +48,9 @@ class RetailDescribe extends Controller return $this->renderError($model->getError() ?: '删除失败'); } + public function getPlate(){ + $list = RetailDescribeEnum::$version; + return $this->renderSuccess(compact('list')); + } + } \ No newline at end of file diff --git a/app/api/controller/Retail.php b/app/api/controller/Retail.php index 15190e16..70fa79e2 100644 --- a/app/api/controller/Retail.php +++ b/app/api/controller/Retail.php @@ -11,12 +11,14 @@ declare (strict_types=1); namespace app\api\controller; +use app\admin\controller\RetailDescribe; use think\response\Json; use app\api\model\Retail as RetailModel; use app\api\model\RetailOrder as RetailOrderModel; use app\api\model\Agreement as AgreementModel; use app\common\model\RetailDescribe as RetailDescribeModel; use app\api\service\order\Checkout as CheckoutService; +use app\api\service\Retail as RetailService; use app\api\service\User as UserService; use app\common\enum\RetailDescribeEnum; @@ -65,77 +67,71 @@ class Retail extends Controller } $model =new \app\api\service\Retail(); $list = $model->userCenter($client); - $list['retail'] = '

- 1、客户直接在商城查看价格,快速比价、下单 + $list['retail'] = '

+ 1-客户直接在商城查看价格,快速比价、下单

-

- 2、所有会员、分销数字化管理 +

+ 2-所有会员、分销数字化管理

-

- 3、所有订单,调货记录,物流状态实时查询 +

+ 3-所有订单,调货记录,物流状态实时查询

-

- 4、供应链资源快速对接 +

+ 4-供应链资源快速对接

-

- 5、商品数据快速上架,商城之间数据实时传输 +

+ 5-商品数据快速上架,商城之间数据实时传输

-

- 6、商品市场价实时自动更新 +

+ 6-商品市场价实时自动更新

-

- 7、货款到账时间支持当天或隔天,支付费率低     +

+ 7-货款到账时间支持当天或隔天,支付费率低    

-

+

   至千分之2.x

-

- 8、支持到店自提、同城闪送 +

+ 8-支持到店自提、同城闪送

-

- 9、促进清洗、安装、维修、回收、租赁服务与产品销售一体化 +

+ 9-促进清洗、安装、维修、回收、租赁服务与产品销售一体化

-

- 10、促进本地商家联盟数字化平台化发展 -

-

-
+

+ 10-促进本地商家联盟数字化平台化发展

'; - $list['wholesale'] = '

- 1、客户直接在商城查看价格,快速比价、下单 -

-

- 2、所有会员、分销数字化管理 + $list['wholesale'] = '

+ 1-采购代发商家实名注册认证,在线直接下单

-

- 3、所有订单,调货记录,物流状态实时查询 +

+ 2-认证商家、服务商数字化管理

-

- 4、供应链资源快速对接 +

+ 3-所有订单,发货记录,物流状态实时查询

-

- 5、商品数据快速上架,商城之间数据实时传输 +

+ 4-所有调货记录在线实时查看

-

- 6、商品市场价实时自动更新 +

+ 5-审单实时做电话、地址校验比对,避免平台单

-

- 7、货款到账时间支持当天或隔天,支付费率低     +

+ 6-供应链资源快速对接

-

-    至千分之2.x +

+ 7-商品数据快速上架,商城之间商品数据实时传输

-

- 8、支持到店自提、同城闪送 +

+ 8-商品市场价实时自动更新

-

- 9、促进清洗、安装、维修、回收、租赁服务与产品销售一体化 +

+ 9-货款到账时间支持当天或隔天,支付费率低    

-

- 10、促进本地商家联盟数字化平台化发展 +

+    至千分之2.x

-

-
+

+ 10-供应商、服务商入驻,销售和推广效益提升

'; return $this->renderSuccess(compact('list')); } @@ -179,4 +175,24 @@ class Retail extends Controller } + /** + * 交易查询 + * @param string $outTradeNo 商户订单号 + * @param string $method 支付方式 + * @param string $client 指定的客户端 + * @return Json + * @throws \cores\exception\BaseException + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function tradeQuery(string $outTradeNo, string $method, string $client): Json + { + $RechargeService = new RetailService; + $result = $RechargeService->setMethod($method)->setClient($client)->tradeQuery($outTradeNo); + $message = $result ? '恭喜您,余额充值成功' : ($RechargeService->getError() ?: '很抱歉,订单未支付,请重新发起'); + return $this->renderSuccess(['isPay' => $result], $message); + } + + } \ No newline at end of file diff --git a/app/api/service/Notify.php b/app/api/service/Notify.php index 49452cd3..020152ec 100644 --- a/app/api/service/Notify.php +++ b/app/api/service/Notify.php @@ -83,6 +83,7 @@ class Notify $platformCertificateFilePath = PaymentTemplateModel::realPathCertFile( PaymentMethodEnum::WECHAT, $fileName, $templateInfo['store_id'] ); + // 验证异步通知是否合法并获取第三方支付交易订单号 $V3 = new WechatPaymentV3(); $outTradeNo = $V3->notify($apiv3Key, $platformCertificateFilePath); @@ -211,6 +212,17 @@ class Notify ->setPaymentData($paymentData) ->handle(); } + //订单支付成功事件(开通商城(批发零售商城)) + if ($tradeInfo['order_type'] == OrderTypeEnum::RETAIL || $tradeInfo['order_type'] == OrderTypeEnum::SALE) { + $service = new Retail\PaySuccess(); + $service->setOrderNo($tradeInfo['order_no']) + ->setMethod($tradeInfo['pay_method']) + ->setTradeId($tradeInfo['trade_id']) + ->setPaymentData($paymentData) + ->handle(); + } + + Log::append('Notify-orderPaySucces', ['message' => '订单支付成功']); } catch (\Throwable $e) { // 记录错误日志 diff --git a/app/api/service/Retail/PaySuccess.php b/app/api/service/Retail/PaySuccess.php index e402558b..064a17f3 100644 --- a/app/api/service/Retail/PaySuccess.php +++ b/app/api/service/Retail/PaySuccess.php @@ -220,7 +220,7 @@ class PaySuccess extends BaseService UserModel::setDecBalance((int)$orderInfo['user_id'], (float)$orderInfo['pay_price']); // 新增余额变动记录 $type = SceneEnum::BUY_SHOP; - if ($this->type == IdentityEnum::DEALER) { + if ($this->type == SceneEnum::DEALER) { $type = SceneEnum::DEALER; } BalanceLogModel::add($type, [ diff --git a/app/api/service/Retail/Payment.php b/app/api/service/Retail/Payment.php index f53548d9..b04ce087 100644 --- a/app/api/service/Retail/Payment.php +++ b/app/api/service/Retail/Payment.php @@ -100,11 +100,11 @@ class Payment extends BaseService // 构建第三方支付请求的参数 $payment = $this->unifiedorder($extra); // 记录第三方交易信息 - // $order_type = OrderTypeEnum::MEMBER;//开通会员 - // if ($this->orderInfo['order_type'] == IdentityEnum::DEALER) { - // $order_type = OrderTypeEnum::DEALER;//开通分销商 - // } - // $this->recordPaymentTrade($payment, $order_type); + $order_type = OrderTypeEnum::RETAIL;//开通零售商城 + if ($this->orderInfo['order_type'] == 20) { + $order_type = OrderTypeEnum::SALE;//开通批发商城 + } + $this->recordPaymentTrade($payment, $order_type); // 返回结果 return compact('payment'); } diff --git a/app/api/service/Store.php b/app/api/service/Store.php index 43249b6c..b46fff8e 100644 --- a/app/api/service/Store.php +++ b/app/api/service/Store.php @@ -196,7 +196,9 @@ class Store extends BaseService public function getStore() { - $storeList = Db::query('select shop_id,shop_name,longitude,latitude from yoshop_store_shop where status = 1 and is_delete= 0'); + $storeId = $this->storeId; + $storeList = Db::query('select shop_id,shop_name,longitude,latitude from yoshop_store_shop where status = 1 and is_delete= 0 AND store_id = ?', + [$storeId]); return $storeList; } diff --git a/app/common/enum/OrderType.php b/app/common/enum/OrderType.php index 45bfdbbf..710b00e4 100644 --- a/app/common/enum/OrderType.php +++ b/app/common/enum/OrderType.php @@ -40,6 +40,12 @@ class OrderType extends EnumBasics // 余额充值订单 const RECHARGE = 100; + //零售商城 + const RETAIL = 70; + + //批发商城 + const SALE = 80; + /** * 获取订单类型值 @@ -75,6 +81,14 @@ class OrderType extends EnumBasics self::WHOLESALER => [ 'name' => '开通采购商订单', 'value' => self::WHOLESALER, + ], + self::RETAIL => [ + 'name' => '开通零售商城订单', + 'value' => self::RETAIL, + ], + self::SALE => [ + 'name' => '开通采批发商城订单', + 'value' => self::SALE, ] ]; } diff --git a/app/common/enum/RetailDescribeEnum.php b/app/common/enum/RetailDescribeEnum.php index 191246e1..4bbf2ff2 100644 --- a/app/common/enum/RetailDescribeEnum.php +++ b/app/common/enum/RetailDescribeEnum.php @@ -18,6 +18,8 @@ class RetailDescribeEnum extends EnumBasics const MULTI_MERCHANT = 11; const CONTENT_MANAGEMENT = 12; const OTHER_FEATURES = 13; + const BUYER = 14; // 采购商 + const SERVICE_PROVIDER = 15; // 服务商 public static $version = [ self::GOODS => "商品", @@ -33,6 +35,8 @@ class RetailDescribeEnum extends EnumBasics self::MULTI_MERCHANT => "多商户", self::CONTENT_MANAGEMENT => "内容管理", self::OTHER_FEATURES => "其他功能", + self::BUYER => "采购商", + self::SERVICE_PROVIDER => "服务商" ]; private function __construct() { diff --git a/app/common/enum/user/balanceLog/Scene.php b/app/common/enum/user/balanceLog/Scene.php index a0bc8efb..8d6e9dbf 100644 --- a/app/common/enum/user/balanceLog/Scene.php +++ b/app/common/enum/user/balanceLog/Scene.php @@ -32,6 +32,9 @@ class Scene extends EnumBasics // 订单退款 const REFUND = 40; + + //购买商城 + const BUY_SHOP = 50; //开通分销商 const DEALER = 70; @@ -69,6 +72,11 @@ class Scene extends EnumBasics 'value' => self::REFUND, 'describe' => '订单退款:%s', ], + self::BUY_SHOP => [ + 'name' => '购买商城', + 'value' => self::BUY_SHOP, + 'describe' => '购买商城:%s', + ], self::DEALER => [ 'name' => '开通分销商', 'value' => self::DEALER, From a8322edc16a8e9f36e536e9bbb2a004f022bda1f Mon Sep 17 00:00:00 2001 From: zengyyh Date: Wed, 7 Aug 2024 22:39:50 +0800 Subject: [PATCH 63/69] pf --- app/admin/controller/RetailDescribe.php | 11 ++++-- app/api/controller/Retail.php | 48 ++++++++----------------- app/store/model/RetailDescribe.php | 2 +- 3 files changed, 24 insertions(+), 37 deletions(-) diff --git a/app/admin/controller/RetailDescribe.php b/app/admin/controller/RetailDescribe.php index 820e4989..3efe207b 100644 --- a/app/admin/controller/RetailDescribe.php +++ b/app/admin/controller/RetailDescribe.php @@ -20,7 +20,10 @@ class RetailDescribe extends Controller { $model = new retDescribeModel; $where = $this->request->get(); - $list = $model->getList($where); + $list = $model->getList($where)->toArray(); + foreach($list['data'] as &$item){ + $item['plate_name'] = RetailDescribeEnum::$version[$item['plate_id']]??''; + } return $this->renderSuccess(compact('list')); } @@ -49,7 +52,11 @@ class RetailDescribe extends Controller } public function getPlate(){ - $list = RetailDescribeEnum::$version; + $list1 = RetailDescribeEnum::$version; + $list = []; + foreach($list1 as $key => $value){ + $list[] = ['id' => $key, 'name' => $value]; + }; return $this->renderSuccess(compact('list')); } diff --git a/app/api/controller/Retail.php b/app/api/controller/Retail.php index 70fa79e2..319a5de3 100644 --- a/app/api/controller/Retail.php +++ b/app/api/controller/Retail.php @@ -100,39 +100,18 @@ class Retail extends Controller

10-促进本地商家联盟数字化平台化发展

'; - $list['wholesale'] = '

- 1-采购代发商家实名注册认证,在线直接下单 -

-

- 2-认证商家、服务商数字化管理 -

-

- 3-所有订单,发货记录,物流状态实时查询 -

-

- 4-所有调货记录在线实时查看 -

-

- 5-审单实时做电话、地址校验比对,避免平台单 -

-

- 6-供应链资源快速对接 -

-

- 7-商品数据快速上架,商城之间商品数据实时传输 -

-

- 8-商品市场价实时自动更新 -

-

- 9-货款到账时间支持当天或隔天,支付费率低     -

-

-    至千分之2.x -

-

- 10-供应商、服务商入驻,销售和推广效益提升 -

'; + $list['wholesale'] = '
+

1-采购代发商家实名注册认证,在线直接下单

+

2-认证商家、服务商数字化管理

+

3-所有订单,发货记录,物流状态实时查询

+

4-所有调货记录在线实时查看

+

5-审单实时做电话、地址校验比对,避免平台单

+

6-供应链资源快速对接

+

7-商品数据快速上架,商城之间商品数据实时传输

+

8-商品市场价实时自动更新

+

9-货款到账时间支持当天或隔天,支付费率低 至千分之 2.x

+

10-供应商、服务商入驻,销售和推广效益提升

+
'; return $this->renderSuccess(compact('list')); } @@ -164,7 +143,8 @@ class Retail extends Controller public function describe() { $type = $this->request->get('type')??10; - $list = RetailDescribeModel::withoutGlobalScope()->where(['description_status' =>10,'type' => $type])->select(); + $list = RetailDescribeModel::withoutGlobalScope()->where(['description_status' =>10,'type' => $type]) + ->order(['sort' => 'asc','create_time' => 'asc'])->select(); $group = []; foreach($list as $item){ diff --git a/app/store/model/RetailDescribe.php b/app/store/model/RetailDescribe.php index 954bfc46..284ddf00 100644 --- a/app/store/model/RetailDescribe.php +++ b/app/store/model/RetailDescribe.php @@ -23,7 +23,7 @@ class RetailDescribe extends RetDescribeModel $filter = $this->getFilter($param); $list = $this->field('*') ->where($filter) - ->order(['create_time' => 'asc','sort' => 'asc']) + ->order(['sort' => 'asc','create_time' => 'asc']) ->paginate($param['pageSize'] ?? 15); return $list; } From 5d6e7be7b95fdd10f6a169613c71a5a1e5fd8724 Mon Sep 17 00:00:00 2001 From: lqmac Date: Thu, 8 Aug 2024 02:05:53 +0800 Subject: [PATCH 64/69] 1 --- app/api/service/order/PaySuccess.php | 45 +++++++++++++++++----------- app/common/model/MerchantPay.php | 5 ++-- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/app/api/service/order/PaySuccess.php b/app/api/service/order/PaySuccess.php index 2a1ed9bb..e24bbe3b 100644 --- a/app/api/service/order/PaySuccess.php +++ b/app/api/service/order/PaySuccess.php @@ -344,27 +344,36 @@ class PaySuccess extends BaseService // 当前订单信息 $orderInfo = $this->getOrderInfo(); // 余额支付 - if ($this->method == PaymentMethodEnum::BALANCE) { - // 更新用户余额 - UserModel::setDecBalance((int)$orderInfo['user_id'], (float)$orderInfo['pay_price']); - // 新增余额变动记录 - BalanceLogModel::add(SceneEnum::CONSUME, [ - 'user_id' => (int)$orderInfo['user_id'], - 'money' => -$orderInfo['pay_price'], - ], ['order_no' => $orderInfo['order_no']]); + if ($this->method == PaymentMethodEnum::BALANCE || $this->method == PaymentMethodEnum::HUIFU) { + if ($this->method == PaymentMethodEnum::BALANCE) { + // 更新用户余额 + UserModel::setDecBalance((int)$orderInfo['user_id'], (float)$orderInfo['pay_price']); + // 新增余额变动记录 + BalanceLogModel::add(SceneEnum::CONSUME, [ + 'user_id' => (int)$orderInfo['user_id'], + 'money' => -$orderInfo['pay_price'], + ], ['order_no' => $orderInfo['order_no']]); + } + - // //增加商户支付详情 - // $model = \app\store\model\Merchant::detail($orderInfo['merchant_id']); - // $precent = 1; + if ($orderInfo['merchant_id']) { + //增加商户支付详情 + $model = \app\store\model\Merchant::detail($orderInfo['merchant_id']); + if ($model) { + $precent = 1; - // if ($model['commission_ratio']) { - // $precent = (1 - $model['commission_ratio'] / 1000); - // } - // $precentPrice = round($precent * $orderInfo['pay_price'], 2); - // (new merchantPayModel())->addDetail($orderInfo, $precentPrice); + if ($model['commission_ratio']) { + $precent = (1 - $model['commission_ratio'] / 1000); + } + $precentPrice = round($precent * $orderInfo['pay_price'], 2); + (new merchantPayModel())->addDetail($orderInfo, $precentPrice, $this->method == PaymentMethodEnum::HUIFU ? 1 : 0); - // //累计商户余额支付金额 - // merchantModel::setIncTotal($orderInfo['merchant_id'], $precentPrice); + //累计商户余额支付金额 + merchantModel::setIncTotal($orderInfo['merchant_id'], $precentPrice); + } + + } + } // 将第三方交易记录更新为已支付状态 if (in_array($this->method, [PaymentMethodEnum::WECHAT, PaymentMethodEnum::ALIPAY, PaymentMethodEnum::HUIFU])) { diff --git a/app/common/model/MerchantPay.php b/app/common/model/MerchantPay.php index 0725e0ee..401f77be 100644 --- a/app/common/model/MerchantPay.php +++ b/app/common/model/MerchantPay.php @@ -34,14 +34,15 @@ class MerchantPay extends BaseModel * @param float $money * @return mixed */ - public function addDetail($orderInfo, $precentPrice) + public function addDetail($orderInfo, $precentPrice, $source = 0) { if (!empty($orderInfo['merchant_id'])) { $data = [ 'order_id' => $orderInfo['order_id'], - //'store_id' => $orderInfo['store_id'], + 'store_id' => $orderInfo['store_id'], 'merchant_id' => $orderInfo['merchant_id'], 'total_amount' => $precentPrice, + 'source' => $source, ]; return $this->save($this->createData($data)); } From 8439c4b56fb93191d5bec8e7a5c76123078add2c Mon Sep 17 00:00:00 2001 From: zengyyh Date: Wed, 28 Aug 2024 23:19:10 +0800 Subject: [PATCH 65/69] 1 --- app/api/service/identity/Payment.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/api/service/identity/Payment.php b/app/api/service/identity/Payment.php index 72c0b08b..dfb8b7dc 100644 --- a/app/api/service/identity/Payment.php +++ b/app/api/service/identity/Payment.php @@ -243,7 +243,7 @@ class Payment extends BaseService private function unifiedorder(array $extra = []): array { // 判断支付方式是否合法 - if (!in_array($this->method, [PaymentMethodEnum::WECHAT, PaymentMethodEnum::ALIPAY])) { + if (!in_array($this->method, [PaymentMethodEnum::WECHAT, PaymentMethodEnum::ALIPAY, PaymentMethodEnum::HUIFU])) { return []; } // 生成第三方交易订单号 (并非主订单号) From e444319489b08b7a9dfa7d0826dcf3ebb786af9c Mon Sep 17 00:00:00 2001 From: zyh Date: Thu, 29 Aug 2024 16:27:45 +0800 Subject: [PATCH 66/69] q --- app/api/controller/Invite.php | 7 ++++++- app/api/controller/Store.php | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/api/controller/Invite.php b/app/api/controller/Invite.php index 32bc38b6..2f84d274 100644 --- a/app/api/controller/Invite.php +++ b/app/api/controller/Invite.php @@ -97,6 +97,7 @@ class Invite extends Controller $data['adoption_num'] = 0; $data['refuse_num'] = 0; $model = new InviteLog(); + $storeId = $this->storeId; $user_ids = $model->inviteeUserIds(); $status = intval($this->request->post('status')); if (!$status) { @@ -117,8 +118,12 @@ class Invite extends Controller } $data['list'] = $list->items(); $data['total'] = $list->total(); + //1.查询需要的邀请人数是多少 + $setting = Setting::where(['key'=>'condition'])->field('values')->find(); + $setting = json_decode($setting,true); + $invite_num = $setting['values']['invite_num'] ?? 10; //审核通过 - $data['adoption_num'] = $applyModel->whereIn('user_id', $user_ids)->where(['status' => WholesalerEnum::ADOPT])->count(); + $data['adoption_num'] = ($applyModel->whereIn('user_id', $user_ids)->where(['status' => WholesalerEnum::ADOPT])->count()).'/'.$invite_num; //审核拒绝 $data['refuse_num'] = $applyModel->whereIn('user_id', $user_ids)->where(['status' => WholesalerEnum::REFUSE])->count(); } diff --git a/app/api/controller/Store.php b/app/api/controller/Store.php index f493bb0f..eb8920ec 100644 --- a/app/api/controller/Store.php +++ b/app/api/controller/Store.php @@ -222,7 +222,7 @@ class Store extends Controller $page = $this->request->param('page') ?? 1; $servers = new successful(); //$list = $servers->list($page); - $list = successful:: withoutGlobalScope()->where('status',10)->order('sort','asc')->paginate(10, false, $page); + $list = successful::where('status',10)->order('sort','asc')->paginate(10, false, $page); $list->each(function ($item, $key) { $imageUrl = UploadFile::withoutGlobalScope()->where('file_id', $item['image_id'])->find(); if ($imageUrl) { From 9bf1c096b615cbab548d857d36cad52b1a3072e7 Mon Sep 17 00:00:00 2001 From: zyh Date: Fri, 30 Aug 2024 10:22:52 +0800 Subject: [PATCH 67/69] 1 --- app/store/model/RetailDescribe.php | 71 ------------------------------ 1 file changed, 71 deletions(-) diff --git a/app/store/model/RetailDescribe.php b/app/store/model/RetailDescribe.php index 62906265..284ddf00 100644 --- a/app/store/model/RetailDescribe.php +++ b/app/store/model/RetailDescribe.php @@ -39,77 +39,6 @@ class RetailDescribe extends RetDescribeModel return $this->where('id' ,$id)->update($data); } - public function del(array $id){ - return $this->whereIn('id' ,$id)->delete(); - } - - /** - * 设置查询条件 - * @param array $param - * @return array - */ - private function getFilter(array $param): array - { - // 设置默认的检索数据 - $params = $this->setQueryDefaultValue($param, [ - 'plate_id' => 0, // 类型id - 'search' => '', // 查询内容 - 'type' => 0, // 商城类型 - 'description_status' => 0, // 状态 - ]); - // 检索查询条件 - $filter = []; - // 类型id - $params['plate_id'] > 0 && $filter[] = ['plate_id', '=', $params['plate_id']]; - // 用户昵称/订单号 - !empty($params['search']) && $filter[] = ['feature|function_description', 'like', "%{$params['search']}%"]; - // 批发商城类型 - $params['type'] > 0 && $filter[] = ['type', '=', (int)$params['type']]; - // 支付状态 - $params['description_status'] > 0 && $filter[] = ['description_status', '=', (int)$params['description_status']]; - return $filter; - } -} -// +---------------------------------------------------------------------- -declare (strict_types=1); - -namespace app\store\model; - -use app\common\model\RetailDescribe as retDescribeModel; - -class RetailDescribe extends RetDescribeModel -{ - - public function getList(array $param = []): \think\Paginator - { - // 设置查询条件 - $filter = $this->getFilter($param); - $list = $this->field('*') - ->where($filter) - ->order(['create_time' => 'asc','sort' => 'asc']) - ->paginate($param['pageSize'] ?? 15); - return $list; - } - - public function detail(int $id){ - return self::where('id',$id)->find(); - } - - public function add(array $data){ - return $this->save($data); - } - public function edit(int $id ,array $data){ - return $this->where('id' ,$id)->update($data); - } - public function del(array $id){ return $this->whereIn('id' ,$id)->delete(); } From 67195549552163c1a103a8f8e06d50444d233f2f Mon Sep 17 00:00:00 2001 From: zyh Date: Fri, 30 Aug 2024 14:13:23 +0800 Subject: [PATCH 68/69] 1 --- app/api/controller/Invite.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/api/controller/Invite.php b/app/api/controller/Invite.php index 2f84d274..3f5e3201 100644 --- a/app/api/controller/Invite.php +++ b/app/api/controller/Invite.php @@ -123,7 +123,8 @@ class Invite extends Controller $setting = json_decode($setting,true); $invite_num = $setting['values']['invite_num'] ?? 10; //审核通过 - $data['adoption_num'] = ($applyModel->whereIn('user_id', $user_ids)->where(['status' => WholesalerEnum::ADOPT])->count()).'/'.$invite_num; + $adoption_num = $applyModel->whereIn('user_id', $user_ids)->where(['status' => WholesalerEnum::ADOPT])->count(); + $data['adoption_num'] = $adoption_num."/".$invite_num; //审核拒绝 $data['refuse_num'] = $applyModel->whereIn('user_id', $user_ids)->where(['status' => WholesalerEnum::REFUSE])->count(); } From 60ebd8a91c5b8a3c20852033283f5b16bfa9130c Mon Sep 17 00:00:00 2001 From: zyh Date: Fri, 6 Sep 2024 11:28:47 +0800 Subject: [PATCH 69/69] 123 --- app/api/controller/Invite.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/api/controller/Invite.php b/app/api/controller/Invite.php index 2e490c49..7d34a2ad 100644 --- a/app/api/controller/Invite.php +++ b/app/api/controller/Invite.php @@ -102,6 +102,7 @@ class Invite extends Controller $data['total'] = 0; $data['adoption_num'] = $adoption_num."/".$invite_num; $data['refuse_num'] = 0; + $data['invite_num'] = 0; $model = new InviteLog(); $storeId = $this->storeId; $user_ids = $model->inviteeUserIds(); @@ -130,6 +131,7 @@ class Invite extends Controller $invite_num = $setting['values']['invite_num'] ?? 10; //审核通过 $adoption_num = $applyModel->whereIn('user_id', $user_ids)->where(['status' => WholesalerEnum::ADOPT])->count(); + $data['invite_num'] = $adoption_num; $data['adoption_num'] = $adoption_num."/".$invite_num; //审核拒绝 $data['refuse_num'] = $applyModel->whereIn('user_id', $user_ids)->where(['status' => WholesalerEnum::REFUSE])->count();