From 7cd251c4ee9012b22dcdb57ff8cc8afd7e05a489 Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Sat, 8 Jun 2024 14:17:05 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=A6=96=E9=A1=B5?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/store/logic/WorkbenchLogic.php | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/app/store/logic/WorkbenchLogic.php b/app/store/logic/WorkbenchLogic.php index 9df3aa60e..28cd120f7 100644 --- a/app/store/logic/WorkbenchLogic.php +++ b/app/store/logic/WorkbenchLogic.php @@ -18,6 +18,7 @@ namespace app\store\logic; use app\common\enum\PayEnum; use app\common\logic\BaseLogic; use app\common\logic\store_order\StoreOrderLogic; +use app\common\model\store_cash_finance_flow\StoreCashFinanceFlow; use app\common\model\store_order\StoreOrder; use app\common\service\ConfigService; use app\common\service\FileService; @@ -30,13 +31,7 @@ use app\common\service\FileService; */ class WorkbenchLogic extends BaseLogic { - /** - * @notes 工作套 - * @param $adminInfo - * @return array - * @author 乔峰 - * @date 2021/12/29 15:58 - */ + public static function index($params) { $data = []; @@ -48,11 +43,17 @@ class WorkbenchLogic extends BaseLogic throw new \Exception('时间范围不能超过一年'); } $orderLogic = new StoreOrderLogic(); + //订单总金额 $data['order_amount'] = $orderLogic->storeOrderSumByDate($params['store_id'], $startTime, $endTime); + //余额支付总金额 $data['balance_amount'] = $orderLogic->storeOrderSumByDate($params['store_id'], $startTime, $endTime, ['pay_type' => PayEnum::BALANCE_PAY]); + //线下收银总金额 $data['cashier_amount'] = $orderLogic->storeOrderSumByDate($params['store_id'], $startTime, $endTime, ['shipping_type' => 3]); - $data['delivery_amount'] = $orderLogic->storeOrderSumByDate($params['store_id'], $startTime, $endTime, ['shipping_type' => 1]); + //现金收银总金额 + $data['cash_amount'] = StoreCashFinanceFlow::where('store_id', $params['store_id'])->whereBetweenTime('create_time', $startTime, $endTime)->sum('cash_price'); + //核销订单金额 $data['verify_amount'] = $orderLogic->storeOrderSumByDate($params['store_id'], $startTime, $endTime, ['shipping_type' => 2]); + //门店成交用户数 $data['user_number'] = StoreOrder::where('store_id', $params['store_id']) ->where('paid', 1) ->whereBetweenTime('create_time', $startTime, $endTime) @@ -122,6 +123,17 @@ class WorkbenchLogic extends BaseLogic 'user_number' => array_values($userListTmp) ] ]; + $data['order_list'] = StoreOrder::with('user')->where('store_id', $params['store_id']) + ->where('paid', 1) + ->whereBetweenTime('create_time', $startTime, $endTime) + ->order('create_time', 'desc') + ->limit(10) + ->select()->toArray(); + $data['pay_type'] = [ + ['name' => '线上收银订单', 'value' => bcsub($data['order_amount'], bcadd($data['verify_amount'], $data['cash_amount'], 2), 2)], + ['name' => '核销订单', 'value' => $data['verify_amount']], + ['name' => '现金收银订单', 'value' => $data['cash_amount']], + ]; return $data; } From ac775b0b68f503b88fb4daec3016ff71dfa2d1e3 Mon Sep 17 00:00:00 2001 From: liu <1873441552@qq.com> Date: Sat, 8 Jun 2024 14:17:44 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E9=80=80=E6=AC=BE=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E5=9F=BA=E7=A1=80=E4=BB=A3=E7=A0=81,=E5=92=8C=E9=A2=84?= =?UTF-8?q?=E7=BA=A6=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/PayController.php | 10 ++++++++++ app/api/logic/order/OrderLogic.php | 1 + app/common/enum/OrderEnum.php | 3 +++ app/common/logic/PayNotifyLogLogic.php | 11 +++++++++-- app/common/logic/PayNotifyLogic.php | 25 ++++++++++++++++++++++++- 5 files changed, 47 insertions(+), 3 deletions(-) diff --git a/app/api/controller/PayController.php b/app/api/controller/PayController.php index afcc79610..fa468d88b 100644 --- a/app/api/controller/PayController.php +++ b/app/api/controller/PayController.php @@ -44,6 +44,16 @@ class PayController extends BaseApiController break; } } + }else{ + if ($result && $result->event_type == 'REFUND.SUCCESS') { + $ciphertext = $result->resource['ciphertext']; + if ($ciphertext['refund_status'] === 'SUCCESS') { + //处理订单 -1判断是退的一单还是拆分的订单 + PayNotifyLogic::handle('refund', $ciphertext['out_trade_no'], $ciphertext); + $app->wechat->success(); + + } + } } } diff --git a/app/api/logic/order/OrderLogic.php b/app/api/logic/order/OrderLogic.php index f61c16aed..d74341178 100644 --- a/app/api/logic/order/OrderLogic.php +++ b/app/api/logic/order/OrderLogic.php @@ -135,6 +135,7 @@ class OrderLogic extends BaseLogic 'vip_price'=>$vipPrice, 'total_num' => count($cart_select),//总数 'pay_type' => $params['pay_type'] ?? 0, + 'reservation_time' => $params['reservation_time'] ?? '', 'cart_id' => implode(',', $cartId), 'store_id' => $params['store_id'] ?? 0, 'shipping_type' => $params['shipping_type'] ?? 1//配送方式 1=快递 ,2=门店自提 diff --git a/app/common/enum/OrderEnum.php b/app/common/enum/OrderEnum.php index 747e3ae55..35f3e685f 100644 --- a/app/common/enum/OrderEnum.php +++ b/app/common/enum/OrderEnum.php @@ -101,6 +101,9 @@ class OrderEnum * 订单状态 * @CANCEL_ORDER 取消售后 */ + const REFUND_GOODS = -2; + const REFUND_PAY = 4; + const CANCEL_ORDER = 5; //退款状态 diff --git a/app/common/logic/PayNotifyLogLogic.php b/app/common/logic/PayNotifyLogLogic.php index 99c2aa792..45af10dae 100644 --- a/app/common/logic/PayNotifyLogLogic.php +++ b/app/common/logic/PayNotifyLogLogic.php @@ -19,8 +19,15 @@ class PayNotifyLogLogic extends BaseLogic $model->pay_type = $payType; $model->order_sn = $data['out_trade_no']; $model->type = $type; - $model->amount = $payType == 'wechat_common' ? $data['amount']['payer_total'] : $data['buyer_pay_amount']; - $model->out_trade_no = $payType == 'wechat_common' ? $data['transaction_id'] : $data['trade_no']; + if($type == PayNotifyLog::TYPE_REFUND){ + $model->amount = $data['amount']['refund']; + $model->out_trade_no = $data['refund_id']; + }else{ + $model->amount = $payType == 'wechat_common' ? $data['amount']['payer_total'] : $data['buyer_pay_amount']; + $model->out_trade_no = $payType == 'wechat_common' ? $data['transaction_id'] : $data['trade_no']; + + } + $model->transaction_id = $data['transaction_id']; $model->attach = $data['attach'] ?? ''; if (isset($data['pay_time'])) { diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index 2f5a7f3d1..8d40b16ed 100644 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -6,6 +6,7 @@ use app\common\enum\OrderEnum; use app\common\enum\PayEnum; use app\common\enum\user\UserShipEnum; use app\common\model\dict\DictType; +use app\common\model\finance\PayNotifyLog; use app\common\model\pay\PayNotify; use app\common\model\store_finance_flow\StoreFinanceFlow; use app\common\model\store_order\StoreOrder; @@ -31,7 +32,12 @@ class PayNotifyLogic extends BaseLogic try { if ($action != 'cash_pay' && $action != 'balancePay') { $payNotifyLogLogic = new PayNotifyLogLogic(); - $payNotifyLogLogic->insert($action, $extra); + if($action == 'refund'){ + $payNotifyLogLogic->insert($action, $extra,PayNotifyLog::TYPE_REFUND); + }else{ + $payNotifyLogLogic->insert($action, $extra); + } + } self::$action($orderSn, $extra); Db::commit(); @@ -120,6 +126,23 @@ class PayNotifyLogic extends BaseLogic return true; } + //退款 + public static function refund($orderSn, $extra = []) + { + //更新状态 + $order = StoreOrder::where('order_id',$orderSn)->findOrEmpty(); +// if ($order->isEmpty() || $order->status == OrderEnum::REFUND_PAY) { +// return true; +// } +// $order->status = OrderEnum::REFUND_PAY; +// $order->refund_status = OrderEnum::REFUND_STATUS_FINISH; +// $order->refund_price = bcdiv($extra['amount']['refund'], 100, 2); +// $order->refund_reason_time = time(); +// $order->refund_num += 1; +// $order->save(); + +// self::afterPay($order,$extra['transaction_id']); + } public static function recharge($orderSn, $extra = []) { From a91cf005e3928a1a336cd3d25fd3ce92d5576c2c Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Sat, 8 Jun 2024 15:07:46 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lists/store_order/StoreOrderLists.php | 23 +++---------------- app/common/lists/BaseDataLists.php | 5 +++- app/common/lists/StoreBillLists.php | 21 +++-------------- .../lists/order/StoreRefundOrderLists.php | 23 +++---------------- app/store/logic/WorkbenchLogic.php | 17 ++++++++++---- 5 files changed, 25 insertions(+), 64 deletions(-) diff --git a/app/admin/lists/store_order/StoreOrderLists.php b/app/admin/lists/store_order/StoreOrderLists.php index df903935e..9972afc4a 100644 --- a/app/admin/lists/store_order/StoreOrderLists.php +++ b/app/admin/lists/store_order/StoreOrderLists.php @@ -29,6 +29,7 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface { return [ '=' => ['order_id', 'pay_type', 'staff_id', 'shipping_type', 'delivery_id'], + 'between_time' => 'create_time' ]; } @@ -47,17 +48,8 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface return StoreOrder::with(['user', 'staff', 'product' => function ($query) { $query->field(['id', 'oid', 'product_id', 'cart_info']); }])->where($this->searchWhere) - ->when(!empty($this->params['start_time']), function ($query) { - $query->whereTime('create_time', '>=', $this->params['start_time']); - }) - ->when(!empty($this->params['end_time']), function ($query) { - if ($this->params['end_time'] == $this->params['start_time']) { - $this->params['end_time'] = strtotime($this->params['end_time']) + 86399; - } - $query->whereTime('create_time', '<=', $this->params['end_time']); - }) ->when(!empty($this->request->adminInfo['store_id']), function ($query) { - $query->where('store_id', '=', $this->request->adminInfo['store_id']); + $query->where('store_id', $this->request->adminInfo['store_id']); }) ->when(!empty($this->params['status']), function ($query) { if ($this->params['status'] == -1) { @@ -97,17 +89,8 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface public function count(): int { return StoreOrder::where($this->searchWhere) - ->when(!empty($this->params['start_time']), function ($query) { - $query->whereTime('create_time', '>=', $this->params['start_time']); - }) - ->when(!empty($this->params['end_time']), function ($query) { - if ($this->params['end_time'] == $this->params['start_time']) { - $this->params['end_time'] = strtotime($this->params['end_time']) + 86399; - } - $query->whereTime('create_time', '<=', $this->params['end_time']); - }) ->when(!empty($this->request->adminInfo['store_id']), function ($query) { - $query->where('store_id', '=', $this->request->adminInfo['store_id']); + $query->where('store_id', $this->request->adminInfo['store_id']); }) ->when(!empty($this->params['status']), function ($query) { if ($this->params['status'] == -1) { diff --git a/app/common/lists/BaseDataLists.php b/app/common/lists/BaseDataLists.php index 901ace193..fcb40e40a 100644 --- a/app/common/lists/BaseDataLists.php +++ b/app/common/lists/BaseDataLists.php @@ -105,6 +105,9 @@ abstract class BaseDataLists implements ListsInterface $endTime = $this->request->get('end_time'); if($endTime){ $this->endTime = strtotime($endTime); + if ($startTime == $endTime) { + $this->endTime = strtotime($endTime) + 86399; + } } $this->start = $this->request->get('start'); $this->end = $this->request->get('end'); @@ -180,4 +183,4 @@ abstract class BaseDataLists implements ListsInterface } } } -} \ No newline at end of file +} diff --git a/app/common/lists/StoreBillLists.php b/app/common/lists/StoreBillLists.php index a7f04c9b1..7d51ed84b 100644 --- a/app/common/lists/StoreBillLists.php +++ b/app/common/lists/StoreBillLists.php @@ -14,6 +14,7 @@ class StoreBillLists extends BaseAdminDataLists implements ListsSearchInterface, public function setSearch(): array { return [ + 'between_time' => 'create_time' ]; } @@ -21,18 +22,10 @@ class StoreBillLists extends BaseAdminDataLists implements ListsSearchInterface, { $this->params['type'] = !empty($this->params['type']) ? $this->params['type'] : 1; return StoreFinanceFlow::with(['user', 'staff']) + ->where($this->searchWhere) ->when(!empty($this->request->adminInfo['store_id']), function ($query) { $query->where('store_id', $this->request->adminInfo['store_id']); }) - ->when(!empty($this->params['start_time']), function ($query) { - $query->whereTime('create_time', '>=', $this->params['start_time']); - }) - ->when(!empty($this->params['end_time']), function ($query) { - if ($this->params['end_time'] == $this->params['start_time']) { - $this->params['end_time'] = strtotime($this->params['end_time']) + 86399; - } - $query->whereTime('create_time', '<=', $this->params['end_time']); - }) ->when(!empty($this->params['type']), function (Query $query) { $income = 1; $expense = 0; @@ -70,18 +63,10 @@ class StoreBillLists extends BaseAdminDataLists implements ListsSearchInterface, public function count(): int { return StoreFinanceFlow::where('1=1') + ->where($this->searchWhere) ->when(!empty($this->request->adminInfo['store_id']), function ($query) { $query->where('store_id', $this->request->adminInfo['store_id']); }) - ->when(!empty($this->params['start_time']), function ($query) { - $query->whereTime('create_time', '>=', $this->params['start_time']); - }) - ->when(!empty($this->params['end_time']), function ($query) { - if ($this->params['end_time'] == $this->params['start_time']) { - $this->params['end_time'] = strtotime($this->params['end_time']) + 86399; - } - $query->whereTime('create_time', '<=', $this->params['end_time']); - }) ->when(!empty($this->params['type']), function (Query $query) { $income = 1; $expense = 0; diff --git a/app/common/lists/order/StoreRefundOrderLists.php b/app/common/lists/order/StoreRefundOrderLists.php index bfe2be0f5..31c4605b9 100644 --- a/app/common/lists/order/StoreRefundOrderLists.php +++ b/app/common/lists/order/StoreRefundOrderLists.php @@ -21,6 +21,7 @@ class StoreRefundOrderLists extends BaseAdminDataLists implements ListsSearchInt { return [ '=' => ['order_id', 'refund_type'], + 'between_time' => 'refund_reason_time' ]; } @@ -42,16 +43,7 @@ class StoreRefundOrderLists extends BaseAdminDataLists implements ListsSearchInt ->where($this->searchWhere) ->where('refund_status', '>', 0) ->when(!empty($this->request->adminInfo['store_id']), function ($query) { - $query->where('store_id', '=', $this->request->adminInfo['store_id']); - }) - ->when(!empty($this->params['start_time']), function ($query) { - $query->whereTime('refund_reason_time', '>=', $this->params['start_time']); - }) - ->when(!empty($this->params['end_time']), function ($query) { - if ($this->params['end_time'] == $this->params['start_time']) { - $this->params['end_time'] = strtotime($this->params['end_time']) + 86399; - } - $query->whereTime('refund_reason_time', '<=', $this->params['end_time']); + $query->where('store_id', $this->request->adminInfo['store_id']); }) ->field(['id', 'store_id', 'staff_id', 'order_id', 'pay_price', 'pay_time', 'pay_type', 'status', 'uid', 'refund_status', 'refund_type', 'refund_reason_wap', 'refund_reason_time', 'refund_reason_wap_explain', 'refund_reason_wap_img', 'refund_reason']) ->limit($this->limitOffset, $this->limitLength) @@ -77,16 +69,7 @@ class StoreRefundOrderLists extends BaseAdminDataLists implements ListsSearchInt return StoreOrder::where($this->searchWhere) ->where('refund_status', '>', 0) ->when(!empty($this->request->adminInfo['store_id']), function ($query) { - $query->where('store_id', '=', $this->request->adminInfo['store_id']); - }) - ->when(!empty($this->params['start_time']), function ($query) { - $query->whereTime('refund_reason_time', '>=', $this->params['start_time']); - }) - ->when(!empty($this->params['end_time']), function ($query) { - if ($this->params['end_time'] == $this->params['start_time']) { - $this->params['end_time'] = strtotime($this->params['end_time']) + 86399; - } - $query->whereTime('refund_reason_time', '<=', $this->params['end_time']); + $query->where('store_id', $this->request->adminInfo['store_id']); }) ->count(); } diff --git a/app/store/logic/WorkbenchLogic.php b/app/store/logic/WorkbenchLogic.php index 28cd120f7..e4f735419 100644 --- a/app/store/logic/WorkbenchLogic.php +++ b/app/store/logic/WorkbenchLogic.php @@ -31,7 +31,7 @@ use app\common\service\FileService; */ class WorkbenchLogic extends BaseLogic { - + public static function index($params) { $data = []; @@ -39,9 +39,6 @@ class WorkbenchLogic extends BaseLogic $endTime = $params['end_time']; $endTime = date('Y-m-d', strtotime($endTime) + 86400); $dateDiff = (new \DateTime($endTime))->diff(new \DateTime($startTime)); - if ($dateDiff->days > 366) { - throw new \Exception('时间范围不能超过一年'); - } $orderLogic = new StoreOrderLogic(); //订单总金额 $data['order_amount'] = $orderLogic->storeOrderSumByDate($params['store_id'], $startTime, $endTime); @@ -78,7 +75,17 @@ class WorkbenchLogic extends BaseLogic } else { $group = 'MONTH(pay_time)'; $i = 0; - while ($i <= $dateDiff->m) { + $month = 0; + if ($dateDiff->y > 0) { + $month = $dateDiff->y * 12; + } + if ($dateDiff->m > 0) { + $month += $dateDiff->m; + } + if ($dateDiff->d > 0) { + $month += 1; + } + while ($i < $month) { $timeRange[] = date('Y-m', strtotime("+$i months", strtotime($startTime))); $i++; }