diff --git a/app/admin/lists/store_finance_flow/StoreFinanceFlowLists.php b/app/admin/lists/store_finance_flow/StoreFinanceFlowLists.php index 6cdb9bff..f6aeaee3 100644 --- a/app/admin/lists/store_finance_flow/StoreFinanceFlowLists.php +++ b/app/admin/lists/store_finance_flow/StoreFinanceFlowLists.php @@ -11,6 +11,7 @@ use app\common\lists\ListsSearchInterface; use app\common\model\system_store\SystemStore; use app\common\model\system_store\SystemStoreStaff; use app\common\model\user\User; +use think\db\Query; /** * 门店流水列表 @@ -30,7 +31,7 @@ class StoreFinanceFlowLists extends BaseAdminDataLists implements ListsSearchInt public function setSearch(): array { return [ - '=' => ['store_id', 'uid', 'create_time'], + '=' => ['store_id', 'uid', 'create_time', 'staff_id'], ]; } @@ -57,16 +58,22 @@ class StoreFinanceFlowLists extends BaseAdminDataLists implements ListsSearchInt $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['keyword']), function (Query $query) { + $userIds = User::where('nickname', 'like', "%{$this->params['keyword']}%")->column('id'); + $query->where(function ($query) use($userIds) { + $query->where('user_id', 'in', $userIds)->whereOr('financial_record_sn', 'like', "%{$this->params['keyword']}%"); + }); }) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select()->each(function ($item) { - if($item['user_id']<=0){ - $item['nickname']='游客'; - }else{ - $id=$item['user_id']; - $item['nickname']=User::where('id',$item['user_id'])->value('nickname')."($id)"; + if ($item['user_id'] <= 0) { + $item['nickname'] = '游客'; + } else { + $id = $item['user_id']; + $item['nickname'] = User::where('id', $item['user_id'])->value('nickname') . "($id)"; } if (!empty($this->request->adminInfo['store_id'])) { $item['financial_pm'] = $item['financial_pm'] == 0 ? 1 : 0; @@ -76,10 +83,10 @@ class StoreFinanceFlowLists extends BaseAdminDataLists implements ListsSearchInt } else { $item['number'] = '+' . $item['number']; } - $item['staff_name']=SystemStoreStaff::where('id',$item['staff_id'])->value('staff_name'); - $item['store_name']=$item['store_id']>0?SystemStore::where('id',$item['store_id'])->value('name'):''; - $item['pay_type_name']=PayEnum::getPaySceneDesc($item['pay_type']); - $item['financial_type_name']=OrderEnum::getFinancialType($item['financial_type']); + $item['staff_name'] = SystemStoreStaff::where('id', $item['staff_id'])->value('staff_name'); + $item['store_name'] = $item['store_id'] > 0 ? SystemStore::where('id', $item['store_id'])->value('name') : ''; + $item['pay_type_name'] = PayEnum::getPaySceneDesc($item['pay_type']); + $item['financial_type_name'] = OrderEnum::getFinancialType($item['financial_type']); }) ->toArray(); } @@ -93,7 +100,26 @@ class StoreFinanceFlowLists extends BaseAdminDataLists implements ListsSearchInt */ public function count(): int { - return StoreFinanceFlow::where($this->searchWhere)->count(); + return StoreFinanceFlow::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']); + }) + ->when(!empty($this->params['keyword']), function (Query $query) { + $userIds = User::where('nickname', 'like', "%{$this->params['keyword']}%")->column('id'); + $query->where(function ($query) use($userIds) { + $query->where('user_id', 'in', $userIds)->whereOr('financial_record_sn', 'like', "%{$this->params['keyword']}%"); + }); + }) + ->count(); } } diff --git a/app/store/controller/finance/FinanceController.php b/app/store/controller/finance/FinanceController.php index 99e20b9e..3363e460 100644 --- a/app/store/controller/finance/FinanceController.php +++ b/app/store/controller/finance/FinanceController.php @@ -25,22 +25,15 @@ class FinanceController extends BaseAdminController ApiDoc\Query(ref: [Definitions::class, "page"]), ApiDoc\ResponseSuccess("data", type: "array", children: [ ['name' => 'id', 'desc' => 'ID', 'type' => 'int'], - ['name' => 'order_id', 'desc' => '订单编号', 'type' => 'string'], - ['name' => 'pay_price', 'desc' => '支付金额', 'type' => 'string'], - ['name' => 'pay_time', 'desc' => '支付时间', 'type' => 'float'], - ['name' => 'pay_type', 'desc' => '支付方式', 'type' => 'float'], - ['name' => 'status_name', 'desc' => '状态', 'type' => 'int'], - ['name' => 'staff_name', 'desc' => '店员', 'type' => 'int'], + ['name' => 'financial_record_sn', 'desc' => '流水号', 'type' => 'string'], + ['name' => 'order_sn', 'desc' => '订单号', 'type' => 'string'], + ['name' => 'number', 'desc' => '金额', 'type' => 'float'], + ['name' => 'create_time', 'desc' => '创建时间', 'type' => 'string'], ['name' => 'nickname', 'desc' => '用户昵称', 'type' => 'string'], - ['name' => 'avatar', 'desc' => '用户头像', 'type' => 'string'], - ['name' => 'product', 'desc' => '商品信息', 'type' => 'array', 'children' => [ - ['name' => 'cart_info', 'desc' => '商品信息', 'type' => 'array', 'children' => [ - ['name' => 'name', 'desc' => '商品名称', 'type' => 'int'], - ['name' => 'image', 'desc' => '图片', 'type' => 'string'], - ['name' => 'cart_num', 'desc' => '购买数量', 'type' => 'string'], - ['name' => 'price', 'desc' => '单价', 'type' => 'string'], - ]], - ]], + ['name' => 'staff_name', 'desc' => '店员', 'type' => 'string'], + ['name' => 'store_name', 'desc' => '店铺名称', 'type' => 'string'], + ['name' => 'pay_type_name', 'desc' => '支付方式', 'type' => 'string'], + ['name' => 'financial_type_name', 'desc' => '流水类型', 'type' => 'string'], ]), ] public function lists() diff --git a/composer.json b/composer.json index e9995738..13a82488 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "source": "https://github.com/walkor/webman" }, "require": { - "php": ">=7.2", + "php": ">=8.1", "workerman/webman-framework": "v1.5.16", "monolog/monolog": "^2.2", "webman/think-orm": "v1.1.1",