From e9df9d904122e31e7cf4e56443d10d90ba29104b Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Mon, 27 May 2024 18:21:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BA=86=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E9=80=BB=E8=BE=91=EF=BC=8C=E5=A2=9E=E5=8A=A0=E4=BA=86=E4=BD=99?= =?UTF-8?q?=E9=A2=9D=E6=98=8E=E7=BB=86=E5=8A=9F=E8=83=BD=EF=BC=8C=E5=B9=B6?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E6=90=9C=E7=B4=A2=E6=9D=A1=E4=BB=B6?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E6=96=B9=E5=BC=8F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../operation/OpurchaseclassController.php | 2 +- .../financial/FinancialRecordController.php | 24 +++++- .../lists/financial/FinancialRecordLists.php | 76 ++++++++++--------- app/common/lists/ListsSearchTrait.php | 6 +- 4 files changed, 66 insertions(+), 42 deletions(-) diff --git a/app/admin/controller/operation/OpurchaseclassController.php b/app/admin/controller/operation/OpurchaseclassController.php index 9775f28..3cd72d8 100644 --- a/app/admin/controller/operation/OpurchaseclassController.php +++ b/app/admin/controller/operation/OpurchaseclassController.php @@ -148,7 +148,7 @@ class OpurchaseclassController extends BaseAdminController $arr=Opurchaseclass::where('id','in',explode(',',$order_arr))->where('is_mer',1)->value('order_arr'); if($arr){ $this->request->__set('class_value',['id'=>explode(',',$arr)]); - $this->request->__set('class_key',['in'=>'id']); + $this->request->__set('class_key',['in'=>['id']]); } return $this->dataLists(new CashierclassStreamLists()); } diff --git a/app/api/controller/financial/FinancialRecordController.php b/app/api/controller/financial/FinancialRecordController.php index a61fa00..58917df 100644 --- a/app/api/controller/financial/FinancialRecordController.php +++ b/app/api/controller/financial/FinancialRecordController.php @@ -54,7 +54,27 @@ class FinancialRecordController extends BaseApiController */ public function api_lists() { - $this->request->__set('is_detail',1); - return $this->dataLists((new FinancialRecordLists)); + $mer_id=$this->request->userInfo['merchant']['mer_id']??0; + if($mer_id!=0){ + $this->request->__set('is_detail',1); + $this->request->__set('class_value',['mer_id'=>$mer_id,'type'=>1]); + $this->request->__set('class_key',['='=>['mer_id','type']]); + return $this->dataLists((new FinancialRecordLists)); + } + return $this->success(); } + + /** + * 余额明细 + */ + public function supplier_list(){ + $id=$this->request->userInfo['supplier']['id']??0; + if($id!=0){ + $this->request->__set('is_detail',1); + $this->request->__set('class_value',['mer_id'=>$id,'type'=>3]); + $this->request->__set('class_key',['='=>['mer_id','type']]); + return $this->dataLists((new FinancialRecordLists)); + } + return $this->success(); + } } diff --git a/app/api/lists/financial/FinancialRecordLists.php b/app/api/lists/financial/FinancialRecordLists.php index 05624cb..4490ef2 100644 --- a/app/api/lists/financial/FinancialRecordLists.php +++ b/app/api/lists/financial/FinancialRecordLists.php @@ -44,45 +44,47 @@ class FinancialRecordLists extends BaseAdminDataLists implements ListsSearchInte */ public function lists(): array { - $mer_id = $this->request->userInfo['merchant']['mer_id'] ?? 0; - if ($mer_id <= 0) { - return []; - } - $where = [ - 'type' => 1, - 'mer_id' => $mer_id, - ]; - $this->where = $where; - $searchWhere=$this->searchWhere; - $is_detail=$this->request->__get('is_detail'); - if($is_detail==1){ - $list = FinancialRecord::where($this->searchWhere) - ->where($where) - ->limit($this->limitOffset, $this->limitLength) - ->order('create_time','desc') - ->select()->each(function ($item) { - $item['user_nickname']=''; - if($item['user_id']!=0){ - $item['user_nickname']=User::where('id',$item['user_id'])->value('nickname'); - } - $item['financial_pm']=$item['financial_pm']==0?"支出":"获得"; - return $item; - }); + $class_value = $this->request->__get('class_value'); + if ($class_value) { + $where = [ + 'type' => $class_value['type'], + 'mer_id' => $class_value['mer_id'], + ]; }else{ + $where=[]; + } + + $this->where = $where; + $searchWhere = $this->searchWhere; + $is_detail = $this->request->__get('is_detail'); + if ($is_detail == 1) { $list = FinancialRecord::where($this->searchWhere) - ->where($where) - ->limit($this->limitOffset, $this->limitLength) - ->field("FROM_UNIXTIME(create_time, '%Y-%m-%d') as record_date, SUM(number) as total_amount") - ->group('record_date') - ->order('record_date') - ->select()->each(function ($item) use($where,$searchWhere) { - $cashier_total_amount=FinancialRecord::where($where)->where($searchWhere)->where('financial_type',OrderEnum::CASHIER_ORDER_PAY)->sum('number'); - $item['cashier_total_amount'] = $cashier_total_amount; - $cashier_cash_total_amount=FinancialRecord::where($where)->where($searchWhere)->where('financial_type',OrderEnum::CASHIER_CASH_ORDER_PAY)->sum('number'); - $item['cashier_cash_total_amount'] = $cashier_cash_total_amount; - $platofrm_total_amount=FinancialRecord::where($where)->where($searchWhere)->where('financial_type',OrderEnum::USER_ORDER_PAY)->sum('number'); - $item['platofrm_total_amount'] = $platofrm_total_amount; - }); + ->where($where) + ->limit($this->limitOffset, $this->limitLength) + ->order('create_time', 'desc') + ->select()->each(function ($item) { + $item['user_nickname'] = ''; + if ($item['user_id'] != 0) { + $item['user_nickname'] = User::where('id', $item['user_id'])->value('nickname'); + } + $item['financial_pm'] = $item['financial_pm'] == 0 ? "支出" : "获得"; + return $item; + }); + } else { + $list = FinancialRecord::where($this->searchWhere) + ->where($where) + ->limit($this->limitOffset, $this->limitLength) + ->field("FROM_UNIXTIME(create_time, '%Y-%m-%d') as record_date, SUM(number) as total_amount") + ->group('record_date') + ->order('record_date') + ->select()->each(function ($item) use ($where, $searchWhere) { + $cashier_total_amount = FinancialRecord::where($where)->where($searchWhere)->where('financial_type', OrderEnum::CASHIER_ORDER_PAY)->sum('number'); + $item['cashier_total_amount'] = $cashier_total_amount; + $cashier_cash_total_amount = FinancialRecord::where($where)->where($searchWhere)->where('financial_type', OrderEnum::CASHIER_CASH_ORDER_PAY)->sum('number'); + $item['cashier_cash_total_amount'] = $cashier_cash_total_amount; + $platofrm_total_amount = FinancialRecord::where($where)->where($searchWhere)->where('financial_type', OrderEnum::USER_ORDER_PAY)->sum('number'); + $item['platofrm_total_amount'] = $platofrm_total_amount; + }); } diff --git a/app/common/lists/ListsSearchTrait.php b/app/common/lists/ListsSearchTrait.php index e1dd6cb..6439682 100644 --- a/app/common/lists/ListsSearchTrait.php +++ b/app/common/lists/ListsSearchTrait.php @@ -26,9 +26,11 @@ trait ListsSearchTrait if($class_key!==null){ foreach($class_key as $key => $value){ if(isset($search[$key])){ - array_push($search[$key], $value); // 添加class_key的搜索条件 + foreach($value as $v){ // 遍历class_key的值,添加到search数组中 + array_push($search[$key], $v); // 添加class_key的搜索条件 + } }else{ - $search[$key] = [$value]; // 创建新的搜索条件 + $search[$key] = [$value[0]]; // 创建新的搜索条件 } } }