From b4be5a65b4f8e2fb803121fd67ca130439bdbc3e Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Tue, 27 Jun 2023 17:59:35 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E7=A1=AE=E8=AE=A4=E6=94=B6?= =?UTF-8?q?=E8=B4=A7=EF=BC=8C=E5=86=99=E5=85=A5=E8=AE=A1=E6=81=AF=E6=95=B0?= =?UTF-8?q?=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/dao/store/order/StoreOrderDao.php | 3 ++ app/common/model/store/order/StoreOrder.php | 6 +++ .../model/store/order/StoreOrderInterest.php | 23 +++++++++ .../order/StoreOrderInterestRepository.php | 18 +++++++ .../store/order/StoreOrderRepository.php | 9 +++- .../store/product/ProductRepository.php | 47 +++++++++++++++++++ .../api/store/product/StoreMicro.php | 41 +++------------- app/event.php | 1 + app/listener/OrderTake.php | 36 ++++++++++++++ 9 files changed, 148 insertions(+), 36 deletions(-) create mode 100644 app/common/model/store/order/StoreOrderInterest.php create mode 100644 app/common/repositories/store/order/StoreOrderInterestRepository.php create mode 100644 app/listener/OrderTake.php diff --git a/app/common/dao/store/order/StoreOrderDao.php b/app/common/dao/store/order/StoreOrderDao.php index 8e9cd5fd..31966cbe 100644 --- a/app/common/dao/store/order/StoreOrderDao.php +++ b/app/common/dao/store/order/StoreOrderDao.php @@ -91,6 +91,9 @@ class StoreOrderDao extends BaseDao ->when(isset($where['activity_type']) && $where['activity_type'] != '', function ($query) use ($where) { $query->where('activity_type', $where['activity_type']); }) + ->when(isset($where['product_type']) && $where['product_type'] != '', function ($query) use ($where) { + $query->where('activity_type', $where['product_type']); + }) ->when(isset($where['status']) && $where['status'] !== '', function ($query) use ($where) { switch ($where['status']) { case 0 : diff --git a/app/common/model/store/order/StoreOrder.php b/app/common/model/store/order/StoreOrder.php index 77ab9451..2a145adb 100644 --- a/app/common/model/store/order/StoreOrder.php +++ b/app/common/model/store/order/StoreOrder.php @@ -177,4 +177,10 @@ class StoreOrder extends BaseModel { return StoreRefundOrder::where('order_id',$this->order_id)->where('status',3)->sum('refund_price'); } + + public function interest() + { + return $this->hasOne(StoreOrderInterest::class, 'order_id', 'order_id'); + } + } diff --git a/app/common/model/store/order/StoreOrderInterest.php b/app/common/model/store/order/StoreOrderInterest.php new file mode 100644 index 00000000..64cd7c14 --- /dev/null +++ b/app/common/model/store/order/StoreOrderInterest.php @@ -0,0 +1,23 @@ +insert($data); + } + +} diff --git a/app/common/repositories/store/order/StoreOrderRepository.php b/app/common/repositories/store/order/StoreOrderRepository.php index 97a88513..35490fe1 100644 --- a/app/common/repositories/store/order/StoreOrderRepository.php +++ b/app/common/repositories/store/order/StoreOrderRepository.php @@ -1689,8 +1689,15 @@ class StoreOrderRepository extends BaseRepository $order->presell_price = $order->pay_price; } } + if ($order->pay_type == StoreGroupOrder::PAY_TYPE_CREDIT_BUY && $order->interest) { + $order->interest_start_time = $order->interest->start_time; + $days = ceil((time() - strtotime($order->interest->start_time)) / 86400); + $interestMoney = bcmul($order->interest->total_price, $order->interest->rate, 2); + $order->interest_money = bcmul($days, $interestMoney, 2); + $order->interest_status = $order->interest->status; + } $order->takeOrderCount = count($order['takeOrderList']); - unset($order['takeOrderList']); + unset($order['takeOrderList'], $order->interest); } return compact( 'count','list'); diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index 77f65452..46cc4586 100644 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -2299,4 +2299,51 @@ class ProductRepository extends BaseRepository return true; } + /** + * 导入商品 + * @param $product_id + * @param $user + * @return bool + * @throws \Exception + */ + public function import($product_id, $user) + { + $mer_id = Db::name('store_service')->where('uid', $user['uid'])->where('status', 1)->value('mer_id'); + if ($mer_id == 0) { + throw new \Exception('商户不存在'); + } + $find = Db::name('store_product')->where('product_id', $product_id)->find(); + if ($find) { + if ($find['product_type'] != 0) { + throw new \Exception('该商品不是普通商品'); + } + $exist = Db::name('store_product')->where('old_product_id', $product_id)->where('mer_id', $mer_id)->find(); + if ($exist) { + throw new \Exception('已经导入过该商品了'); + } + $find['attrValue'] = Db::name('store_product_attr_value')->where('product_id', $find['product_id'])->field('image,price,cost,ot_price,svip_price,stock,bar_code,weight,volume')->select(); + $find['content'] = Db::name('store_product_content')->where('product_id', $find['product_id'])->value('content'); + $find['is_show'] = 0; + $find['mer_id'] = $mer_id; + $find['temp_id'] = ""; + $find['give_coupon_ids'] = []; + $find['params'] = []; + $find['extend'] = []; + $find['param_temp_id'] = []; + $find['mer_labels'] = []; + $find['attr'] = []; + $find['delivery_way'] = [0 => "2"]; + $find["guarantee_template_id"] = ""; + $find['product_type'] = 0; + $find['mer_cate_id'] = [0 => 0]; + $find['is_used'] = 1; + $find['status'] = 1; + $find['mer_status'] = 1; + $find['old_product_id'] = $product_id; + $find['slider_image'] = explode(',', $find['slider_image']); + unset($find['product_id'], $find['create_time']); + } + return $this->create($find, 0); + } + } diff --git a/app/controller/api/store/product/StoreMicro.php b/app/controller/api/store/product/StoreMicro.php index 4e854beb..9b40d72d 100644 --- a/app/controller/api/store/product/StoreMicro.php +++ b/app/controller/api/store/product/StoreMicro.php @@ -50,42 +50,13 @@ class StoreMicro extends BaseController public function ProductImport(){ $product_id = $this->request->param('id', 0); $user = $this->request->userInfo(); - $mer_id =Db::name('store_service')->where('uid',$user['uid'])->where('status',1)->value('mer_id'); - if ($mer_id==0) return app('json')->fail('商户id不能为空'); - $find=Db::name('store_product')->where('product_id',$product_id)->find(); - if($find){ - if($find['product_type']!=0){ - return app('json')->fail('该商品不是普通商品'); - } - $exist = Db::name('store_product')->where('old_product_id', $product_id)->where('mer_id', $mer_id)->find(); - if($exist){ - return app('json')->fail('已经导入过该商品了'); - } - $find['attrValue']=Db::name('store_product_attr_value')->where('product_id',$find['product_id'])->field('image,price,cost,ot_price,svip_price,stock,bar_code,weight,volume')->select(); - $find['content']=Db::name('store_product_content')->where('product_id',$find['product_id'])->value('content'); - $find['is_show']=0; - $find['mer_id']=$mer_id; - $find['temp_id']=""; - $find['give_coupon_ids']=[]; - $find['params']=[]; - $find['extend']=[]; - $find['param_temp_id']=[]; - $find['mer_labels']=[]; - $find['attr']=[]; - $find['delivery_way']=[ 0 => "2"]; - $find["guarantee_template_id"] = ""; - $find['product_type']=0; - $find['mer_cate_id']=[0 => 0]; - $find['is_used']=1; - $find['status']=1; - $find['mer_status']=1; - $find['old_product_id']=$product_id; - $find['slider_image']=explode(',',$find['slider_image']); - unset($find['product_id'],$find['create_time']); + try { + /** @var ProductRepository $productRepository */ + $productRepository = app()->make(ProductRepository::class); + $a = $productRepository->import($product_id, $user); + } catch (\Exception $e) { + return app('json')->fail($e->getMessage()); } - /** @var ProductRepository $make */ - $make = app()->make(ProductRepository::class); - $a=$make->create($find,0); if($a){ return app('json')->success(['data'=>$a,'msg'=>'导入成功']); }else{ diff --git a/app/event.php b/app/event.php index f9f7d132..089e8908 100644 --- a/app/event.php +++ b/app/event.php @@ -67,6 +67,7 @@ return [ 'product.create'=>[\app\listener\ProductCreate::class], 'product.sell'=>[\app\listener\CloudProduct::class], //商品上下架 'refund.after'=>[\app\listener\AfterRefund::class], + 'order.take'=>[\app\listener\OrderTake::class], ], 'subscribe' => [], diff --git a/app/listener/OrderTake.php b/app/listener/OrderTake.php new file mode 100644 index 00000000..859e6c3b --- /dev/null +++ b/app/listener/OrderTake.php @@ -0,0 +1,36 @@ +make(StoreOrderInterestRepository::class); + $merchantId = Merchant::where('uid', $order['uid'])->value('mer_id'); + $data = [ + 'order_id' => $order['order_id'], + 'mer_id' => $merchantId, + 'to_mer_id' => $order['mer_id'], + 'total_price' => $order['total_price'], + 'rate' => $order['merchant']['interest_rate'], + 'start_time' => date('Y-m-d H:i:s', strtotime("+{$order['merchant']['settle_cycle']} days")), + ]; + return $storeOrderInterestRepository->create($data); + } + +}