From b65ce4717a878fb562614707d4384f97a955e6ac Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Thu, 26 Sep 2024 10:56:02 +0800 Subject: [PATCH 1/9] =?UTF-8?q?feat:=20=E9=87=8D=E6=9E=84=E4=BA=86?= =?UTF-8?q?=E9=80=80=E6=AC=BE=E9=80=BB=E8=BE=91=EF=BC=8C=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E4=BA=86=E4=BB=A3=E7=A0=81=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../logic/store_order/StoreOrderLogic.php | 38 +++---------------- app/common/logic/PayNotifyLogic.php | 2 +- 2 files changed, 6 insertions(+), 34 deletions(-) diff --git a/app/admin/logic/store_order/StoreOrderLogic.php b/app/admin/logic/store_order/StoreOrderLogic.php index 94910e3b0..57a1a28d2 100644 --- a/app/admin/logic/store_order/StoreOrderLogic.php +++ b/app/admin/logic/store_order/StoreOrderLogic.php @@ -132,49 +132,21 @@ class StoreOrderLogic extends BaseLogic $refund = (new \app\common\logic\store_order\StoreOrderLogic()) ->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]); + self::refundProduct($detail, $params); return '退款成功'; } } //余额支付 采购款支付 if (in_array($detail['pay_type'], [PayEnum::BALANCE_PAY, PayEnum::PURCHASE_FUNDS])) { PayNotifyLogic::balance_purchase_refund($detail,0,$params['refund_price']); + self::refundProduct($detail, $params); return '退款成功'; } //现金支付 if ($detail['pay_type'] = PayEnum::CASH_PAY) { PayNotifyLogic::cash_refund($params['order_id']); + self::refundProduct($detail, $params); return '退款成功'; } @@ -208,7 +180,7 @@ class StoreOrderLogic extends BaseLogic } } - public function refundProduct($detail, $params) + public static function refundProduct($detail, $params) { $refund_price = $params['refund_price']; $refund_num = 0; @@ -237,9 +209,9 @@ class StoreOrderLogic extends BaseLogic $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]); - StoreOrderCartInfo::where('oid', $detail['id'])->update(['is_pay' => -1]); } } diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index 7ec32a306..ae5f8b2c2 100644 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -855,7 +855,7 @@ class PayNotifyLogic extends BaseLogic $updateData[] = [ 'id' => $StoreBranchProduct['id'], 'stock' => $StoreBranchProduct['stock'] + $v['cart_num'], - // 'sales' => ['inc', $v['cart_num']] + 'sales' => ['dec', $v['cart_num']] // 'sales' => ['inc', $v['cart_num']] ]; } From 8a66d9162071f41e553cffb9672d5793b8906623 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Thu, 26 Sep 2024 11:38:54 +0800 Subject: [PATCH 2/9] =?UTF-8?q?feat(system=5Fstore=5Fstorage):=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=95=86=E5=93=81=E5=85=A5=E5=BA=93API=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SystemStoreStorageController.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/api/controller/system_store_storage/SystemStoreStorageController.php b/app/api/controller/system_store_storage/SystemStoreStorageController.php index a2dcf4cea..2aec9d636 100644 --- a/app/api/controller/system_store_storage/SystemStoreStorageController.php +++ b/app/api/controller/system_store_storage/SystemStoreStorageController.php @@ -6,7 +6,8 @@ namespace app\api\controller\system_store_storage; use app\api\controller\BaseApiController; use app\api\lists\system_store_storage\SystemStoreStorageLists; use app\api\lists\system_store_storage\SystemStoreStorageGroupLists; - +use app\common\model\store_branch_product\StoreBranchProduct; +use app\common\model\system_store_storage\SystemStoreStorage; /** * 门店入库控制器 @@ -36,4 +37,15 @@ class SystemStoreStorageController extends BaseApiController return $this->dataLists(new SystemStoreStorageGroupLists()); } + public function warehousing_add() { + $params = $this->request->post(); + $find=SystemStoreStorage::where('id',$params['id'])->find(); + if($find){ + $find->status=1; + $find->save(); + StoreBranchProduct::where(['product_id'=>$find['product_id'],'store_id'=>$find['store_id']])->inc('stock',$find['nums'])->update(); + return $this->success('操作成功'); + } + return $this->fail('操作失败'); + } } From 4e2fcf669f0e157a42a33d0227e02a0e8e2d6d27 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Thu, 26 Sep 2024 17:21:44 +0800 Subject: [PATCH 3/9] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E9=97=A8?= =?UTF-8?q?=E5=BA=97=E5=85=A5=E5=BA=93=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SystemStoreStorageController.php | 3 +++ .../store_branch_product/StoreBranchProduct.php | 12 ++++++++++-- app/common/model/store_order/StoreOrder.php | 12 +++++++++++- .../store_order_cart_info/StoreOrderCartInfo.php | 12 +++++++++++- app/common/model/store_product/StoreProduct.php | 12 ++++++++++-- app/common/model/user/User.php | 10 +++++++++- .../model/warehouse_product/WarehouseProduct.php | 12 +++++++++++- .../WarehouseProductStorege.php | 12 +++++++++++- 8 files changed, 76 insertions(+), 9 deletions(-) diff --git a/app/api/controller/system_store_storage/SystemStoreStorageController.php b/app/api/controller/system_store_storage/SystemStoreStorageController.php index 2aec9d636..c1e1fd1a1 100644 --- a/app/api/controller/system_store_storage/SystemStoreStorageController.php +++ b/app/api/controller/system_store_storage/SystemStoreStorageController.php @@ -37,6 +37,9 @@ class SystemStoreStorageController extends BaseApiController return $this->dataLists(new SystemStoreStorageGroupLists()); } + /** + * @notes 门店入库 + */ public function warehousing_add() { $params = $this->request->post(); $find=SystemStoreStorage::where('id',$params['id'])->find(); diff --git a/app/common/model/store_branch_product/StoreBranchProduct.php b/app/common/model/store_branch_product/StoreBranchProduct.php index ae0ad6b83..e03539d9e 100644 --- a/app/common/model/store_branch_product/StoreBranchProduct.php +++ b/app/common/model/store_branch_product/StoreBranchProduct.php @@ -41,10 +41,18 @@ class StoreBranchProduct extends BaseModel { return $this->hasOne(StoreProduct::class,'id','product_id'); } - + public static function onBeforeWrite($data) + { + try { + $where = $data->getWhere(); + $find = self::where($where)->field(array_keys($data->toArray()))->find()->toArray(); + channelLog(array_merge($find, $where),'branch_product','更新前'); + } catch (Throwable $e) { + Log::error('branch_product:' . $e->getMessage()); + } + } public static function onAfterWrite($data){ try{ - channelLog($data->getOrigin(),'branch_product','更新前'); channelLog($data->toArray(),'branch_product','更新后'); }catch(Throwable $e){ Log::error('branch_product:'.$e->getMessage()); diff --git a/app/common/model/store_order/StoreOrder.php b/app/common/model/store_order/StoreOrder.php index 815958362..d87ac40fe 100644 --- a/app/common/model/store_order/StoreOrder.php +++ b/app/common/model/store_order/StoreOrder.php @@ -101,9 +101,19 @@ class StoreOrder extends BaseModel ->group('days')->select()->toArray(); } + public static function onBeforeWrite($data) + { + try { + $where = $data->getWhere(); + $find = self::where($where)->field(array_keys($data->toArray()))->find()->toArray(); + channelLog(array_merge($find, $where),'store_order','更新前'); + } catch (Throwable $e) { + Log::error('store_order:' . $e->getMessage()); + } + } + public static function onAfterWrite($data){ try{ - channelLog($data->getOrigin(),'store_order','更新前'); channelLog($data->toArray(),'store_order','更新后'); }catch(Throwable $e){ Log::error('store_order:'.$e->getMessage()); diff --git a/app/common/model/store_order_cart_info/StoreOrderCartInfo.php b/app/common/model/store_order_cart_info/StoreOrderCartInfo.php index 93b2b3518..677c9a710 100644 --- a/app/common/model/store_order_cart_info/StoreOrderCartInfo.php +++ b/app/common/model/store_order_cart_info/StoreOrderCartInfo.php @@ -21,9 +21,19 @@ class StoreOrderCartInfo extends BaseModel return $this->hasOne(StoreBranchProduct::class,'id','product_id')->bind(['store_name','image','unit','price']); } + public static function onBeforeWrite($data) + { + try { + $where = $data->getWhere(); + $find = self::where($where)->field(array_keys($data->toArray()))->find()->toArray(); + channelLog(array_merge($find, $where),'store_order_cart_info','更新前'); + } catch (Throwable $e) { + Log::error('store_order_cart_info:' . $e->getMessage()); + } + } + public static function onAfterWrite($data){ try{ - channelLog($data->getOrigin(),'store_order_cart_info','更新前'); channelLog($data->toArray(),'store_order_cart_info','更新后'); }catch(Throwable $e){ Log::error('store_order_cart_info:'.$e->getMessage()); diff --git a/app/common/model/store_product/StoreProduct.php b/app/common/model/store_product/StoreProduct.php index ddcfe97e9..8d95ef264 100644 --- a/app/common/model/store_product/StoreProduct.php +++ b/app/common/model/store_product/StoreProduct.php @@ -33,10 +33,18 @@ class StoreProduct extends BaseModel return $this->hasOne(StoreCategory::class,'id','cate_id')->bind(['class_name'=>'name']); } - + public static function onBeforeWrite($data) + { + try { + $where = $data->getWhere(); + $find = self::where($where)->field(array_keys($data->toArray()))->find()->toArray(); + channelLog(array_merge($find, $where),'product','更新前'); + } catch (Throwable $e) { + Log::error('product:' . $e->getMessage()); + } + } public static function onAfterWrite($data){ try{ - channelLog($data->getOrigin(),'product','更新前'); channelLog($data->toArray(),'product','更新后'); }catch(Throwable $e){ Log::error('product:'.$e->getMessage()); diff --git a/app/common/model/user/User.php b/app/common/model/user/User.php index 704b7ed2a..8d615a728 100644 --- a/app/common/model/user/User.php +++ b/app/common/model/user/User.php @@ -197,9 +197,17 @@ class User extends BaseModel })->field("FROM_UNIXTIME($create_time,'$timeType') as days,count(id) as num")->group('days')->select()->toArray(); } + public static function onBeforeWrite($data){ + try{ + $where=$data->getWhere(); + $find=self::where($where)->field(array_keys($data->toArray()))->find()->toArray(); + channelLog(array_merge($find,$where),'user','更新前'); + }catch(Throwable $e){ + Log::error('user:'.$e->getMessage()); + } + } public static function onAfterWrite($data){ try{ - channelLog($data->getOrigin(),'user','更新前'); channelLog($data->toArray(),'user','更新后'); }catch(Throwable $e){ Log::error('user:'.$e->getMessage()); diff --git a/app/common/model/warehouse_product/WarehouseProduct.php b/app/common/model/warehouse_product/WarehouseProduct.php index 24e61c73e..7ca934e18 100644 --- a/app/common/model/warehouse_product/WarehouseProduct.php +++ b/app/common/model/warehouse_product/WarehouseProduct.php @@ -19,9 +19,19 @@ class WarehouseProduct extends BaseModel protected $name = 'warehouse_product'; protected $deleteTime = 'delete_time'; + public static function onBeforeWrite($data) + { + try { + $where = $data->getWhere(); + $find = self::where($where)->field(array_keys($data->toArray()))->find()->toArray(); + channelLog(array_merge($find, $where),'warehouse_product','更新前'); + } catch (Throwable $e) { + Log::error('warehouse_product:' . $e->getMessage()); + } + } + public static function onAfterWrite($data){ try{ - channelLog($data->getOrigin(),'warehouse_product','更新前'); channelLog($data->toArray(),'warehouse_product','更新后'); }catch(Throwable $e){ Log::error('warehouse_product:'.$e->getMessage()); diff --git a/app/common/model/warehouse_product_storege/WarehouseProductStorege.php b/app/common/model/warehouse_product_storege/WarehouseProductStorege.php index 9d86d6924..e120dcf09 100644 --- a/app/common/model/warehouse_product_storege/WarehouseProductStorege.php +++ b/app/common/model/warehouse_product_storege/WarehouseProductStorege.php @@ -18,10 +18,20 @@ class WarehouseProductStorege extends BaseModel use SoftDelete; protected $name = 'warehouse_product_storege'; protected $deleteTime = 'delete_time'; + + public static function onBeforeWrite($data) + { + try { + $where = $data->getWhere(); + $find = self::where($where)->field(array_keys($data->toArray()))->find()->toArray(); + channelLog(array_merge($find, $where), 'warehouse_product_storege', '更新前'); + } catch (Throwable $e) { + Log::error('warehouse_product_storege:' . $e->getMessage()); + } + } public static function onAfterWrite($data) { try { - channelLog($data->getOrigin(), 'warehouse_product_storege', '更新前'); channelLog($data->toArray(), 'warehouse_product_storege', '更新后'); } catch (Throwable $e) { Log::error('warehouse_product_storege:' . $e->getMessage()); From 5e13b684a8a7e9b9725eda393506cbc51c4b35b3 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Thu, 26 Sep 2024 21:20:57 +0800 Subject: [PATCH 4/9] =?UTF-8?q?feat(OrderController):=20=E5=9C=A8=E8=AE=A2?= =?UTF-8?q?=E5=8D=95API=E4=B8=AD=E5=A2=9E=E5=8A=A0=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E7=BB=B4=E6=8A=A4=E6=9A=82=E5=81=9C=E4=BA=A4=E6=98=93=E6=8F=90?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/order/OrderController.php | 2 ++ app/store/controller/store_order/StoreOrderController.php | 1 + 2 files changed, 3 insertions(+) diff --git a/app/api/controller/order/OrderController.php b/app/api/controller/order/OrderController.php index 3a126f617..fdfea135d 100644 --- a/app/api/controller/order/OrderController.php +++ b/app/api/controller/order/OrderController.php @@ -121,6 +121,8 @@ class OrderController extends BaseApiController */ public function createOrder() { + return $this->fail('系统维护中,暂停交易。维护时间2024年9月27日-28日'); + $cartId = (array)$this->request->post('cart_id', []); $store_id =$this->request->post('store_id', 0); $pay_type = (int)$this->request->post('pay_type'); diff --git a/app/store/controller/store_order/StoreOrderController.php b/app/store/controller/store_order/StoreOrderController.php index 5d7939187..228780a16 100644 --- a/app/store/controller/store_order/StoreOrderController.php +++ b/app/store/controller/store_order/StoreOrderController.php @@ -159,6 +159,7 @@ class StoreOrderController extends BaseAdminController */ public function createOrder() { + return $this->fail('系统维护中,暂停交易。维护时间2024年9月27日-28日'); $cartId = (array)$this->request->post('cart_id', []); $pay_type = (int)$this->request->post('pay_type'); $addressId = (int)$this->request->post('address_id'); From 362c3481405359b8671afbe8be6d5218719f21ef Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Thu, 26 Sep 2024 21:29:19 +0800 Subject: [PATCH 5/9] =?UTF-8?q?feat(OrderController,=20StoreOrderControlle?= =?UTF-8?q?r):=20=E7=A7=BB=E9=99=A4=E7=B3=BB=E7=BB=9F=E7=BB=B4=E6=8A=A4?= =?UTF-8?q?=E6=9A=82=E5=81=9C=E4=BA=A4=E6=98=93=E6=8F=90=E7=A4=BA=EF=BC=8C?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=AE=A2=E5=8D=95API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/order/OrderController.php | 2 -- app/store/controller/store_order/StoreOrderController.php | 1 - 2 files changed, 3 deletions(-) diff --git a/app/api/controller/order/OrderController.php b/app/api/controller/order/OrderController.php index fdfea135d..3a126f617 100644 --- a/app/api/controller/order/OrderController.php +++ b/app/api/controller/order/OrderController.php @@ -121,8 +121,6 @@ class OrderController extends BaseApiController */ public function createOrder() { - return $this->fail('系统维护中,暂停交易。维护时间2024年9月27日-28日'); - $cartId = (array)$this->request->post('cart_id', []); $store_id =$this->request->post('store_id', 0); $pay_type = (int)$this->request->post('pay_type'); diff --git a/app/store/controller/store_order/StoreOrderController.php b/app/store/controller/store_order/StoreOrderController.php index 228780a16..5d7939187 100644 --- a/app/store/controller/store_order/StoreOrderController.php +++ b/app/store/controller/store_order/StoreOrderController.php @@ -159,7 +159,6 @@ class StoreOrderController extends BaseAdminController */ public function createOrder() { - return $this->fail('系统维护中,暂停交易。维护时间2024年9月27日-28日'); $cartId = (array)$this->request->post('cart_id', []); $pay_type = (int)$this->request->post('pay_type'); $addressId = (int)$this->request->post('address_id'); From e2e470d0926aa74839224ad25e2163f24743c5f9 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Fri, 27 Sep 2024 18:16:07 +0800 Subject: [PATCH 6/9] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=BA=97?= =?UTF-8?q?=E9=93=BA=E6=94=B6=E6=94=AFAPI=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BranchProductController.php | 3 ++ app/api/controller/store/StoreController.php | 43 +++++++++++++++++++ .../StoreOrderCartInfoController.php | 7 ++- .../SystemStoreStorageController.php | 11 +++++ .../SystemStoreStorageGroupLists.php | 5 +++ .../SystemStoreStorageLists.php | 6 +++ 6 files changed, 73 insertions(+), 2 deletions(-) diff --git a/app/api/controller/branch_product/BranchProductController.php b/app/api/controller/branch_product/BranchProductController.php index c08f43515..df4786119 100644 --- a/app/api/controller/branch_product/BranchProductController.php +++ b/app/api/controller/branch_product/BranchProductController.php @@ -4,6 +4,7 @@ namespace app\api\controller\branch_product; use app\api\controller\BaseApiController; use app\api\lists\branch_product\BranchProductLists; +use app\common\model\system_store\SystemStoreStaff; class BranchProductController extends BaseApiController { @@ -14,6 +15,8 @@ class BranchProductController extends BaseApiController */ public function lists() { + $store_id=SystemStoreStaff::where('uid',$this->userId)->value('store_id'); + $this->request->__set('store_id',$store_id); return $this->dataLists(new BranchProductLists()); } } diff --git a/app/api/controller/store/StoreController.php b/app/api/controller/store/StoreController.php index 5bbfb08e5..a9b554b3b 100644 --- a/app/api/controller/store/StoreController.php +++ b/app/api/controller/store/StoreController.php @@ -13,10 +13,15 @@ use app\common\enum\PayEnum; use app\common\logic\PaymentLogic; use app\common\logic\PayNotifyLogic; use app\common\model\Config; +use app\common\model\store_finance_flow\StoreFinanceFlow; +use app\common\model\store_order\StoreOrder; +use app\common\model\system_store\SystemStore; +use app\common\model\system_store\SystemStoreStaff; use app\common\model\user\User; use app\common\model\user\UserAddress; use app\common\model\user_create_log\UserCreateLog; use app\common\model\user_recharge\UserRecharge; +use app\common\model\warehouse_product\WarehouseProduct; use app\common\service\Curl; use Exception; use support\Cache; @@ -210,4 +215,42 @@ class StoreController extends BaseApiController ]; return $this->success('ok',['menu'=>$menu]); } + + /** + * 店铺收支 + */ + public function store_statistics(){ + $store_id=SystemStoreStaff::where('uid',$this->userId)->value('store_id'); + if(!$store_id){ + return $this->fail('请先绑定店铺'); + } + $total_price=WarehouseProduct::where('store_id',$store_id)->where('financial_pm',0)->sum('total_price'); + $order=StoreOrder::where('store_id',$store_id)->where('refund_status',0)->field('sum(refund_price) as refund_price,sum(pay_price) as pay_price')->find(); + $pay_price=bcsub($order['pay_price'],$order['refund_price'],2); + + $commission=StoreFinanceFlow::where('store_id',$store_id)->where('financial_pm',0)->where('financial_type',3)->sum('number'); + $bond=StoreFinanceFlow::where('store_id',$store_id)->where('financial_pm',0)->where('financial_type',11)->sum('number'); + $vip=StoreFinanceFlow::where('store_id',$store_id)->where('financial_pm',0)->where('financial_type',12)->sum('number'); + $village=StoreFinanceFlow::where('store_id',$store_id)->where('financial_pm',0)->where('financial_type',14)->sum('number'); + $brigade=StoreFinanceFlow::where('store_id',$store_id)->where('financial_pm',0)->where('financial_type',15)->sum('number'); + $attrition=StoreFinanceFlow::where('store_id',$store_id)->where('financial_pm',0)->where('financial_type',16)->sum('number'); + + $money=bcadd($commission,$bond,2); + $money=bcadd($money,$vip,2); + $money=bcadd($money,$village,2); + $money=bcadd($money,$brigade,2); + $expenditure=bcadd($money,$attrition,2); + + + $store_money=SystemStore::where('id',$store_id)->value('store_money'); + + $list=[ + ['name'=>'手续费','data'=>[$commission]], + ['name'=>'保证金','data'=>[$bond]], + ['name'=>'厨师','data'=>[$vip]], + ['name'=>'村长','data'=>[$village]], + ['name'=>'队长','data'=>[$brigade]], + ]; + return $this->success('ok',['total_price'=>$total_price,'pay_price'=>$pay_price,'list'=>$list,'attrition'=>$attrition,'store_money'=>$store_money,'expenditure'=>$expenditure]); + } } diff --git a/app/api/controller/store_order_cart_info/StoreOrderCartInfoController.php b/app/api/controller/store_order_cart_info/StoreOrderCartInfoController.php index e85d6710d..5134d6129 100644 --- a/app/api/controller/store_order_cart_info/StoreOrderCartInfoController.php +++ b/app/api/controller/store_order_cart_info/StoreOrderCartInfoController.php @@ -6,6 +6,7 @@ namespace app\api\controller\store_order_cart_info; use app\api\controller\BaseApiController; use app\api\lists\store_order_cart_info\StoreOrderCartInfoGroupLists; use app\api\lists\store_order_cart_info\StoreOrderCartInfoLists; +use app\common\model\system_store\SystemStoreStaff; /** * 商品销量控制器 @@ -22,13 +23,15 @@ class StoreOrderCartInfoController extends BaseApiController */ public function lists() { - $this->request->__set('store_id',5); + $store_id=SystemStoreStaff::where('uid',$this->userId)->value('store_id'); + $this->request->__set('store_id',$store_id); return $this->dataLists(new StoreOrderCartInfoLists()); } public function group_lists() { - $this->request->__set('store_id',5); + $store_id=SystemStoreStaff::where('uid',$this->userId)->value('store_id'); + $this->request->__set('store_id',$store_id); return $this->dataLists(new StoreOrderCartInfoGroupLists()); } } diff --git a/app/api/controller/system_store_storage/SystemStoreStorageController.php b/app/api/controller/system_store_storage/SystemStoreStorageController.php index c1e1fd1a1..a9eb68379 100644 --- a/app/api/controller/system_store_storage/SystemStoreStorageController.php +++ b/app/api/controller/system_store_storage/SystemStoreStorageController.php @@ -7,6 +7,7 @@ use app\api\controller\BaseApiController; use app\api\lists\system_store_storage\SystemStoreStorageLists; use app\api\lists\system_store_storage\SystemStoreStorageGroupLists; use app\common\model\store_branch_product\StoreBranchProduct; +use app\common\model\system_store\SystemStoreStaff; use app\common\model\system_store_storage\SystemStoreStorage; /** @@ -24,6 +25,11 @@ class SystemStoreStorageController extends BaseApiController */ public function lists() { + $store_id=SystemStoreStaff::where('uid',$this->userId)->value('store_id'); + if(!$store_id){ + return $this->fail('请先绑定店铺'); + } + $this->request->__set('store_id',$store_id); return $this->dataLists(new SystemStoreStorageLists()); } /** @@ -34,6 +40,11 @@ class SystemStoreStorageController extends BaseApiController */ public function group_lists() { + $store_id=SystemStoreStaff::where('uid',$this->userId)->value('store_id'); + if(!$store_id){ + return $this->fail('请先绑定店铺'); + } + $this->request->__set('store_id',$store_id); return $this->dataLists(new SystemStoreStorageGroupLists()); } diff --git a/app/api/lists/system_store_storage/SystemStoreStorageGroupLists.php b/app/api/lists/system_store_storage/SystemStoreStorageGroupLists.php index 84fbaca3d..f44c869fc 100644 --- a/app/api/lists/system_store_storage/SystemStoreStorageGroupLists.php +++ b/app/api/lists/system_store_storage/SystemStoreStorageGroupLists.php @@ -62,6 +62,11 @@ class SystemStoreStorageGroupLists extends BaseApiDataLists implements ListsSear */ public function lists(): array { + $store_id=$this->request->__get('store_id'); + if(!$store_id){ + return []; + } + $this->searchWhere[] = ['store_id', '=', $store_id]; $fields = 'store_id,product_id,sum(nums) as nums,mark'; if ($this->request->get('store_name')) { $store_name = $this->request->get('store_name'); diff --git a/app/api/lists/system_store_storage/SystemStoreStorageLists.php b/app/api/lists/system_store_storage/SystemStoreStorageLists.php index f3674d2cb..eccaa3362 100644 --- a/app/api/lists/system_store_storage/SystemStoreStorageLists.php +++ b/app/api/lists/system_store_storage/SystemStoreStorageLists.php @@ -62,6 +62,12 @@ class SystemStoreStorageLists extends BaseApiDataLists implements ListsSearchInt */ public function lists(): array { + $store_id=$this->request->__get('store_id'); + if(!$store_id){ + return []; + } + $this->searchWhere[] = ['store_id', '=', $store_id]; + $fields = 'id,store_id,staff_id,product_id,warehouse_id,nums,mark,status'; if ($this->request->get('store_name')) { $store_name = $this->request->get('store_name'); From a0bc9222074fc06c93fba56f92bfc738e7529984 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sat, 28 Sep 2024 09:24:54 +0800 Subject: [PATCH 7/9] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=E4=BA=86?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E7=9B=B8=E5=85=B3=E7=9A=84API=E9=80=BB?= =?UTF-8?q?=E8=BE=91=EF=BC=8C=E7=A7=BB=E9=99=A4=E4=BA=86=E4=B8=8D=E5=BF=85?= =?UTF-8?q?=E8=A6=81=E7=9A=84=E7=BB=8F=E7=BA=AC=E5=BA=A6=E5=8F=82=E6=95=B0?= =?UTF-8?q?=EF=BC=8C=E5=B9=B6=E4=BC=98=E5=8C=96=E4=BA=86=E6=88=90=E6=9C=AC?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=E6=96=B9=E5=BC=8F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/order/OrderController.php | 8 +----- app/api/logic/order/OrderLogic.php | 26 +++----------------- app/common/logic/PayNotifyLogic.php | 2 +- 3 files changed, 6 insertions(+), 30 deletions(-) diff --git a/app/api/controller/order/OrderController.php b/app/api/controller/order/OrderController.php index 3a126f617..9b0e7b86c 100644 --- a/app/api/controller/order/OrderController.php +++ b/app/api/controller/order/OrderController.php @@ -339,18 +339,12 @@ class OrderController extends BaseApiController public function detail() { $order_id = (int)$this->request->get('order_id'); - $lat = $this->request->get('lat', ''); - $lng = $this->request->get('long', ''); $where = [ 'id' => $order_id, 'uid' => $this->userId, ]; $url = 'https://' . $this->request->host(true); - $parm = [ - 'lat' => $lat, - 'long' => $lng - ]; - $order = OrderLogic::detail($where, $url, $parm); + $order = OrderLogic::detail($where, $url); if ($order) { return $this->data($order); } else { diff --git a/app/api/logic/order/OrderLogic.php b/app/api/logic/order/OrderLogic.php index 046e50d24..c420d9581 100644 --- a/app/api/logic/order/OrderLogic.php +++ b/app/api/logic/order/OrderLogic.php @@ -149,7 +149,7 @@ class OrderLogic extends BaseLogic //利润 // $cart_select[$k]['profit'] = bcmul($v['cart_num'], $onePrice, 2); //利润 - $cart_select[$k]['purchase'] = bcmul($v['cart_num'], $find['purchase'], 2) ?? 0; //成本 + $cart_select[$k]['total_purchase'] = bcmul($v['cart_num'], $find['purchase'], 2) ?? 0; //成本 $cart_select[$k]['pay_price'] = bcmul($v['cart_num'], $price, 2); //订单支付金额 $cart_select[$k]['store_price'] = bcmul($v['cart_num'], $find['cost'], 2) ?? 0; //商户价 $cart_select[$k]['vip_price'] = bcmul($v['cart_num'], $find['vip_price'], 2) ?? 0; //vip售价 @@ -181,13 +181,14 @@ class OrderLogic extends BaseLogic $cart_select[$k]['cart_info'] = json_encode($cartInfo); //理论上每笔都是拆分了 $cart_select[$k]['name'] = $find['store_name']; + $cart_select[$k]['purchase'] = $find['purchase']; $cart_select[$k]['imgs'] = $find['image']; $cart_select[$k]['store_id'] = $params['store_id'] ?? 0; $cart_select[$k]['unit_name'] = StoreProductUnit::where(['id' => $find['unit']])->value('name'); $cart_select[$k]['total_price'] = $cart_select[$k]['pay_price']; self::$total_price = bcadd(self::$total_price, $cart_select[$k]['total_price'], 2); self::$pay_price = bcadd(self::$pay_price, $cart_select[$k]['pay_price'], 2); - self::$cost = bcadd(self::$cost, $cart_select[$k]['purchase'], 2); + self::$cost = bcadd(self::$cost, $cart_select[$k]['total_purchase'], 2); self::$store_price = bcadd(self::$store_price, $cart_select[$k]['store_price'], 2); //商户价 self::$deduction_price = bcadd(self::$deduction_price, $deduction_price, 2); //抵扣金额 // self::$frozen_money = bcadd(self::$frozen_money, $cart_select[$k]['vip_frozen_price'], 2); //返还金额 @@ -343,7 +344,6 @@ class OrderLogic extends BaseLogic $goods_list[$k]['oid'] = $order->id; $goods_list[$k]['uid'] = $uid; $goods_list[$k]['cart_id'] = implode(',', $cartId); - $goods_list[$k]['delivery_id'] = $params['store_id']; //商家id } (new StoreOrderCartInfo())->saveAll($goods_list); $where = ['is_pay' => 0]; @@ -500,13 +500,11 @@ class OrderLogic extends BaseLogic if ($find) { $find['goods_list'] = StoreOrderCartInfo::where('oid', $find['id']) - ->field('product_id,cart_num nums,store_id')->select()->each(function ($item) use ($find) { + ->field('product_id,cart_num nums,store_id,price')->select()->each(function ($item) { $find = StoreProduct::where('id', $item['product_id'])->withTrashed()->find(); - $item['store_name'] = $find['store_name']; $item['nums'] = floatval($item['nums']); $item['image'] = $find['image']; - $item['price'] = $find['price']; $item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name') ?? ''; $item['msg'] = '预计48小时发货'; return $item; @@ -523,22 +521,6 @@ class OrderLogic extends BaseLogic $tmpFilename = $generator->getBarcode($find['verify_code'], $generator::TYPE_CODE_128); $find['verify_base64'] = 'data:image/png;base64,' . base64_encode($tmpFilename); } - //处理返回最近的店铺 - if ($param['lat'] && $param['long']) { - $storeAll = SystemStore::field('id,name,phone,address,detailed_address,latitude,longitude')->select()->toArray(); - $nearestStore = null; - $minDistance = PHP_FLOAT_MAX; - foreach ($storeAll as $value) { - $value['distance'] = haversineDistance($value['latitude'], $value['longitude'], $param['lat'], $param['long']); - if ($value['distance'] < $minDistance) { - $minDistance = $value['distance']; - $nearestStore = $value; - } - } - if ($nearestStore) { - $find['near_store'] = $nearestStore; - } - } } return $find; } diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index ae5f8b2c2..2647d6275 100644 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -684,7 +684,7 @@ class PayNotifyLogic extends BaseLogic } try { - $info = StoreOrderCartInfo::where('oid', $order['id'])->field('store_id,product_id,price,cart_num')->select(); + $info = StoreOrderCartInfo::where('oid', $order['id'])->field('store_id,product_id,price,purchase,cart_num')->select(); $comm = new CommissionProductLogic(); foreach ($info as $k => $v) { $comm->calculate_product_flow($v, $order, $village_uid, $brigade_uid, $user_ship); From 218aa8c23f8fcb29ae6f707eea260b176b5f0dbf Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sat, 28 Sep 2024 09:48:04 +0800 Subject: [PATCH 8/9] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=E4=BC=9A?= =?UTF-8?q?=E5=91=98=E5=88=A9=E6=B6=A6=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 --- app/common/logic/CommissionProductLogic.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/common/logic/CommissionProductLogic.php b/app/common/logic/CommissionProductLogic.php index 0e3e29b48..ba685ae95 100644 --- a/app/common/logic/CommissionProductLogic.php +++ b/app/common/logic/CommissionProductLogic.php @@ -120,9 +120,11 @@ class CommissionProductLogic extends BaseLogic $data[] =$this->attrition('零售损耗', $order, $find, $price, $total_price,$attrition_number); } } elseif ($user['user_ship'] == 1) { - $vip_number = bcmul($total_price, 0.06, 2); //会员利润 - $data[] = $this->vip_user('零售会员', $order, $find, $uid, $price, $total_price, $vip_number,0.06); - $number1 = bcadd($number1, $vip_number, 2); + if(bcsub($user['total_recharge_amount'],$user['purchase_funds'],2)>$user['first_purchase_funds']){ + $vip_number = bcmul($total_price, 0.06, 2); //会员利润 + $data[] = $this->vip_user('零售会员', $order, $find, $uid, $price, $total_price, $vip_number,0.06); + $number1 = bcadd($number1, $vip_number, 2); + } if ($rose >= 12 && $village_uid>0) { $village_number = bcmul($total_price, 0.01, 2); //村长利润 $data[] =$this->village('零售村长', $order, $find, $village_uid, $price, $total_price, $village_number,0.01); From bb562f86ee34c57e34d9476996f6d2aaa2314eb0 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sat, 28 Sep 2024 10:54:09 +0800 Subject: [PATCH 9/9] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E4=BA=86?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E5=A4=84=E7=90=86=E6=9C=BA=E5=88=B6=EF=BC=8C?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BA=86=E4=BB=A3=E7=A0=81=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/logic/order/OrderLogic.php | 2 +- app/common/logic/CommissionProductLogic.php | 5 +++-- .../store_branch_product/StoreBranchProduct.php | 8 ++++++-- app/common/model/store_order/StoreOrder.php | 12 ++++++++---- .../store_order_cart_info/StoreOrderCartInfo.php | 8 ++++++-- app/common/model/store_product/StoreProduct.php | 8 ++++++-- app/common/model/user/User.php | 8 ++++++-- .../model/warehouse_product/WarehouseProduct.php | 8 ++++++-- .../WarehouseProductStorege.php | 8 ++++++-- 9 files changed, 48 insertions(+), 19 deletions(-) diff --git a/app/api/logic/order/OrderLogic.php b/app/api/logic/order/OrderLogic.php index c420d9581..856c5b75a 100644 --- a/app/api/logic/order/OrderLogic.php +++ b/app/api/logic/order/OrderLogic.php @@ -351,7 +351,7 @@ class OrderLogic extends BaseLogic Db::commit(); return $order; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); throw new BusinessException($e->getMessage()); } diff --git a/app/common/logic/CommissionProductLogic.php b/app/common/logic/CommissionProductLogic.php index ba685ae95..13584e2a7 100644 --- a/app/common/logic/CommissionProductLogic.php +++ b/app/common/logic/CommissionProductLogic.php @@ -120,7 +120,9 @@ class CommissionProductLogic extends BaseLogic $data[] =$this->attrition('零售损耗', $order, $find, $price, $total_price,$attrition_number); } } elseif ($user['user_ship'] == 1) { - if(bcsub($user['total_recharge_amount'],$user['purchase_funds'],2)>$user['first_purchase_funds']){ + if($order['pay_type']==18 && bcsub($user['total_recharge_amount'],$user['purchase_funds'],2)<$user['first_purchase_funds']){ + + }else{ $vip_number = bcmul($total_price, 0.06, 2); //会员利润 $data[] = $this->vip_user('零售会员', $order, $find, $uid, $price, $total_price, $vip_number,0.06); $number1 = bcadd($number1, $vip_number, 2); @@ -158,7 +160,6 @@ class CommissionProductLogic extends BaseLogic if ($rose >= 6) { $data[] = $this->platform('零售平台', $order, $find, $price, $total_price,$platform_number); } - (new StoreFinanceFlowProduct())->saveAll($data); } diff --git a/app/common/model/store_branch_product/StoreBranchProduct.php b/app/common/model/store_branch_product/StoreBranchProduct.php index e03539d9e..494edb295 100644 --- a/app/common/model/store_branch_product/StoreBranchProduct.php +++ b/app/common/model/store_branch_product/StoreBranchProduct.php @@ -45,8 +45,12 @@ class StoreBranchProduct extends BaseModel { try { $where = $data->getWhere(); - $find = self::where($where)->field(array_keys($data->toArray()))->find()->toArray(); - channelLog(array_merge($find, $where),'branch_product','更新前'); + if($data){ + $find = self::where($where)->field(array_keys($data->toArray()))->find(); + if($find){ + channelLog(array_merge($find->toArray(), $where),'branch_product','更新前'); + } + } } catch (Throwable $e) { Log::error('branch_product:' . $e->getMessage()); } diff --git a/app/common/model/store_order/StoreOrder.php b/app/common/model/store_order/StoreOrder.php index d87ac40fe..e373c780f 100644 --- a/app/common/model/store_order/StoreOrder.php +++ b/app/common/model/store_order/StoreOrder.php @@ -105,10 +105,14 @@ class StoreOrder extends BaseModel { try { $where = $data->getWhere(); - $find = self::where($where)->field(array_keys($data->toArray()))->find()->toArray(); - channelLog(array_merge($find, $where),'store_order','更新前'); + if($data){ + $find = self::where($where)->field(array_keys($data->toArray()))->find(); + if($find){ + channelLog(array_merge($find->toArray(), $where),'store_order','更新前'); + } + } } catch (Throwable $e) { - Log::error('store_order:' . $e->getMessage()); + Log::error('store_order:更新前' . $e->getMessage()); } } @@ -116,7 +120,7 @@ class StoreOrder extends BaseModel try{ channelLog($data->toArray(),'store_order','更新后'); }catch(Throwable $e){ - Log::error('store_order:'.$e->getMessage()); + Log::error('store_order:更新后'.$e->getMessage()); } } } diff --git a/app/common/model/store_order_cart_info/StoreOrderCartInfo.php b/app/common/model/store_order_cart_info/StoreOrderCartInfo.php index 677c9a710..a3c407b10 100644 --- a/app/common/model/store_order_cart_info/StoreOrderCartInfo.php +++ b/app/common/model/store_order_cart_info/StoreOrderCartInfo.php @@ -25,8 +25,12 @@ class StoreOrderCartInfo extends BaseModel { try { $where = $data->getWhere(); - $find = self::where($where)->field(array_keys($data->toArray()))->find()->toArray(); - channelLog(array_merge($find, $where),'store_order_cart_info','更新前'); + if($data){ + $find = self::where($where)->field(array_keys($data->toArray()))->find(); + if($find){ + channelLog(array_merge($find->toArray(),$where),'store_order_cart_info','更新前'); + } + } } catch (Throwable $e) { Log::error('store_order_cart_info:' . $e->getMessage()); } diff --git a/app/common/model/store_product/StoreProduct.php b/app/common/model/store_product/StoreProduct.php index 8d95ef264..9dcaed539 100644 --- a/app/common/model/store_product/StoreProduct.php +++ b/app/common/model/store_product/StoreProduct.php @@ -37,8 +37,12 @@ class StoreProduct extends BaseModel { try { $where = $data->getWhere(); - $find = self::where($where)->field(array_keys($data->toArray()))->find()->toArray(); - channelLog(array_merge($find, $where),'product','更新前'); + if($data){ + $find = self::where($where)->field(array_keys($data->toArray()))->find(); + if ($find) { + channelLog(array_merge($find->toArray(), $where), 'product', '更新前'); + } + } } catch (Throwable $e) { Log::error('product:' . $e->getMessage()); } diff --git a/app/common/model/user/User.php b/app/common/model/user/User.php index 8d615a728..78c226694 100644 --- a/app/common/model/user/User.php +++ b/app/common/model/user/User.php @@ -200,8 +200,12 @@ class User extends BaseModel public static function onBeforeWrite($data){ try{ $where=$data->getWhere(); - $find=self::where($where)->field(array_keys($data->toArray()))->find()->toArray(); - channelLog(array_merge($find,$where),'user','更新前'); + if($data){ + $find=self::where($where)->field(array_keys($data->toArray()))->find(); + if($find){ + channelLog(array_merge($find->toArray(),$where),'user','更新前'); + } + } }catch(Throwable $e){ Log::error('user:'.$e->getMessage()); } diff --git a/app/common/model/warehouse_product/WarehouseProduct.php b/app/common/model/warehouse_product/WarehouseProduct.php index 7ca934e18..fb086e088 100644 --- a/app/common/model/warehouse_product/WarehouseProduct.php +++ b/app/common/model/warehouse_product/WarehouseProduct.php @@ -23,8 +23,12 @@ class WarehouseProduct extends BaseModel { try { $where = $data->getWhere(); - $find = self::where($where)->field(array_keys($data->toArray()))->find()->toArray(); - channelLog(array_merge($find, $where),'warehouse_product','更新前'); + if($data){ + $find = self::where($where)->field(array_keys($data->toArray()))->find(); + if($find){ + channelLog(array_merge($find->toArray(), $where),'warehouse_product','更新前'); + } + } } catch (Throwable $e) { Log::error('warehouse_product:' . $e->getMessage()); } diff --git a/app/common/model/warehouse_product_storege/WarehouseProductStorege.php b/app/common/model/warehouse_product_storege/WarehouseProductStorege.php index e120dcf09..172b611f8 100644 --- a/app/common/model/warehouse_product_storege/WarehouseProductStorege.php +++ b/app/common/model/warehouse_product_storege/WarehouseProductStorege.php @@ -23,8 +23,12 @@ class WarehouseProductStorege extends BaseModel { try { $where = $data->getWhere(); - $find = self::where($where)->field(array_keys($data->toArray()))->find()->toArray(); - channelLog(array_merge($find, $where), 'warehouse_product_storege', '更新前'); + if($data){ + $find = self::where($where)->field(array_keys($data->toArray()))->find(); + if($find){ + channelLog(array_merge($find->toArray(), $where), 'warehouse_product_storege', '更新前'); + } + } } catch (Throwable $e) { Log::error('warehouse_product_storege:' . $e->getMessage()); }