From 20095c8085ef5d23039897256bc63e27af1e89d1 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Wed, 11 Sep 2024 15:15:07 +0800 Subject: [PATCH 1/4] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=E4=BA=86?= =?UTF-8?q?=E5=95=86=E5=93=81=E8=AE=A2=E5=8D=95=E9=80=BB=E8=BE=91=E5=92=8C?= =?UTF-8?q?=E4=BD=A3=E9=87=91=E8=AE=A1=E7=AE=97=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../StoreOrderCartInfoLists.php | 5 +- .../logic/store_order/StoreOrderLogic.php | 64 +++++------ app/common/logic/CommissionProductLogic.php | 100 +++++++++++------- app/common/logic/CommissionnLogic.php | 4 +- .../logic/store_order/StoreOrderLogic.php | 31 ++++-- 5 files changed, 123 insertions(+), 81 deletions(-) diff --git a/app/admin/lists/store_order_cart_info/StoreOrderCartInfoLists.php b/app/admin/lists/store_order_cart_info/StoreOrderCartInfoLists.php index 2d92d411f..859a8987e 100644 --- a/app/admin/lists/store_order_cart_info/StoreOrderCartInfoLists.php +++ b/app/admin/lists/store_order_cart_info/StoreOrderCartInfoLists.php @@ -51,7 +51,7 @@ class StoreOrderCartInfoLists extends BaseAdminDataLists implements ListsSearchI public function lists(): array { return StoreOrderCartInfo::where($this->searchWhere) - ->field('oid,uid,cart_info,product_id,store_id,cart_num,price,total_price,create_time')->limit($this->limitOffset, $this->limitLength) + ->field('oid,uid,product_id,store_id,cart_num,price,total_price,create_time')->limit($this->limitOffset, $this->limitLength) ->select()->each(function ($item) { $find=StoreProduct::where('id',$item['product_id'])->field('image,unit,store_name,store_info')->find(); if($find){ @@ -75,6 +75,8 @@ class StoreOrderCartInfoLists extends BaseAdminDataLists implements ListsSearchI $item['store_info']=$find['store_info'];//商品规格 $item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name')??""; $item['cate_name'] = StoreCategory::where('id', $find['cate_id'])->value('name')??""; + $item['pay_price'] =$item['total_price']; + $item['cart_info'] = $item->toArray()??[]; }else{ $item['image']='';//商品图片 $item['unit_name']='';//商品图片 @@ -83,6 +85,7 @@ class StoreOrderCartInfoLists extends BaseAdminDataLists implements ListsSearchI $item['store_info']='';//商品规格-(数据库叫商品简介) $item['nickname']=''; $item['system_store']=''; + $item['cart_info']=[]; } return $item; //返回处理后的数据。 }) diff --git a/app/admin/logic/store_order/StoreOrderLogic.php b/app/admin/logic/store_order/StoreOrderLogic.php index fc29cda10..d340cad97 100644 --- a/app/admin/logic/store_order/StoreOrderLogic.php +++ b/app/admin/logic/store_order/StoreOrderLogic.php @@ -118,42 +118,44 @@ class StoreOrderLogic extends BaseLogic public static function refund($detail, $params) { if (isset($params['product_arr']) && count($params['product_arr']) > 0) { - $refund_price = $params['refund_price']; - $refund_num = 0; - foreach ($params['product_arr'] as $k => $v) { - $find = StoreOrderCartInfo::where('oid', $detail['id'])->where('product_id', $v['product_id'])->find(); - if ($find) { - $refund_num += $v['cart_num']; - $cart_num = bcsub($find['cart_num'], $v['cart_num']); - $total_price = bcmul($find['price'], $cart_num); - $data = ['cart_num' => $cart_num, 'total_price' => $total_price]; - StoreOrderCartInfo::where('id', $find['id'])->update($data); - $arr = StoreFinanceFlowProduct::where('oid', $detail['id'])->where('product_id', $v['product_id'])->select()->toArray(); - foreach ($arr as $key => $value) { - $value['cart_num'] = $cart_num; - $value['total_price'] = bcmul($cart_num, $value['price'], 2); - $value['number'] = bcmul($value['total_price'], $value['rate'], 2); - StoreFinanceFlowProduct::where('id', $value['id'])->update(['delete_time' => time()]); - unset($value['id']); - $value['create_time'] = strtotime($value['create_time']); - $value['update_time'] = strtotime($value['update_time']); - StoreFinanceFlowProduct::create($value); - } - } - } - $village_uid = StoreFinanceFlow::where('order_id', $detail['id'])->where('financial_type', 14)->value('other_uid'); - $brigade_uid = StoreFinanceFlow::where('order_id', $detail['id'])->where('financial_type', 15)->value('other_uid'); - $transaction_id = StoreFinanceFlow::where('order_id', $detail['id'])->value('transaction_id'); - StoreFinanceFlow::where('order_id', $detail['id'])->update(['delete_time' => time()]); - CommissionnLogic::setStore($detail, $village_uid, $brigade_uid, $transaction_id); - - StoreOrder::where('id', $detail['oid'])->update(['refund_price' => $refund_price, 'refund_num' => $refund_num]); //微信支付 if (in_array($detail['pay_type'], [PayEnum::WECHAT_PAY_MINI, PayEnum::WECHAT_PAY_BARCODE])) { $money = (int)bcmul($params['refund_price'], 100); + $pay_price = (int)bcmul($detail['pay_price'], 100); $refund = (new \app\common\logic\store_order\StoreOrderLogic()) - ->refund($params['order_id'], $money, $detail['pay_price']); + ->refund($params['order_id'], $money, $pay_price); if ($refund) { + $refund_price = $params['refund_price']; + $refund_num = 0; + foreach ($params['product_arr'] as $k => $v) { + $find = StoreOrderCartInfo::where('oid', $detail['id'])->where('product_id', $v['product_id'])->find(); + if ($find) { + $refund_num += $v['cart_num']; + $cart_num = bcsub($find['cart_num'], $v['cart_num']); + $total_price = bcmul($find['price'], $cart_num); + $data = ['cart_num' => $cart_num, 'total_price' => $total_price]; + StoreOrderCartInfo::where('id', $find['id'])->update($data); + $arr = StoreFinanceFlowProduct::where('oid', $detail['id'])->where('product_id', $v['product_id'])->select()->toArray(); + foreach ($arr as $key => $value) { + $value['cart_num'] = $cart_num; + $value['total_price'] = bcmul($cart_num, $value['price'], 2); + $value['number'] = bcmul($value['total_price'], $value['rate'], 2); + StoreFinanceFlowProduct::where('id', $value['id'])->update(['delete_time' => time()]); + unset($value['id']); + $value['create_time'] = strtotime($value['create_time']); + $value['update_time'] = strtotime($value['update_time']); + StoreFinanceFlowProduct::create($value); + } + } + } + $village_uid = StoreFinanceFlow::where('order_id', $detail['id'])->where('financial_type', 14)->value('other_uid'); + $brigade_uid = StoreFinanceFlow::where('order_id', $detail['id'])->where('financial_type', 15)->value('other_uid'); + $transaction_id = StoreFinanceFlow::where('order_id', $detail['id'])->value('transaction_id'); + StoreFinanceFlow::where('order_id', $detail['id'])->update(['delete_time' => time()]); + $detail['refund_price']=$refund_price; + CommissionnLogic::setStore($detail, $village_uid, $brigade_uid, $transaction_id); + + StoreOrder::where('id', $detail['oid'])->update(['refund_price' => $refund_price, 'refund_num' => $refund_num]); return '退款成功'; } } diff --git a/app/common/logic/CommissionProductLogic.php b/app/common/logic/CommissionProductLogic.php index 17fce9c02..68d2e52cb 100644 --- a/app/common/logic/CommissionProductLogic.php +++ b/app/common/logic/CommissionProductLogic.php @@ -7,6 +7,7 @@ use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_finance_flow_product\StoreFinanceFlowProduct; use app\common\model\store_order_cart_info\StoreOrderCartInfo; use app\common\model\store_product\StoreProduct; +use app\common\model\user\User; use PDO; use support\Log; @@ -51,8 +52,8 @@ class CommissionProductLogic extends BaseLogic */ public function a($find, $order, $village_uid, $brigade_uid, $user_ship, $product) { - $total_price = bcmul($product['price'], $find['cart_num']); - $purchase_price = bcmul($product['purchase'], $find['cart_num']); + $total_price = bcmul($product['price'], $find['cart_num'], 2); + $purchase_price = bcmul($product['purchase'], $find['cart_num'], 2); $price = $product['purchase']; $brigade_number = bcmul($purchase_price, 0.02, 2); //队长 @@ -69,43 +70,60 @@ class CommissionProductLogic extends BaseLogic $number4 = bcadd($attrition_number, $number2, 2); //会员 - if ($order['spread_uid'] > 0 || $user_ship > 0) { - if (in_array($user_ship, [2, 3])) { - $vip_number = bcmul($purchase_price, 0.05, 2); //会员利润 - $data[] = [ - 'nickname' => '会员', - 'store_id' => $order['store_id'], - 'product_id' => $find['product_id'], - 'price' => $price, - 'other_uid' => $order['spread_uid'], - 'total_price' => $purchase_price, - 'cart_num' => $find['cart_num'], - 'rate' => 0.05, - 'number' => $vip_number, - 'oid' => $order['id'], - 'type' => 0, - 'status' => 1, - ]; - $number4=bcadd($number4, $vip_number, 2); - } else { - $vip_number = bcmul($purchase_price, 0.07, 2); //会员利润 - $data[] = [ - 'nickname' => '会员', - 'store_id' => $order['store_id'], - 'product_id' => $find['product_id'], - 'other_uid' => $order['spread_uid'], - 'price' => $price, - 'total_price' => $purchase_price, - 'cart_num' => $find['cart_num'], - 'rate' => 0.07, - 'number' => $vip_number, - 'oid' => $order['id'], - 'type' => 0, - 'status' => 1, - ]; - $number4=bcadd($number4, $vip_number, 2); + $uid = 0; + if ($order['spread_uid'] > 0) { + $uid = $order['spread_uid']; + } + if ($order['uid'] > 0) { + $uid = $order['uid']; + } + $user = User::where('id', $uid)->find(); + $delete_time=null; + $nickname='会员'; + if ($user) { + $moeny = bcsub($user['total_recharge_amount'], $user['purchase_funds'], 2); + if ($moeny < $user['first_purchase_funds']) { + $delete_time=1; + $nickname='首充没用完,会员不分配'; } } + if (in_array($user_ship, [2, 3])) { + $vip_number = bcmul($purchase_price, 0.05, 2); //会员利润 + $data[] = [ + 'nickname' => $nickname, + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'price' => $price, + 'other_uid' => $uid, + 'total_price' => $purchase_price, + 'cart_num' => $find['cart_num'], + 'rate' => 0.05, + 'number' => $vip_number, + 'oid' => $order['id'], + 'type' => 0, + 'status' => 1, + 'delete_time'=>$delete_time + ]; + $number4 = bcadd($number4, $vip_number, 2); + } else { + $vip_number = bcmul($purchase_price, 0.07, 2); //会员利润 + $data[] = [ + 'nickname' => $nickname, + 'store_id' => $order['store_id'], + 'product_id' => $find['product_id'], + 'other_uid' => $uid, + 'price' => $price, + 'total_price' => $purchase_price, + 'cart_num' => $find['cart_num'], + 'rate' => 0.07, + 'number' => $vip_number, + 'oid' => $order['id'], + 'type' => 0, + 'status' => 1, + 'delete_time'=>$delete_time + ]; + $number4 = bcadd($number4, $vip_number, 2); + } //门店利润 if ($number3 <= 0) { $store_number = 0; @@ -202,8 +220,8 @@ class CommissionProductLogic extends BaseLogic */ public function b($find, $order, $product, $user_ship) { - $total_price = bcmul($product['price'], $find['cart_num']); - $purchase_price = bcmul($product['purchase'], $find['cart_num']); + $total_price = bcmul($product['price'], $find['cart_num'], 2); + $purchase_price = bcmul($product['purchase'], $find['cart_num'], 2); $price = $product['purchase']; $brigade_number = bcmul($purchase_price, 0.02, 2); //队长 @@ -312,8 +330,8 @@ class CommissionProductLogic extends BaseLogic public function c($find, $order, $village_uid, $brigade_uid, $user_ship, $product) { // $rose = bcdiv($product['rose'], 100, 2); - $total_price = bcmul($product['price'], $find['cart_num']); - $purchase_price = bcmul($product['purchase'], $find['cart_num']); + $total_price = bcmul($product['price'], $find['cart_num'], 2); + $purchase_price = bcmul($product['purchase'], $find['cart_num'], 2); $price = $product['price']; $brigade_number = bcmul($total_price, 0.02, 2); //队长 $village_number = bcmul($brigade_number, 0.1, 2); //村长 diff --git a/app/common/logic/CommissionnLogic.php b/app/common/logic/CommissionnLogic.php index 79c823916..d3da5fd75 100644 --- a/app/common/logic/CommissionnLogic.php +++ b/app/common/logic/CommissionnLogic.php @@ -106,7 +106,7 @@ class CommissionnLogic extends BaseLogic $financeLogic = new StoreFinanceFlowLogic(); $financeLogic->order = $order; $financeLogic->user['uid'] = $order['uid']; - $pay_price = $order['pay_price']; + $pay_price=bcsub($order['pay_price'],$order['refund_price'],2); $number = StoreFinanceFlowProduct::where('oid', $order['id'])->sum('number'); $fees = bcsub($pay_price, $number, 2); if ($fees > 0) { @@ -124,7 +124,7 @@ class CommissionnLogic extends BaseLogic $financeLogic->user['uid'] = $order['uid']; $financeLogic->other_arr['vip_uid'] = $uid; $financeLogic->order = $order; - $financeLogic->in($transaction_id, $order['pay_price'], OrderEnum::USER_ORDER_PAY, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); //用户订单支付 + $financeLogic->in($transaction_id, bcsub($order['pay_price'],$order['refund_price'],2), OrderEnum::USER_ORDER_PAY, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); //用户订单支付 //缴纳齐全了就加商户没有就加到平台 $money_limt = SystemStore::where('id', $order['store_id'])->field('paid_deposit,security_deposit')->find(); diff --git a/app/common/logic/store_order/StoreOrderLogic.php b/app/common/logic/store_order/StoreOrderLogic.php index 1141ae14d..a67acfad3 100644 --- a/app/common/logic/store_order/StoreOrderLogic.php +++ b/app/common/logic/store_order/StoreOrderLogic.php @@ -250,12 +250,31 @@ class StoreOrderLogic extends BaseLogic if ($order['pay_type'] == 19){ $order['deduction_price'] = "0.00"; } - - $detail =StoreOrderCartInfo::where('oid',$order['id'])->find()->toArray(); + $product=StoreOrderCartInfo::where(['oid'=>$order['id']]) + ->field('oid,uid,product_id,store_id,cart_num,price,total_price,create_time') + ->select()->each(function ($item) { + $find=StoreProduct::where('id',$item['product_id'])->field('image,unit,store_name,store_info')->find(); + if($find){ + $item['image']=$find['image'];//商品图片 + $item['name']=$find['store_name'];//商品名称 + $item['store_info']=$find['store_info'];//商品规格 + $item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name')??""; + $item['pay_price'] =$item['total_price']; + $item['cart_info'] = $item->toArray()??[]; + }else{ + $item['image']='';//商品图片 + $item['unit_name']='';//商品图片 + $item['cate_name']='';//商品图片 + $item['store_name']='';//商品名称 + $item['store_info']='';//商品规格-(数据库叫商品简介) + $item['nickname']=''; + $item['system_store']=''; + $item['cart_info']=[]; + } + return $item; //返回处理后的数据。 + }); + $order['product']=$product; $vip =0; - if(isset($detail['cart_info']['vip']) && $detail['cart_info']['vip'] == 1){ - $vip = 1; - } $order['vip'] = $vip; return $order->toArray(); } @@ -371,7 +390,7 @@ class StoreOrderLogic extends BaseLogic return false; } catch (Exception $e) { \support\Log::info($e->extra['message'] ?? $e->getMessage()); - throw new BusinessException($e->getMessage()); + throw new BusinessException($e->extra['message'] ?? $e->getMessage()); } } From 6b0d5e3edb88e02bdb86717e04018079c2470c8f Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Wed, 11 Sep 2024 17:10:15 +0800 Subject: [PATCH 2/4] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=E5=BA=93?= =?UTF-8?q?=E5=AD=98=E8=AE=A1=E7=AE=97=E6=96=B9=E5=BC=8F=E4=BB=A5=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=BA=93=E5=AD=98=E6=80=BB=E9=87=8F=E7=9A=84=E6=98=BE?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/lists/statistics/StoreProductLists.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/admin/lists/statistics/StoreProductLists.php b/app/admin/lists/statistics/StoreProductLists.php index d80652d02..af5b65560 100644 --- a/app/admin/lists/statistics/StoreProductLists.php +++ b/app/admin/lists/statistics/StoreProductLists.php @@ -92,6 +92,11 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa ->each(function ($item) { // 计算总库存 $unit_name=StoreProductUnit::where('id',$item->unit)->value('name'); + if($item->total_stock){ + $item->total_stock=bcadd($item->total_stock??0,$item->warehouse_stock??0,2).'|'.$unit_name; + }else{ + $item->total_stock=''; + } $item->sales=$item->sales.'|'.$unit_name; $item->store_stock=$item->store_stock.'|'.$unit_name; $item->warehouse_stock=$item->warehouse_stock.'|'.$unit_name; @@ -115,11 +120,6 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa }else{ $item->total_price='0元'; } - if($item->total_stock){ - $item->total_stock=bcadd($item->total_stock,$item->warehouse_stock,2).'|'.$unit_name; - }else{ - $item->total_stock=''; - } }) ->toArray(); return $list; From 40cc604461beacc924076c16fef28ba43d124c45 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Wed, 11 Sep 2024 17:58:23 +0800 Subject: [PATCH 3/4] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E7=A7=AF=E5=88=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/logic/UserSignLogic.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/common/logic/UserSignLogic.php b/app/common/logic/UserSignLogic.php index 47cfc609b..7e0d443cf 100644 --- a/app/common/logic/UserSignLogic.php +++ b/app/common/logic/UserSignLogic.php @@ -67,7 +67,7 @@ class UserSignLogic extends BaseLogic $write = self::write($order, $total_vip, 0, 1, 9); self::write_log($write, $total_vip, 0, 7); self::write_log($write, $total_vip, 0, 9, 0); - User::where('id', $order->uid)->inc('integral', $total_vip)->update(); + User::where('id', $order->uid)->update(['integral'=>$total_vip,'first_purchase_funds'=>$order['price']]); } return true; } From bbbed26fbf2ce2d1204c69e01adc18c46c145db4 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Wed, 11 Sep 2024 21:47:14 +0800 Subject: [PATCH 4/4] feat(StoreOrderLists, UserRechargeLists, OrderLogic): updated lists, logic for orders & refunds, fixed bugs, improved code quality --- .../lists/store_order/StoreOrderLists.php | 2 ++ .../lists/user_recharge/UserRechargeLists.php | 33 ++++++++++++++++++- app/api/logic/order/OrderLogic.php | 2 -- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/app/admin/lists/store_order/StoreOrderLists.php b/app/admin/lists/store_order/StoreOrderLists.php index ac3ab608b..187af04e6 100644 --- a/app/admin/lists/store_order/StoreOrderLists.php +++ b/app/admin/lists/store_order/StoreOrderLists.php @@ -148,6 +148,8 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface 'nickname' => '用户', 'total_price' => '总金额', 'pay_price' => '实际支付', + 'status_name' => '状态', + 'refund_price' => '退款金额', 'pay_time' => '支付时间', ]; return $data; diff --git a/app/admin/lists/user_recharge/UserRechargeLists.php b/app/admin/lists/user_recharge/UserRechargeLists.php index c1e7a1ee3..01d0a4670 100644 --- a/app/admin/lists/user_recharge/UserRechargeLists.php +++ b/app/admin/lists/user_recharge/UserRechargeLists.php @@ -7,13 +7,14 @@ use app\admin\lists\BaseAdminDataLists; use app\common\model\user_recharge\UserRecharge; use app\common\lists\ListsSearchInterface; use app\common\model\user\User; +use app\common\lists\ListsExcelInterface; /** * 充值记录列表 * Class UserRechargeLists * @package app\admin\listsuser_recharge */ -class UserRechargeLists extends BaseAdminDataLists implements ListsSearchInterface +class UserRechargeLists extends BaseAdminDataLists implements ListsSearchInterface,ListsExcelInterface { @@ -88,4 +89,34 @@ class UserRechargeLists extends BaseAdminDataLists implements ListsSearchInterfa return UserRecharge::where($this->searchWhere)->count(); } + /** + * @notes 导出文件名 + * @return string + * @author 乔峰 + * @date 2022/11/24 16:17 + */ + public function setFileName(): string + { + return '订单列表'; + } + + + /** + * @notes 导出字段 + * @return string[] + * @author 乔峰 + * @date 2022/11/24 16:17 + */ + public function setExcelFields(): array + { + $data = [ + 'id' => 'ID', + 'order_id'=>'订单号', + 'nickname' => '用户', + 'price' => '实际支付', + 'paid_name' => '状态', + 'pay_time' => '支付时间', + ]; + return $data; + } } \ No newline at end of file diff --git a/app/api/logic/order/OrderLogic.php b/app/api/logic/order/OrderLogic.php index e444f5863..fb9ac27af 100644 --- a/app/api/logic/order/OrderLogic.php +++ b/app/api/logic/order/OrderLogic.php @@ -302,8 +302,6 @@ class OrderLogic extends BaseLogic if ($uid > 0) { $address = UserAddress::where(['uid' => $uid])->find(); if ($address) { - $_order['real_name'] = $address['real_name']; - $_order['user_phone'] = $address['phone']; if ($address['area']) { $_order['user_address'] = Db::name('geo_area')->where('area_code', $address['area'])->value('area_name') ?? ''; }