From fff61c55ab87728771c426e31e286f1c34b8da19 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sun, 21 Jan 2024 18:44:58 +0800 Subject: [PATCH 01/31] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/admin/store/StoreProduct.php | 8 +-- app/controller/api/Common.php | 7 +-- app/controller/api/Demo.php | 55 +-------------------- crmeb/services/QrcodeService.php | 16 +++++- 4 files changed, 21 insertions(+), 65 deletions(-) diff --git a/app/controller/admin/store/StoreProduct.php b/app/controller/admin/store/StoreProduct.php index bbdf129a..83337161 100644 --- a/app/controller/admin/store/StoreProduct.php +++ b/app/controller/admin/store/StoreProduct.php @@ -301,10 +301,12 @@ class StoreProduct extends BaseController $this->repository->updates($ids,$data); return app('json')->success('修改成功'); } - public function copy(){ - $product=$this->repository->getAdminOneProduct(6300,0); + //**复制商品 */ + public function copy($product_id=0,$mer_id=0){ + if($product_id==0) return app('json')->fail('参数错误'); + $product=$this->repository->getAdminOneProduct($product_id,0); $product = $product->toArray(); - $product['mer_id']=113; + $product['mer_id']=$mer_id; $product['old_product_id']=$product['product_id']; return $this->repository->create($product, 0,1); diff --git a/app/controller/api/Common.php b/app/controller/api/Common.php index 816eea9d..190f22f9 100644 --- a/app/controller/api/Common.php +++ b/app/controller/api/Common.php @@ -653,12 +653,7 @@ class Common extends BaseController $imageInfo = null; } if (!$imageInfo) { - $imageInfo = app()->make(QrcodeService::class)->getQRCodePath($data['code'], $name,['code'=>[ - 'r' => 255, - 'g' => 221, - 'b' => 167, - 'a' => 0, - ]]); + $imageInfo = app()->make(QrcodeService::class)->getQRCodePath($data['code'], $name,['code'=>1]); if (is_string($imageInfo)) throw new ValidateException('二维码生成失败'); $imageInfo['dir'] = tidy_url($imageInfo['dir'], null, $siteUrl); diff --git a/app/controller/api/Demo.php b/app/controller/api/Demo.php index cad9fbe9..d433392d 100644 --- a/app/controller/api/Demo.php +++ b/app/controller/api/Demo.php @@ -30,60 +30,7 @@ class Demo extends BaseController { public function index() { - $data=[ - - 6923644264192, - 6923644210151, - 6921665735042, - 6921665731693, - 6921665731679, - 6921665730825, - 6921665707940, - 6921665701054, - 6920208995349, - 6920208986163, - 6920208960866, - 6920208960064, - 6920208924394, - 6920208924035, - 6920208924011, - 6919188019961, - 6919188019961, - 6908791503943, - 6908791006024, - 6907992507385, - ]; - $mer_id=167; - foreach ($data as $item) { - $store_product_attr_value=Db::name('store_product_attr_value')->alias('a') - ->join('store_product b','a.product_id=b.product_id and b.product_type=98') - ->where('a.bar_code',$item)->value('a.product_id'); - if($store_product_attr_value){ - $find=Db::name('store_product_attr_value')->alias('a') - ->join('store_product b','a.product_id=b.product_id and b.product_type=0 and b.mer_id='.$mer_id) - ->where('a.bar_code',$item)->field('a.product_id,b.cate_id')->find(); - if($find){ - $cloud_product=Db::name('cloud_product')->where('product_id',$find['product_id'])->where('mer_id',$mer_id)->value('product_id'); - if(!$cloud_product){ - $source_mer_id = Db::name('store_product')->where('product_id', $store_product_attr_value)->value('mer_id'); - $datas = [ - 'product_id' => $find['product_id'], - 'cate_id' => $find['cate_id'], - 'mer_id' => $mer_id, - 'source_mer_id' => $source_mer_id, - 'street_code' => 510521107, - 'type_id' => 17, - 'category_id' => 2566, - 'weight' => 1, - 'status' => 1, - 'create_time' => date('Y-m-d H:i:s'), - 'mer_labels' =>'', - ]; - Db::name('cloud_product')->insert($datas); - } - } - } - } + halt(1); $mer_id = 104; $file = request()->file('file'); diff --git a/crmeb/services/QrcodeService.php b/crmeb/services/QrcodeService.php index 0fba8528..1bdcfe12 100644 --- a/crmeb/services/QrcodeService.php +++ b/crmeb/services/QrcodeService.php @@ -41,10 +41,22 @@ class QrcodeService if (!$siteUrl) return '请前往后台设置->系统设置->网站域名 填写您的域名格式为:http://域名'; $info = []; $outfile = Config::get('qrcode.cache_dir'); - $code = new QrCode($url); + $code = new QrCode(); if(isset($data['code'])){ - $code->setForegroundColor($data['code']); + $code->setForegroundColor([ + 'r' => 248, + 'g' => 150, + 'b' => 46, + 'a' => 0, + ]); + $code->setBackgroundColor([ + 'r' => 255, + 'g' => 246, + 'b' => 235, + 'a' => 0, + ]); } + $code->setText($url); if ($uploadType === 1) { if (!is_dir('./public/' . $outfile)) mkdir('./public/' . $outfile, 0777, true); From f0322b61a0ffe2929b65a7fd8664a86b3cc31d99 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sun, 21 Jan 2024 19:21:38 +0800 Subject: [PATCH 02/31] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/Auth.php | 1 + app/controller/api/Demo.php | 6 ++++-- crmeb/jobs/ProductCopyJob.php | 36 +++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 crmeb/jobs/ProductCopyJob.php diff --git a/app/controller/api/Auth.php b/app/controller/api/Auth.php index 0048b4e2..dfe0b51e 100644 --- a/app/controller/api/Auth.php +++ b/app/controller/api/Auth.php @@ -410,6 +410,7 @@ class Auth extends BaseController }else{ $data['show_controller_applet']=false; } + $data['red_pack_balance']=Db::name('store_consumption_user')->where('uid',$data['uid'])->where('status',0)->sum('balance'); return app('json')->success($data); } diff --git a/app/controller/api/Demo.php b/app/controller/api/Demo.php index d433392d..965bb767 100644 --- a/app/controller/api/Demo.php +++ b/app/controller/api/Demo.php @@ -19,7 +19,8 @@ use think\facade\Db; use crmeb\services\UploadService; use Exception; use ZipArchive; - +use think\facade\Queue; +use crmeb\jobs\ProductCopyJob; /** * Class Auth * @package app\controller\api @@ -30,7 +31,8 @@ class Demo extends BaseController { public function index() { - + // Queue::push(ProductCopyJob::class, ['product_id' => 0, 'mer_id' =>0]);//短信通知 + halt(1); $mer_id = 104; $file = request()->file('file'); diff --git a/crmeb/jobs/ProductCopyJob.php b/crmeb/jobs/ProductCopyJob.php new file mode 100644 index 00000000..0c253122 --- /dev/null +++ b/crmeb/jobs/ProductCopyJob.php @@ -0,0 +1,36 @@ + +// +---------------------------------------------------------------------- + + +namespace crmeb\jobs; + + +use crmeb\interfaces\JobInterface; +use app\controller\admin\store\StoreProduct; + + +class ProductCopyJob implements JobInterface +{ + + public function fire($job, $data) + { + $make = app()->make(StoreProduct::class); + $make->copyProduct($data['id'],$data['copy_id']); + $job->delete(); + } + + + public function failed($data) + { + // TODO: Implement failed() method. + } +} From c9d4018c8fe9477dea21dca7dcf11315e3490e6e Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sun, 21 Jan 2024 19:28:52 +0800 Subject: [PATCH 03/31] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/user/User.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controller/api/user/User.php b/app/controller/api/user/User.php index b584233f..85dea752 100644 --- a/app/controller/api/user/User.php +++ b/app/controller/api/user/User.php @@ -541,7 +541,8 @@ class User extends BaseController */ public function qrcode(){ $common= app()->make(Common::class); - $data=$common->Qrcode(['code'=>'shop_'.$this->user->uid,'id'=>$this->user->uid]); + $siteUrl = systemConfig('site_url'); + $data=$common->Qrcode(['code'=>$siteUrl.'download/index.html?code=shop_'.$this->user->uid,'id'=>$this->user->uid]); return app('json')->success(['url'=>$data]); } } From d92ce3d5eaaf8f8bafb06084fd555dbd3b10c5bf Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sun, 21 Jan 2024 19:52:49 +0800 Subject: [PATCH 04/31] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../order/StoreOrderCreateRepository.php | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/app/common/repositories/store/order/StoreOrderCreateRepository.php b/app/common/repositories/store/order/StoreOrderCreateRepository.php index 972be47b..b7d0076c 100644 --- a/app/common/repositories/store/order/StoreOrderCreateRepository.php +++ b/app/common/repositories/store/order/StoreOrderCreateRepository.php @@ -35,10 +35,12 @@ class StoreOrderCreateRepository extends StoreOrderRepository { protected $store_consumption_user; protected $consumption_money; + protected $balance; public function v2CartIdByOrderInfo($user, array $cartId, array $takes = null, array $useCoupon = null, bool $useIntegral = false, int $addressId = null, $createOrder = false, $consumption_id = 0) { $uid = $user->uid; + $this->balance = 0; $userIntegral = $user->integral; $key = md5(json_encode(compact('cartId', 'takes', 'useCoupon', 'useIntegral', 'addressId'))) . $uid; app()->make(StoreCouponUserRepository::class)->failCoupon(); @@ -154,6 +156,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository if ($consumption_id > 0) { $this->store_consumption_user = Db::name('store_consumption_user')->where('coupon_user_id', $consumption_id)->where('uid', $uid)->find(); + $this->balance=$this->store_consumption_user['balance']; } // 循环计算每个店铺的订单数据 委托商品是否设置收货方式 ? foreach ($merchantCartList as &$merchantCart) { @@ -565,33 +568,33 @@ class StoreOrderCreateRepository extends StoreOrderRepository $pay_price = $org_price; } //计算总红包金额 - $a = 0; if ($consumption_id > 0) { if ($this->store_consumption_user) { if ($this->store_consumption_user['type'] == 2) { $a = bcdiv($pay_price, 6); - if ($this->store_consumption_user['balance'] > $a) { + if ($this->balance > $a) { $pay_price = bcsub($pay_price, $a, 2); $this->consumption_money = bcadd($this->consumption_money, $a); - $this->store_consumption_user['balance'] = bcsub($this->store_consumption_user['balance'], $a); + $this->balance = bcsub($this->balance, $a); } else { - $a = $this->store_consumption_user['balance']; - $pay_price = bcsub($pay_price, $this->store_consumption_user['balance'], 2); - $this->consumption_money = bcadd($this->consumption_money, $this->store_consumption_user['balance']); - $this->store_consumption_user['balance'] = 0; + $pay_price = bcsub($pay_price, $this->balance, 2); + $this->consumption_money = bcadd($this->consumption_money, $this->balance); + $this->balance = 0; } } if ($this->store_consumption_user['type'] == 1) { - if ($pay_price > $this->store_consumption_user['balance']) { - $pay_price = bcsub($pay_price, $this->store_consumption_user['balance'], 2); - $this->consumption_money = $this->store_consumption_user['balance']; - $a = $this->store_consumption_user['balance']; + if ($pay_price > $this->balance) { + $pay_price = bcsub($pay_price, $this->balance, 2); + $this->consumption_money = bcadd($this->consumption_money, $this->balance); + $this->balance=0; } else { - $this->consumption_money = $pay_price; $pay_price = 0; - $a = $this->consumption_money; + $this->consumption_money = bcadd($this->consumption_money, $pay_price); + $this->balance = $pay_price; + } } + } } @@ -611,7 +614,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository $merchantCart['order']['postage_price'] = $merchantCart['order']['postage_price']; $merchantCart['order']['procure_price'] = $merchantCart['order']['procure_price']; $merchantCart['order']['consumption_id'] = $consumption_id; - $merchantCart['order']['consumption_money'] = $a; + $merchantCart['order']['consumption_money'] = $this->balance; $order_price = bcadd($order_price, $pay_price, 2); $order_total_price = bcadd($order_total_price, $total_price, 2); From 32ebe6ce1ca270edd81c2b8cb0f33d0ae61d13e9 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sun, 21 Jan 2024 20:08:31 +0800 Subject: [PATCH 05/31] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/cache.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/cache.php b/config/cache.php index 15796fa0..620d58b3 100644 --- a/config/cache.php +++ b/config/cache.php @@ -16,7 +16,7 @@ return [ // 默认缓存驱动 - 'default' => env('INSTALLED', false) ? env('cache.driver', 'redis') : 'file', + 'default' => 'redis', // 缓存连接方式配置 'stores' => [ From c04d4d19d6eaeced6450139728112e181e00c637 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sun, 21 Jan 2024 20:28:41 +0800 Subject: [PATCH 06/31] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dao/store/consumption/StoreConsumptionDao.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/common/dao/store/consumption/StoreConsumptionDao.php b/app/common/dao/store/consumption/StoreConsumptionDao.php index 5e375f1e..29ecd6a0 100644 --- a/app/common/dao/store/consumption/StoreConsumptionDao.php +++ b/app/common/dao/store/consumption/StoreConsumptionDao.php @@ -25,7 +25,15 @@ class StoreConsumptionDao extends BaseDao */ public function getValidList() { - return StoreConsumption::whereIn('type', [StoreConsumption::TYPE_OWNER_CONSUMPTION, StoreConsumption::TYPE_PULL_CONSUMPTION])->where('status', StoreConsumption::STATUS_ENABLE)->field('coupon_id,start_time,end_time,title')->select(); + return StoreConsumption::whereIn('type', [StoreConsumption::TYPE_OWNER_CONSUMPTION, StoreConsumption::TYPE_PULL_CONSUMPTION])->where('status', StoreConsumption::STATUS_ENABLE) + ->field('coupon_id,start_time,end_time,title')->select()->each(function ($item){ + if($item['title']==['无门槛实物通用红包']){ + $item['title'] = '用户推荐拉新活动'; + }else{ + $item['title'] = '用户消费补贴活动'; + } + return $item; + }); } public function getOne($id) From d004a8ad16e10b6626bdf5b52d829ec72519897a Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sun, 21 Jan 2024 20:40:21 +0800 Subject: [PATCH 07/31] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/dao/store/consumption/StoreConsumptionDao.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/common/dao/store/consumption/StoreConsumptionDao.php b/app/common/dao/store/consumption/StoreConsumptionDao.php index 29ecd6a0..bc4b3162 100644 --- a/app/common/dao/store/consumption/StoreConsumptionDao.php +++ b/app/common/dao/store/consumption/StoreConsumptionDao.php @@ -27,7 +27,7 @@ class StoreConsumptionDao extends BaseDao { return StoreConsumption::whereIn('type', [StoreConsumption::TYPE_OWNER_CONSUMPTION, StoreConsumption::TYPE_PULL_CONSUMPTION])->where('status', StoreConsumption::STATUS_ENABLE) ->field('coupon_id,start_time,end_time,title')->select()->each(function ($item){ - if($item['title']==['无门槛实物通用红包']){ + if($item['title']=='无门槛实物通用红包'){ $item['title'] = '用户推荐拉新活动'; }else{ $item['title'] = '用户消费补贴活动'; From 1b2aed7a4f43c0cf06efb3ae7a9bcdd6b4ec5fc5 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sun, 21 Jan 2024 20:51:02 +0800 Subject: [PATCH 08/31] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/repositories/user/UserRepository.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/common/repositories/user/UserRepository.php b/app/common/repositories/user/UserRepository.php index 8c16a1b3..5eacd8c5 100644 --- a/app/common/repositories/user/UserRepository.php +++ b/app/common/repositories/user/UserRepository.php @@ -673,6 +673,10 @@ class UserRepository extends BaseRepository ]; if($code){ $data['promotion_code']=$code; + $shop=explode('shop_',$code); + if(count($shop)==2){ + $data['spread_uid']=$shop[1]; + } Cache::delete('promote_'.$ip); } return $this->create($user_type, $data); From 9b07143f00068446b33acf19b4fc2a1aeb3429dd Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sun, 21 Jan 2024 21:09:22 +0800 Subject: [PATCH 09/31] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/dao/store/StoreActivityUserDao.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/common/dao/store/StoreActivityUserDao.php b/app/common/dao/store/StoreActivityUserDao.php index 2a99f9d6..0baddc95 100644 --- a/app/common/dao/store/StoreActivityUserDao.php +++ b/app/common/dao/store/StoreActivityUserDao.php @@ -116,12 +116,12 @@ class StoreActivityUserDao extends BaseDao ->where('activity_id', $activityId) ->where('status', StoreActivityOrder::STATUS_VALID) ->find(); - if (empty($myOrder)) { + $userInfo = User::where('spread_uid', $userId)->field('uid,nickname,avatar')->select()->toArray(); + if (empty($myOrder)||empty($myOrder['total_amount'])) { return ['target' => $target, 'allow_receive' => false, 'user_info' => $userInfo]; } $storeConsumptionUserDao = new StoreConsumptionUserDao(); $scope = $storeConsumptionUserDao->getScope($consumption, $myOrder['total_amount']); - $userInfo = User::where('spread_uid', $userId)->field('uid,nickname,avatar')->select()->toArray(); $orders = StoreActivityOrder::where('spread_id', $userId) ->whereIn('user_id', array_column($userInfo, 'uid')) ->where('activity_id', $activityId) From 6026efc4df734eb43f8afb5ea5980eb2dd208a2d Mon Sep 17 00:00:00 2001 From: lewis <604446095@qq.com> Date: Sun, 21 Jan 2024 21:16:33 +0800 Subject: [PATCH 10/31] =?UTF-8?q?=E8=B0=83=E6=95=B4=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E7=BA=A2=E5=8C=85=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/dao/store/StoreActivityUserDao.php | 28 +++++++++++++++--- .../consumption/StoreConsumptionUserDao.php | 2 +- config/{crmeb.php => crmeb.php.back} | Bin config/{swoole.php => swoole.php.back} | 0 4 files changed, 25 insertions(+), 5 deletions(-) rename config/{crmeb.php => crmeb.php.back} (100%) rename config/{swoole.php => swoole.php.back} (100%) diff --git a/app/common/dao/store/StoreActivityUserDao.php b/app/common/dao/store/StoreActivityUserDao.php index 2a99f9d6..2f72d398 100644 --- a/app/common/dao/store/StoreActivityUserDao.php +++ b/app/common/dao/store/StoreActivityUserDao.php @@ -183,13 +183,19 @@ class StoreActivityUserDao extends BaseDao ->whereIn('type', $type) ->where('status', StoreConsumptionUser::STATUS_UNUSED) ->sum('balance'); - $query = UserBill::with('storeConsumptionUser') - ->field('link_id,create_time') + $query = UserBill::field('link_id,create_time,number coupon_price,mark') ->where('uid', $userId) ->where('category', 'red_pack') ->where('type', "red_pack_{$type}"); $count = $query->count(); $record = $query->page($page)->limit($limit)->select()->toArray(); + foreach ($record as &$item) { + $item['order_amount'] = 0; + if (mb_strpos($item['mark'], '订单金额:') !== false) { + $item['order_amount'] = mb_substr($item['mark'], mb_strpos($item['mark'], '订单金额:') + 5); + } + unset($item['mark']); + } return ['total_amount' => $totalAmount, 'count' => $count, 'record' => $record]; } @@ -206,10 +212,24 @@ class StoreActivityUserDao extends BaseDao ->field('SUM(balance) as total_amount,type') ->group('type') ->select()->toArray(); - foreach ($totalAmount as &$item) { + $totalAmount = reset_index($totalAmount, 'type'); + $result = [ + [ + 'type' => 1, + 'total_amount' => 0.00 + ], + [ + 'type' => 2, + 'total_amount' => 0.00 + ] + ]; + foreach ($result as &$item) { + if (isset($totalAmount[$item['type']])) { + $item['total_amount'] = $totalAmount[$item['type']]['total_amount']; + } $item['type_cn'] = StoreConsumptionUser::TYPE_MAP[$item['type']]; } - return $totalAmount; + return $result; } } diff --git a/app/common/dao/store/consumption/StoreConsumptionUserDao.php b/app/common/dao/store/consumption/StoreConsumptionUserDao.php index 511d3c50..698f5f5e 100644 --- a/app/common/dao/store/consumption/StoreConsumptionUserDao.php +++ b/app/common/dao/store/consumption/StoreConsumptionUserDao.php @@ -230,7 +230,7 @@ class StoreConsumptionUserDao extends BaseDao 'status' => 1, 'title' => '获得' . $title, 'number' => $couponPrice, - 'mark' => '获得' . $title . $couponPrice, + 'mark' => '获得' . $title . $couponPrice . ",订单金额:{$amount}", 'balance' => 0 ]); } diff --git a/config/crmeb.php b/config/crmeb.php.back similarity index 100% rename from config/crmeb.php rename to config/crmeb.php.back diff --git a/config/swoole.php b/config/swoole.php.back similarity index 100% rename from config/swoole.php rename to config/swoole.php.back From f39c34e86fcc317b147c41b471b0babbbb57b672 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sun, 21 Jan 2024 21:21:25 +0800 Subject: [PATCH 11/31] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/Common.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controller/api/Common.php b/app/controller/api/Common.php index 190f22f9..9e549515 100644 --- a/app/controller/api/Common.php +++ b/app/controller/api/Common.php @@ -644,7 +644,7 @@ class Common extends BaseController public function Qrcode($data) { $siteUrl = systemConfig('site_url'); - $name = md5('orcode' . date('Ymd')) . '.png'; + $name = md5('orcode'.$data['id'] . date('Ymd')) . '.png'; $attachmentRepository = app()->make(AttachmentRepository::class); $imageInfo = $attachmentRepository->getWhere(['attachment_name' => $name]); From 3ce108920aa635b8e1642967608876266e66a966 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sun, 21 Jan 2024 21:23:36 +0800 Subject: [PATCH 12/31] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/Common.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controller/api/Common.php b/app/controller/api/Common.php index 9e549515..cbd5aa15 100644 --- a/app/controller/api/Common.php +++ b/app/controller/api/Common.php @@ -644,7 +644,7 @@ class Common extends BaseController public function Qrcode($data) { $siteUrl = systemConfig('site_url'); - $name = md5('orcode'.$data['id'] . date('Ymd')) . '.png'; + $name = 'orcode'.$data['id'] .md5(date('Ymd')) . '.png'; $attachmentRepository = app()->make(AttachmentRepository::class); $imageInfo = $attachmentRepository->getWhere(['attachment_name' => $name]); From 4df2a3755c0c70e90ceb5b6f62e0d0351bb6e611 Mon Sep 17 00:00:00 2001 From: lewis <604446095@qq.com> Date: Sun, 21 Jan 2024 21:30:17 +0800 Subject: [PATCH 13/31] =?UTF-8?q?=E8=B0=83=E6=95=B4=E8=87=AA=E6=8F=90?= =?UTF-8?q?=E7=AD=96=E7=95=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repositories/store/order/StoreOrderCreateRepository.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/common/repositories/store/order/StoreOrderCreateRepository.php b/app/common/repositories/store/order/StoreOrderCreateRepository.php index b7d0076c..6e3c036f 100644 --- a/app/common/repositories/store/order/StoreOrderCreateRepository.php +++ b/app/common/repositories/store/order/StoreOrderCreateRepository.php @@ -449,7 +449,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository 'platformCoupon' => $platformCoupon, 'svip_coupon_merge' => $svip_coupon_merge, 'postage_price' => $postage_price, - 'isTake' => intval($allowDelivery == false), + 'isTake' => intval($allowDelivery == false || count($takes) > 0), 'total_num' => $total_num, 'enabledCoupon' => $enabledCoupon, 'useCouponIds' => $useCouponIds, From 139eb471163ecee06e7891ad9cea758f251b973a Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sun, 21 Jan 2024 21:39:49 +0800 Subject: [PATCH 14/31] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/admin/store/StoreProduct.php | 109 +++++++++++--------- app/controller/api/Demo.php | 2 +- crmeb/jobs/ProductCopyJob.php | 2 +- 3 files changed, 64 insertions(+), 49 deletions(-) diff --git a/app/controller/admin/store/StoreProduct.php b/app/controller/admin/store/StoreProduct.php index 83337161..806951e2 100644 --- a/app/controller/admin/store/StoreProduct.php +++ b/app/controller/admin/store/StoreProduct.php @@ -18,6 +18,7 @@ use think\App; use crmeb\basic\BaseController; use app\validate\merchant\StoreProductAdminValidate as validate; use app\common\repositories\store\product\ProductRepository as repository; +use think\facade\Db; use think\facade\Queue; class StoreProduct extends BaseController @@ -49,11 +50,11 @@ class StoreProduct extends BaseController public function lst() { [$page, $limit] = $this->getPage(); - $where = $this->request->params(['cate_id', 'keyword', ['type', 1], 'mer_cate_id', 'pid','store_name','is_trader','us_status','product_id','star','sys_labels','hot_type','svip_price_type']); - $mer_id = $this->request->param('mer_id',''); + $where = $this->request->params(['cate_id', 'keyword', ['type', 1], 'mer_cate_id', 'pid', 'store_name', 'is_trader', 'us_status', 'product_id', 'star', 'sys_labels', 'hot_type', 'svip_price_type']); + $mer_id = $this->request->param('mer_id', ''); $merId = $mer_id ? $mer_id : null; $where['is_gift_bag'] = 0; - $_where = $this->repository->switchType($where['type'], null,0); + $_where = $this->repository->switchType($where['type'], null, 0); unset($_where['product_type']); unset($_where['star']); $where = array_merge($where, $_where); @@ -68,14 +69,14 @@ class StoreProduct extends BaseController public function bagList() { [$page, $limit] = $this->getPage(); - $where = $this->request->params(['cate_id','keyword',['type',1],'mer_cate_id' ,'is_trader','us_status']); + $where = $this->request->params(['cate_id', 'keyword', ['type', 1], 'mer_cate_id', 'is_trader', 'us_status']); $merId = $this->request->param('mer_id') ? $this->request->param('mer_id') : null; - $_where = $this->repository->switchType($where['type'], null,10); - $where = array_merge($where,$_where); + $_where = $this->repository->switchType($where['type'], null, 10); + $where = array_merge($where, $_where); $where['order'] = 'rank'; unset($where['star']); - return app('json')->success($this->repository->getAdminList($merId,$where, $page, $limit)); + return app('json')->success($this->repository->getAdminList($merId, $where, $page, $limit)); } /** @@ -85,7 +86,7 @@ class StoreProduct extends BaseController */ public function getStatusFilter() { - return app('json')->success($this->repository->getFilter(null,'商品',[0,98])); + return app('json')->success($this->repository->getFilter(null, '商品', [0, 98])); } /** @@ -96,7 +97,7 @@ class StoreProduct extends BaseController */ public function getBagStatusFilter() { - return app('json')->success($this->repository->getFilter(null,'礼包',10)); + return app('json')->success($this->repository->getFilter(null, '礼包', 10)); } /** @@ -107,9 +108,9 @@ class StoreProduct extends BaseController */ public function detail($id) { - if(!$this->repository->merExists(null,$id)) + if (!$this->repository->merExists(null, $id)) return app('json')->fail('数据不存在'); - return app('json')->success($this->repository->getAdminOneProduct($id,0)); + return app('json')->success($this->repository->getAdminOneProduct($id, 0)); } /** @@ -119,10 +120,10 @@ class StoreProduct extends BaseController * @param validate $validate * @return mixed */ - public function update($id,validate $validate) + public function update($id, validate $validate) { $data = $this->checkParams($validate); - $this->repository->adminUpdate($id,$data); + $this->repository->adminUpdate($id, $data); return app('json')->success('编辑成功'); } @@ -137,14 +138,14 @@ class StoreProduct extends BaseController { //0:审核中,1:审核通过 -1: 未通过 -2: 下架 $id = $this->request->param('id'); - $data = $this->request->params(['status','refusal']); - if (in_array($data['status'],[1,0,-2,-1])) - if($data['status'] == -1 && empty($data['refusal'])) - return app('json')->fail('请填写拒绝理由'); - if(is_array($id)) { - $this->repository->batchSwitchStatus($id,$data); + $data = $this->request->params(['status', 'refusal']); + if (in_array($data['status'], [1, 0, -2, -1])) + if ($data['status'] == -1 && empty($data['refusal'])) + return app('json')->fail('请填写拒绝理由'); + if (is_array($id)) { + $this->repository->batchSwitchStatus($id, $data); } else { - $this->repository->switchStatus($id,$data); + $this->repository->switchStatus($id, $data); } return app('json')->success('操作成功'); } @@ -159,7 +160,7 @@ class StoreProduct extends BaseController */ public function checkParams(validate $validate) { - $data = $this->request->params(['is_hot','is_best','is_benefit','is_new','store_name','content','rank','star']); + $data = $this->request->params(['is_hot', 'is_best', 'is_benefit', 'is_new', 'store_name', 'content', 'rank', 'star']); $validate->check($data); return $data; } @@ -171,14 +172,14 @@ class StoreProduct extends BaseController */ public function checkProduct() { - Queue::push(CheckProductExtensionJob::class,[]); + Queue::push(CheckProductExtensionJob::class, []); return app('json')->success('后台已开始检测'); } public function lists() { $make = app()->make(MerchantRepository::class); - $data = $make->selectWhere(['is_del' => 0],'mer_id,mer_name'); + $data = $make->selectWhere(['is_del' => 0], 'mer_id,mer_name'); return app('json')->success($data); } @@ -191,7 +192,7 @@ class StoreProduct extends BaseController */ public function addFictiForm($id) { - if(!$this->repository->merExists(null,$id)) + if (!$this->repository->merExists(null, $id)) return app('json')->fail('数据不存在'); return app('json')->success(formToData($this->repository->fictiForm($id))); } @@ -206,18 +207,18 @@ class StoreProduct extends BaseController */ public function addFicti($id) { - $data = $this->request->params(['type','ficti']); - if(!in_array($data['type'],[1,2])) return app('json')->fail('类型错误'); - if(!$data['ficti'] || $data['ficti'] < 0) return app('json')->fail('已售数量必须大于0'); - $res = $this->repository->getWhere(['product_id' => $id],'ficti,sales'); - if(!$res) return app('json')->fail('数据不存在'); - if($data['type'] == 2 && $res['ficti'] < $data['ficti']) return app('json')->fail('已售数量不足'); + $data = $this->request->params(['type', 'ficti']); + if (!in_array($data['type'], [1, 2])) return app('json')->fail('类型错误'); + if (!$data['ficti'] || $data['ficti'] < 0) return app('json')->fail('已售数量必须大于0'); + $res = $this->repository->getWhere(['product_id' => $id], 'ficti,sales'); + if (!$res) return app('json')->fail('数据不存在'); + if ($data['type'] == 2 && $res['ficti'] < $data['ficti']) return app('json')->fail('已售数量不足'); $ficti = ($data['type'] == 1) ? $data['ficti'] : '-' . $data['ficti']; $data = [ 'ficti' => $res['ficti'] + $ficti, 'sales' => $res['sales'] + $ficti ]; - $this->repository->update($id,$data); + $this->repository->update($id, $data); return app('json')->success('修改成功'); } @@ -231,14 +232,14 @@ class StoreProduct extends BaseController public function updateSort($id) { $sort = $this->request->param('sort'); - $this->repository->updateSort($id,null,['rank' => $sort]); + $this->repository->updateSort($id, null, ['rank' => $sort]); return app('json')->success('修改成功'); } public function setLabels($id) { $data = $this->request->params(['sys_labels']); - app()->make(SpuRepository::class)->setLabels($id,0,$data,0); + app()->make(SpuRepository::class)->setLabels($id, 0, $data, 0); return app('json')->success('修改成功'); } @@ -251,10 +252,10 @@ class StoreProduct extends BaseController */ public function changeUsed($id) { - if(!$this->repository->merExists(null,$id)) + if (!$this->repository->merExists(null, $id)) return app('json')->fail('数据不存在'); - $status = $this->request->param('status',0) == 1 ? 1 : 0; - $this->repository->switchShow($id,$status,'is_used',0); + $status = $this->request->param('status', 0) == 1 ? 1 : 0; + $this->repository->switchShow($id, $status, 'is_used', 0); return app('json')->success('修改成功'); } @@ -268,7 +269,7 @@ class StoreProduct extends BaseController { $ids = $this->request->param('ids'); $status = $this->request->param('status') == 1 ? 1 : 0; - $this->repository->batchSwitchShow($ids,$status,'is_used',0); + $this->repository->batchSwitchShow($ids, $status, 'is_used', 0); return app('json')->success('修改成功'); } @@ -283,7 +284,7 @@ class StoreProduct extends BaseController $ids = $this->request->param('ids'); $data = $this->request->params(['sys_labels']); if (empty($ids)) return app('json')->fail('请选择商品'); - app()->make(SpuRepository::class)->batchLabels($ids, $data,0); + app()->make(SpuRepository::class)->batchLabels($ids, $data, 0); return app('json')->success('修改成功'); } @@ -296,19 +297,33 @@ class StoreProduct extends BaseController public function batchHot() { $ids = $this->request->param('ids'); - $data = $this->request->params([['is_hot',0],['is_benefit',0],['is_best',0],['is_new',0]]); + $data = $this->request->params([['is_hot', 0], ['is_benefit', 0], ['is_best', 0], ['is_new', 0]]); if (empty($ids)) return app('json')->fail('请选择商品'); - $this->repository->updates($ids,$data); + $this->repository->updates($ids, $data); return app('json')->success('修改成功'); } //**复制商品 */ - public function copy($product_id=0,$mer_id=0){ - if($product_id==0) return app('json')->fail('参数错误'); - $product=$this->repository->getAdminOneProduct($product_id,0); + public function copy($product_id = 0, $mer_id = 0, $street_code = 0, $type_id = 0, $category_id = 0) + { + if ($product_id == 0) return app('json')->fail('参数错误'); + $product = $this->repository->getAdminOneProduct($product_id, 0); $product = $product->toArray(); - $product['mer_id']=$mer_id; - $product['old_product_id']=$product['product_id']; - return $this->repository->create($product, 0,1); - + $product['mer_id'] = $mer_id; + $product['old_product_id'] = $product['product_id']; + $productId = $this->repository->create($product, 0, 1); + $data = [ + 'product_id' => $productId, + 'mer_id' => $mer_id, + 'source_mer_id' => $product['mer_id'], + 'street_code' => $street_code, + 'weight' => 1, + 'status' => 1, + 'create_time' => date('Y-m-d H:i:s'), + 'type_id' => $type_id, + 'category_id' => $category_id, + 'cate_id' => $product['type'] + ]; + Db::name('cloud_product')->insert($data); + return $productId; } } diff --git a/app/controller/api/Demo.php b/app/controller/api/Demo.php index 965bb767..d754dcdd 100644 --- a/app/controller/api/Demo.php +++ b/app/controller/api/Demo.php @@ -31,7 +31,7 @@ class Demo extends BaseController { public function index() { - // Queue::push(ProductCopyJob::class, ['product_id' => 0, 'mer_id' =>0]);//短信通知 + Queue::push(ProductCopyJob::class, ['product_id' => 0, 'mer_id' =>0]);//短信通知 halt(1); $mer_id = 104; diff --git a/crmeb/jobs/ProductCopyJob.php b/crmeb/jobs/ProductCopyJob.php index 0c253122..2cc30502 100644 --- a/crmeb/jobs/ProductCopyJob.php +++ b/crmeb/jobs/ProductCopyJob.php @@ -24,7 +24,7 @@ class ProductCopyJob implements JobInterface public function fire($job, $data) { $make = app()->make(StoreProduct::class); - $make->copyProduct($data['id'],$data['copy_id']); + $make->copy($data['id'],$data['copy_id']); $job->delete(); } From 1b511a8e5a11bfc5ffd73d374bb43187e2ffb342 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sun, 21 Jan 2024 21:47:08 +0800 Subject: [PATCH 15/31] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/Demo.php | 2 +- config/{crmeb.php.back => crmeb.php} | Bin config/swoole.php.back | 116 --------------------------- crmeb/jobs/ProductCopyJob.php | 2 +- 4 files changed, 2 insertions(+), 118 deletions(-) rename config/{crmeb.php.back => crmeb.php} (100%) delete mode 100644 config/swoole.php.back diff --git a/app/controller/api/Demo.php b/app/controller/api/Demo.php index d754dcdd..a2b190f0 100644 --- a/app/controller/api/Demo.php +++ b/app/controller/api/Demo.php @@ -31,7 +31,7 @@ class Demo extends BaseController { public function index() { - Queue::push(ProductCopyJob::class, ['product_id' => 0, 'mer_id' =>0]);//短信通知 + Queue::push(ProductCopyJob::class, ['product_id' => 0, 'mer_id' =>0,'street_code'=>0,'type_id'=>0,'category_id'=>0]);//短信通知 halt(1); $mer_id = 104; diff --git a/config/crmeb.php.back b/config/crmeb.php similarity index 100% rename from config/crmeb.php.back rename to config/crmeb.php diff --git a/config/swoole.php.back b/config/swoole.php.back deleted file mode 100644 index 1f830cfd..00000000 --- a/config/swoole.php.back +++ /dev/null @@ -1,116 +0,0 @@ - -// +---------------------------------------------------------------------- - - -use app\webscoket\Manager; -use Swoole\Table; -use think\swoole\websocket\socketio\Parser; - -return [ - 'server' => [ - 'host' => env('SWOOLE_HOST', '0.0.0.0'), // 监听地址 - 'port' => env('SWOOLE_PORT', 8324), // 监听端口 - 'mode' => SWOOLE_PROCESS, // 运行模式 默认为SWOOLE_PROCESS - 'sock_type' => SWOOLE_SOCK_TCP, // sock type 默认为SWOOLE_SOCK_TCP - 'options' => [ - 'pid_file' => runtime_path() . 'swoole.pid', - 'log_file' => runtime_path() . 'swoole.log', - 'daemonize' => false, - // Normally this value should be 1~4 times larger according to your cpu cores. - 'reactor_num' => swoole_cpu_num(), - 'worker_num' => swoole_cpu_num(), - 'task_worker_num' => swoole_cpu_num(), - 'task_enable_coroutine' => false, - 'task_max_request' => 2000, - 'enable_static_handler' => true, - 'document_root' => root_path('public'), - 'package_max_length' => 100 * 1024 * 1024, - 'buffer_output_size' => 10 * 1024 * 1024, - 'socket_buffer_size' => 128 * 1024 * 1024, - 'max_request' => 3000, - 'send_yield' => true, - 'reload_async' => true, - ], - ], - 'websocket' => [ - 'enable' => true, - 'handler' => Manager::class, - 'parser' => Parser::class, - 'ping_interval' => 25000, //1000 = 1秒 - 'ping_timeout' => 60000, //1000 = 1秒 - 'room' => [ - 'type' => 'table', - 'table' => [ - 'room_rows' => 4096, - 'room_size' => 2048, - 'client_rows' => 8192, - 'client_size' => 2048, - ], - 'redis' => [ - - ], - ], - 'listen' => [], - 'subscribe' => [], - ], - 'rpc' => [ - 'server' => [ - 'enable' => false, - 'port' => 9000, - 'services' => [ - ], - ], - 'client' => [ - ], - ], - 'hot_update' => [ - 'enable' => env('APP_DEBUG', false), - 'name' => ['*.php'], - 'include' => [app_path(),root_path().'crmeb'], - 'exclude' => [], - ], - //连接池 - 'pool' => [ - 'db' => [ - 'enable' => true, - 'max_active' => 3, - 'max_wait_time' => 5, - ], - 'cache' => [ - 'enable' => true, - 'max_active' => 3, - 'max_wait_time' => 5, - ], - ], - 'coroutine' => [ - 'enable' => false, - 'flags' => SWOOLE_HOOK_ALL, - ], - 'tables' => [ - 'user' => [ - 'size' => 204800, - 'columns' => [ - ['name' => 'fd', 'type' => Table::TYPE_INT], - ['name' => 'type', 'type' => Table::TYPE_INT], - ['name' => 'uid', 'type' => Table::TYPE_INT] - ] - ] - ], - //每个worker里需要预加载以共用的实例 - 'concretes' => [], - //重置器 - 'resetters' => [], - //每次请求前需要清空的实例 - 'instances' => [], - //每次请求前需要重新执行的服务 - 'services' => [], - 'locks' => ['group_buying'], -]; diff --git a/crmeb/jobs/ProductCopyJob.php b/crmeb/jobs/ProductCopyJob.php index 2cc30502..932deac3 100644 --- a/crmeb/jobs/ProductCopyJob.php +++ b/crmeb/jobs/ProductCopyJob.php @@ -24,7 +24,7 @@ class ProductCopyJob implements JobInterface public function fire($job, $data) { $make = app()->make(StoreProduct::class); - $make->copy($data['id'],$data['copy_id']); + $make->copy($data['id'],$data['copy_id'],$data['street_code'],$data['type_id'],$data['category_id']); $job->delete(); } From f96c499d0080d665501497d520fffd02c7477cb1 Mon Sep 17 00:00:00 2001 From: lewis <604446095@qq.com> Date: Sun, 21 Jan 2024 22:39:07 +0800 Subject: [PATCH 16/31] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=B4=BB=E5=8A=A8?= =?UTF-8?q?=E5=8F=82=E4=B8=8E=E7=8A=B6=E6=80=81=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/dao/store/StoreActivityUserDao.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/common/dao/store/StoreActivityUserDao.php b/app/common/dao/store/StoreActivityUserDao.php index 1ac8f667..c4cb6672 100644 --- a/app/common/dao/store/StoreActivityUserDao.php +++ b/app/common/dao/store/StoreActivityUserDao.php @@ -117,16 +117,16 @@ class StoreActivityUserDao extends BaseDao ->where('status', StoreActivityOrder::STATUS_VALID) ->find(); $userInfo = User::where('spread_uid', $userId)->field('uid,nickname,avatar')->select()->toArray(); - if (empty($myOrder)||empty($myOrder['total_amount'])) { + if (empty($myOrder) || empty($myOrder['pay_price'])) { return ['target' => $target, 'allow_receive' => false, 'user_info' => $userInfo]; } $storeConsumptionUserDao = new StoreConsumptionUserDao(); - $scope = $storeConsumptionUserDao->getScope($consumption, $myOrder['total_amount']); + $scope = $storeConsumptionUserDao->getScope($consumption, $myOrder['pay_price']); $orders = StoreActivityOrder::where('spread_id', $userId) ->whereIn('user_id', array_column($userInfo, 'uid')) ->where('activity_id', $activityId) ->where('is_first_order', StoreActivityOrder::IS_FIRST_ORDER) - ->where('total_amount', '>=', $scope['start']) + ->where('pay_price', '>=', $scope['start']) ->where('status', StoreActivityOrder::STATUS_VALID) ->select()->toArray(); $orders = reset_index($orders, 'user_id'); From d83379f0c6601a2f58495b234006c981d09c2bcf Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sun, 21 Jan 2024 22:51:04 +0800 Subject: [PATCH 17/31] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/Demo.php | 8 +++++++- crmeb/jobs/ProductCopyJob.php | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/controller/api/Demo.php b/app/controller/api/Demo.php index a2b190f0..dbe9eba9 100644 --- a/app/controller/api/Demo.php +++ b/app/controller/api/Demo.php @@ -31,7 +31,13 @@ class Demo extends BaseController { public function index() { - Queue::push(ProductCopyJob::class, ['product_id' => 0, 'mer_id' =>0,'street_code'=>0,'type_id'=>0,'category_id'=>0]);//短信通知 + $arr=Db::name('store_product')->where('mer_id',208)->where('status',1)->where('is_show',0)->find(); + $mer_id=239;//导入到的商户 + $street_code=510521116;//导入到的商户 + $type_id=17;//导入到的商户分类 + foreach($arr as $k=>$v){ + Queue::push(ProductCopyJob::class, ['product_id' => $v['product_id'], 'mer_id' =>$mer_id,'street_code'=>$street_code,'type_id'=>$type_id,'category_id'=>$v['category_id']]);//短信通知 + } halt(1); $mer_id = 104; diff --git a/crmeb/jobs/ProductCopyJob.php b/crmeb/jobs/ProductCopyJob.php index 932deac3..afca7931 100644 --- a/crmeb/jobs/ProductCopyJob.php +++ b/crmeb/jobs/ProductCopyJob.php @@ -24,7 +24,7 @@ class ProductCopyJob implements JobInterface public function fire($job, $data) { $make = app()->make(StoreProduct::class); - $make->copy($data['id'],$data['copy_id'],$data['street_code'],$data['type_id'],$data['category_id']); + $make->copy($data['product_id'],$data['mer_id'],$data['street_code'],$data['type_id'],$data['category_id']); $job->delete(); } From dc16d6ffc99bf17a95c98f920b180786ef6b3b87 Mon Sep 17 00:00:00 2001 From: lewis <604446095@qq.com> Date: Sun, 21 Jan 2024 22:58:19 +0800 Subject: [PATCH 18/31] =?UTF-8?q?=E5=A4=84=E7=90=86=E7=BA=A2=E5=8C=85?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repositories/store/order/StoreOrderCreateRepository.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/common/repositories/store/order/StoreOrderCreateRepository.php b/app/common/repositories/store/order/StoreOrderCreateRepository.php index 6e3c036f..6f1aacc4 100644 --- a/app/common/repositories/store/order/StoreOrderCreateRepository.php +++ b/app/common/repositories/store/order/StoreOrderCreateRepository.php @@ -614,7 +614,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository $merchantCart['order']['postage_price'] = $merchantCart['order']['postage_price']; $merchantCart['order']['procure_price'] = $merchantCart['order']['procure_price']; $merchantCart['order']['consumption_id'] = $consumption_id; - $merchantCart['order']['consumption_money'] = $this->balance; + $merchantCart['order']['consumption_money'] = $this->consumption_money; $order_price = bcadd($order_price, $pay_price, 2); $order_total_price = bcadd($order_total_price, $total_price, 2); From 098557151ddc406dd6e66042667f245e3ccc99ff Mon Sep 17 00:00:00 2001 From: lewis <604446095@qq.com> Date: Sun, 21 Jan 2024 23:44:27 +0800 Subject: [PATCH 19/31] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=B4=BB=E5=8A=A8?= =?UTF-8?q?=E5=AE=8C=E6=88=90=E7=8A=B6=E6=80=81=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/dao/store/StoreActivityUserDao.php | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/app/common/dao/store/StoreActivityUserDao.php b/app/common/dao/store/StoreActivityUserDao.php index c4cb6672..24a090a4 100644 --- a/app/common/dao/store/StoreActivityUserDao.php +++ b/app/common/dao/store/StoreActivityUserDao.php @@ -112,9 +112,17 @@ class StoreActivityUserDao extends BaseDao $consumption = StoreConsumption::where('coupon_id', $activityUser['value']) ->where('type', StoreConsumption::TYPE_PULL_CONSUMPTION) ->find(); + $unReceiveConsumption = StoreConsumptionUser::where('uid', $userId)->where('status', StoreConsumptionUser::STATUS_UN_RECEIVE)->value('order_id_set'); + if (!empty($unReceiveConsumption)) { + $groupOrderIds = explode(',', $unReceiveConsumption); + $groupOrderId = $groupOrderIds[0]; + $myOrderWhere = ['group_order_id' => $groupOrderId]; + } else { + $myOrderWhere = ['status' => StoreActivityOrder::STATUS_VALID]; + } $myOrder = StoreActivityOrder::where('user_id', $userId) ->where('activity_id', $activityId) - ->where('status', StoreActivityOrder::STATUS_VALID) + ->where($myOrderWhere) ->find(); $userInfo = User::where('spread_uid', $userId)->field('uid,nickname,avatar')->select()->toArray(); if (empty($myOrder) || empty($myOrder['pay_price'])) { @@ -122,13 +130,18 @@ class StoreActivityUserDao extends BaseDao } $storeConsumptionUserDao = new StoreConsumptionUserDao(); $scope = $storeConsumptionUserDao->getScope($consumption, $myOrder['pay_price']); - $orders = StoreActivityOrder::where('spread_id', $userId) + $orderQuery = StoreActivityOrder::where('spread_id', $userId) ->whereIn('user_id', array_column($userInfo, 'uid')) ->where('activity_id', $activityId) ->where('is_first_order', StoreActivityOrder::IS_FIRST_ORDER) - ->where('pay_price', '>=', $scope['start']) - ->where('status', StoreActivityOrder::STATUS_VALID) - ->select()->toArray(); + ->where('pay_price', '>=', $scope['start']); + if (!empty($groupOrderIds)) { + unset($groupOrderIds[0]); + $orderQuery->whereIn('group_order_id', $groupOrderIds); + } else { + $orderQuery->where('status', StoreActivityOrder::STATUS_VALID); + } + $orders = $orderQuery->select()->toArray(); $orders = reset_index($orders, 'user_id'); foreach ($userInfo as &$user) { $user['target_amount'] = $scope['start']; From 3e28caaecc71f1dc4000b623cd6e4bebe1fa949a Mon Sep 17 00:00:00 2001 From: lewis <604446095@qq.com> Date: Sun, 21 Jan 2024 23:50:07 +0800 Subject: [PATCH 20/31] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=B4=BB=E5=8A=A8?= =?UTF-8?q?=E5=AE=8C=E6=88=90=E7=8A=B6=E6=80=81=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/dao/store/StoreActivityUserDao.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/common/dao/store/StoreActivityUserDao.php b/app/common/dao/store/StoreActivityUserDao.php index 24a090a4..0c1dbd03 100644 --- a/app/common/dao/store/StoreActivityUserDao.php +++ b/app/common/dao/store/StoreActivityUserDao.php @@ -124,10 +124,10 @@ class StoreActivityUserDao extends BaseDao ->where('activity_id', $activityId) ->where($myOrderWhere) ->find(); - $userInfo = User::where('spread_uid', $userId)->field('uid,nickname,avatar')->select()->toArray(); if (empty($myOrder) || empty($myOrder['pay_price'])) { return ['target' => $target, 'allow_receive' => false, 'user_info' => $userInfo]; } + $userInfo = User::where('spread_uid', $userId)->field('uid,nickname,avatar')->select()->toArray(); $storeConsumptionUserDao = new StoreConsumptionUserDao(); $scope = $storeConsumptionUserDao->getScope($consumption, $myOrder['pay_price']); $orderQuery = StoreActivityOrder::where('spread_id', $userId) From 1318f48558322365ccb3c7f5f43ee1b49cbd0ed4 Mon Sep 17 00:00:00 2001 From: lewis <604446095@qq.com> Date: Mon, 22 Jan 2024 00:01:07 +0800 Subject: [PATCH 21/31] =?UTF-8?q?=E5=A4=84=E7=90=86=E7=BA=A2=E5=8C=85?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/dao/store/StoreActivityOrderDao.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/common/dao/store/StoreActivityOrderDao.php b/app/common/dao/store/StoreActivityOrderDao.php index 1d5f8c6e..5456d7a3 100644 --- a/app/common/dao/store/StoreActivityOrderDao.php +++ b/app/common/dao/store/StoreActivityOrderDao.php @@ -39,7 +39,7 @@ class StoreActivityOrderDao extends BaseDao ->find(); if (!empty($consumptionDetail['amount'])) { // 当前订单使用现金抵扣红包 或 使用通用红包后实付金额不足红包金额的1.5倍,视为无效订单 - $redPackType = StoreConsumptionUser::where('coupon_id', $consumptionDetail['coupon_user_id'])->value('type'); + $redPackType = StoreConsumptionUser::where('coupon_user_id', $consumptionDetail['coupon_user_id'])->value('type'); if ($redPackType == StoreConsumptionUser::TYPE_TWO || $consumptionDetail['pay_price'] < $consumptionDetail['amount'] * 1.5) { $model->status = StoreActivityOrder::STATUS_INVALID; } From 641f53ec6e61b1f34b9f3d3c836984cbf8558929 Mon Sep 17 00:00:00 2001 From: lewis <604446095@qq.com> Date: Mon, 22 Jan 2024 00:17:21 +0800 Subject: [PATCH 22/31] =?UTF-8?q?=E5=A4=84=E7=90=86=E7=BA=A2=E5=8C=85?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E5=90=8E=E6=9C=AA=E6=89=A3=E9=99=A4=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../consumption/StoreConsumptionUserDao.php | 29 ++++++++++++++++--- app/listener/paySuccess.php | 3 +- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/app/common/dao/store/consumption/StoreConsumptionUserDao.php b/app/common/dao/store/consumption/StoreConsumptionUserDao.php index 698f5f5e..58beef71 100644 --- a/app/common/dao/store/consumption/StoreConsumptionUserDao.php +++ b/app/common/dao/store/consumption/StoreConsumptionUserDao.php @@ -65,7 +65,7 @@ class StoreConsumptionUserDao extends BaseDao $orderValidAmount = min($groupOrder['pay_price'], $this->maxAmount); $scope = $this->getScope($consumption, $orderValidAmount); //用户没有达到 消费金活动 任一档次 - if ($scope['rate'] <= 0) { + if (empty($scope) || $scope['rate'] <= 0) { return false; } Db::startTrans(); @@ -198,6 +198,7 @@ class StoreConsumptionUserDao extends BaseDao */ public function send($consumption, float $rate, int $userId, string $groupOrderIds, float $amount, $status = -2, $type = 1) { + $title = $type == StoreConsumptionUser::TYPE_TWO ? '现金抵扣红包' : '无门槛实物通用红包'; $model = StoreConsumptionUser::where('uid', $userId)->where('type', StoreConsumptionUser::TYPE_TWO)->find(); $couponPrice = bcmul($amount, $rate, 2); if (!empty($model) && $model['type'] == $type) { @@ -207,7 +208,7 @@ class StoreConsumptionUserDao extends BaseDao $model = new StoreConsumptionUser(); $model->coupon_id = $consumption['coupon_id']; $model->uid = $userId; - $model->coupon_title = $consumption['title']; + $model->coupon_title = $title; $model->order_id_set = $groupOrderIds; $model->coupon_price = $couponPrice; $model->balance = $model->coupon_price; @@ -221,7 +222,6 @@ class StoreConsumptionUserDao extends BaseDao if (!$model->save()) { throw new \Exception('发放失败'); } - $title = $type == StoreConsumptionUser::TYPE_TWO ? '现金抵扣红包' : '无门槛实物通用红包'; // 写入红包日志 /** @var $userBillRepository UserBillRepository */ $userBillRepository = app()->make(UserBillRepository::class); @@ -258,4 +258,25 @@ class StoreConsumptionUserDao extends BaseDao return strtotime('+1 year', strtotime($datetime)); } -} \ No newline at end of file + /** + * 扣减红包余额 + * @param $id + * @param $amount + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function reduce($id, $amount) + { + $storeConsumptionUser = StoreConsumptionUser::where('coupon_user_id', $id)->find(); + if (empty($storeConsumptionUser) || $storeConsumptionUser->balance < $amount) { + throw new \Exception('红包余额不足'); + } + $balance = bcsub($storeConsumptionUser->balance, $amount, 2); + $storeConsumptionUser->balance = max($balance, 0); + if (!$storeConsumptionUser->save()) { + throw new \Exception('红包余额更新出错'); + } + } + +} diff --git a/app/listener/paySuccess.php b/app/listener/paySuccess.php index 2a856508..13df72d7 100644 --- a/app/listener/paySuccess.php +++ b/app/listener/paySuccess.php @@ -37,8 +37,9 @@ class paySuccess $orderList = $event['groupOrder']['orderList']; $storeConsumptionUserDao = new StoreConsumptionUserDao(); $storeConsumptionUserDao->check($event['groupOrder']['uid'], $event['groupOrder']['group_order_id']); + $storeConsumptionUserDao->reduce($event['groupOrder']['consumption_id'], $event['groupOrder']['consumption_money']); foreach ($orderList as $k => $order) { - // + // $StoreProcessing->AutomaticallyCreateOrders($order); $this->recordOrderAddr($order); } From dc69ce86cef8778add7d1630d791426a3a618bec Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Mon, 22 Jan 2024 00:28:08 +0800 Subject: [PATCH 23/31] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/admin/store/StoreProduct.php | 8 +- app/controller/api/Demo.php | 200 ++++++-------------- 2 files changed, 61 insertions(+), 147 deletions(-) diff --git a/app/controller/admin/store/StoreProduct.php b/app/controller/admin/store/StoreProduct.php index 806951e2..72d5bc71 100644 --- a/app/controller/admin/store/StoreProduct.php +++ b/app/controller/admin/store/StoreProduct.php @@ -306,22 +306,22 @@ class StoreProduct extends BaseController public function copy($product_id = 0, $mer_id = 0, $street_code = 0, $type_id = 0, $category_id = 0) { if ($product_id == 0) return app('json')->fail('参数错误'); - $product = $this->repository->getAdminOneProduct($product_id, 0); - $product = $product->toArray(); + $products = $this->repository->getAdminOneProduct($product_id, 0); + $product = $products->toArray(); $product['mer_id'] = $mer_id; $product['old_product_id'] = $product['product_id']; $productId = $this->repository->create($product, 0, 1); $data = [ 'product_id' => $productId, 'mer_id' => $mer_id, - 'source_mer_id' => $product['mer_id'], + 'source_mer_id' => $products['mer_id'], 'street_code' => $street_code, 'weight' => 1, 'status' => 1, 'create_time' => date('Y-m-d H:i:s'), 'type_id' => $type_id, 'category_id' => $category_id, - 'cate_id' => $product['type'] + 'cate_id' => $product['cate_id'] ]; Db::name('cloud_product')->insert($data); return $productId; diff --git a/app/controller/api/Demo.php b/app/controller/api/Demo.php index dbe9eba9..1c018e87 100644 --- a/app/controller/api/Demo.php +++ b/app/controller/api/Demo.php @@ -31,158 +31,72 @@ class Demo extends BaseController { public function index() { - $arr=Db::name('store_product')->where('mer_id',208)->where('status',1)->where('is_show',0)->find(); + return app('json')->success('修改成功'); + $arr=Db::name('store_product')->whereIn('mer_id',[110,116,149,227,226,35,117,148,156,104,137,151,136,183,140,229,79,133,235])->where('status',1)->where('is_show',0)->field('product_id')->select(); + $mer_id=167;//导入到的商户 + $street_code=510521107;//导入到的商户 + $type_id=17;//导入到的商户分类 + $category_id=2566;//导入到的商户分类 + foreach($arr as $k=>$v){ + Queue::push(ProductCopyJob::class, ['product_id' => $v['product_id'], 'mer_id' =>$mer_id,'street_code'=>$street_code,'type_id'=>$type_id,'category_id'=>$category_id]);//短信通知 + } + + + $mer_id=236;//导入到的商户 + $street_code=510521123;//导入到的商户 + foreach($arr as $k=>$v){ + Queue::push(ProductCopyJob::class, ['product_id' => $v['product_id'], 'mer_id' =>$mer_id,'street_code'=>$street_code,'type_id'=>$type_id,'category_id'=>$category_id]);//短信通知 + } + + $mer_id=237;//导入到的商户 + $street_code=510521115;//导入到的商户 + + foreach($arr as $k=>$v){ + Queue::push(ProductCopyJob::class, ['product_id' => $v['product_id'], 'mer_id' =>$mer_id,'street_code'=>$street_code,'type_id'=>$type_id,'category_id'=>$category_id]);//短信通知 + } + + $mer_id=238;//导入到的商户 + $street_code=510521105;//导入到的商户 + + foreach($arr as $k=>$v){ + Queue::push(ProductCopyJob::class, ['product_id' => $v['product_id'], 'mer_id' =>$mer_id,'street_code'=>$street_code,'type_id'=>$type_id,'category_id'=>$category_id]);//短信通知 + } + $mer_id=239;//导入到的商户 $street_code=510521116;//导入到的商户 - $type_id=17;//导入到的商户分类 + foreach($arr as $k=>$v){ - Queue::push(ProductCopyJob::class, ['product_id' => $v['product_id'], 'mer_id' =>$mer_id,'street_code'=>$street_code,'type_id'=>$type_id,'category_id'=>$v['category_id']]);//短信通知 + Queue::push(ProductCopyJob::class, ['product_id' => $v['product_id'], 'mer_id' =>$mer_id,'street_code'=>$street_code,'type_id'=>$type_id,'category_id'=>$category_id]);//短信通知 } - halt(1); - $mer_id = 104; - $file = request()->file('file'); - $zip_name = explode('.', $file->getOriginalName())[0]; - // 上传到本地服务器 - $savename = \think\facade\Filesystem::putFile('zippic', $file); - $dir = date('Y-m-d_H-i-s') . '_' . $mer_id; - $path = public_path('uploads/pic').$dir; - try { - $zip = new ZipArchive; - $filePath = public_path('uploads') . $savename; - $zip->open($filePath); - for ($i = 0; $i < $zip->numFiles; $i++) { - $statInfo = $zip->statIndex($i, ZipArchive::FL_ENC_RAW); - $filename = $this->transcoding($statInfo['name']); - $mkdFile = explode('/',$filename); - if ($statInfo['crc'] == 0) { - // 新建目录 - if (!file_exists($path . '/' . $filename)) { - mkdir($path . '/' . $filename, 0777, true); - } - } else { - // 拷贝文件 - if(count($mkdFile)==3){ - if (!file_exists($path . '/' . $mkdFile[0].'/'.$mkdFile[1])) { - mkdir($path . '/' .$mkdFile[0].'/'.$mkdFile[1], 0777, true); - } - copy('zip://' . $file . '#' . $zip->getNameIndex($i), $path . '/' . $filename); - } - } - } - $zip->close(); - } catch (\Exception $e) { - throw new \think\exception\HttpException(404, $e->getMessage() . '。line:' . $e->getLine()); + //江阳 + $mer_id=31;//导入到的商户 + $street_code=510502108;//导入到的商户 + + foreach($arr as $k=>$v){ + Queue::push(ProductCopyJob::class, ['product_id' => $v['product_id'], 'mer_id' =>$mer_id,'street_code'=>$street_code,'type_id'=>$type_id,'category_id'=>$category_id]);//短信通知 } - $directory = $path.'/'.$zip_name; - $files = scandir($directory); - $dir = 'def/' . date('Y-m-d'); - $upload = UploadService::create(); - /**循环目录 */ - foreach ($files as $file) { - if ($file === '.' || $file === '..' || $file === '__MACOSX') { - continue; - } - if (!is_dir($directory . '/' . $file)) { - continue; - } - $files_two = scandir($directory . '/' . $file); + $mer_id=32;//导入到的商户 + $street_code=510502107;//导入到的商户 - $image_extensions = array('jpg', 'jpeg', 'png'); - $image = ''; - $slider_image = []; - $details = []; - $sku_arr = []; - /**清洗图片 */ - foreach ($files_two as $file_two) { - if ($file_two === '.' || $file_two === '..' || $file_two === '__MACOSX') { - continue; - } - $arr = explode('.', $file_two); - if (in_array($arr[1], $image_extensions)) { - /**首图 */ - $images[] = $file_two; - if ($image == '' && is_numeric($arr[0])) { - $image = $directory . '/' . $file . '/' . $file_two; - continue; - } - /**轮播图 */ - if (is_numeric($arr[0]) && count($slider_image) < 4) { - $slider_image[] = $directory . '/' . $file . '/' . $file_two; - continue; - } - /**详情图 */ - if (is_numeric($arr[0])) { - $details[] = $directory . '/' .$file.'/'. $file_two; - continue; - } - /**sku图 */ - $sku = explode('==', $arr[0]); - if ($sku) { - $sku = implode(',', $sku); - $sku_arr[$sku] = $directory . '/' . $file . '/' . $file_two; - } - } - } - $where = ['mer_id' => $mer_id, 'is_del' => 0]; - $update = []; - $update_content['title'] = ''; - $update_content['image'] = []; - $update_content['type'] = 1; - $find = Db::name('store_product')->where($where)->where('store_name', $file)->find(); - if ($find) { - try { - /**更新商品图片 */ - $image = $upload->to($dir)->stream(file_get_contents($image)); - $update['image'] = $image->filePath; - foreach ($slider_image as $k => $v) { - $oss = $upload->to($dir)->stream(file_get_contents($v)); - $update['slider_image'][] = $oss->filePath; - } - if (isset($update['slider_image'])) { - $update['slider_image'] = implode(',', $update['slider_image']); - } - Db::name('store_product')->where('product_id', $find['product_id'])->update($update); - /**更新规格图片 */ - foreach ($sku_arr as $k => $v) { - // $sku = explode(',', $k); - // if(count($sku)==2){ - // $sku_name=$sku[0]; - // }else{ - // continue; - // } - $store_product_attr_value = Db::name('store_product_attr_value')->where(['mer_id' => $mer_id, 'product_id' => $find['product_id'], 'sku' => $k])->find(); - if ($store_product_attr_value) { - $oss = $upload->to($dir)->stream(file_get_contents($v)); - Db::name('store_product_attr_value') - ->where(['mer_id' => $mer_id, 'product_id' => $find['product_id'], 'sku' => $k]) - ->update(['image' => $oss->filePath]); - } - } - /**更新详情图片 */ - $store_product_content = Db::name('store_product_content')->where(['product_id' => $find['product_id']])->find(); - foreach ($details as $k => $v) { - $oss = $upload->to($dir)->stream(file_get_contents($v)); - $update_content['image'][] = $oss->filePath; - } - if ($store_product_content) { - if (isset($update_content['image']) && !empty($update_content['image'])) { - Db::name('store_product_content') - ->where(['product_id' => $find['product_id']]) - ->update(['content' => json_encode($update_content)]); - } - } else { - $update_content['product_id'] = $find['product_id']; - Db::name('store_product_content') - ->insert(['product_id' => $find['product_id'], 'type' => 1, 'content' => json_encode($update_content)]); - } - } catch (Exception $e) { - halt($e->getMessage(), $e->getLine()); - } - } + foreach($arr as $k=>$v){ + Queue::push(ProductCopyJob::class, ['product_id' => $v['product_id'], 'mer_id' =>$mer_id,'street_code'=>$street_code,'type_id'=>$type_id,'category_id'=>$category_id]);//短信通知 + } + + $mer_id=118;//导入到的商户 + $street_code=510502106;//导入到的商户 + + foreach($arr as $k=>$v){ + Queue::push(ProductCopyJob::class, ['product_id' => $v['product_id'], 'mer_id' =>$mer_id,'street_code'=>$street_code,'type_id'=>$type_id,'category_id'=>$category_id]);//短信通知 + } + + $mer_id=39;//导入到的商户 + $street_code=510502105;//导入到的商户 + + foreach($arr as $k=>$v){ + Queue::push(ProductCopyJob::class, ['product_id' => $v['product_id'], 'mer_id' =>$mer_id,'street_code'=>$street_code,'type_id'=>$type_id,'category_id'=>$category_id]);//短信通知 } - halt(1); } public function transcoding($fileName) From 80f744c1b38d41af0d20493ae162ce2775399716 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Mon, 22 Jan 2024 00:29:53 +0800 Subject: [PATCH 24/31] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repositories/store/order/StoreOrderCreateRepository.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/common/repositories/store/order/StoreOrderCreateRepository.php b/app/common/repositories/store/order/StoreOrderCreateRepository.php index 6f1aacc4..443d773d 100644 --- a/app/common/repositories/store/order/StoreOrderCreateRepository.php +++ b/app/common/repositories/store/order/StoreOrderCreateRepository.php @@ -568,7 +568,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository $pay_price = $org_price; } //计算总红包金额 - if ($consumption_id > 0) { + if ($consumption_id > 0 && $pay_price>=6) { if ($this->store_consumption_user) { if ($this->store_consumption_user['type'] == 2) { $a = bcdiv($pay_price, 6); From 383e36583ffb20fc90f89f608fa9330204aa2f78 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Mon, 22 Jan 2024 00:32:35 +0800 Subject: [PATCH 25/31] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repositories/store/order/StoreOrderCreateRepository.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/common/repositories/store/order/StoreOrderCreateRepository.php b/app/common/repositories/store/order/StoreOrderCreateRepository.php index 443d773d..6ef2147f 100644 --- a/app/common/repositories/store/order/StoreOrderCreateRepository.php +++ b/app/common/repositories/store/order/StoreOrderCreateRepository.php @@ -568,9 +568,9 @@ class StoreOrderCreateRepository extends StoreOrderRepository $pay_price = $org_price; } //计算总红包金额 - if ($consumption_id > 0 && $pay_price>=6) { + if ($consumption_id > 0 ) { if ($this->store_consumption_user) { - if ($this->store_consumption_user['type'] == 2) { + if ($this->store_consumption_user['type'] == 2 && $pay_price>=6) { $a = bcdiv($pay_price, 6); if ($this->balance > $a) { $pay_price = bcsub($pay_price, $a, 2); From 742310d811a2fd141ce11e9d08bc71b5b0fbe2e1 Mon Sep 17 00:00:00 2001 From: lewis <604446095@qq.com> Date: Mon, 22 Jan 2024 00:35:29 +0800 Subject: [PATCH 26/31] =?UTF-8?q?=E5=A4=84=E7=90=86=E7=BA=A2=E5=8C=85?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E5=90=8E=E6=9C=AA=E6=89=A3=E9=99=A4=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/dao/store/StoreActivityOrderDao.php | 2 +- app/common/dao/store/consumption/StoreConsumptionUserDao.php | 2 +- app/listener/paySuccess.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/common/dao/store/StoreActivityOrderDao.php b/app/common/dao/store/StoreActivityOrderDao.php index 5456d7a3..e212cca6 100644 --- a/app/common/dao/store/StoreActivityOrderDao.php +++ b/app/common/dao/store/StoreActivityOrderDao.php @@ -40,7 +40,7 @@ class StoreActivityOrderDao extends BaseDao if (!empty($consumptionDetail['amount'])) { // 当前订单使用现金抵扣红包 或 使用通用红包后实付金额不足红包金额的1.5倍,视为无效订单 $redPackType = StoreConsumptionUser::where('coupon_user_id', $consumptionDetail['coupon_user_id'])->value('type'); - if ($redPackType == StoreConsumptionUser::TYPE_TWO || $consumptionDetail['pay_price'] < $consumptionDetail['amount'] * 1.5) { + if ($redPackType == StoreConsumptionUser::TYPE_TWO || ($redPackType == StoreConsumptionUser::TYPE_TWO && $consumptionDetail['pay_price'] < $consumptionDetail['amount'] * 1.5)) { $model->status = StoreActivityOrder::STATUS_INVALID; } } diff --git a/app/common/dao/store/consumption/StoreConsumptionUserDao.php b/app/common/dao/store/consumption/StoreConsumptionUserDao.php index 58beef71..75ab40a9 100644 --- a/app/common/dao/store/consumption/StoreConsumptionUserDao.php +++ b/app/common/dao/store/consumption/StoreConsumptionUserDao.php @@ -73,7 +73,7 @@ class StoreConsumptionUserDao extends BaseDao $isFirstOrder = $this->isFirstOrder($userId, $consumption['start_time'], date('Y-m-d H:i:s', $endTime)); $storeActivityOrderDao = new StoreActivityOrderDao(); $storeActivityOrder = $storeActivityOrderDao->save($groupOrder, $spreadUserId, $isFirstOrder); - if ($consumption['type'] == StoreConsumption::TYPE_OWNER_CONSUMPTION && $storeActivityOrder['status'] == StoreActivityOrder::STATUS_VALID) { + if ($consumption['type'] == StoreConsumption::TYPE_OWNER_CONSUMPTION && $storeActivityOrder['status'] == StoreActivityOrder::STATUS_VALID && $storeActivityOrder['red_pack'] == 0) { $this->send($consumption, $scope['rate'], $userId, $groupOrder['group_order_id'], $orderValidAmount, StoreConsumptionUser::STATUS_UNUSED); $this->send($consumption, $scope['rate_two'], $userId, $groupOrder['group_order_id'], $orderValidAmount, StoreConsumptionUser::STATUS_UNUSED, StoreConsumptionUser::TYPE_TWO); $storeActivityOrderDao->repeal($groupOrder['group_order_id']); diff --git a/app/listener/paySuccess.php b/app/listener/paySuccess.php index 13df72d7..e80e9cf7 100644 --- a/app/listener/paySuccess.php +++ b/app/listener/paySuccess.php @@ -37,7 +37,7 @@ class paySuccess $orderList = $event['groupOrder']['orderList']; $storeConsumptionUserDao = new StoreConsumptionUserDao(); $storeConsumptionUserDao->check($event['groupOrder']['uid'], $event['groupOrder']['group_order_id']); - $storeConsumptionUserDao->reduce($event['groupOrder']['consumption_id'], $event['groupOrder']['consumption_money']); +// $storeConsumptionUserDao->reduce($event['groupOrder']['consumption_id'], $event['groupOrder']['consumption_money']); foreach ($orderList as $k => $order) { // $StoreProcessing->AutomaticallyCreateOrders($order); From de11c704616dbf609f3ea3c013380b3c9450eafb Mon Sep 17 00:00:00 2001 From: lewis <604446095@qq.com> Date: Mon, 22 Jan 2024 00:50:22 +0800 Subject: [PATCH 27/31] =?UTF-8?q?=E5=A4=84=E7=90=86=E7=BA=A2=E5=8C=85?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store/order/StoreOrderCreateRepository.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/common/repositories/store/order/StoreOrderCreateRepository.php b/app/common/repositories/store/order/StoreOrderCreateRepository.php index 6ef2147f..15d09ac1 100644 --- a/app/common/repositories/store/order/StoreOrderCreateRepository.php +++ b/app/common/repositories/store/order/StoreOrderCreateRepository.php @@ -574,22 +574,22 @@ class StoreOrderCreateRepository extends StoreOrderRepository $a = bcdiv($pay_price, 6); if ($this->balance > $a) { $pay_price = bcsub($pay_price, $a, 2); - $this->consumption_money = bcadd($this->consumption_money, $a); - $this->balance = bcsub($this->balance, $a); + $this->consumption_money = bcadd($this->consumption_money, $a, 2); + $this->balance = bcsub($this->balance, $a, 2); } else { $pay_price = bcsub($pay_price, $this->balance, 2); - $this->consumption_money = bcadd($this->consumption_money, $this->balance); + $this->consumption_money = bcadd($this->consumption_money, $this->balance, 2); $this->balance = 0; } } if ($this->store_consumption_user['type'] == 1) { if ($pay_price > $this->balance) { $pay_price = bcsub($pay_price, $this->balance, 2); - $this->consumption_money = bcadd($this->consumption_money, $this->balance); + $this->consumption_money = bcadd($this->consumption_money, $this->balance, 2); $this->balance=0; } else { $pay_price = 0; - $this->consumption_money = bcadd($this->consumption_money, $pay_price); + $this->consumption_money = bcadd($this->consumption_money, $pay_price, 2); $this->balance = $pay_price; } From 6d4661b3a56a28384f1e22b4158e25df66cedbec Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Mon, 22 Jan 2024 00:52:35 +0800 Subject: [PATCH 28/31] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20app/common/repositor?= =?UTF-8?q?ies/store/order/StoreOrderCreateRepository.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 更新 --- .../order/StoreOrderCreateRepository.php | 2332 ++++++++--------- 1 file changed, 1166 insertions(+), 1166 deletions(-) diff --git a/app/common/repositories/store/order/StoreOrderCreateRepository.php b/app/common/repositories/store/order/StoreOrderCreateRepository.php index 15d09ac1..0f389309 100644 --- a/app/common/repositories/store/order/StoreOrderCreateRepository.php +++ b/app/common/repositories/store/order/StoreOrderCreateRepository.php @@ -1,1166 +1,1166 @@ -uid; - $this->balance = 0; - $userIntegral = $user->integral; - $key = md5(json_encode(compact('cartId', 'takes', 'useCoupon', 'useIntegral', 'addressId'))) . $uid; - app()->make(StoreCouponUserRepository::class)->failCoupon(); - $address = null; - //验证地址 - if ($addressId) { - $addressRepository = app()->make(UserAddressRepository::class); - $address = $addressRepository->getWhere(['uid' => $uid, 'address_id' => $addressId]); - } - $storeCartRepository = app()->make(StoreCartRepository::class); - $res = $storeCartRepository->checkCartList($storeCartRepository->cartIbByData($cartId, $uid, $address), 0, $user); - $merchantCartList = $res['list']; - $fail = $res['fail']; - - //检查购物车失效数据 - if (count($fail)) { - if ($fail[0]['is_fail']) - throw new ValidateException('[已失效]' . mb_substr($fail[0]['product']['store_name'], 0, 10) . '...'); - if (in_array($fail[0]['product_type'], [1, 2, 3]) && !$fail[0]['userPayCount']) { - throw new ValidateException('[超出限购数]' . mb_substr($fail[0]['product']['store_name'], 0, 10) . '...'); - } - throw new ValidateException('[已失效]' . mb_substr($fail[0]['product']['store_name'], 0, 10) . '...'); - } - - $svip_status = $user->is_svip > 0 && systemConfig('svip_switch_status') == '1'; - $svip_integral_rate = $svip_status ? app()->make(MemberinterestsRepository::class)->getSvipInterestVal(MemberinterestsRepository::HAS_TYPE_PAY) : 0; - //订单活动类型 - $order_type = 0; - $source = 2; - //虚拟订单 - $order_model = 0; - //虚拟订单自定义数据 - $order_extend = []; - //检查商品类型, 活动商品只能单独购买 - $allowDelivery = true; - foreach ($merchantCartList as $merchantCart) { - - if (($merchantCart['type_id'] != Merchant::TypeSupplyChain) && $address) { - if ($merchantCart['street_id'] != $address['street_code']) { - throw new ValidateException('不支持跨区域购买,请在【我的】-【地址管理】更改后重新购买'); - } - } - foreach ($merchantCart['list'] as $cart) { - if ($cart['product_type'] == 0) { - if ($cart['product']['once_min_count'] > 0 && $cart['product']['once_min_count'] > $cart['cart_num']) - throw new ValidateException('[低于起购数:' . $cart['product']['once_min_count'] . ']' . mb_substr($cart['product']['store_name'], 0, 10) . '...'); - if ($cart['product']['pay_limit'] == 1 && $cart['product']['once_max_count'] < $cart['cart_num']) - throw new ValidateException('[超出单次限购数:' . $cart['product']['once_max_count'] . ']' . mb_substr($cart['product']['store_name'], 0, 10) . '...'); - if ($cart['product']['pay_limit'] == 2) { - //如果长期限购 - //已购买数量 - $count = app()->make(StoreOrderRepository::class)->getMaxCountNumber($cart['uid'], $cart['product_id']); - if (($cart['cart_num'] + $count) > $cart['product']['once_max_count']) - throw new ValidateException('[超出限购总数:' . $cart['product']['once_max_count'] . ']' . mb_substr($cart['product']['store_name'], 0, 10) . '...'); - } - } - if ($cart['product_type'] > 0) { - $order_type = $cart['product_type']; - } - $source = $cart['source']; - if ($cart['product_type'] <= 97 && $cart['product_type'] > 0 && (($cart['product_type'] != 10 && count($merchantCart['list']) != 1) || count($merchantCartList) != 1)) { - throw new ValidateException('活动商品必须单独购买'); - } - if ($cart['product']['type'] && (count($merchantCart['list']) != 1 || count($merchantCartList) != 1)) { - throw new ValidateException('虚拟商品必须单独购买'); - } - $order_model = $cart['product']['type']; - if ($cart['product']['extend']) { - $order_extend = json_decode($cart['product']['extend'], true); - } - if ($address) { - if ($cart['source'] == 0 || $cart['source'] == 103) { - $userAddressCode = ($address['province_code'] ?? '') . ',' . ($address['city_code'] ?? '') . ',' . ($address['district_code'] ?? '') . ',' . ($address['street_code'] ?? '') . ',' . ($address['village_code'] ?? '') . ',' . ($address['brigade_id'] ?? 0); - $getUrl = env('LOGISTICS_HOST_URL') . '/api/hasCourier?user_address_code=' . $userAddressCode; - $curl = new Curl(); - $response = $curl->get($getUrl); - $courierData = json_decode($response, true); - if (empty($courierData['data']['user_id'])) { - $allowDelivery = false; - } - } - } - } - } - // if (($order_type == 98 || $order_type == 99) && count($merchantCartList) > 1) { - // throw new ValidateException('采购、委托商品不支持跨店购买'); - // } - $community = []; - unset($merchantCart, $cart); - $order_price = 0; - $total_true_price = 0; - $order_total_price = 0; - $order_coupon_price = 0; - $noDeliver = false; - $presellType = 0; - $fn = []; - if (in_array($source, [0, 2, 103])) { - $enabledPlatformCoupon = true; - } else { - $enabledPlatformCoupon = false; - } - $order_total_postage = 0; - $platformCoupon = []; - - - //套餐订单 - if ($order_type == 10) { - app()->make(StoreDiscountRepository::class) - ->check($merchantCartList[0]['list'][0]['source_id'], $merchantCartList[0]['list'], $user); - } - $orderDeliveryStatus = true; - $order_svip_discount = 0; - - if ($consumption_id > 0) { - $this->store_consumption_user = Db::name('store_consumption_user')->where('coupon_user_id', $consumption_id)->where('uid', $uid)->find(); - $this->balance=$this->store_consumption_user['balance']; - } - // 循环计算每个店铺的订单数据 委托商品是否设置收货方式 ? - foreach ($merchantCartList as &$merchantCart) { - if ($order_type == 98 && !empty($deliverMethodArray)) { - $merchantCart['delivery_way'] = $deliverMethodArray; - } - $postageRule = []; - $total_price = 0; - $total_num = 0; - $valid_total_price = 0; - $postage_price = 0; - $product_price = []; - $final_price = 0; - $down_price = 0; - $total_svip_discount = 0; - - //是否自提 - $isTake = in_array($merchantCart['mer_id'], $takes ?? []); - - // if (!$createOrder && !$isTake) { - // $isTake = count($merchantCart['delivery_way']) == 1 && $merchantCart['delivery_way'][0] == '1'; - // } - - $merTake = in_array('1', $merchantCart['delivery_way'], true); - $merDelivery = (!$merchantCart['delivery_way'] || !count($merchantCart['delivery_way']) || in_array('2', $merchantCart['delivery_way'], true)); - $_merTake = $merTake; - $_merDelivery = $merDelivery; - $deliveryStatus = true; - if ($createOrder && $isTake && !$merTake) { - $deliveryStatus = false; - // throw new ValidateException('[仅支持快递配送]' . $merchantCart['mer_name']); - } - $product_cart = []; - - foreach ($merchantCart['list'] as $k => $cart) { - //获取订单类型, 活动商品单次只能购买一个 - if ($cart['product']['delivery_way']) { - $delivery_way = explode(',', $cart['product']['delivery_way']); - $proTake = in_array('1', $delivery_way, true); - $merTake = $merTake && $proTake; - $proDelivery = (!count($delivery_way) || in_array('2', $delivery_way, true)); - $merDelivery = $merDelivery && $proDelivery; - $merchantCart['list'][$k]['allow_take'] = true; - $merchantCart['list'][$k]['allow_delivery'] = $allowDelivery; - } else { - $merchantCart['list'][$k]['allow_take'] = true; - $merchantCart['list'][$k]['allow_delivery'] = $allowDelivery; - } - if ($createOrder && $isTake && !$merTake) { - $deliveryStatus = false; - // throw new ValidateException('[仅支持快递配送]' . $cart['product']['store_name']); - } - } - if (!$merDelivery && !$merTake) { - $deliveryStatus = false; - // throw new ValidateException('部分商品配送方式不一致,请单独下单'); - } - if ($deliveryStatus && !$isTake && ($merDelivery || $merTake)) { - $isTake = $merDelivery ? 0 : 1; - } - - unset($cart); - - $enabledCoupon = !($order_type && $order_type != 2); - - //只有预售和普通商品可以用优惠券 - if (!$enabledCoupon) { - $merchantCart['coupon'] = []; - } - $svip_coupon_merge = merchantConfig($merchantCart['mer_id'], 'svip_coupon_merge'); - $use_svip = 0; - //获取运费规则和统计商品数据 - foreach ($merchantCart['list'] as &$cart) { - if ($cart['product_type'] == 10 && $cart['productDiscountAttr']) { - $cart['productAttr']['price'] = $cart['productDiscountAttr']['active_price']; - $cart['productAttr']['show_svip_price'] = false; - } - - if ($cart['cart_num'] <= 0) { - throw new ValidateException('购买商品数必须大于0'); - } - $svip_discount = 0; - $realPrice = $this->cartByPrice($cart); - if (in_array($source, [9, 10, 11, 12, 13])) { - if ($realPrice == 0) { - throw new ValidateException('价格必须大于0'); - } - $cart['product']['price'] = $realPrice; - $cart['productAttr']['price'] = $realPrice; - $cart['productAttr']['stock'] = $cart['cart_num']; - } - $price = bcmul($cart['cart_num'], $realPrice, 2); - $cart['total_price'] = $price; - $cart['postage_price'] = 0; - $cart['svip_discount'] = 0; - $total_price = bcadd($total_price, $price, 2); - $total_num += $cart['cart_num']; - $_price = bcmul($cart['cart_num'], $this->cartByCouponPrice($cart), 2); - $cart['svip_coupon_merge'] = 1; - if ($cart['productAttr']['show_svip_price'] && !$cart['product_type']) { - $svip_discount = max(bcmul($cart['cart_num'], bcsub($cart['productAttr']['org_price'] ?? 0, $cart['productAttr']['price'], 2), 2), 0); - if ($svip_coupon_merge != '1') { - $_price = 0; - $cart['svip_coupon_merge'] = 0; - } - $use_svip = 1; - } - $valid_total_price = bcadd($valid_total_price, $_price, 2); - $cart['allow_price'] = $_price; - $temp1 = $cart['product']['temp']; - $cart['temp_number'] = 0; - $total_svip_discount = bcadd($total_svip_discount, $svip_discount, 2); - $cart['svip_discount'] = $svip_discount; - - if (!isset($product_cart[$cart['product_id']])) - $product_cart[$cart['product_id']] = [$cart['cart_id']]; - else - $product_cart[$cart['product_id']][] = $cart['cart_id']; - - if ($_price > 0) { - $product_price[$cart['product_id']] = bcadd($product_price[$cart['product_id']] ?? 0, $_price, 2); - } - - if (!$temp1) continue; - - $number = $this->productByTempNumber($cart); - if ($number <= 0) continue; - $cart['temp_number'] = $number; - - if ($order_model || !$temp1 || ($cart['product_type'] == 10 && $cart['productDiscount']['free_shipping'])) { - continue; - } - - $free = $temp1['free'][0] ?? null; - $region = $temp1['region'][0] ?? null; - - if (!$cart['product']['delivery_free'] && !$isTake && (!$address || !$cart['product']['temp'] || ($temp1['undelivery'] == 2 && !$free && (!$region || !$region['city_id'])))) { - $cart['undelivered'] = true; - $noDeliver = true; - continue; - } - $cart['undelivered'] = (!$isTake) && $temp1['undelivery'] == 1 && isset($temp1['undelives']); - $fn[] = function () use ($cart) { - unset($cart['product']['temp']); - }; - - if ($cart['undelivered']) { - $noDeliver = true; - continue; - } - if ($cart['product']['delivery_free']) { - continue; - } - $tempId = $cart['product']['temp_id']; - if (!isset($postageRule[$tempId])) { - $postageRule[$tempId] = [ - 'free' => null, - 'region' => null, - 'cart' => [], - 'price' => 0, - ]; - } - - $freeRule = $postageRule[$tempId]['free']; - $regionRule = $postageRule[$tempId]['region']; - $postageRule[$tempId]['cart'][] = $cart['cart_id']; - $postageRule[$tempId]['price'] = bcadd($postageRule[$tempId]['price'], $cart['price'], 2); - - if ($temp1['appoint'] && $free) { - if (!isset($freeRule)) { - $freeRule = $free; - $freeRule['cart_price'] = 0; - $freeRule['cart_number'] = 0; - } - $freeRule['cart_number'] = bcadd($freeRule['cart_number'], $number, 2); - $freeRule['cart_price'] = bcadd($freeRule['cart_price'], $price, 2); - } - - if ($region) { - if (!isset($regionRule)) { - $regionRule = $region; - $regionRule['cart_price'] = 0; - $regionRule['cart_number'] = 0; - } - $regionRule['cart_number'] = bcadd($regionRule['cart_number'], $number, 2); - $regionRule['cart_price'] = bcadd($regionRule['cart_price'], $price, 2); - } - $postageRule[$tempId]['free'] = $freeRule; - $postageRule[$tempId]['region'] = $regionRule; - } - unset($cart); - - if (!$isTake) { - //计算运费 - foreach ($postageRule as $item) { - $freeRule = $item['free']; - if ($freeRule && $freeRule['cart_number'] >= $freeRule['number'] && $freeRule['cart_price'] >= $freeRule['price']) - continue; - if (!$item['region']) continue; - $regionRule = $item['region']; - $postage = $regionRule['first_price']; - if ($regionRule['first'] > 0 && $regionRule['cart_number'] > $regionRule['first']) { - $num = ceil(bcdiv(bcsub($regionRule['cart_number'], $regionRule['first'], 2), $regionRule['continue'], 2)); - $postage = bcadd($postage, bcmul($num, $regionRule['continue_price'], 2), 2); - } - $postage_price = bcadd($postage_price, $postage, 2); - $cartNum = count($item['cart']); - //计算每个商品的运费比例 - foreach ($merchantCart['list'] as &$cart) { - if (in_array($cart['cart_id'], $item['cart'])) { - if (--$cartNum) { - $cart['postage_price'] = bcmul($postage, bcdiv($cart['temp_number'], $regionRule['cart_number'], 3), 2); - $postage = bcsub($postage, $cart['postage_price'], 2); - } else { - $cart['postage_price'] = $postage; - } - } - } - unset($cart); - } - unset($item); - } - - $coupon_price = 0; - $use_coupon_product = []; - $use_store_coupon = 0; - - $useCouponFlag = isset($useCoupon[$merchantCart['mer_id']]); - $merCouponIds = (array)($useCoupon[$merchantCart['mer_id']] ?? []); - $merCouponIds = array_reverse($merCouponIds); - $sortIds = $merCouponIds; - // $all_coupon_product = []; - unset($defaultSort); - $defaultSort = []; - if (count($merCouponIds)) { - foreach ($merchantCart['coupon'] as &$item) { - $defaultSort[] = &$item; - if (!in_array($item['coupon_user_id'], $sortIds, true)) { - $sortIds[] = $item['coupon_user_id']; - } - } - unset($item); - usort($merchantCart['coupon'], function ($a, $b) use ($sortIds) { - return array_search($a['coupon_user_id'], $sortIds) > array_search($b['coupon_user_id'], $sortIds) ? 1 : -1; - }); - } - - $pay_price = max(bcsub($valid_total_price, $coupon_price, 2), 0); - $_pay_price = $pay_price; - - - $productCouponRate = []; - $storeCouponRate = null; - $useCouponIds = []; - - - if ($use_store_coupon) { - $storeCouponRate = [ - 'rate' => $pay_price > 0 ? bcdiv($use_store_coupon['coupon_price'], $pay_price, 4) : 1, - 'coupon_price' => $use_store_coupon['coupon_price'], - 'price' => $coupon_price - ]; - $useCouponIds[] = $use_store_coupon['coupon_user_id']; - } - - //计算单个商品实际支付金额 - foreach ($merchantCart['list'] as $_k => &$cart) { - $cartTotalPrice = bcmul($this->cartByPrice($cart), $cart['cart_num'], 2); - $_cartTotalPrice = $cartTotalPrice; - - //单个商品实际支付金额 - $cart['coupon_price'] = bcsub($_cartTotalPrice, $cartTotalPrice, 2); - $cart['true_price'] = $cartTotalPrice; - } - $procure = $this->cartByPrice($cart, 1); - $procure_price = bcmul($cart['cart_num'], $procure, 2); - unset($cart, $_k); - $total_true_price = bcadd($_pay_price, $total_true_price, 2); - if (count($merchantCartList) > 1 || count($merchantCart['list']) > 1) { - $orderDeliveryStatus = $orderDeliveryStatus && $deliveryStatus; - } - $merchantCart['order'] = [ - 'true_price' => $_pay_price, - 'platform_coupon_price' => 0, - 'valid_total_price' => $valid_total_price, - 'total_price' => $total_price, - 'final_price' => $final_price, - 'down_price' => $down_price, - 'coupon_price' => $coupon_price, - 'platformCoupon' => $platformCoupon, - 'svip_coupon_merge' => $svip_coupon_merge, - 'postage_price' => $postage_price, - 'isTake' => intval($allowDelivery == false || count($takes) > 0), - 'total_num' => $total_num, - 'enabledCoupon' => $enabledCoupon, - 'useCouponIds' => $useCouponIds, - 'allow_take' => true, - 'allow_delivery' => $allowDelivery, - 'delivery_status' => $deliveryStatus, - 'svip_discount' => $total_svip_discount, - 'use_svip' => $use_svip, - 'procure_price' => $procure_price - ]; - $order_total_postage = bcadd($order_total_postage, $postage_price, 2); - $order_svip_discount = bcadd($total_svip_discount, $order_svip_discount, 2); - if (count($defaultSort)) { - $merchantCart['coupon'] = &$defaultSort; - } - } - unset($merchantCart); - - $usePlatformCouponId = 0; - $total_platform_coupon_price = 0; - $usePlatformCouponFlag = isset($useCoupon[0]); - - foreach ($merchantCartList as &$merchantCart) { - if (!$merchantCart['order']['use_svip']) - continue; - $totalMergePrice = 0; - foreach ($merchantCart['list'] as &$cart) { - if (!$cart['svip_coupon_merge']) { - $totalMergePrice = bcadd($totalMergePrice, $cart['true_price'], 2); - $cart['allow_price'] = $cart['true_price']; - } - } - unset($cart); - if ($totalMergePrice > 0) { - $total_true_price = bcadd($total_true_price, $totalMergePrice, 2); - $merchantCart['order']['valid_total_price'] = bcadd($merchantCart['order']['valid_total_price'], $totalMergePrice, 2); - $merchantCart['order']['true_price'] = $merchantCart['order']['valid_total_price']; - } - } - unset($merchantCart); - //计算平台券优惠金额 - // if ($total_true_price > 0) { - $StoreCouponUser = app()->make(StoreCouponUserRepository::class); - $platformCoupon = $StoreCouponUser->validUserPlatformCoupon($uid); - $platformConsumption = []; - //消费金 - if ($source == 103) { - $ConsumptionWhere = [ - 'uid' => $uid, - 'status' => 0, - 'is_fail' => 0 - ]; - - $platformConsumption = Db::name('store_consumption_user')->where($ConsumptionWhere)->limit(100)->order('create_time', 'desc') - ->field('coupon_user_id,uid,coupon_title,coupon_price,balance,start_time,end_time') - ->select()->each(function ($item) { - $item['describe'] = '仅限平台指定商家商品可使用'; - return $item; - }); - } - // } - - $usePlatformCouponId = 0; - $total_platform_coupon_price = 0; - - //积分配置 - $sysIntegralConfig = systemConfig(['integral_money', 'integral_status', 'integral_order_rate']); - $merIntegralFlag = false; - $order_total_integral = 0; - $order_total_integral_price = 0; - $order_total_give_integral = 0; - $allow_no_address = true; - - foreach ($merchantCartList as &$merchantCart) { - $merchantCart['take'] = [ - 'mer_integral_rate' => 0, - 'mer_integral_status' => 0, - ]; - $allow_no_address = $allow_no_address && $merchantCart['order']['isTake']; - foreach ($merchantCart['config'] as $config) { - $merchantCart['take'][$config['config_key']] = $config['value']; - } - $merIntegralConfig = $merchantCart['take']; - unset($merchantCart['config']); - $merIntegralConfig['mer_integral_rate'] = min(1, $merIntegralConfig['mer_integral_rate'] > 0 ? bcdiv($merIntegralConfig['mer_integral_rate'], 100, 4) : $merIntegralConfig['mer_integral_rate']); - $total_integral = 0; - $total_integral_price = 0; - $merIntegralFlag = $merIntegralFlag || ((bool)$merIntegralConfig['mer_integral_status']); - $integralFlag = $useIntegral && $sysIntegralConfig['integral_status'] && $sysIntegralConfig['integral_money'] > 0 && $merIntegralConfig['mer_integral_status']; - - $order_total_integral = bcadd($order_total_integral, $total_integral, 0); - $order_total_integral_price = bcadd($order_total_integral_price, $total_integral_price, 2); - - $_pay_price = $merchantCart['order']['true_price']; - $valid_total_price = $merchantCart['order']['valid_total_price']; - $total_price = $merchantCart['order']['total_price']; - $final_price = $merchantCart['order']['final_price']; - $down_price = $merchantCart['order']['down_price']; - $coupon_price = $merchantCart['order']['coupon_price']; - $postage_price = $merchantCart['order']['postage_price']; - - //计算订单商品金额 - $org_price = bcadd(bcsub($total_price, $valid_total_price, 2), max($_pay_price, 0), 2); - if ($presellType == 2) { - $org_price = max(bcsub($org_price, $final_price, 2), $down_price); - } - - //获取可优惠金额 - $coupon_price = min($coupon_price, bcsub($total_price, $down_price, 2)); - $order_coupon_price = bcadd($coupon_price, $order_coupon_price, 2); - - //计算订单金额 - if ($order_type != 2 || $presellType != 2) { - $pay_price = bcadd($postage_price, $org_price, 2); - } else { - $pay_price = $org_price; - } - //计算总红包金额 - if ($consumption_id > 0 ) { - if ($this->store_consumption_user) { - if ($this->store_consumption_user['type'] == 2 && $pay_price>=6) { - $a = bcdiv($pay_price, 6); - if ($this->balance > $a) { - $pay_price = bcsub($pay_price, $a, 2); - $this->consumption_money = bcadd($this->consumption_money, $a, 2); - $this->balance = bcsub($this->balance, $a, 2); - } else { - $pay_price = bcsub($pay_price, $this->balance, 2); - $this->consumption_money = bcadd($this->consumption_money, $this->balance, 2); - $this->balance = 0; - } - } - if ($this->store_consumption_user['type'] == 1) { - if ($pay_price > $this->balance) { - $pay_price = bcsub($pay_price, $this->balance, 2); - $this->consumption_money = bcadd($this->consumption_money, $this->balance, 2); - $this->balance=0; - } else { - $pay_price = 0; - $this->consumption_money = bcadd($this->consumption_money, $pay_price, 2); - $this->balance = $pay_price; - - } - } - - } - } - - $giveIntegralFlag = $sysIntegralConfig['integral_status'] && $sysIntegralConfig['integral_order_rate'] > 0; - $total_give_integral = 0; - - foreach ($fn as $callback) { - $callback(); - } - $merchantCart['order']['order_type'] = $order_type; - $merchantCart['order']['total_give_integral'] = $total_give_integral; - $merchantCart['order']['total_integral_price'] = $total_integral_price; - $merchantCart['order']['total_integral'] = $total_integral; - $merchantCart['order']['org_price'] = $org_price; - $merchantCart['order']['pay_price'] = $pay_price; - $merchantCart['order']['coupon_price'] = $coupon_price; - $merchantCart['order']['postage_price'] = $merchantCart['order']['postage_price']; - $merchantCart['order']['procure_price'] = $merchantCart['order']['procure_price']; - $merchantCart['order']['consumption_id'] = $consumption_id; - $merchantCart['order']['consumption_money'] = $this->consumption_money; - - $order_price = bcadd($order_price, $pay_price, 2); - $order_total_price = bcadd($order_total_price, $total_price, 2); - } - unset($merchantCart); - - if ($order_model) { - $allow_no_address = false; - } - - foreach ($merchantCartList as &$merchantCart) { - foreach ($merchantCart['list'] as &$cart) { - $cart['total_price'] = bcadd($cart['total_price'], $cart['svip_discount'], 2); - } - unset($cart); - $merchantCart['order']['total_price'] = bcadd($merchantCart['order']['total_price'], $merchantCart['order']['svip_discount'], 2); - $order_total_price = bcadd($order_total_price, $merchantCart['order']['svip_discount'], 2); - } - unset($merchantCart); - $status = ($address || $order_model || $allow_no_address) ? ($noDeliver ? 'noDeliver' : 'finish') : 'noAddress'; - $order = $merchantCartList; - $consumption_money = $this->consumption_money; - $total_price = $order_total_price; - $openIntegral = $merIntegralFlag && !$order_type && $sysIntegralConfig['integral_status'] && $sysIntegralConfig['integral_money'] > 0; - $total_coupon = bcadd($order_svip_discount, bcadd(bcadd($total_platform_coupon_price, $order_coupon_price, 2), $order_total_integral_price, 2), 2); - $is_self_pickup = true; - if($order_type=='balance' &&$source!=103){ - throw new ValidateException('余额支付只能用于里海云仓'); - } - return compact( - 'is_self_pickup', - 'order_type', - 'source', - 'order_model', - 'order_extend', - 'order_total_postage', - 'order_price', - 'total_price', - 'community', - 'enabledPlatformCoupon', - 'platformCoupon', - 'usePlatformCouponId', - 'order_total_integral', - 'order_total_integral_price', - 'order_total_give_integral', - 'order_svip_discount', - 'total_platform_coupon_price', - 'total_coupon', - 'order_coupon_price', - 'order', - 'status', - 'address', - 'openIntegral', - 'useIntegral', - 'key', - 'platformConsumption', - 'consumption_money', - 'consumption_id' - ) + ['allow_address' => !$allow_no_address, 'order_delivery_status' => $orderDeliveryStatus]; - } - - public function v2CreateOrder(int $pay_type, $user, array $cartId, array $extend, array $mark, array $receipt_data, array $takes = null, array $useCoupon = null, bool $useIntegral = false, int $addressId = null, array $post, int $product_type = 0, $consumption_id = 0) - { - $uid = $user->uid; - $orderInfo = $this->v2CartIdByOrderInfo($user, $cartId, $takes, $useCoupon, $useIntegral, $addressId, true, $consumption_id); - $order_model = $orderInfo['order_model']; - $order_extend = $orderInfo['order_extend']; - if (!$orderInfo['order_delivery_status']) { - throw new ValidateException('部分商品配送方式不一致,请单独下单'); - } - if ($orderInfo['order_price'] > 1000000) { - throw new ValidateException('支付金额超出最大限制'); - } - if ($orderInfo['status'] == 'noDeliver') throw new ValidateException('商品不支持该区域'); - if ($orderInfo['status'] == 'noAddress') throw new ValidateException('请选择地址'); - if (!$order_model && $orderInfo['allow_address']) { - if (!$orderInfo['address']) throw new ValidateException('请选择正确的收货地址'); - if (!$orderInfo['address']['province_id']) throw new ValidateException('请完善收货地址信息'); - $extend = []; - } else if (count($order_extend)) { - $extend = app()->make(OrderVirtualFieldValidate::class)->load($order_extend, $extend); - } else { - $extend = []; - } - $orderType = $orderInfo['order_type']; - if ($orderType == 0 && $pay_type == StoreGroupOrder::PAY_TYPE_CREDIT_BUY) { - throw new ValidateException('该商品不支持先货后款'); - } - if (!in_array($orderType, [0, 98, 99]) && (count($orderInfo['order']) > 1 || ($orderType != 10 && count($orderInfo['order'][0]['list']) > 1))) { - throw new ValidateException('活动商品请单独购买'); - } - - $merchantCartList = $orderInfo['order']; - $cartSpread = 0; - $hasTake = false; - - foreach ($merchantCartList as $merchantCart) { - if ($merchantCart['order']['isTake']) { - $hasTake = true; - } - //检查发票状态 - if (isset($receipt_data[$merchantCart['mer_id']]) && !$merchantCart['openReceipt']) - throw new ValidateException('该店铺不支持开发票'); - if ($pay_type == StoreGroupOrder::PAY_TYPE_CREDIT_BUY && !$merchantCart['credit_buy']) { - throw new ValidateException("{$merchantCart['mer_name']}不支持先货后款"); - } - - foreach ($merchantCart['list'] as $cart) { - if (!$cartSpread && $cart['spread_id']) { - $cartSpread = $cart['spread_id']; - } - } - } - if (($orderType == 98 || $orderType == 99) && count($merchantCartList) > 1) { - throw new ValidateException('采购、委托商品不支持跨店购买'); - } - if ($hasTake) { - app()->make(UserAddressValidate::class)->scene('take')->check($post); - } - - if ($cartSpread) { - app()->make(UserRepository::class)->bindSpread($user, $cartSpread); - } - - $isSelfBuy = $user->is_promoter && systemConfig('extension_self') ? 1 : 0; - if ($isSelfBuy) { - $spreadUser = $user; - $topUser = $user->valid_spread; - } else { - $spreadUser = $user->valid_spread; - $topUser = $user->valid_top; - } - $spreadUid = $spreadUser->uid ?? 0; - $topUid = $topUser->uid ?? 0; - - $merchantRepository = app()->make(MerchantRepository::class); - $giveCouponIds = []; - $ex = systemConfig('extension_status'); //是否开启分销 - $address = $orderInfo['address']; - $allUseCoupon = $orderInfo['usePlatformCouponId'] ? [$orderInfo['usePlatformCouponId']] : []; - $totalNum = 0; - $totalPostage = 0; - $totalCost = 0; - $cartIds = []; - $orderList = []; - foreach ($merchantCartList as $k => $merchantCart) { - $cost = 0; - $total_extension_one = 0; - $total_extension_two = 0; - //计算佣金和赠送的优惠券 - foreach ($merchantCart['list'] as &$cart) { - $cartIds[] = $cart['cart_id']; - $giveCouponIds = array_merge($giveCouponIds, $cart['product']['give_coupon_ids'] ?: []); - $cart['cost'] = $cart['productAttr']['cost']; - $cost = bcadd(bcmul($cart['cost'], $cart['cart_num'], 2), $cost, 2); - $extension_one = 0; - $extension_two = 0; - $cart['extension_one'] = $extension_one; - $cart['extension_two'] = $extension_two; - $total_extension_one = bcadd($total_extension_one, bcmul($extension_one, $cart['cart_num'], 2), 2); - $total_extension_two = bcadd($total_extension_two, bcmul($extension_two, $cart['cart_num'], 2), 2); - } - unset($cart); - - $rate = 0; - if ($merchantCart['commission_rate'] > 0) { - $rate = $merchantCart['commission_rate']; - } else if (isset($merchantCart['merchantCategory']['commission_rate']) && $merchantCart['merchantCategory']['commission_rate'] > 0) { - $rate = bcmul($merchantCart['merchantCategory']['commission_rate'], 100, 4); - } - $user_address = isset($address) ? ($address['province'] . $address['city'] . $address['district'] . $address['street'] . $address['village'] . $address['brigade'] . $address['detail']) : ''; - $user_address_code = isset($address) ? ($address['province_code'] . ',' . $address['city_code'] . ',' . $address['district_code'] . ',' . $address['street_code'] . ',' . $address['village_code'] . ',' . $address['brigade_id']) : ''; - //整理订单数据 - $_order = [ - 'cartInfo' => $merchantCart, - 'activity_type' => $orderInfo['order_type'], - 'source' => $orderInfo['source'] ?? 2, - 'commission_rate' => (float)$rate, - 'order_type' => $merchantCart['order']['isTake'] ? 1 : 0, - 'is_virtual' => $order_model ? 1 : 0, - 'extension_one' => $total_extension_one, - 'extension_two' => $total_extension_two, - 'order_sn' => $this->getNewOrderId(StoreOrderRepository::TYPE_SN_ORDER) . ($k + 1), - 'uid' => $uid, - 'spread_uid' => $spreadUid, - 'top_uid' => $topUid, - 'is_selfbuy' => $isSelfBuy, - 'real_name' => $merchantCart['order']['isTake'] ? $post['real_name'] : ($address['real_name'] ?? ''), - 'user_phone' => $merchantCart['order']['isTake'] ? $post['phone'] : ($address['phone'] ?? ''), - 'user_address' => $user_address, - 'user_address_code' => $user_address_code, - 'cart_id' => implode(',', array_column($merchantCart['list'], 'cart_id')), - 'total_num' => $merchantCart['order']['total_num'], - 'total_price' => $merchantCart['order']['total_price'], - 'total_postage' => $merchantCart['order']['postage_price'], - 'pay_postage' => $merchantCart['order']['postage_price'], - 'svip_discount' => $merchantCart['order']['svip_discount'], - 'pay_price' => $merchantCart['order']['pay_price'], - 'integral' => $merchantCart['order']['total_integral'], - 'integral_price' => $merchantCart['order']['total_integral_price'], - 'give_integral' => $merchantCart['order']['total_give_integral'], - 'mer_id' => $merchantCart['mer_id'], - 'cost' => $cost, - 'order_extend' => count($extend) ? json_encode($extend, JSON_UNESCAPED_UNICODE) : '', - 'coupon_id' => implode(',', $merchantCart['order']['useCouponIds']), - 'mark' => $mark[$merchantCart['mer_id']] ?? '', - 'coupon_price' => bcadd($merchantCart['order']['coupon_price'], $merchantCart['order']['platform_coupon_price'], 2), - 'platform_coupon_price' => $merchantCart['order']['platform_coupon_price'], - 'pay_type' => $pay_type, - 'procure_price' => $merchantCart['order']['procure_price'], - 'consumption_id' => $merchantCart['order']['consumption_id'], - 'consumption_money' => $merchantCart['order']['consumption_money'], - ]; - $allUseCoupon = array_merge($allUseCoupon, $merchantCart['order']['useCouponIds']); - $orderList[] = $_order; - $totalPostage = bcadd($totalPostage, $_order['total_postage'], 2); - $totalCost = bcadd($totalCost, $cost, 2); - $totalNum += $merchantCart['order']['total_num']; - } - //总订单组 - $groupOrder = [ - 'uid' => $uid, - 'group_order_sn' => count($orderList) === 1 ? $orderList[0]['order_sn'] : ($this->getNewOrderId(StoreOrderRepository::TYPE_SN_ORDER) . '0'), - 'total_postage' => $totalPostage, - 'total_price' => $orderInfo['total_price'], - 'total_num' => $totalNum, - 'real_name' => $address['real_name'] ?? '', - 'user_phone' => $address['phone'] ?? '', - 'user_address' => $user_address, - 'pay_price' => $orderInfo['order_price'], - 'coupon_price' => bcadd($orderInfo['total_platform_coupon_price'], $orderInfo['order_coupon_price'], 2), - 'pay_postage' => $totalPostage, - 'cost' => $totalCost, - 'coupon_id' => $orderInfo['usePlatformCouponId'] > 0 ? $orderInfo['usePlatformCouponId'] : '', - 'pay_type' => $pay_type, - 'give_coupon_ids' => $giveCouponIds, - 'integral' => $orderInfo['order_total_integral'], - 'integral_price' => $orderInfo['order_total_integral_price'], - 'give_integral' => $orderInfo['order_total_give_integral'], - 'consumption_id' => $orderInfo['consumption_id'], - 'consumption_money' => $orderInfo['consumption_money'], - ]; - event('order.create.before', compact('groupOrder', 'orderList')); - $group = Db::transaction(function () use ($ex, $user, $topUid, $spreadUid, $uid, $receipt_data, $cartIds, $allUseCoupon, $groupOrder, $orderList, $orderInfo) { - $storeGroupOrderRepository = app()->make(StoreGroupOrderRepository::class); - $storeCartRepository = app()->make(StoreCartRepository::class); - /** @var ProductAttrValueRepository $attrValueRepository */ - $attrValueRepository = app()->make(ProductAttrValueRepository::class); - /** @var ProductRepository $productRepository */ - $productRepository = app()->make(ProductRepository::class); - $storeOrderProductRepository = app()->make(StoreOrderProductRepository::class); - $couponUserRepository = app()->make(StoreCouponUserRepository::class); - //订单记录 - $storeOrderStatusRepository = app()->make(StoreOrderStatusRepository::class); - $userMerchantRepository = app()->make(UserMerchantRepository::class); - - //减库存 - foreach ($orderList as $order) { - foreach ($order['cartInfo']['list'] as $cart) { - if (!isset($uniqueList[$cart['productAttr']['product_id'] . $cart['productAttr']['unique']])) - $uniqueList[$cart['productAttr']['product_id'] . $cart['productAttr']['unique']] = true; - else - throw new ValidateException('购物车商品信息重复'); - - try { - if ($cart['product_type'] == '1') { - $attrValueRepository->descSkuStock($cart['product']['old_product_id'], $cart['productAttr']['sku'], $cart['cart_num']); - $productRepository->descStock($cart['product']['old_product_id'], $cart['cart_num']); - } else if ($cart['product_type'] == '2') { - $productPresellSkuRepository = app()->make(ProductPresellSkuRepository::class); - $productPresellSkuRepository->descStock($cart['productPresellAttr']['product_presell_id'], $cart['productPresellAttr']['unique'], $cart['cart_num']); - $attrValueRepository->descStock($cart['productAttr']['product_id'], $cart['productAttr']['unique'], $cart['cart_num']); - $productRepository->descStock($cart['product']['product_id'], $cart['cart_num']); - } else if ($cart['product_type'] == '3') { - app()->make(ProductAssistSkuRepository::class)->descStock($cart['productAssistAttr']['product_assist_id'], $cart['productAssistAttr']['unique'], $cart['cart_num']); - $productRepository->descStock($cart['product']['old_product_id'], $cart['cart_num']); - $attrValueRepository->descStock($cart['product']['old_product_id'], $cart['productAttr']['unique'], $cart['cart_num']); - } else if ($cart['product_type'] == '4') { - app()->make(ProductGroupSkuRepository::class)->descStock($cart['activeSku']['product_group_id'], $cart['activeSku']['unique'], $cart['cart_num']); - $productRepository->descStock($cart['product']['old_product_id'], $cart['cart_num']); - $attrValueRepository->descStock($cart['product']['old_product_id'], $cart['productAttr']['unique'], $cart['cart_num']); - } else { - if ($cart['source'] == StoreCartDao::SOURCE_COMMUNITY_RESALE) { - /** @var CommunityRepository $communityRepository */ - $communityRepository = app()->make(CommunityRepository::class); - $communityRepository->saleOrCancel($cart['source_id']); - $attrValueRepository->incSales($cart['productAttr']['product_id'], $cart['productAttr']['unique'], $cart['cart_num']); - $productRepository->incSales($cart['product']['product_id'], $cart['cart_num']); - } else { - $attrValueRepository->descStock($cart['productAttr']['product_id'], $cart['productAttr']['unique'], $cart['cart_num']); - $productRepository->descStock($cart['product']['product_id'], $cart['cart_num']); - } - /** @var PurchaseRecordRepository $purchaseRecordRepo */ - $purchaseRecordRepo = app()->make(PurchaseRecordRepository::class); - $purchaseRecordRepo->incSalesVolume($cart['product']['product_id'], $cart['productAttr']['unique'], $cart['cart_num']); - if ($cart['integral'] && $cart['integral']['use'] > 0) { - $productRepository->incIntegral($cart['product']['product_id'], $cart['integral']['use'], $cart['integral']['price']); - } - } - } catch (\Exception $e) { - throw new ValidateException('库存不足'); - } - } - } - - if ($orderInfo['order_type'] == 10 && !app()->make(StoreDiscountRepository::class)->decStock($orderList[0]['cartInfo']['list'][0]['source_id'])) { - throw new ValidateException('套餐库不足'); - } - - //修改购物车状态 - $storeCartRepository->updates($cartIds, [ - 'is_pay' => 1 - ]); - - //使用优惠券 - if (count($allUseCoupon)) { - $couponUserRepository->updates($allUseCoupon, [ - 'use_time' => date('Y-m-d H:i:s'), - 'status' => 1 - ]); - } - - //创建订单 - $groupOrder = $storeGroupOrderRepository->create($groupOrder); - $bills = []; - $consumptionDetails=[]; - if ($groupOrder['integral'] > 0) { - $user->integral = bcsub($user->integral, $groupOrder['integral'], 0); - app()->make(UserBillRepository::class)->decBill($user['uid'], 'integral', 'deduction', [ - 'link_id' => $groupOrder['group_order_id'], - 'status' => 1, - 'title' => '购买商品', - 'number' => $groupOrder['integral'], - 'mark' => '购买商品使用积分抵扣' . floatval($groupOrder['integral_price']) . '元', - 'balance' => $user->integral - ]); - $user->save(); - } - - if ($groupOrder['consumption_money'] > 0) { - $balance = 0; - $store_consumption_user = Db::name('store_consumption_user')->where('uid',$uid)->where('coupon_user_id', $groupOrder['consumption_id'])->where('status', 0)->find(); - if ($store_consumption_user) { - if ($store_consumption_user['type'] == 1) { - if ($store_consumption_user['balance'] > $groupOrder['consumption_money']) { - $balance = bcsub($store_consumption_user['balance'], $groupOrder['consumption_money'], 2); - $balanceArr = ['balance' => $balance]; - Db::name('store_consumption_user')->where('coupon_user_id', $store_consumption_user['coupon_user_id'])->update($balanceArr); - } else { - $balanceArr = ['balance' => 0, 'status' => 1]; - Db::name('store_consumption_user')->where('coupon_user_id', $store_consumption_user['coupon_user_id'])->update($balanceArr); - } - } - } - app()->make(UserBillRepository::class)->decBill($user['uid'], 'consumption', 'deduction', [ - 'link_id' => $groupOrder['group_order_id'], - 'status' => 1, - 'title' => '购买商品', - 'number' => $groupOrder['consumption_money'], - 'mark' => '购买商品使用红包抵扣' . floatval($groupOrder['consumption_money']) . '元', - 'balance' => $balance - ]); - } - - foreach ($orderList as $k => $order) { - $orderList[$k]['group_order_id'] = $groupOrder->group_order_id; - } - - $orderProduct = []; - $orderStatus = []; - foreach ($orderList as $order) { - if ($order['pay_type'] == StoreGroupOrder::PAY_TYPE_CREDIT_BUY) { - $order['status'] = StoreOrder::STATUS_WAIT_CONFIRM; - } - $cartInfo = $order['cartInfo']; - unset($order['cartInfo']); - //创建子订单 - $_order = $this->dao->create($order); - - if ($order['integral'] > 0) { - $bills[] = [ - 'uid' => $uid, - 'link_id' => $_order->order_id, - 'pm' => 0, - 'title' => '积分抵扣', - 'category' => 'mer_integral', - 'type' => 'deduction', - 'number' => $order['integral'], - 'balance' => $user->integral, - 'mark' => '购买商品使用' . $order['integral'] . '积分抵扣' . floatval($order['integral_price']) . '元', - 'mer_id' => $order['mer_id'], - 'status' => 1 - ]; - } - if ($order['consumption_money'] > 0) { - $consumptionDetails[] = [ - 'user_id' => $uid, - 'order_id' => $_order->order_id, - 'group_order_id' => $groupOrder->group_order_id, - 'coupon_user_id' => $order['consumption_id'], - 'type' => 1, - 'amount' => $order['consumption_money'], - 'pay_price' => $order['pay_price'], - 'create_time' => time() - ]; - } - - //创建发票信息 - if (isset($receipt_data[$_order['mer_id']])) { - app()->make(StoreOrderReceiptRepository::class)->add($receipt_data[$_order['mer_id']], $_order); - } - - $orderStatus[] = [ - 'order_id' => $_order->order_id, - 'order_sn' => $_order->order_sn, - 'type' => $storeOrderStatusRepository::TYPE_ORDER, - 'change_message' => '订单生成', - 'change_type' => $storeOrderStatusRepository::ORDER_STATUS_CREATE, - 'uid' => $user->uid, - 'nickname' => $user->nickname, - 'user_type' => $storeOrderStatusRepository::U_TYPE_USER, - ]; - - foreach ($cartInfo['list'] as $cart) { - $productPrice = $cart['true_price']; - $extension_one = $cart['extension_one']; - $extension_two = $cart['extension_two']; - - //计算预售订单尾款 - if ($cartInfo['order']['order_type'] == 2) { - $finalPrice = max(bcsub($cartInfo['order']['final_price'], $cartInfo['order']['coupon_price'], 2), 0); - $allFinalPrice = $order['order_type'] ? $finalPrice : bcadd($finalPrice, $order['pay_postage'], 2); - if ($cart['productPresell']['presell_type'] == 1) { - $productPrice = bcsub($cartInfo['order']['pay_price'], $order['pay_postage'], 2); - } else { - $productPrice = bcadd($cartInfo['order']['pay_price'], $finalPrice, 2); - } - //生成尾款订单 - if ($cart['productPresell']['presell_type'] == 2) { - $presellOrderRepository = app()->make(PresellOrderRepository::class); - $presellOrderRepository->create([ - 'uid' => $uid, - 'order_id' => $_order->order_id, - 'mer_id' => $_order->mer_id, - 'final_start_time' => $cart['productPresell']['final_start_time'], - 'final_end_time' => $cart['productPresell']['final_end_time'], - 'pay_price' => $allFinalPrice, - 'presell_order_sn' => $this->getNewOrderId(StoreOrderRepository::TYPE_SN_PRESELL) - ]); - } - app()->make(ProductPresellSkuRepository::class)->incCount($cart['source_id'], $cart['productAttr']['unique'], 'one_take'); - } - - $order_cart = [ - 'product' => $cart['product'], - 'productAttr' => $cart['productAttr'], - 'product_type' => $cart['product_type'] - ]; - - if ($cart['product_type'] == '2') { - $order_cart['productPresell'] = $cart['productPresell']; - $order_cart['productPresellAttr'] = $cart['productPresellAttr']; - $order_cart['final_extension_one'] = $cart['final_extension_one'] ?? 0; - $order_cart['final_extension_two'] = $cart['final_extension_two'] ?? 0; - $order_cart['presell_extension_one'] = $cart['presell_extension_one'] ?? 0; - $order_cart['presell_extension_two'] = $cart['presell_extension_two'] ?? 0; - } else if ($cart['product_type'] == '3') { - $order_cart['productAssistAttr'] = $cart['productAssistAttr']; - $order_cart['productAssistSet'] = $cart['productAssistSet']; - } else if ($cart['product_type'] == '4') { - $order_cart['activeSku'] = $cart['activeSku']; - } else if ($cart['product_type'] == '10') { - $order_cart['active'] = $cart['productDiscount']; - $order_cart['activeSku'] = $cart['productDiscountAttr']; - } - $product_source_id = 0; - $product_mer_id = 0; - if ($cart['source'] == 103) { - $old_product_id = Db::name('store_product')->where('product_id', $cart['product_id'])->value('old_product_id'); - if ($old_product_id) { - $old_mer_id = Db::name('store_product')->where('product_id', $old_product_id)->value('mer_id'); - $product_mer_id = $old_mer_id; - $product_source_id = $old_product_id; - } - } - $orderProduct[] = [ - 'order_id' => $_order->order_id, - 'cart_id' => $cart['cart_id'], - 'uid' => $uid, - 'product_id' => $cart['product_id'], - 'activity_id' => $cart['source'] >= 2 ? $cart['source_id'] : $cart['product_id'], - 'total_price' => $cart['total_price'], - 'product_price' => $productPrice, - 'extension_one' => $extension_one, - 'extension_two' => $extension_two, - 'postage_price' => $cart['postage_price'], - 'svip_discount' => $cart['svip_discount'], - 'cost' => $cart['cost'], - 'coupon_price' => $cart['coupon_price'], - 'platform_coupon_price' => $cart['platform_coupon_price'], - 'product_sku' => $cart['productAttr']['unique'], - 'product_num' => $cart['cart_num'], - 'refund_num' => $cart['cart_num'], - 'integral_price' => $cart['integral']['price'] ?? 0, - 'integral' => $cart['integral'] ? bcdiv($cart['integral']['use'], $cart['cart_num'], 0) : 0, - 'integral_total' => $cart['integral'] ? $cart['integral']['use'] : 0, - 'product_type' => $cart['product_type'], - 'source' => $cart['source'], - 'source_id' => $cart['source_id'], - 'cart_info' => json_encode($order_cart), - 'product_source_id' => $product_source_id, - 'product_mer_id' => $product_mer_id, - ]; - } - - $userMerchantRepository->getInfo($uid, $order['mer_id']); - app()->make(MerchantRepository::class)->incSales($order['mer_id'], $order['total_num']); - } - - if (count($bills) > 0) { - app()->make(UserBillRepository::class)->insertAll($bills); - } - if (count($consumptionDetails) > 0) { - Db::name('store_consumption_detail')->insertAll($consumptionDetails); - } - $storeOrderStatusRepository->batchCreateLog($orderStatus); - $storeOrderProductRepository->insertAll($orderProduct); - event('order.create', compact('groupOrder')); - return $groupOrder; - }); - foreach ($merchantCartList as $merchantCart) { - foreach ($merchantCart['list'] as $cart) { - if (($cart['productAttr']['stock'] - $cart['cart_num']) < (int)merchantConfig($merchantCart['mer_id'], 'mer_store_stock')) { - SwooleTaskService::merchant('notice', [ - 'type' => 'min_stock', - 'data' => [ - 'title' => '库存不足', - 'message' => $cart['product']['store_name'] . '(' . $cart['productAttr']['sku'] . ')库存不足', - 'id' => $cart['product']['product_id'] - ] - ], $merchantCart['mer_id']); - } - } - } - // Queue::push(SendSmsJob::class, ['tempId' => 'ORDER_CREATE', 'id' => $group->group_order_id, - // 'activity_type'=>$group->activity_type,'order_id'=>$group->order_id]); - return $group; - } -} +uid; + $this->balance = 0; + $userIntegral = $user->integral; + $key = md5(json_encode(compact('cartId', 'takes', 'useCoupon', 'useIntegral', 'addressId'))) . $uid; + app()->make(StoreCouponUserRepository::class)->failCoupon(); + $address = null; + //验证地址 + if ($addressId) { + $addressRepository = app()->make(UserAddressRepository::class); + $address = $addressRepository->getWhere(['uid' => $uid, 'address_id' => $addressId]); + } + $storeCartRepository = app()->make(StoreCartRepository::class); + $res = $storeCartRepository->checkCartList($storeCartRepository->cartIbByData($cartId, $uid, $address), 0, $user); + $merchantCartList = $res['list']; + $fail = $res['fail']; + + //检查购物车失效数据 + if (count($fail)) { + if ($fail[0]['is_fail']) + throw new ValidateException('[已失效]' . mb_substr($fail[0]['product']['store_name'], 0, 10) . '...'); + if (in_array($fail[0]['product_type'], [1, 2, 3]) && !$fail[0]['userPayCount']) { + throw new ValidateException('[超出限购数]' . mb_substr($fail[0]['product']['store_name'], 0, 10) . '...'); + } + throw new ValidateException('[已失效]' . mb_substr($fail[0]['product']['store_name'], 0, 10) . '...'); + } + + $svip_status = $user->is_svip > 0 && systemConfig('svip_switch_status') == '1'; + $svip_integral_rate = $svip_status ? app()->make(MemberinterestsRepository::class)->getSvipInterestVal(MemberinterestsRepository::HAS_TYPE_PAY) : 0; + //订单活动类型 + $order_type = 0; + $source = 2; + //虚拟订单 + $order_model = 0; + //虚拟订单自定义数据 + $order_extend = []; + //检查商品类型, 活动商品只能单独购买 + $allowDelivery = true; + foreach ($merchantCartList as $merchantCart) { + + if (($merchantCart['type_id'] != Merchant::TypeSupplyChain) && $address) { + if ($merchantCart['street_id'] != $address['street_code']) { + throw new ValidateException('不支持跨区域购买,请在【我的】-【地址管理】更改后重新购买'); + } + } + foreach ($merchantCart['list'] as $cart) { + if ($cart['product_type'] == 0) { + if ($cart['product']['once_min_count'] > 0 && $cart['product']['once_min_count'] > $cart['cart_num']) + throw new ValidateException('[低于起购数:' . $cart['product']['once_min_count'] . ']' . mb_substr($cart['product']['store_name'], 0, 10) . '...'); + if ($cart['product']['pay_limit'] == 1 && $cart['product']['once_max_count'] < $cart['cart_num']) + throw new ValidateException('[超出单次限购数:' . $cart['product']['once_max_count'] . ']' . mb_substr($cart['product']['store_name'], 0, 10) . '...'); + if ($cart['product']['pay_limit'] == 2) { + //如果长期限购 + //已购买数量 + $count = app()->make(StoreOrderRepository::class)->getMaxCountNumber($cart['uid'], $cart['product_id']); + if (($cart['cart_num'] + $count) > $cart['product']['once_max_count']) + throw new ValidateException('[超出限购总数:' . $cart['product']['once_max_count'] . ']' . mb_substr($cart['product']['store_name'], 0, 10) . '...'); + } + } + if ($cart['product_type'] > 0) { + $order_type = $cart['product_type']; + } + $source = $cart['source']; + if ($cart['product_type'] <= 97 && $cart['product_type'] > 0 && (($cart['product_type'] != 10 && count($merchantCart['list']) != 1) || count($merchantCartList) != 1)) { + throw new ValidateException('活动商品必须单独购买'); + } + if ($cart['product']['type'] && (count($merchantCart['list']) != 1 || count($merchantCartList) != 1)) { + throw new ValidateException('虚拟商品必须单独购买'); + } + $order_model = $cart['product']['type']; + if ($cart['product']['extend']) { + $order_extend = json_decode($cart['product']['extend'], true); + } + if ($address) { + if ($cart['source'] == 0 || $cart['source'] == 103) { + $userAddressCode = ($address['province_code'] ?? '') . ',' . ($address['city_code'] ?? '') . ',' . ($address['district_code'] ?? '') . ',' . ($address['street_code'] ?? '') . ',' . ($address['village_code'] ?? '') . ',' . ($address['brigade_id'] ?? 0); + $getUrl = env('LOGISTICS_HOST_URL') . '/api/hasCourier?user_address_code=' . $userAddressCode; + $curl = new Curl(); + $response = $curl->get($getUrl); + $courierData = json_decode($response, true); + if (empty($courierData['data']['user_id'])) { + $allowDelivery = false; + } + } + } + } + } + // if (($order_type == 98 || $order_type == 99) && count($merchantCartList) > 1) { + // throw new ValidateException('采购、委托商品不支持跨店购买'); + // } + $community = []; + unset($merchantCart, $cart); + $order_price = 0; + $total_true_price = 0; + $order_total_price = 0; + $order_coupon_price = 0; + $noDeliver = false; + $presellType = 0; + $fn = []; + if (in_array($source, [0, 2, 103])) { + $enabledPlatformCoupon = true; + } else { + $enabledPlatformCoupon = false; + } + $order_total_postage = 0; + $platformCoupon = []; + + + //套餐订单 + if ($order_type == 10) { + app()->make(StoreDiscountRepository::class) + ->check($merchantCartList[0]['list'][0]['source_id'], $merchantCartList[0]['list'], $user); + } + $orderDeliveryStatus = true; + $order_svip_discount = 0; + + if ($consumption_id > 0) { + $this->store_consumption_user = Db::name('store_consumption_user')->where('coupon_user_id', $consumption_id)->where('uid', $uid)->find(); + $this->balance=$this->store_consumption_user['balance']; + } + // 循环计算每个店铺的订单数据 委托商品是否设置收货方式 ? + foreach ($merchantCartList as &$merchantCart) { + if ($order_type == 98 && !empty($deliverMethodArray)) { + $merchantCart['delivery_way'] = $deliverMethodArray; + } + $postageRule = []; + $total_price = 0; + $total_num = 0; + $valid_total_price = 0; + $postage_price = 0; + $product_price = []; + $final_price = 0; + $down_price = 0; + $total_svip_discount = 0; + + //是否自提 + $isTake = in_array($merchantCart['mer_id'], $takes ?? []); + + // if (!$createOrder && !$isTake) { + // $isTake = count($merchantCart['delivery_way']) == 1 && $merchantCart['delivery_way'][0] == '1'; + // } + + $merTake = in_array('1', $merchantCart['delivery_way'], true); + $merDelivery = (!$merchantCart['delivery_way'] || !count($merchantCart['delivery_way']) || in_array('2', $merchantCart['delivery_way'], true)); + $_merTake = $merTake; + $_merDelivery = $merDelivery; + $deliveryStatus = true; + if ($createOrder && $isTake && !$merTake) { + $deliveryStatus = false; + // throw new ValidateException('[仅支持快递配送]' . $merchantCart['mer_name']); + } + $product_cart = []; + + foreach ($merchantCart['list'] as $k => $cart) { + //获取订单类型, 活动商品单次只能购买一个 + if ($cart['product']['delivery_way']) { + $delivery_way = explode(',', $cart['product']['delivery_way']); + $proTake = in_array('1', $delivery_way, true); + $merTake = $merTake && $proTake; + $proDelivery = (!count($delivery_way) || in_array('2', $delivery_way, true)); + $merDelivery = $merDelivery && $proDelivery; + $merchantCart['list'][$k]['allow_take'] = true; + $merchantCart['list'][$k]['allow_delivery'] = $allowDelivery; + } else { + $merchantCart['list'][$k]['allow_take'] = true; + $merchantCart['list'][$k]['allow_delivery'] = $allowDelivery; + } + if ($createOrder && $isTake && !$merTake) { + $deliveryStatus = false; + // throw new ValidateException('[仅支持快递配送]' . $cart['product']['store_name']); + } + } + if (!$merDelivery && !$merTake) { + $deliveryStatus = false; + // throw new ValidateException('部分商品配送方式不一致,请单独下单'); + } + if ($deliveryStatus && !$isTake && ($merDelivery || $merTake)) { + $isTake = $merDelivery ? 0 : 1; + } + + unset($cart); + + $enabledCoupon = !($order_type && $order_type != 2); + + //只有预售和普通商品可以用优惠券 + if (!$enabledCoupon) { + $merchantCart['coupon'] = []; + } + $svip_coupon_merge = merchantConfig($merchantCart['mer_id'], 'svip_coupon_merge'); + $use_svip = 0; + //获取运费规则和统计商品数据 + foreach ($merchantCart['list'] as &$cart) { + if ($cart['product_type'] == 10 && $cart['productDiscountAttr']) { + $cart['productAttr']['price'] = $cart['productDiscountAttr']['active_price']; + $cart['productAttr']['show_svip_price'] = false; + } + + if ($cart['cart_num'] <= 0) { + throw new ValidateException('购买商品数必须大于0'); + } + $svip_discount = 0; + $realPrice = $this->cartByPrice($cart); + if (in_array($source, [9, 10, 11, 12, 13])) { + if ($realPrice == 0) { + throw new ValidateException('价格必须大于0'); + } + $cart['product']['price'] = $realPrice; + $cart['productAttr']['price'] = $realPrice; + $cart['productAttr']['stock'] = $cart['cart_num']; + } + $price = bcmul($cart['cart_num'], $realPrice, 2); + $cart['total_price'] = $price; + $cart['postage_price'] = 0; + $cart['svip_discount'] = 0; + $total_price = bcadd($total_price, $price, 2); + $total_num += $cart['cart_num']; + $_price = bcmul($cart['cart_num'], $this->cartByCouponPrice($cart), 2); + $cart['svip_coupon_merge'] = 1; + if ($cart['productAttr']['show_svip_price'] && !$cart['product_type']) { + $svip_discount = max(bcmul($cart['cart_num'], bcsub($cart['productAttr']['org_price'] ?? 0, $cart['productAttr']['price'], 2), 2), 0); + if ($svip_coupon_merge != '1') { + $_price = 0; + $cart['svip_coupon_merge'] = 0; + } + $use_svip = 1; + } + $valid_total_price = bcadd($valid_total_price, $_price, 2); + $cart['allow_price'] = $_price; + $temp1 = $cart['product']['temp']; + $cart['temp_number'] = 0; + $total_svip_discount = bcadd($total_svip_discount, $svip_discount, 2); + $cart['svip_discount'] = $svip_discount; + + if (!isset($product_cart[$cart['product_id']])) + $product_cart[$cart['product_id']] = [$cart['cart_id']]; + else + $product_cart[$cart['product_id']][] = $cart['cart_id']; + + if ($_price > 0) { + $product_price[$cart['product_id']] = bcadd($product_price[$cart['product_id']] ?? 0, $_price, 2); + } + + if (!$temp1) continue; + + $number = $this->productByTempNumber($cart); + if ($number <= 0) continue; + $cart['temp_number'] = $number; + + if ($order_model || !$temp1 || ($cart['product_type'] == 10 && $cart['productDiscount']['free_shipping'])) { + continue; + } + + $free = $temp1['free'][0] ?? null; + $region = $temp1['region'][0] ?? null; + + if (!$cart['product']['delivery_free'] && !$isTake && (!$address || !$cart['product']['temp'] || ($temp1['undelivery'] == 2 && !$free && (!$region || !$region['city_id'])))) { + $cart['undelivered'] = true; + $noDeliver = true; + continue; + } + $cart['undelivered'] = (!$isTake) && $temp1['undelivery'] == 1 && isset($temp1['undelives']); + $fn[] = function () use ($cart) { + unset($cart['product']['temp']); + }; + + if ($cart['undelivered']) { + $noDeliver = true; + continue; + } + if ($cart['product']['delivery_free']) { + continue; + } + $tempId = $cart['product']['temp_id']; + if (!isset($postageRule[$tempId])) { + $postageRule[$tempId] = [ + 'free' => null, + 'region' => null, + 'cart' => [], + 'price' => 0, + ]; + } + + $freeRule = $postageRule[$tempId]['free']; + $regionRule = $postageRule[$tempId]['region']; + $postageRule[$tempId]['cart'][] = $cart['cart_id']; + $postageRule[$tempId]['price'] = bcadd($postageRule[$tempId]['price'], $cart['price'], 2); + + if ($temp1['appoint'] && $free) { + if (!isset($freeRule)) { + $freeRule = $free; + $freeRule['cart_price'] = 0; + $freeRule['cart_number'] = 0; + } + $freeRule['cart_number'] = bcadd($freeRule['cart_number'], $number, 2); + $freeRule['cart_price'] = bcadd($freeRule['cart_price'], $price, 2); + } + + if ($region) { + if (!isset($regionRule)) { + $regionRule = $region; + $regionRule['cart_price'] = 0; + $regionRule['cart_number'] = 0; + } + $regionRule['cart_number'] = bcadd($regionRule['cart_number'], $number, 2); + $regionRule['cart_price'] = bcadd($regionRule['cart_price'], $price, 2); + } + $postageRule[$tempId]['free'] = $freeRule; + $postageRule[$tempId]['region'] = $regionRule; + } + unset($cart); + + if (!$isTake) { + //计算运费 + foreach ($postageRule as $item) { + $freeRule = $item['free']; + if ($freeRule && $freeRule['cart_number'] >= $freeRule['number'] && $freeRule['cart_price'] >= $freeRule['price']) + continue; + if (!$item['region']) continue; + $regionRule = $item['region']; + $postage = $regionRule['first_price']; + if ($regionRule['first'] > 0 && $regionRule['cart_number'] > $regionRule['first']) { + $num = ceil(bcdiv(bcsub($regionRule['cart_number'], $regionRule['first'], 2), $regionRule['continue'], 2)); + $postage = bcadd($postage, bcmul($num, $regionRule['continue_price'], 2), 2); + } + $postage_price = bcadd($postage_price, $postage, 2); + $cartNum = count($item['cart']); + //计算每个商品的运费比例 + foreach ($merchantCart['list'] as &$cart) { + if (in_array($cart['cart_id'], $item['cart'])) { + if (--$cartNum) { + $cart['postage_price'] = bcmul($postage, bcdiv($cart['temp_number'], $regionRule['cart_number'], 3), 2); + $postage = bcsub($postage, $cart['postage_price'], 2); + } else { + $cart['postage_price'] = $postage; + } + } + } + unset($cart); + } + unset($item); + } + + $coupon_price = 0; + $use_coupon_product = []; + $use_store_coupon = 0; + + $useCouponFlag = isset($useCoupon[$merchantCart['mer_id']]); + $merCouponIds = (array)($useCoupon[$merchantCart['mer_id']] ?? []); + $merCouponIds = array_reverse($merCouponIds); + $sortIds = $merCouponIds; + // $all_coupon_product = []; + unset($defaultSort); + $defaultSort = []; + if (count($merCouponIds)) { + foreach ($merchantCart['coupon'] as &$item) { + $defaultSort[] = &$item; + if (!in_array($item['coupon_user_id'], $sortIds, true)) { + $sortIds[] = $item['coupon_user_id']; + } + } + unset($item); + usort($merchantCart['coupon'], function ($a, $b) use ($sortIds) { + return array_search($a['coupon_user_id'], $sortIds) > array_search($b['coupon_user_id'], $sortIds) ? 1 : -1; + }); + } + + $pay_price = max(bcsub($valid_total_price, $coupon_price, 2), 0); + $_pay_price = $pay_price; + + + $productCouponRate = []; + $storeCouponRate = null; + $useCouponIds = []; + + + if ($use_store_coupon) { + $storeCouponRate = [ + 'rate' => $pay_price > 0 ? bcdiv($use_store_coupon['coupon_price'], $pay_price, 4) : 1, + 'coupon_price' => $use_store_coupon['coupon_price'], + 'price' => $coupon_price + ]; + $useCouponIds[] = $use_store_coupon['coupon_user_id']; + } + + //计算单个商品实际支付金额 + foreach ($merchantCart['list'] as $_k => &$cart) { + $cartTotalPrice = bcmul($this->cartByPrice($cart), $cart['cart_num'], 2); + $_cartTotalPrice = $cartTotalPrice; + + //单个商品实际支付金额 + $cart['coupon_price'] = bcsub($_cartTotalPrice, $cartTotalPrice, 2); + $cart['true_price'] = $cartTotalPrice; + } + $procure = $this->cartByPrice($cart, 1); + $procure_price = bcmul($cart['cart_num'], $procure, 2); + unset($cart, $_k); + $total_true_price = bcadd($_pay_price, $total_true_price, 2); + if (count($merchantCartList) > 1 || count($merchantCart['list']) > 1) { + $orderDeliveryStatus = $orderDeliveryStatus && $deliveryStatus; + } + $merchantCart['order'] = [ + 'true_price' => $_pay_price, + 'platform_coupon_price' => 0, + 'valid_total_price' => $valid_total_price, + 'total_price' => $total_price, + 'final_price' => $final_price, + 'down_price' => $down_price, + 'coupon_price' => $coupon_price, + 'platformCoupon' => $platformCoupon, + 'svip_coupon_merge' => $svip_coupon_merge, + 'postage_price' => $postage_price, + 'isTake' => intval($allowDelivery == false || count($takes) > 0), + 'total_num' => $total_num, + 'enabledCoupon' => $enabledCoupon, + 'useCouponIds' => $useCouponIds, + 'allow_take' => true, + 'allow_delivery' => $allowDelivery, + 'delivery_status' => $deliveryStatus, + 'svip_discount' => $total_svip_discount, + 'use_svip' => $use_svip, + 'procure_price' => $procure_price + ]; + $order_total_postage = bcadd($order_total_postage, $postage_price, 2); + $order_svip_discount = bcadd($total_svip_discount, $order_svip_discount, 2); + if (count($defaultSort)) { + $merchantCart['coupon'] = &$defaultSort; + } + } + unset($merchantCart); + + $usePlatformCouponId = 0; + $total_platform_coupon_price = 0; + $usePlatformCouponFlag = isset($useCoupon[0]); + + foreach ($merchantCartList as &$merchantCart) { + if (!$merchantCart['order']['use_svip']) + continue; + $totalMergePrice = 0; + foreach ($merchantCart['list'] as &$cart) { + if (!$cart['svip_coupon_merge']) { + $totalMergePrice = bcadd($totalMergePrice, $cart['true_price'], 2); + $cart['allow_price'] = $cart['true_price']; + } + } + unset($cart); + if ($totalMergePrice > 0) { + $total_true_price = bcadd($total_true_price, $totalMergePrice, 2); + $merchantCart['order']['valid_total_price'] = bcadd($merchantCart['order']['valid_total_price'], $totalMergePrice, 2); + $merchantCart['order']['true_price'] = $merchantCart['order']['valid_total_price']; + } + } + unset($merchantCart); + //计算平台券优惠金额 + // if ($total_true_price > 0) { + $StoreCouponUser = app()->make(StoreCouponUserRepository::class); + $platformCoupon = $StoreCouponUser->validUserPlatformCoupon($uid); + $platformConsumption = []; + //消费金 + if ($source == 103) { + $ConsumptionWhere = [ + 'uid' => $uid, + 'status' => 0, + 'is_fail' => 0 + ]; + + $platformConsumption = Db::name('store_consumption_user')->where($ConsumptionWhere)->limit(100)->order('create_time', 'desc') + ->field('coupon_user_id,uid,coupon_title,coupon_price,balance,start_time,end_time') + ->select()->each(function ($item) { + $item['describe'] = '仅限平台指定商家商品可使用'; + return $item; + }); + } + // } + + $usePlatformCouponId = 0; + $total_platform_coupon_price = 0; + + //积分配置 + $sysIntegralConfig = systemConfig(['integral_money', 'integral_status', 'integral_order_rate']); + $merIntegralFlag = false; + $order_total_integral = 0; + $order_total_integral_price = 0; + $order_total_give_integral = 0; + $allow_no_address = true; + + foreach ($merchantCartList as &$merchantCart) { + $merchantCart['take'] = [ + 'mer_integral_rate' => 0, + 'mer_integral_status' => 0, + ]; + $allow_no_address = $allow_no_address && $merchantCart['order']['isTake']; + foreach ($merchantCart['config'] as $config) { + $merchantCart['take'][$config['config_key']] = $config['value']; + } + $merIntegralConfig = $merchantCart['take']; + unset($merchantCart['config']); + $merIntegralConfig['mer_integral_rate'] = min(1, $merIntegralConfig['mer_integral_rate'] > 0 ? bcdiv($merIntegralConfig['mer_integral_rate'], 100, 4) : $merIntegralConfig['mer_integral_rate']); + $total_integral = 0; + $total_integral_price = 0; + $merIntegralFlag = $merIntegralFlag || ((bool)$merIntegralConfig['mer_integral_status']); + $integralFlag = $useIntegral && $sysIntegralConfig['integral_status'] && $sysIntegralConfig['integral_money'] > 0 && $merIntegralConfig['mer_integral_status']; + + $order_total_integral = bcadd($order_total_integral, $total_integral, 0); + $order_total_integral_price = bcadd($order_total_integral_price, $total_integral_price, 2); + + $_pay_price = $merchantCart['order']['true_price']; + $valid_total_price = $merchantCart['order']['valid_total_price']; + $total_price = $merchantCart['order']['total_price']; + $final_price = $merchantCart['order']['final_price']; + $down_price = $merchantCart['order']['down_price']; + $coupon_price = $merchantCart['order']['coupon_price']; + $postage_price = $merchantCart['order']['postage_price']; + + //计算订单商品金额 + $org_price = bcadd(bcsub($total_price, $valid_total_price, 2), max($_pay_price, 0), 2); + if ($presellType == 2) { + $org_price = max(bcsub($org_price, $final_price, 2), $down_price); + } + + //获取可优惠金额 + $coupon_price = min($coupon_price, bcsub($total_price, $down_price, 2)); + $order_coupon_price = bcadd($coupon_price, $order_coupon_price, 2); + + //计算订单金额 + if ($order_type != 2 || $presellType != 2) { + $pay_price = bcadd($postage_price, $org_price, 2); + } else { + $pay_price = $org_price; + } + //计算总红包金额 + if ($consumption_id > 0 ) { + if ($this->store_consumption_user) { + if ($this->store_consumption_user['type'] == 2 && $pay_price>=6) { + $a = bcdiv($pay_price, 6); + if ($this->balance > $a) { + $pay_price = bcsub($pay_price, $a, 2); + $this->consumption_money = bcadd($this->consumption_money, $a, 2); + $this->balance = bcsub($this->balance, $a, 2); + } else { + $pay_price = bcsub($pay_price, $this->balance, 2); + $this->consumption_money = bcadd($this->consumption_money, $this->balance, 2); + $this->balance = 0; + } + } + if ($this->store_consumption_user['type'] == 1) { + if ($pay_price > $this->balance) { + $pay_price = bcsub($pay_price, $this->balance, 2); + $this->consumption_money = bcadd($this->consumption_money, $this->balance, 2); + $this->balance=0; + } else { + $pay_price = 0; + $this->consumption_money = bcadd($this->consumption_money, $pay_price, 2); + $this->balance = $pay_price; + + } + } + + } + } + + $giveIntegralFlag = $sysIntegralConfig['integral_status'] && $sysIntegralConfig['integral_order_rate'] > 0; + $total_give_integral = 0; + + foreach ($fn as $callback) { + $callback(); + } + $merchantCart['order']['order_type'] = $order_type; + $merchantCart['order']['total_give_integral'] = $total_give_integral; + $merchantCart['order']['total_integral_price'] = $total_integral_price; + $merchantCart['order']['total_integral'] = $total_integral; + $merchantCart['order']['org_price'] = $org_price; + $merchantCart['order']['pay_price'] = $pay_price; + $merchantCart['order']['coupon_price'] = $coupon_price; + $merchantCart['order']['postage_price'] = $merchantCart['order']['postage_price']; + $merchantCart['order']['procure_price'] = $merchantCart['order']['procure_price']; + $merchantCart['order']['consumption_id'] = $consumption_id; + $merchantCart['order']['consumption_money'] = $this->consumption_money; + + $order_price = bcadd($order_price, $pay_price, 2); + $order_total_price = bcadd($order_total_price, $total_price, 2); + } + unset($merchantCart); + + if ($order_model) { + $allow_no_address = false; + } + + foreach ($merchantCartList as &$merchantCart) { + foreach ($merchantCart['list'] as &$cart) { + $cart['total_price'] = bcadd($cart['total_price'], $cart['svip_discount'], 2); + } + unset($cart); + $merchantCart['order']['total_price'] = bcadd($merchantCart['order']['total_price'], $merchantCart['order']['svip_discount'], 2); + $order_total_price = bcadd($order_total_price, $merchantCart['order']['svip_discount'], 2); + } + unset($merchantCart); + $status = ($address || $order_model || $allow_no_address) ? ($noDeliver ? 'noDeliver' : 'finish') : 'noAddress'; + $order = $merchantCartList; + $consumption_money = $this->consumption_money; + $total_price = $order_total_price; + $openIntegral = $merIntegralFlag && !$order_type && $sysIntegralConfig['integral_status'] && $sysIntegralConfig['integral_money'] > 0; + $total_coupon = bcadd($order_svip_discount, bcadd(bcadd($total_platform_coupon_price, $order_coupon_price, 2), $order_total_integral_price, 2), 2); + $is_self_pickup = true; + if($order_type=='balance' &&$source!=103 &&$createOrder==true){ + throw new ValidateException('余额支付只能用于里海云仓'); + } + return compact( + 'is_self_pickup', + 'order_type', + 'source', + 'order_model', + 'order_extend', + 'order_total_postage', + 'order_price', + 'total_price', + 'community', + 'enabledPlatformCoupon', + 'platformCoupon', + 'usePlatformCouponId', + 'order_total_integral', + 'order_total_integral_price', + 'order_total_give_integral', + 'order_svip_discount', + 'total_platform_coupon_price', + 'total_coupon', + 'order_coupon_price', + 'order', + 'status', + 'address', + 'openIntegral', + 'useIntegral', + 'key', + 'platformConsumption', + 'consumption_money', + 'consumption_id' + ) + ['allow_address' => !$allow_no_address, 'order_delivery_status' => $orderDeliveryStatus]; + } + + public function v2CreateOrder(int $pay_type, $user, array $cartId, array $extend, array $mark, array $receipt_data, array $takes = null, array $useCoupon = null, bool $useIntegral = false, int $addressId = null, array $post, int $product_type = 0, $consumption_id = 0) + { + $uid = $user->uid; + $orderInfo = $this->v2CartIdByOrderInfo($user, $cartId, $takes, $useCoupon, $useIntegral, $addressId, true, $consumption_id); + $order_model = $orderInfo['order_model']; + $order_extend = $orderInfo['order_extend']; + if (!$orderInfo['order_delivery_status']) { + throw new ValidateException('部分商品配送方式不一致,请单独下单'); + } + if ($orderInfo['order_price'] > 1000000) { + throw new ValidateException('支付金额超出最大限制'); + } + if ($orderInfo['status'] == 'noDeliver') throw new ValidateException('商品不支持该区域'); + if ($orderInfo['status'] == 'noAddress') throw new ValidateException('请选择地址'); + if (!$order_model && $orderInfo['allow_address']) { + if (!$orderInfo['address']) throw new ValidateException('请选择正确的收货地址'); + if (!$orderInfo['address']['province_id']) throw new ValidateException('请完善收货地址信息'); + $extend = []; + } else if (count($order_extend)) { + $extend = app()->make(OrderVirtualFieldValidate::class)->load($order_extend, $extend); + } else { + $extend = []; + } + $orderType = $orderInfo['order_type']; + if ($orderType == 0 && $pay_type == StoreGroupOrder::PAY_TYPE_CREDIT_BUY) { + throw new ValidateException('该商品不支持先货后款'); + } + if (!in_array($orderType, [0, 98, 99]) && (count($orderInfo['order']) > 1 || ($orderType != 10 && count($orderInfo['order'][0]['list']) > 1))) { + throw new ValidateException('活动商品请单独购买'); + } + + $merchantCartList = $orderInfo['order']; + $cartSpread = 0; + $hasTake = false; + + foreach ($merchantCartList as $merchantCart) { + if ($merchantCart['order']['isTake']) { + $hasTake = true; + } + //检查发票状态 + if (isset($receipt_data[$merchantCart['mer_id']]) && !$merchantCart['openReceipt']) + throw new ValidateException('该店铺不支持开发票'); + if ($pay_type == StoreGroupOrder::PAY_TYPE_CREDIT_BUY && !$merchantCart['credit_buy']) { + throw new ValidateException("{$merchantCart['mer_name']}不支持先货后款"); + } + + foreach ($merchantCart['list'] as $cart) { + if (!$cartSpread && $cart['spread_id']) { + $cartSpread = $cart['spread_id']; + } + } + } + if (($orderType == 98 || $orderType == 99) && count($merchantCartList) > 1) { + throw new ValidateException('采购、委托商品不支持跨店购买'); + } + if ($hasTake) { + app()->make(UserAddressValidate::class)->scene('take')->check($post); + } + + if ($cartSpread) { + app()->make(UserRepository::class)->bindSpread($user, $cartSpread); + } + + $isSelfBuy = $user->is_promoter && systemConfig('extension_self') ? 1 : 0; + if ($isSelfBuy) { + $spreadUser = $user; + $topUser = $user->valid_spread; + } else { + $spreadUser = $user->valid_spread; + $topUser = $user->valid_top; + } + $spreadUid = $spreadUser->uid ?? 0; + $topUid = $topUser->uid ?? 0; + + $merchantRepository = app()->make(MerchantRepository::class); + $giveCouponIds = []; + $ex = systemConfig('extension_status'); //是否开启分销 + $address = $orderInfo['address']; + $allUseCoupon = $orderInfo['usePlatformCouponId'] ? [$orderInfo['usePlatformCouponId']] : []; + $totalNum = 0; + $totalPostage = 0; + $totalCost = 0; + $cartIds = []; + $orderList = []; + foreach ($merchantCartList as $k => $merchantCart) { + $cost = 0; + $total_extension_one = 0; + $total_extension_two = 0; + //计算佣金和赠送的优惠券 + foreach ($merchantCart['list'] as &$cart) { + $cartIds[] = $cart['cart_id']; + $giveCouponIds = array_merge($giveCouponIds, $cart['product']['give_coupon_ids'] ?: []); + $cart['cost'] = $cart['productAttr']['cost']; + $cost = bcadd(bcmul($cart['cost'], $cart['cart_num'], 2), $cost, 2); + $extension_one = 0; + $extension_two = 0; + $cart['extension_one'] = $extension_one; + $cart['extension_two'] = $extension_two; + $total_extension_one = bcadd($total_extension_one, bcmul($extension_one, $cart['cart_num'], 2), 2); + $total_extension_two = bcadd($total_extension_two, bcmul($extension_two, $cart['cart_num'], 2), 2); + } + unset($cart); + + $rate = 0; + if ($merchantCart['commission_rate'] > 0) { + $rate = $merchantCart['commission_rate']; + } else if (isset($merchantCart['merchantCategory']['commission_rate']) && $merchantCart['merchantCategory']['commission_rate'] > 0) { + $rate = bcmul($merchantCart['merchantCategory']['commission_rate'], 100, 4); + } + $user_address = isset($address) ? ($address['province'] . $address['city'] . $address['district'] . $address['street'] . $address['village'] . $address['brigade'] . $address['detail']) : ''; + $user_address_code = isset($address) ? ($address['province_code'] . ',' . $address['city_code'] . ',' . $address['district_code'] . ',' . $address['street_code'] . ',' . $address['village_code'] . ',' . $address['brigade_id']) : ''; + //整理订单数据 + $_order = [ + 'cartInfo' => $merchantCart, + 'activity_type' => $orderInfo['order_type'], + 'source' => $orderInfo['source'] ?? 2, + 'commission_rate' => (float)$rate, + 'order_type' => $merchantCart['order']['isTake'] ? 1 : 0, + 'is_virtual' => $order_model ? 1 : 0, + 'extension_one' => $total_extension_one, + 'extension_two' => $total_extension_two, + 'order_sn' => $this->getNewOrderId(StoreOrderRepository::TYPE_SN_ORDER) . ($k + 1), + 'uid' => $uid, + 'spread_uid' => $spreadUid, + 'top_uid' => $topUid, + 'is_selfbuy' => $isSelfBuy, + 'real_name' => $merchantCart['order']['isTake'] ? $post['real_name'] : ($address['real_name'] ?? ''), + 'user_phone' => $merchantCart['order']['isTake'] ? $post['phone'] : ($address['phone'] ?? ''), + 'user_address' => $user_address, + 'user_address_code' => $user_address_code, + 'cart_id' => implode(',', array_column($merchantCart['list'], 'cart_id')), + 'total_num' => $merchantCart['order']['total_num'], + 'total_price' => $merchantCart['order']['total_price'], + 'total_postage' => $merchantCart['order']['postage_price'], + 'pay_postage' => $merchantCart['order']['postage_price'], + 'svip_discount' => $merchantCart['order']['svip_discount'], + 'pay_price' => $merchantCart['order']['pay_price'], + 'integral' => $merchantCart['order']['total_integral'], + 'integral_price' => $merchantCart['order']['total_integral_price'], + 'give_integral' => $merchantCart['order']['total_give_integral'], + 'mer_id' => $merchantCart['mer_id'], + 'cost' => $cost, + 'order_extend' => count($extend) ? json_encode($extend, JSON_UNESCAPED_UNICODE) : '', + 'coupon_id' => implode(',', $merchantCart['order']['useCouponIds']), + 'mark' => $mark[$merchantCart['mer_id']] ?? '', + 'coupon_price' => bcadd($merchantCart['order']['coupon_price'], $merchantCart['order']['platform_coupon_price'], 2), + 'platform_coupon_price' => $merchantCart['order']['platform_coupon_price'], + 'pay_type' => $pay_type, + 'procure_price' => $merchantCart['order']['procure_price'], + 'consumption_id' => $merchantCart['order']['consumption_id'], + 'consumption_money' => $merchantCart['order']['consumption_money'], + ]; + $allUseCoupon = array_merge($allUseCoupon, $merchantCart['order']['useCouponIds']); + $orderList[] = $_order; + $totalPostage = bcadd($totalPostage, $_order['total_postage'], 2); + $totalCost = bcadd($totalCost, $cost, 2); + $totalNum += $merchantCart['order']['total_num']; + } + //总订单组 + $groupOrder = [ + 'uid' => $uid, + 'group_order_sn' => count($orderList) === 1 ? $orderList[0]['order_sn'] : ($this->getNewOrderId(StoreOrderRepository::TYPE_SN_ORDER) . '0'), + 'total_postage' => $totalPostage, + 'total_price' => $orderInfo['total_price'], + 'total_num' => $totalNum, + 'real_name' => $address['real_name'] ?? '', + 'user_phone' => $address['phone'] ?? '', + 'user_address' => $user_address, + 'pay_price' => $orderInfo['order_price'], + 'coupon_price' => bcadd($orderInfo['total_platform_coupon_price'], $orderInfo['order_coupon_price'], 2), + 'pay_postage' => $totalPostage, + 'cost' => $totalCost, + 'coupon_id' => $orderInfo['usePlatformCouponId'] > 0 ? $orderInfo['usePlatformCouponId'] : '', + 'pay_type' => $pay_type, + 'give_coupon_ids' => $giveCouponIds, + 'integral' => $orderInfo['order_total_integral'], + 'integral_price' => $orderInfo['order_total_integral_price'], + 'give_integral' => $orderInfo['order_total_give_integral'], + 'consumption_id' => $orderInfo['consumption_id'], + 'consumption_money' => $orderInfo['consumption_money'], + ]; + event('order.create.before', compact('groupOrder', 'orderList')); + $group = Db::transaction(function () use ($ex, $user, $topUid, $spreadUid, $uid, $receipt_data, $cartIds, $allUseCoupon, $groupOrder, $orderList, $orderInfo) { + $storeGroupOrderRepository = app()->make(StoreGroupOrderRepository::class); + $storeCartRepository = app()->make(StoreCartRepository::class); + /** @var ProductAttrValueRepository $attrValueRepository */ + $attrValueRepository = app()->make(ProductAttrValueRepository::class); + /** @var ProductRepository $productRepository */ + $productRepository = app()->make(ProductRepository::class); + $storeOrderProductRepository = app()->make(StoreOrderProductRepository::class); + $couponUserRepository = app()->make(StoreCouponUserRepository::class); + //订单记录 + $storeOrderStatusRepository = app()->make(StoreOrderStatusRepository::class); + $userMerchantRepository = app()->make(UserMerchantRepository::class); + + //减库存 + foreach ($orderList as $order) { + foreach ($order['cartInfo']['list'] as $cart) { + if (!isset($uniqueList[$cart['productAttr']['product_id'] . $cart['productAttr']['unique']])) + $uniqueList[$cart['productAttr']['product_id'] . $cart['productAttr']['unique']] = true; + else + throw new ValidateException('购物车商品信息重复'); + + try { + if ($cart['product_type'] == '1') { + $attrValueRepository->descSkuStock($cart['product']['old_product_id'], $cart['productAttr']['sku'], $cart['cart_num']); + $productRepository->descStock($cart['product']['old_product_id'], $cart['cart_num']); + } else if ($cart['product_type'] == '2') { + $productPresellSkuRepository = app()->make(ProductPresellSkuRepository::class); + $productPresellSkuRepository->descStock($cart['productPresellAttr']['product_presell_id'], $cart['productPresellAttr']['unique'], $cart['cart_num']); + $attrValueRepository->descStock($cart['productAttr']['product_id'], $cart['productAttr']['unique'], $cart['cart_num']); + $productRepository->descStock($cart['product']['product_id'], $cart['cart_num']); + } else if ($cart['product_type'] == '3') { + app()->make(ProductAssistSkuRepository::class)->descStock($cart['productAssistAttr']['product_assist_id'], $cart['productAssistAttr']['unique'], $cart['cart_num']); + $productRepository->descStock($cart['product']['old_product_id'], $cart['cart_num']); + $attrValueRepository->descStock($cart['product']['old_product_id'], $cart['productAttr']['unique'], $cart['cart_num']); + } else if ($cart['product_type'] == '4') { + app()->make(ProductGroupSkuRepository::class)->descStock($cart['activeSku']['product_group_id'], $cart['activeSku']['unique'], $cart['cart_num']); + $productRepository->descStock($cart['product']['old_product_id'], $cart['cart_num']); + $attrValueRepository->descStock($cart['product']['old_product_id'], $cart['productAttr']['unique'], $cart['cart_num']); + } else { + if ($cart['source'] == StoreCartDao::SOURCE_COMMUNITY_RESALE) { + /** @var CommunityRepository $communityRepository */ + $communityRepository = app()->make(CommunityRepository::class); + $communityRepository->saleOrCancel($cart['source_id']); + $attrValueRepository->incSales($cart['productAttr']['product_id'], $cart['productAttr']['unique'], $cart['cart_num']); + $productRepository->incSales($cart['product']['product_id'], $cart['cart_num']); + } else { + $attrValueRepository->descStock($cart['productAttr']['product_id'], $cart['productAttr']['unique'], $cart['cart_num']); + $productRepository->descStock($cart['product']['product_id'], $cart['cart_num']); + } + /** @var PurchaseRecordRepository $purchaseRecordRepo */ + $purchaseRecordRepo = app()->make(PurchaseRecordRepository::class); + $purchaseRecordRepo->incSalesVolume($cart['product']['product_id'], $cart['productAttr']['unique'], $cart['cart_num']); + if ($cart['integral'] && $cart['integral']['use'] > 0) { + $productRepository->incIntegral($cart['product']['product_id'], $cart['integral']['use'], $cart['integral']['price']); + } + } + } catch (\Exception $e) { + throw new ValidateException('库存不足'); + } + } + } + + if ($orderInfo['order_type'] == 10 && !app()->make(StoreDiscountRepository::class)->decStock($orderList[0]['cartInfo']['list'][0]['source_id'])) { + throw new ValidateException('套餐库不足'); + } + + //修改购物车状态 + $storeCartRepository->updates($cartIds, [ + 'is_pay' => 1 + ]); + + //使用优惠券 + if (count($allUseCoupon)) { + $couponUserRepository->updates($allUseCoupon, [ + 'use_time' => date('Y-m-d H:i:s'), + 'status' => 1 + ]); + } + + //创建订单 + $groupOrder = $storeGroupOrderRepository->create($groupOrder); + $bills = []; + $consumptionDetails=[]; + if ($groupOrder['integral'] > 0) { + $user->integral = bcsub($user->integral, $groupOrder['integral'], 0); + app()->make(UserBillRepository::class)->decBill($user['uid'], 'integral', 'deduction', [ + 'link_id' => $groupOrder['group_order_id'], + 'status' => 1, + 'title' => '购买商品', + 'number' => $groupOrder['integral'], + 'mark' => '购买商品使用积分抵扣' . floatval($groupOrder['integral_price']) . '元', + 'balance' => $user->integral + ]); + $user->save(); + } + + if ($groupOrder['consumption_money'] > 0) { + $balance = 0; + $store_consumption_user = Db::name('store_consumption_user')->where('uid',$uid)->where('coupon_user_id', $groupOrder['consumption_id'])->where('status', 0)->find(); + if ($store_consumption_user) { + if ($store_consumption_user['type'] == 1) { + if ($store_consumption_user['balance'] > $groupOrder['consumption_money']) { + $balance = bcsub($store_consumption_user['balance'], $groupOrder['consumption_money'], 2); + $balanceArr = ['balance' => $balance]; + Db::name('store_consumption_user')->where('coupon_user_id', $store_consumption_user['coupon_user_id'])->update($balanceArr); + } else { + $balanceArr = ['balance' => 0, 'status' => 1]; + Db::name('store_consumption_user')->where('coupon_user_id', $store_consumption_user['coupon_user_id'])->update($balanceArr); + } + } + } + app()->make(UserBillRepository::class)->decBill($user['uid'], 'consumption', 'deduction', [ + 'link_id' => $groupOrder['group_order_id'], + 'status' => 1, + 'title' => '购买商品', + 'number' => $groupOrder['consumption_money'], + 'mark' => '购买商品使用红包抵扣' . floatval($groupOrder['consumption_money']) . '元', + 'balance' => $balance + ]); + } + + foreach ($orderList as $k => $order) { + $orderList[$k]['group_order_id'] = $groupOrder->group_order_id; + } + + $orderProduct = []; + $orderStatus = []; + foreach ($orderList as $order) { + if ($order['pay_type'] == StoreGroupOrder::PAY_TYPE_CREDIT_BUY) { + $order['status'] = StoreOrder::STATUS_WAIT_CONFIRM; + } + $cartInfo = $order['cartInfo']; + unset($order['cartInfo']); + //创建子订单 + $_order = $this->dao->create($order); + + if ($order['integral'] > 0) { + $bills[] = [ + 'uid' => $uid, + 'link_id' => $_order->order_id, + 'pm' => 0, + 'title' => '积分抵扣', + 'category' => 'mer_integral', + 'type' => 'deduction', + 'number' => $order['integral'], + 'balance' => $user->integral, + 'mark' => '购买商品使用' . $order['integral'] . '积分抵扣' . floatval($order['integral_price']) . '元', + 'mer_id' => $order['mer_id'], + 'status' => 1 + ]; + } + if ($order['consumption_money'] > 0) { + $consumptionDetails[] = [ + 'user_id' => $uid, + 'order_id' => $_order->order_id, + 'group_order_id' => $groupOrder->group_order_id, + 'coupon_user_id' => $order['consumption_id'], + 'type' => 1, + 'amount' => $order['consumption_money'], + 'pay_price' => $order['pay_price'], + 'create_time' => time() + ]; + } + + //创建发票信息 + if (isset($receipt_data[$_order['mer_id']])) { + app()->make(StoreOrderReceiptRepository::class)->add($receipt_data[$_order['mer_id']], $_order); + } + + $orderStatus[] = [ + 'order_id' => $_order->order_id, + 'order_sn' => $_order->order_sn, + 'type' => $storeOrderStatusRepository::TYPE_ORDER, + 'change_message' => '订单生成', + 'change_type' => $storeOrderStatusRepository::ORDER_STATUS_CREATE, + 'uid' => $user->uid, + 'nickname' => $user->nickname, + 'user_type' => $storeOrderStatusRepository::U_TYPE_USER, + ]; + + foreach ($cartInfo['list'] as $cart) { + $productPrice = $cart['true_price']; + $extension_one = $cart['extension_one']; + $extension_two = $cart['extension_two']; + + //计算预售订单尾款 + if ($cartInfo['order']['order_type'] == 2) { + $finalPrice = max(bcsub($cartInfo['order']['final_price'], $cartInfo['order']['coupon_price'], 2), 0); + $allFinalPrice = $order['order_type'] ? $finalPrice : bcadd($finalPrice, $order['pay_postage'], 2); + if ($cart['productPresell']['presell_type'] == 1) { + $productPrice = bcsub($cartInfo['order']['pay_price'], $order['pay_postage'], 2); + } else { + $productPrice = bcadd($cartInfo['order']['pay_price'], $finalPrice, 2); + } + //生成尾款订单 + if ($cart['productPresell']['presell_type'] == 2) { + $presellOrderRepository = app()->make(PresellOrderRepository::class); + $presellOrderRepository->create([ + 'uid' => $uid, + 'order_id' => $_order->order_id, + 'mer_id' => $_order->mer_id, + 'final_start_time' => $cart['productPresell']['final_start_time'], + 'final_end_time' => $cart['productPresell']['final_end_time'], + 'pay_price' => $allFinalPrice, + 'presell_order_sn' => $this->getNewOrderId(StoreOrderRepository::TYPE_SN_PRESELL) + ]); + } + app()->make(ProductPresellSkuRepository::class)->incCount($cart['source_id'], $cart['productAttr']['unique'], 'one_take'); + } + + $order_cart = [ + 'product' => $cart['product'], + 'productAttr' => $cart['productAttr'], + 'product_type' => $cart['product_type'] + ]; + + if ($cart['product_type'] == '2') { + $order_cart['productPresell'] = $cart['productPresell']; + $order_cart['productPresellAttr'] = $cart['productPresellAttr']; + $order_cart['final_extension_one'] = $cart['final_extension_one'] ?? 0; + $order_cart['final_extension_two'] = $cart['final_extension_two'] ?? 0; + $order_cart['presell_extension_one'] = $cart['presell_extension_one'] ?? 0; + $order_cart['presell_extension_two'] = $cart['presell_extension_two'] ?? 0; + } else if ($cart['product_type'] == '3') { + $order_cart['productAssistAttr'] = $cart['productAssistAttr']; + $order_cart['productAssistSet'] = $cart['productAssistSet']; + } else if ($cart['product_type'] == '4') { + $order_cart['activeSku'] = $cart['activeSku']; + } else if ($cart['product_type'] == '10') { + $order_cart['active'] = $cart['productDiscount']; + $order_cart['activeSku'] = $cart['productDiscountAttr']; + } + $product_source_id = 0; + $product_mer_id = 0; + if ($cart['source'] == 103) { + $old_product_id = Db::name('store_product')->where('product_id', $cart['product_id'])->value('old_product_id'); + if ($old_product_id) { + $old_mer_id = Db::name('store_product')->where('product_id', $old_product_id)->value('mer_id'); + $product_mer_id = $old_mer_id; + $product_source_id = $old_product_id; + } + } + $orderProduct[] = [ + 'order_id' => $_order->order_id, + 'cart_id' => $cart['cart_id'], + 'uid' => $uid, + 'product_id' => $cart['product_id'], + 'activity_id' => $cart['source'] >= 2 ? $cart['source_id'] : $cart['product_id'], + 'total_price' => $cart['total_price'], + 'product_price' => $productPrice, + 'extension_one' => $extension_one, + 'extension_two' => $extension_two, + 'postage_price' => $cart['postage_price'], + 'svip_discount' => $cart['svip_discount'], + 'cost' => $cart['cost'], + 'coupon_price' => $cart['coupon_price'], + 'platform_coupon_price' => $cart['platform_coupon_price'], + 'product_sku' => $cart['productAttr']['unique'], + 'product_num' => $cart['cart_num'], + 'refund_num' => $cart['cart_num'], + 'integral_price' => $cart['integral']['price'] ?? 0, + 'integral' => $cart['integral'] ? bcdiv($cart['integral']['use'], $cart['cart_num'], 0) : 0, + 'integral_total' => $cart['integral'] ? $cart['integral']['use'] : 0, + 'product_type' => $cart['product_type'], + 'source' => $cart['source'], + 'source_id' => $cart['source_id'], + 'cart_info' => json_encode($order_cart), + 'product_source_id' => $product_source_id, + 'product_mer_id' => $product_mer_id, + ]; + } + + $userMerchantRepository->getInfo($uid, $order['mer_id']); + app()->make(MerchantRepository::class)->incSales($order['mer_id'], $order['total_num']); + } + + if (count($bills) > 0) { + app()->make(UserBillRepository::class)->insertAll($bills); + } + if (count($consumptionDetails) > 0) { + Db::name('store_consumption_detail')->insertAll($consumptionDetails); + } + $storeOrderStatusRepository->batchCreateLog($orderStatus); + $storeOrderProductRepository->insertAll($orderProduct); + event('order.create', compact('groupOrder')); + return $groupOrder; + }); + foreach ($merchantCartList as $merchantCart) { + foreach ($merchantCart['list'] as $cart) { + if (($cart['productAttr']['stock'] - $cart['cart_num']) < (int)merchantConfig($merchantCart['mer_id'], 'mer_store_stock')) { + SwooleTaskService::merchant('notice', [ + 'type' => 'min_stock', + 'data' => [ + 'title' => '库存不足', + 'message' => $cart['product']['store_name'] . '(' . $cart['productAttr']['sku'] . ')库存不足', + 'id' => $cart['product']['product_id'] + ] + ], $merchantCart['mer_id']); + } + } + } + // Queue::push(SendSmsJob::class, ['tempId' => 'ORDER_CREATE', 'id' => $group->group_order_id, + // 'activity_type'=>$group->activity_type,'order_id'=>$group->order_id]); + return $group; + } +} From fc7fe819fcf51bf35252e41bd086907125759c50 Mon Sep 17 00:00:00 2001 From: lewis <604446095@qq.com> Date: Mon, 22 Jan 2024 01:06:44 +0800 Subject: [PATCH 29/31] =?UTF-8?q?=E5=A4=84=E7=90=86=E7=BA=A2=E5=8C=85?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repositories/store/order/StoreOrderCreateRepository.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/common/repositories/store/order/StoreOrderCreateRepository.php b/app/common/repositories/store/order/StoreOrderCreateRepository.php index 15d09ac1..dcb31b6f 100644 --- a/app/common/repositories/store/order/StoreOrderCreateRepository.php +++ b/app/common/repositories/store/order/StoreOrderCreateRepository.php @@ -588,9 +588,9 @@ class StoreOrderCreateRepository extends StoreOrderRepository $this->consumption_money = bcadd($this->consumption_money, $this->balance, 2); $this->balance=0; } else { + $this->consumption_money = $pay_price; + $this->balance = bcsub($this->balance, $pay_price, 2); $pay_price = 0; - $this->consumption_money = bcadd($this->consumption_money, $pay_price, 2); - $this->balance = $pay_price; } } From aa07cc9a5030aa85c2e05d2dd881c8315ae26cce Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Mon, 22 Jan 2024 10:37:04 +0800 Subject: [PATCH 30/31] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/Demo.php | 70 +++-------------------------------- crmeb/jobs/ProductCopyJob.php | 17 +++++++-- 2 files changed, 20 insertions(+), 67 deletions(-) diff --git a/app/controller/api/Demo.php b/app/controller/api/Demo.php index 1c018e87..05be8965 100644 --- a/app/controller/api/Demo.php +++ b/app/controller/api/Demo.php @@ -30,73 +30,15 @@ use crmeb\jobs\ProductCopyJob; class Demo extends BaseController { public function index() - { - return app('json')->success('修改成功'); - $arr=Db::name('store_product')->whereIn('mer_id',[110,116,149,227,226,35,117,148,156,104,137,151,136,183,140,229,79,133,235])->where('status',1)->where('is_show',0)->field('product_id')->select(); - $mer_id=167;//导入到的商户 - $street_code=510521107;//导入到的商户 - $type_id=17;//导入到的商户分类 - $category_id=2566;//导入到的商户分类 - foreach($arr as $k=>$v){ - Queue::push(ProductCopyJob::class, ['product_id' => $v['product_id'], 'mer_id' =>$mer_id,'street_code'=>$street_code,'type_id'=>$type_id,'category_id'=>$category_id]);//短信通知 - } + { return app('json')->success('修改成功'); + // $arr=Db::name('store_product')->whereIn('mer_id',[110,116,149,227,226,35,117,148,156,104,137,151,136,183,140,229,79,133,235])->where('is_del',1)->field('product_id')->select(); + // foreach($arr as $item){ - $mer_id=236;//导入到的商户 - $street_code=510521123;//导入到的商户 - foreach($arr as $k=>$v){ - Queue::push(ProductCopyJob::class, ['product_id' => $v['product_id'], 'mer_id' =>$mer_id,'street_code'=>$street_code,'type_id'=>$type_id,'category_id'=>$category_id]);//短信通知 - } + // Queue::push(ProductCopyJob::class, ['product_id' => $item['product_id']]);//短信通知 - $mer_id=237;//导入到的商户 - $street_code=510521115;//导入到的商户 - - foreach($arr as $k=>$v){ - Queue::push(ProductCopyJob::class, ['product_id' => $v['product_id'], 'mer_id' =>$mer_id,'street_code'=>$street_code,'type_id'=>$type_id,'category_id'=>$category_id]);//短信通知 - } - - $mer_id=238;//导入到的商户 - $street_code=510521105;//导入到的商户 - - foreach($arr as $k=>$v){ - Queue::push(ProductCopyJob::class, ['product_id' => $v['product_id'], 'mer_id' =>$mer_id,'street_code'=>$street_code,'type_id'=>$type_id,'category_id'=>$category_id]);//短信通知 - } - - $mer_id=239;//导入到的商户 - $street_code=510521116;//导入到的商户 - - foreach($arr as $k=>$v){ - Queue::push(ProductCopyJob::class, ['product_id' => $v['product_id'], 'mer_id' =>$mer_id,'street_code'=>$street_code,'type_id'=>$type_id,'category_id'=>$category_id]);//短信通知 - } - - //江阳 - $mer_id=31;//导入到的商户 - $street_code=510502108;//导入到的商户 - - foreach($arr as $k=>$v){ - Queue::push(ProductCopyJob::class, ['product_id' => $v['product_id'], 'mer_id' =>$mer_id,'street_code'=>$street_code,'type_id'=>$type_id,'category_id'=>$category_id]);//短信通知 - } - - $mer_id=32;//导入到的商户 - $street_code=510502107;//导入到的商户 - - foreach($arr as $k=>$v){ - Queue::push(ProductCopyJob::class, ['product_id' => $v['product_id'], 'mer_id' =>$mer_id,'street_code'=>$street_code,'type_id'=>$type_id,'category_id'=>$category_id]);//短信通知 - } - - $mer_id=118;//导入到的商户 - $street_code=510502106;//导入到的商户 - - foreach($arr as $k=>$v){ - Queue::push(ProductCopyJob::class, ['product_id' => $v['product_id'], 'mer_id' =>$mer_id,'street_code'=>$street_code,'type_id'=>$type_id,'category_id'=>$category_id]);//短信通知 - } - - $mer_id=39;//导入到的商户 - $street_code=510502105;//导入到的商户 - - foreach($arr as $k=>$v){ - Queue::push(ProductCopyJob::class, ['product_id' => $v['product_id'], 'mer_id' =>$mer_id,'street_code'=>$street_code,'type_id'=>$type_id,'category_id'=>$category_id]);//短信通知 - } + // } + } public function transcoding($fileName) diff --git a/crmeb/jobs/ProductCopyJob.php b/crmeb/jobs/ProductCopyJob.php index afca7931..111d9fb7 100644 --- a/crmeb/jobs/ProductCopyJob.php +++ b/crmeb/jobs/ProductCopyJob.php @@ -16,15 +16,26 @@ namespace crmeb\jobs; use crmeb\interfaces\JobInterface; use app\controller\admin\store\StoreProduct; +use think\facade\Db; - +/** + * 本地跑远程线程专门使用 + */ class ProductCopyJob implements JobInterface { public function fire($job, $data) { - $make = app()->make(StoreProduct::class); - $make->copy($data['product_id'],$data['mer_id'],$data['street_code'],$data['type_id'],$data['category_id']); + // $arrs= Db::name('store_product')->where('old_product_id',$data['product_id'])->select(); + // foreach($arrs as $it){ + // $res= Db::name('store_product')->where('product_id',$it['product_id'])->update(['is_del'=>1,'is_show'=>0,'is_used'=>0,'status'=>-2]); + // if($res){ + // Db::name('cloud_product')->where('product_id',$it['product_id'])->delete(); + + // } + // } + // $make = app()->make(StoreProduct::class); + // $make->copy($data['product_id'],$data['mer_id'],$data['street_code'],$data['type_id'],$data['category_id']); $job->delete(); } From ab0d2e62fe0d592021db7e3233307dd286b6cdc0 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Mon, 22 Jan 2024 10:48:44 +0800 Subject: [PATCH 31/31] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/Demo.php | 13 ++++++++----- app/controller/api/store/product/CloudWarehouse.php | 2 +- app/controller/merchant/store/product/Product.php | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/controller/api/Demo.php b/app/controller/api/Demo.php index 05be8965..019ae041 100644 --- a/app/controller/api/Demo.php +++ b/app/controller/api/Demo.php @@ -30,14 +30,17 @@ use crmeb\jobs\ProductCopyJob; class Demo extends BaseController { public function index() - { return app('json')->success('修改成功'); + { + return app('json')->success('修改成功'); + //[31,32,118,39,167,236,237,238,239] + // return app('json')->success('修改成功');>whereIn('mer_id',[110,116,149,227,226,35,117,148,156,104,137,151,136,183,140,229,79,133,235])-> - // $arr=Db::name('store_product')->whereIn('mer_id',[110,116,149,227,226,35,117,148,156,104,137,151,136,183,140,229,79,133,235])->where('is_del',1)->field('product_id')->select(); - // foreach($arr as $item){ + $arr=Db::name('store_product')->whereIn('mer_id',[31,32,118,39,167,236,237,238,239])->where('is_show',1)->where('stock',0)->field('product_id')->select(); + foreach($arr as $item){ - // Queue::push(ProductCopyJob::class, ['product_id' => $item['product_id']]);//短信通知 + Queue::push(ProductCopyJob::class, ['product_id' => $item['product_id']]);//短信通知 - // } + } } diff --git a/app/controller/api/store/product/CloudWarehouse.php b/app/controller/api/store/product/CloudWarehouse.php index eebcc1ce..6e867c11 100644 --- a/app/controller/api/store/product/CloudWarehouse.php +++ b/app/controller/api/store/product/CloudWarehouse.php @@ -90,7 +90,7 @@ class CloudWarehouse extends BaseController if ($value['mer_labels'] == ',5,') { $list[$k]['mer_labels_name'] = '五日达'; } else { - $list[$k]['mer_labels_name'] = '次日达'; + $list[$k]['mer_labels_name'] = '同城'; } } } diff --git a/app/controller/merchant/store/product/Product.php b/app/controller/merchant/store/product/Product.php index e810819a..db78e094 100644 --- a/app/controller/merchant/store/product/Product.php +++ b/app/controller/merchant/store/product/Product.php @@ -468,7 +468,7 @@ class Product extends BaseController if ($value['mer_labels'] == ',5,') { $select[$k]['mer_labels_name'] = '五日达'; } else { - $select[$k]['mer_labels_name'] = '次日达'; + $select[$k]['mer_labels_name'] = '同城'; } } }