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++; }