From ee667156678fe039c83207f67efe4ba6934e51c0 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sat, 8 Jun 2024 15:19:56 +0800 Subject: [PATCH 1/8] =?UTF-8?q?feat(StoreOrderLogic):=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E6=8A=98=E6=89=A3=E7=8E=87=E8=AE=A1=E7=AE=97=E6=96=B9=E5=BC=8F?= =?UTF-8?q?=E5=8F=8A=E9=80=80=E6=AC=BE=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../logic/store_order/StoreOrderLogic.php | 9 +-------- .../store_order/StoreOrderController.php | 18 +++++++++++++++++- app/store/lists/cart/CartList.php | 4 ++-- .../lists/store_order/StoreOrderLists.php | 2 +- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/app/common/logic/store_order/StoreOrderLogic.php b/app/common/logic/store_order/StoreOrderLogic.php index 6aa9803f8..e550d4851 100644 --- a/app/common/logic/store_order/StoreOrderLogic.php +++ b/app/common/logic/store_order/StoreOrderLogic.php @@ -81,7 +81,7 @@ class StoreOrderLogic extends BaseLogic $pay_price = bcdiv(bcmul($pay_price, $discountRate, 4), '1', 2); } else { - $discountRate = bcdiv(1, '100', 2); + $discountRate = bcdiv(100, '100', 2); $pay_price = bcdiv(bcmul($pay_price, $discountRate, 4), '1', 2); } if (!empty(self::$total) && !empty($pay_price)) { @@ -235,13 +235,6 @@ class StoreOrderLogic extends BaseLogic 'total' => $total, 'currency' => 'CNY', ], - // '_action' => 'jsapi', // jsapi 退款,默认 - // '_action' => 'app', // app 退款 - // '_action' => 'combine', // 合单退款 - // '_action' => 'h5', // h5 退款 - // '_action' => 'miniapp', // 小程序退款 - // '_action' => 'native', // native 退款 - ]; $res = $wechat->wechat->refund($order); diff --git a/app/store/controller/store_order/StoreOrderController.php b/app/store/controller/store_order/StoreOrderController.php index 89e3a7546..a9cdc2be2 100644 --- a/app/store/controller/store_order/StoreOrderController.php +++ b/app/store/controller/store_order/StoreOrderController.php @@ -2,7 +2,8 @@ namespace app\store\controller\store_order; - +use app\api\logic\order\OrderLogic; +use app\api\validate\OrderValidate; use app\store\lists\store_order\StoreOrderLists; use app\common\controller\Definitions; use app\common\enum\PayEnum; @@ -11,6 +12,7 @@ use app\common\logic\PayNotifyLogic; use app\common\logic\SystemStoreStaffLogic; use app\store\controller\BaseAdminController; use app\common\logic\store_order\StoreOrderLogic; +use app\common\model\store_order\StoreOrder; use app\store\validate\store_order\StoreOrderValidate; use hg\apidoc\annotation as ApiDoc; use Webman\RedisQueue\Redis; @@ -173,4 +175,18 @@ class StoreOrderController extends BaseAdminController return $this->fail(StoreOrderLogic::getError()); } } + + public function writeoff_order() + { + $params = (new OrderValidate())->post()->goCheck('check'); + $count = StoreOrder::where('verify_code',$params['verify_code'])->count(); + if(empty($count)){ + return $this->fail('无该核销码请检查'); + } + $res = OrderLogic::writeOff($params); + if ($res) { + return $this->success('核销成功'); + } + return $this->fail('核销失败'.OrderLogic::getError()); + } } diff --git a/app/store/lists/cart/CartList.php b/app/store/lists/cart/CartList.php index f64814803..e16f45c1e 100644 --- a/app/store/lists/cart/CartList.php +++ b/app/store/lists/cart/CartList.php @@ -43,8 +43,8 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists */ public function lists($where = []): array { - $this->searchWhere[]=['staff_id'=>$this->adminId]; - $this->searchWhere[]=['is_pay'=>0]; + $this->searchWhere[]=['staff_id','=',$this->adminId]; + $this->searchWhere[]=['is_pay','=',0]; $list = Cart::where($this->searchWhere) ->field('id,product_id,cart_num,store_id') ->limit($this->limitOffset, $this->limitLength) diff --git a/app/store/lists/store_order/StoreOrderLists.php b/app/store/lists/store_order/StoreOrderLists.php index 1df54d420..3eebf5b0b 100644 --- a/app/store/lists/store_order/StoreOrderLists.php +++ b/app/store/lists/store_order/StoreOrderLists.php @@ -27,7 +27,7 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface public function setSearch(): array { return [ - '=' => ['pay_type'], + '=' => ['pay_type','paid'], '%like%' => ['order_id'], 'between_time' => 'create_time', ]; From 92cc14fabac9322711d4cb6886ccdc3523d66382 Mon Sep 17 00:00:00 2001 From: liu <1873441552@qq.com> Date: Sat, 8 Jun 2024 15:34:14 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E6=8A=98=E6=89=A3=E4=BB=B7=E6=A0=BC?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/logic/order/OrderLogic.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/api/logic/order/OrderLogic.php b/app/api/logic/order/OrderLogic.php index d74341178..a243ad507 100644 --- a/app/api/logic/order/OrderLogic.php +++ b/app/api/logic/order/OrderLogic.php @@ -64,7 +64,7 @@ class OrderLogic extends BaseLogic continue; } if(isset($check) && $check['status'] == 1){ - $find['price'] = StoreProduct::where('product_id',$find['product_id'])->value('ot_price'); + $find['price'] = StoreProduct::where('id',$find['product_id'])->withTrashed()->value('ot_price'); } $cart_select[$k]['total'] = bcmul($v['cart_num'], $find['price'], 2);//钱 $cart_select[$k]['price'] = $find['price']; @@ -94,8 +94,9 @@ class OrderLogic extends BaseLogic $vipPrice = 0; if(isset($check) && $check['status'] == 1){ // $discountRate = '0.99';//首单逻辑 - $discountRate = $check['remark']; - $discountRate = bcdiv($discountRate, '100', 2); +// $pay_price 是价格 + $discountRate = $check['remark'];//折扣 + $discountRate = bcdiv($discountRate, '10', 2); $pay_price = bcdiv(bcmul($pay_price, $discountRate, 4), '1', 2); }else{ $userVip = User::where('id',\request()->userId)->value('user_ship'); From d05d73c86cfa9fd92465f2251bc437396ac62f6f Mon Sep 17 00:00:00 2001 From: liu <1873441552@qq.com> Date: Sat, 8 Jun 2024 15:37:11 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=AE=BF=E9=97=AE?= =?UTF-8?q?=E5=BA=97=E9=93=BAid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/logic/user/UserVisitLogic.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/api/logic/user/UserVisitLogic.php b/app/api/logic/user/UserVisitLogic.php index 860b1601f..fa00f3e4d 100644 --- a/app/api/logic/user/UserVisitLogic.php +++ b/app/api/logic/user/UserVisitLogic.php @@ -30,6 +30,7 @@ }else{ StoreVisit::create([ 'uid' => $uid, + 'store_id' => $params['store_id']??0, 'product_id' => $params['product_id'], 'cate_id' => $params['cate_id'], 'count' => 1, From c721213510cf8cf964b2ef0b572b0574906aeb09 Mon Sep 17 00:00:00 2001 From: liu <1873441552@qq.com> Date: Sat, 8 Jun 2024 15:42:24 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E9=80=80=E6=AC=BE=E6=95=B0=E9=87=8F?= =?UTF-8?q?=E5=8F=96=E6=B6=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/validate/OrderValidate.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/api/validate/OrderValidate.php b/app/api/validate/OrderValidate.php index f7e076323..f223800f6 100644 --- a/app/api/validate/OrderValidate.php +++ b/app/api/validate/OrderValidate.php @@ -19,7 +19,7 @@ class OrderValidate extends BaseValidate protected $rule = [ 'verify_code' => 'require', 'refund_message' => 'require', - 'refund_num' => 'require|number', +// 'refund_num' => 'require|number', 'id' => 'require|number', 'old_cart_id' => 'require|array', 'refund_type' => 'require|number', @@ -33,7 +33,7 @@ class OrderValidate extends BaseValidate protected $field = [ 'verify_code' => '验证码', 'refund_message' => '退款原因', - 'refund_num' => '退款数量', +// 'refund_num' => '退款数量', 'id' => '订单id', 'old_cart_id' => '购物车id', 'refund_type' => '退款申请类型', @@ -57,7 +57,7 @@ class OrderValidate extends BaseValidate */ public function sceneAdd() { - return $this->only(['refund_message','refund_num','id','old_cart_id','refund_type']); + return $this->only(['refund_message','id','old_cart_id','refund_type']); } From 8644e3d571366f43a5cfe7ffcb0ac577780c571e Mon Sep 17 00:00:00 2001 From: liu <1873441552@qq.com> Date: Sat, 8 Jun 2024 15:44:49 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E5=88=97=E8=A1=A8=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/lists/product/ProductLists.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/api/lists/product/ProductLists.php b/app/api/lists/product/ProductLists.php index e43bdd698..22d92843d 100644 --- a/app/api/lists/product/ProductLists.php +++ b/app/api/lists/product/ProductLists.php @@ -138,7 +138,7 @@ class ProductLists extends BaseAdminDataLists implements ListsSearchInterface $check = DictType::where('type','activities')->find(); foreach ($data as &$value){ if(isset($check) && $check['status'] == 1){ - $value['price'] = StoreProduct::where('product_id',$value['product_id'])->value('ot_price'); + $value['price'] = StoreProduct::where('id',$value['product_id'])->value('ot_price'); } $value['is_default'] = 0; if($store_id == 2){ From 528f9aff9355bed5cc2256961b52c4c800cde08b Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sat, 8 Jun 2024 16:01:17 +0800 Subject: [PATCH 6/8] =?UTF-8?q?feat(StoreBranchProductLists):=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E6=9F=A5=E8=AF=A2=E6=9D=A1=E4=BB=B6=EF=BC=8C=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E5=BA=93=E5=AD=98=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../StoreBranchProductLists.php | 4 +-- app/common/lists/ListsSearchTrait.php | 30 ++++++++++++------- .../lists/store_order/StoreOrderLists.php | 6 ++-- .../lists/store_product/StoreProductLists.php | 2 +- 4 files changed, 26 insertions(+), 16 deletions(-) diff --git a/app/admin/lists/store_branch_product/StoreBranchProductLists.php b/app/admin/lists/store_branch_product/StoreBranchProductLists.php index 2bfd247fb..ef57faf8d 100644 --- a/app/admin/lists/store_branch_product/StoreBranchProductLists.php +++ b/app/admin/lists/store_branch_product/StoreBranchProductLists.php @@ -29,7 +29,7 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI { return [ '=' => ['product_id', 'cate_id','store_id'], - '%like%' => ['store_name|bar_code'], + '%pipe_like%' => ['store_name_code'=>'store_name|bar_code'], ]; } @@ -63,7 +63,7 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI } }) ->limit($this->limitOffset, $this->limitLength) - ->order(['sort' => 'desc', 'id' => 'desc']) + ->order(['sort' => 'desc','stock'=>'desc','id' => 'desc']) ->select() ->each(function ($item) { $item['system_store_name']=SystemStore::where('id',$item['store_id'])->value('name'); diff --git a/app/common/lists/ListsSearchTrait.php b/app/common/lists/ListsSearchTrait.php index 6439682cb..4a92cef50 100644 --- a/app/common/lists/ListsSearchTrait.php +++ b/app/common/lists/ListsSearchTrait.php @@ -22,23 +22,22 @@ trait ListsSearchTrait return []; } $where = []; - $class_key=$this->request->__get('class_key'); - if($class_key!==null){ - foreach($class_key as $key => $value){ - if(isset($search[$key])){ - foreach($value as $v){ // 遍历class_key的值,添加到search数组中 + $class_key = $this->request->__get('class_key'); + if ($class_key !== null) { + foreach ($class_key as $key => $value) { + if (isset($search[$key])) { + foreach ($value as $v) { // 遍历class_key的值,添加到search数组中 array_push($search[$key], $v); // 添加class_key的搜索条件 } - }else{ + } else { $search[$key] = [$value[0]]; // 创建新的搜索条件 } } } - $class_value=$this->request->__get('class_value'); // 获取class_value的值 - if($class_value!==null){ - $this->params=array_merge($this->params,$class_value); - + $class_value = $this->request->__get('class_value'); // 获取class_value的值 + if ($class_value !== null) { + $this->params = array_merge($this->params, $class_value); } foreach ($search as $whereType => $whereFields) { switch ($whereType) { @@ -57,6 +56,15 @@ trait ListsSearchTrait $where[] = [$whereField, $whereType, $this->params[$paramsName]]; } break; + case '%pipe_like%': + foreach ($whereFields as $k=>$whereField) { + $paramsName = substr_symbol_behind($whereField); + if (!isset($this->params[$k]) || empty($this->params[$k])) { + continue; + } + $where[] = [$whereField, 'like', '%' . $this->params[$k] . '%']; + } + break; case '%like%': foreach ($whereFields as $whereField) { $paramsName = substr_symbol_behind($whereField); @@ -109,4 +117,4 @@ trait ListsSearchTrait } return $where; } -} \ No newline at end of file +} diff --git a/app/store/lists/store_order/StoreOrderLists.php b/app/store/lists/store_order/StoreOrderLists.php index 3eebf5b0b..e7f4c1452 100644 --- a/app/store/lists/store_order/StoreOrderLists.php +++ b/app/store/lists/store_order/StoreOrderLists.php @@ -54,14 +54,16 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface $this->searchWhere[] = ['pay_type','=',7]; } return StoreOrder::where($this->searchWhere) - ->field(['id', 'order_id', 'pay_price', 'pay_time', 'pay_type', 'status']) + ->field(['id', 'order_id', 'pay_price', 'pay_time', 'pay_type', 'status','paid']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select()->each(function ($item) use ($store_id) { $item['pay_time'] = $item['pay_time'] > 0 ? date('Y-m-d H:i:s', $item['pay_time']) : ''; $item['status_name'] = OrderEnum::getOrderType($item['status']) ?? ''; if ($item['paid'] == 0) { - $item['status_name'] = '待支付'; + $item['paid_name'] = '待支付'; + }else{ + $item['paid_name'] = '已支付'; } $product_id = StoreOrderCartInfo::where('oid', $item['id'])->limit(3)->column('product_id'); if ($product_id) { diff --git a/app/store/lists/store_product/StoreProductLists.php b/app/store/lists/store_product/StoreProductLists.php index e9491d41d..d436fa4d9 100644 --- a/app/store/lists/store_product/StoreProductLists.php +++ b/app/store/lists/store_product/StoreProductLists.php @@ -28,7 +28,7 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa public function setSearch(): array { return [ - '=' => ['store_name', 'cate_id', 'store_id'], + '=' => ['cate_id', 'store_id'] ]; } From b6aa59e1b8334a559ee4bfe4321a7453ff56337c Mon Sep 17 00:00:00 2001 From: liu <1873441552@qq.com> Date: Sat, 8 Jun 2024 16:24:34 +0800 Subject: [PATCH 7/8] =?UTF-8?q?=E5=88=9B=E5=BB=BA=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=E6=88=90=E6=9C=AC=E5=92=8C=E5=88=A9=E6=B6=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/logic/order/OrderLogic.php | 262 +++++++++++++++-------------- app/common/enum/OrderEnum.php | 3 + 2 files changed, 143 insertions(+), 122 deletions(-) diff --git a/app/api/logic/order/OrderLogic.php b/app/api/logic/order/OrderLogic.php index a243ad507..9b8416efa 100644 --- a/app/api/logic/order/OrderLogic.php +++ b/app/api/logic/order/OrderLogic.php @@ -39,6 +39,8 @@ use Yansongda\Pay\Event\PayEnd; class OrderLogic extends BaseLogic { public static $total; + public static $cost; + public static $profit; /** * @notes 获取购物车商品信息 @@ -56,16 +58,24 @@ class OrderLogic extends BaseLogic } try { self::$total = 0; + self::$cost = 0;//成本 + self::$profit = 0;//利润 + /** 计算价格 */ - $check = DictType::where('type','activities')->find(); + $check = DictType::where('type', 'activities')->find(); foreach ($cart_select as $k => $v) { $find = StoreBranchProduct::where(['id' => $v['goods']])->field('store_name,image,unit,price,product_id')->find(); if (!$find) { continue; } - if(isset($check) && $check['status'] == 1){ - $find['price'] = StoreProduct::where('id',$find['product_id'])->withTrashed()->value('ot_price'); + $productBase = StoreProduct::where('id', $find['product_id'])->withTrashed()->field('price,ot_price,cost')->find(); + if (isset($check) && $check['status'] == 1) { + $find['price'] = $productBase['ot_price']; } + //利润 + $onePrice = bcsub($productBase['price'], $productBase['ot_price'], 2); + $cart_select[$k]['profit'] = bcmul($v['cart_num'], $onePrice, 2);//利润 + $cart_select[$k]['cost'] = bcmul($v['cart_num'], $productBase['cost'], 2) ?? 0; $cart_select[$k]['total'] = bcmul($v['cart_num'], $find['price'], 2);//钱 $cart_select[$k]['price'] = $find['price']; $cart_select[$k]['product_id'] = $v['goods']; @@ -77,63 +87,69 @@ class OrderLogic extends BaseLogic $cartInfo['image'] = $find['image']; //计算好vip价格 $vipPrice = self::dealVip($find['price']); - if($vipPrice){ + if ($vipPrice) { $cartInfo['price'] = $vipPrice; } - $cartInfo['vip_price'] = $cart_select[$k]['total'] - $vipPrice??0; + $cartInfo['vip_price'] = $cart_select[$k]['total'] - $vipPrice ?? 0; $cart_select[$k]['cart_info'] = json_encode($cartInfo); //理论上每笔都是拆分了 $cart_select[$k]['name'] = $find['store_name']; $cart_select[$k]['imgs'] = $find['image']; $cart_select[$k]['unit_name'] = StoreProductUnit::where(['id' => $find['unit']])->value('name'); self::$total = bcadd(self::$total, $cart_select[$k]['total'], 2); + self::$cost = bcadd(self::$cost, $cart_select[$k]['cost'], 2); + self::$profit = bcadd(self::$profit, $cart_select[$k]['profit'], 2); } //TODO 收单打9.9折 会员按照比例打折 等级按照充值去升级 $pay_price = self::$total; // $check = StoreOrder::where('uid',\request()->userId)->count();//首单逻辑 $vipPrice = 0; - if(isset($check) && $check['status'] == 1){ + if (isset($check) && $check['status'] == 1) { // $discountRate = '0.99';//首单逻辑 // $pay_price 是价格 $discountRate = $check['remark'];//折扣 $discountRate = bcdiv($discountRate, '10', 2); - $pay_price = bcdiv(bcmul($pay_price, $discountRate, 4), '1', 2); - }else{ - $userVip = User::where('id',\request()->userId)->value('user_ship'); - if($userVip){ - switch ($userVip){ + $pay_price = bcdiv(bcmul($pay_price, $discountRate, 4), '1', 2); + } else { + $userVip = User::where('id', \request()->userId)->value('user_ship'); + if ($userVip) { + switch ($userVip) { case UserShipEnum::VIP1: - $discountRate = UserShip::where('id',UserShipEnum::VIP1)->value('discount'); + $discountRate = UserShip::where('id', UserShipEnum::VIP1)->value('discount'); break; case UserShipEnum::VIP2: - $discountRate = UserShip::where('id',UserShipEnum::VIP2)->value('discount'); + $discountRate = UserShip::where('id', UserShipEnum::VIP2)->value('discount'); break; case UserShipEnum::VIP3: - $discountRate = UserShip::where('id',UserShipEnum::VIP3)->value('discount'); + $discountRate = UserShip::where('id', UserShipEnum::VIP3)->value('discount'); break; case UserShipEnum::VIP4: - $discountRate = UserShip::where('id',UserShipEnum::VIP4)->value('discount'); + $discountRate = UserShip::where('id', UserShipEnum::VIP4)->value('discount'); break; case UserShipEnum::VIP5: - $discountRate = UserShip::where('id',UserShipEnum::VIP5)->value('discount'); + $discountRate = UserShip::where('id', UserShipEnum::VIP5)->value('discount'); break; default: $discountRate = 1; } $discountRate = bcdiv($discountRate, '100', 2); - $pay_price = bcdiv(bcmul($pay_price, $discountRate, 4), '1', 2); + $pay_price = bcdiv(bcmul($pay_price, $discountRate, 4), '1', 2); } } - if(!empty(self::$total) && !empty($pay_price)){ + if (!empty(self::$total) && !empty($pay_price)) { bcscale(2); $vipPrice = bcsub(self::$total, $pay_price, 2); } + + //成本价 收益 $order = [ 'create_time' => time(), 'order_id' => getNewOrderId('PF'), 'total_price' => self::$total,//总价 + 'cost' => self::$cost,//成本价 + 'profit' => self::$profit,//利润 'pay_price' => $pay_price,//后期可能有降价抵扣 - 'vip_price'=>$vipPrice, + 'vip_price' => $vipPrice, 'total_num' => count($cart_select),//总数 'pay_type' => $params['pay_type'] ?? 0, 'reservation_time' => $params['reservation_time'] ?? '', @@ -168,6 +184,7 @@ class OrderLogic extends BaseLogic $_order['mobile'] = $user['mobile']; $_order['pay_type'] = $orderInfo['order']['pay_type']; $_order['verify_code'] = $verify_code; + $_order['reservation_time'] = null; if (isset($params['reservation_time'])) { $_order['reservation_time'] = $params['reservation_time']; $_order['reservation'] = YesNoEnum::YES; @@ -453,11 +470,11 @@ class OrderLogic extends BaseLogic //取消售后 public static function cancelSell($where) { - return StoreOrder::where($where)->update( + return StoreOrder::where($where)->update( [ - 'refund_status'=>OrderEnum::CANCEL_SALE, - 'status'=>OrderEnum::CANCEL_ORDER, - 'refund_cancle_time'=>date('Y-m-d H:i:s',time()) + 'refund_status' => OrderEnum::CANCEL_SALE, + 'status' => OrderEnum::CANCEL_ORDER, + 'refund_cancle_time' => date('Y-m-d H:i:s', time()) ] ); @@ -512,149 +529,151 @@ class OrderLogic extends BaseLogic } - public static function write_count($info,$params) + public static function write_count($info, $params) { - $store_id = SystemStoreStaff::where('phone',$info['mobile'])->value('store_id'); - if(empty($store_id)){ + $store_id = SystemStoreStaff::where('phone', $info['mobile'])->value('store_id'); + if (empty($store_id)) { throw new \Exception('该用户未绑定店铺请查看'); } $query = StoreOrderCartInfo::alias('o') - ->leftJoin('store_branch_product p','p.id = o.product_id') - ->leftJoin('store_order s','s.id = o.oid') + ->leftJoin('store_branch_product p', 'p.id = o.product_id') + ->leftJoin('store_order s', 's.id = o.oid') ->field('o.oid,p.store_name,s.order_id') - ->where('o.store_id',$store_id); + ->where('o.store_id', $store_id); - if(isset($params['name']) && $params['name']){ - if($params['name'] && preg_match('/[\x{4e00}-\x{9fff}]+/u', $params['name'])==1){ - $query->where('p.store_name','like','%'.$params['name'].'%'); - }else{ - $query->where('s.order_id',$params['name']); + if (isset($params['name']) && $params['name']) { + if ($params['name'] && preg_match('/[\x{4e00}-\x{9fff}]+/u', $params['name']) == 1) { + $query->where('p.store_name', 'like', '%' . $params['name'] . '%'); + } else { + $query->where('s.order_id', $params['name']); } } $product = $query->select(); - if(empty($product)){ + if (empty($product)) { return [ - 'no_send'=>0, - 'send'=>0 + 'no_send' => 0, + 'send' => 0 ]; } $oids = array_column($product->toArray(), 'oid'); $uniqueOids = array_unique($oids); - $no_send = StoreOrder::whereIn('id',$uniqueOids) - ->where('status',1)->count(); - $send = StoreOrder::whereIn('id',$uniqueOids) - ->where('status',2)->count(); + $no_send = StoreOrder::whereIn('id', $uniqueOids) + ->where('status', 1)->count(); + $send = StoreOrder::whereIn('id', $uniqueOids) + ->where('status', 2)->count(); return [ - 'no_send'=>$no_send, - 'send'=>$send + 'no_send' => $no_send, + 'send' => $send ]; } public static function getOne($code) { - return StoreOrder::with(['store'])->where('verify_code',$code) + return StoreOrder::with(['store'])->where('verify_code', $code) ->select()->each(function ($item) { - $item['goods_list']=StoreOrderCartInfo::where('oid',$item['id'])->with('goodsName')->field('product_id,cart_num,verify_code,is_writeoff,writeoff_time')->limit(3)->select(); - $item['goods_count']=count(explode(',',$item['cart_id'])); + $item['goods_list'] = StoreOrderCartInfo::where('oid', $item['id'])->with('goodsName')->field('product_id,cart_num,verify_code,is_writeoff,writeoff_time')->limit(3)->select(); + $item['goods_count'] = count(explode(',', $item['cart_id'])); return $item; //返回处理后的数据。 }) ->toArray(); } - public static function write_list($info,$status,$params) + public static function write_list($info, $status, $params) { - $store_id = SystemStoreStaff::where('phone',$info['mobile'])->value('store_id'); - if(empty($store_id)){ + $store_id = SystemStoreStaff::where('phone', $info['mobile'])->value('store_id'); + if (empty($store_id)) { throw new \Exception('该用户未绑定店铺请查看'); } //先查商品相似 $query = StoreOrderCartInfo::alias('o') - ->leftJoin('store_branch_product p','p.id = o.product_id') - ->leftJoin('store_order s','s.id = o.oid') + ->leftJoin('store_branch_product p', 'p.id = o.product_id') + ->leftJoin('store_order s', 's.id = o.oid') ->field('o.oid,p.store_name,s.order_id') - ->where('o.store_id',$store_id); + ->where('o.store_id', $store_id); - if(isset($params['name']) && $params['name']){ - if($params['name'] && preg_match('/[\x{4e00}-\x{9fff}]+/u', $params['name'])==1){ - $query->where('p.store_name','like','%'.$params['name'].'%'); - }else{ - $query->where('s.order_id',$params['name']); + if (isset($params['name']) && $params['name']) { + if ($params['name'] && preg_match('/[\x{4e00}-\x{9fff}]+/u', $params['name']) == 1) { + $query->where('p.store_name', 'like', '%' . $params['name'] . '%'); + } else { + $query->where('s.order_id', $params['name']); } } $product = $query->select(); - if(empty($product)){ + if (empty($product)) { return [ - 'list'=>[], - 'count'=>0 + 'list' => [], + 'count' => 0 ]; } - $oids = array_column($product->toArray(), 'oid'); - $uniqueOids = array_unique($oids); - $query = StoreOrder::with(['store']) - ->whereIn('id',$uniqueOids) - ->where('status',$status); + $oids = array_column($product->toArray(), 'oid'); + $uniqueOids = array_unique($oids); + $query = StoreOrder::with(['store']) + ->whereIn('id', $uniqueOids) + ->where('status', $status); $count = $query->count(); $list = $query ->page($params['page_no'], $params['page_size']) ->order(['id' => 'desc']) ->select() - ->each(function($item){ - $item['goods_list']=StoreOrderCartInfo::where('oid',$item['id'])->with('goodsName')->field('product_id,cart_num,verify_code,is_writeoff,writeoff_time')->limit(3)->select(); - $item['goods_count']=count(explode(',',$item['cart_id'])); + ->each(function ($item) { + $item['goods_list'] = StoreOrderCartInfo::where('oid', $item['id'])->with('goodsName')->field('product_id,cart_num,verify_code,is_writeoff,writeoff_time')->limit(3)->select(); + $item['goods_count'] = count(explode(',', $item['cart_id'])); }) ->toArray(); return [ - 'list'=>$list, - 'count'=>$count + 'list' => $list, + 'count' => $count ]; } - public static function dealRefund($uid,$params) + public static function dealRefund($uid, $params) { //todo 单子不是完成的不允许退款 //单笔不拆单子直接修改状态 - $order = StoreOrder::where('id',$params['id'])->withTrashed()->findOrEmpty(); - if(count($params['old_cart_id']) ==1){ + $order = StoreOrder::where('id', $params['id'])->withTrashed()->findOrEmpty(); + $params['refund_num'] = 1;//todo 拿实际数量 + if (count($params['old_cart_id']) == 1) { $order->refund_status = OrderEnum::REFUND_STATUS_YES; $order->status = OrderEnum::ALREADY_REFUND; - $order->refund_reason_wap_explain =$params['refund_message']??''; - $order->refund_num = $params['refund_num']; - $refund_price_cart = StoreOrderCartInfo::where('oid',$params['id']) + $order->refund_reason_wap_explain = $params['refund_message'] ?? ''; + $order->mark = $params['mark'] ?? ''; + $order->refund_num = $params['refund_num'] ?? 1; + $refund_price_cart = StoreOrderCartInfo::where('oid', $params['id']) ->field('id,oid,cart_info') ->find()->toArray(); $vipPrice = $order['vip_price']; $price = $refund_price_cart['cart_info']['price'] * $params['refund_num']; $onePrice = 0; bcscale(2); - if($vipPrice){ + if ($vipPrice) { //每单的vip价格 $onePrice = bcdiv($vipPrice, $refund_price_cart['cart_info']['cart_num']); } - if($price > $onePrice){ - $price =bcsub($price, $onePrice); + if ($price > $onePrice) { + $price = bcsub($price, $onePrice); } $order->refund_price = $price; $order->refund_type = $params['refund_type']; $order->save(); - }else{ + } else { // 多单的情况 拆主订单为新的2单 修改新的2单的核销码 修改cart_info的核销码 和订单id 退款直接退一单的钱 $order->delete_time = time(); $order->save(); Db::startTrans(); try { $order = $order->toArray(); - $cart_info = StoreOrderCartInfo::where('oid',$params['id']) - ->whereNotIn('old_cart_id',$params['old_cart_id']) + $cart_info = StoreOrderCartInfo::where('oid', $params['id']) + ->whereNotIn('old_cart_id', $params['old_cart_id']) ->select()->toArray(); - if($cart_info){ - $leftOrder = self::dealCreateLeftOrder($order,$cart_info,$params); + if ($cart_info) { + $leftOrder = self::dealCreateLeftOrder($order, $cart_info, $params); self::dealChangeCartInfo($leftOrder); } - $refundOrder = self::dealCreateRefundOrder($order,$params); + $refundOrder = self::dealCreateRefundOrder($order, $params); self::dealChangeCartInfo($refundOrder); // d($leftOrder,$refundOrder); Db::commit(); @@ -675,28 +694,27 @@ class OrderLogic extends BaseLogic $code = $leftOrder->verify_code; $new_oid = $leftOrder->id; $old_id = $leftOrder->pid; - $car_id = explode(',',$leftOrder->cart_id); - return StoreOrderCartInfo::where('oid',$old_id) - ->whereIn('old_cart_id',$car_id) + $car_id = explode(',', $leftOrder->cart_id); + return StoreOrderCartInfo::where('oid', $old_id) + ->whereIn('old_cart_id', $car_id) ->update([ - 'oid'=>$new_oid, - 'verify_code'=>$code + 'oid' => $new_oid, + 'verify_code' => $code ]); } - - public static function dealCreateLeftOrder($order,$cart_info,$params) + public static function dealCreateLeftOrder($order, $cart_info, $params) { //查出不在这个退货中的数据 - $order['order_id'] = $order['order_id'].'-2'; + $order['order_id'] = $order['order_id'] . '-2'; $order['pid'] = $order['id']; unset($order['id']); - $allOldCartIds =[]; + $allOldCartIds = []; $totalTotal = 0; $totalPrice = 0; $totalVipPrice = 0; - foreach ($cart_info as $value){ + foreach ($cart_info as $value) { if (isset($value['old_cart_id'])) { $allOldCartIds[] = $value['old_cart_id']; } @@ -712,7 +730,7 @@ class OrderLogic extends BaseLogic } } } - $order['cart_id'] = implode(',',$allOldCartIds); + $order['cart_id'] = implode(',', $allOldCartIds); $order['total_num'] = count($cart_info); $order['refund_type'] = $params['refund_type']; $order['total_price'] = number_format($totalTotal, 2); @@ -722,24 +740,24 @@ class OrderLogic extends BaseLogic $order['create_time'] = time(); $order['update_time'] = null; $order['delete_time'] = null; - return StoreOrder::create($order); + return StoreOrder::create($order); } - - public static function dealCreateRefundOrder($order,$params) + public static function dealCreateRefundOrder($order, $params) { - $order['order_id'] = $order['order_id'].'-1'; + $order['order_id'] = $order['order_id'] . '-1'; $order['pid'] = $order['id']; unset($order['id']); - $order['cart_id'] = implode(',',$params['old_cart_id']); + $order['cart_id'] = implode(',', $params['old_cart_id']); - $order['refund_status'] = OrderEnum::REFUND_STATUS_YES; - $order['status'] = OrderEnum::ALREADY_REFUND; - $order['refund_num'] = $params['refund_num'];//按数量整单退剩余的 - $order['refund_reason_wap_explain'] = $params['refund_message']??''; + $order['refund_status'] = OrderEnum::REFUND_STATUS_YES; + $order['status'] = OrderEnum::ALREADY_REFUND; + $order['refund_num'] = $params['refund_num'];//按数量整单退剩余的 + $order['refund_reason_wap_explain'] = $params['refund_message'] ?? ''; + $order['mark'] = $params['mark'] ?? ''; $order['total_num'] = count($params['old_cart_id']); - $refund_price_cart = StoreOrderCartInfo::whereIn('old_cart_id',$params['old_cart_id']) + $refund_price_cart = StoreOrderCartInfo::whereIn('old_cart_id', $params['old_cart_id']) ->field('id,oid,cart_info') ->select()->toArray(); $totalTotals = array_column(array_column($refund_price_cart, 'cart_info'), 'total'); @@ -759,49 +777,49 @@ class OrderLogic extends BaseLogic $order['total_price'] = number_format($totalTotal, 2); $order['pay_price'] = number_format($totalPrice, 2); $order['vip_price'] = number_format($totalVipPrices, 2); - $order['refund_price'] = number_format($totalPrice, 2); + $order['refund_price'] = number_format($totalPrice, 2); $order['verify_code'] = verificationCode(); $order['refund_reason_time'] = time(); - $order['create_time'] = time()+1; + $order['create_time'] = time() + 1; $order['update_time'] = null; $order['delete_time'] = null; - return StoreOrder::create($order); + return StoreOrder::create($order); } public static function dealVip($pay_price) { - $check = DictType::where('type','activities')->find(); - if(isset($check) && $check['status'] == 1){ + $check = DictType::where('type', 'activities')->find(); + if (isset($check) && $check['status'] == 1) { // $discountRate = '0.99';//首单逻辑 $discountRate = $check['remark']; $discountRate = bcdiv($discountRate, '100', 2); - $pay_price = bcdiv(bcmul($pay_price, $discountRate, 4), '1', 2); - }else{ - $userVip = User::where('id',\request()->userId)->value('user_ship'); - if($userVip){ - switch ($userVip){ + $pay_price = bcdiv(bcmul($pay_price, $discountRate, 4), '1', 2); + } else { + $userVip = User::where('id', \request()->userId)->value('user_ship'); + if ($userVip) { + switch ($userVip) { case UserShipEnum::VIP1: - $discountRate = UserShip::where('id',UserShipEnum::VIP1)->value('discount'); + $discountRate = UserShip::where('id', UserShipEnum::VIP1)->value('discount'); break; case UserShipEnum::VIP2: - $discountRate = UserShip::where('id',UserShipEnum::VIP2)->value('discount'); + $discountRate = UserShip::where('id', UserShipEnum::VIP2)->value('discount'); break; case UserShipEnum::VIP3: - $discountRate = UserShip::where('id',UserShipEnum::VIP3)->value('discount'); + $discountRate = UserShip::where('id', UserShipEnum::VIP3)->value('discount'); break; case UserShipEnum::VIP4: - $discountRate = UserShip::where('id',UserShipEnum::VIP4)->value('discount'); + $discountRate = UserShip::where('id', UserShipEnum::VIP4)->value('discount'); break; case UserShipEnum::VIP5: - $discountRate = UserShip::where('id',UserShipEnum::VIP5)->value('discount'); + $discountRate = UserShip::where('id', UserShipEnum::VIP5)->value('discount'); break; default: $discountRate = 1; } $discountRate = bcdiv($discountRate, '100', 2); - $pay_price = bcdiv(bcmul($pay_price, $discountRate, 4), '1', 2); + $pay_price = bcdiv(bcmul($pay_price, $discountRate, 4), '1', 2); } } return $pay_price; diff --git a/app/common/enum/OrderEnum.php b/app/common/enum/OrderEnum.php index 35f3e685f..fb11a30b8 100644 --- a/app/common/enum/OrderEnum.php +++ b/app/common/enum/OrderEnum.php @@ -18,6 +18,7 @@ class OrderEnum * @SUPPLIER_ORDER_OBTAINS 供应链订单获得 * @PLATFORM_ORDER_PAY 平台订单支付 * @SYSTEM_SET 系统设置 + * @OWN_GET 平台收入 */ const USER_ORDER_PAY = 1; const MERCHANT_ORDER_OBTAINS = 2; @@ -30,6 +31,8 @@ class OrderEnum const CASHIER_ORDER_PAY = 9; const CASHIER_CASH_ORDER_PAY = 10; + const OWN_GET = 3; + /** * 收入支出类型 From 1450fd25828d554f111b48ffd18ae0041873c299 Mon Sep 17 00:00:00 2001 From: liu <1873441552@qq.com> Date: Sat, 8 Jun 2024 16:35:28 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E5=BA=97=E9=93=BAid?= =?UTF-8?q?=E5=8E=BB=E8=BF=94=E5=9B=9E=E9=85=8D=E9=80=81=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/logic/order/OrderLogic.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/api/logic/order/OrderLogic.php b/app/api/logic/order/OrderLogic.php index 9b8416efa..27c2b2ca0 100644 --- a/app/api/logic/order/OrderLogic.php +++ b/app/api/logic/order/OrderLogic.php @@ -157,6 +157,10 @@ class OrderLogic extends BaseLogic 'store_id' => $params['store_id'] ?? 0, 'shipping_type' => $params['shipping_type'] ?? 1//配送方式 1=快递 ,2=门店自提 ]; + $order['default_delivery'] = 0; + if($params['store_id']){ + $order['default_delivery'] = SystemStore::where('id',$params['store_id'])->value('default_delivery'); + } } catch (\Exception $e) { self::setError($e->getMessage()); return false;