From f1eb9293b172189cc219d19be2a134616b5dad49 Mon Sep 17 00:00:00 2001 From: liqi Date: Sat, 4 Jan 2025 17:00:46 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../base/StatementAccountController.php | 61 +++++++++++-------- 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/admin/controllers/base/StatementAccountController.php b/admin/controllers/base/StatementAccountController.php index 9fc81c3..675d43a 100644 --- a/admin/controllers/base/StatementAccountController.php +++ b/admin/controllers/base/StatementAccountController.php @@ -197,35 +197,23 @@ class StatementAccountController extends BaseAdminController ]; } else {//药品 // 设置查询条件,查找状态为1的对账记录,按ID降序排序 - $query = Reconciliation::find()->alias('r')->where(['r.status' => 1])->orderBy(['id' => SORT_DESC]); + $query = Reconciliation::find()->alias('r')->where(['r.status' => 1]); - // 获取搜索参数:门店名称和药品名称 - $store_name = $get['store_name']; + // 获取搜索参数:和药品名称 $drug_name = $get['drug_name']; - // 根据门店名称过滤门店 - $query->joinWith(['store' => function ($s) use ($store_name) { - $s->alias('s'); - if (!empty($store_name)) { - $s->andWhere([ - 'or', - ['like', 's.name', $store_name], - ['like', 's.shouzimu', $store_name], - ]); - } - }]); // 根据药品名称过滤药品 - $query->joinWith(['drug' => function ($d) use ($drug_name) { - $d->alias('d'); - if (!empty($drug_name)) { + $query->joinWith(['drug' => function ($d) use ($drug_name) { + $d->alias('d'); + if (!empty($drug_name)) { $d->andWhere([ 'or', ['like', 'd.drug_name', $drug_name], ['like', 'd.pinyin_simple', $drug_name], ]); - } - }]); + } + }]); // 根据门店ID过滤对账记录 if (!empty($get['store_id'])) { @@ -284,7 +272,8 @@ class StatementAccountController extends BaseAdminController 'treatement_fee' => 'productOrder.treatement_price' ] ]; - $list = $this->create($query, $get)->getModels(); +// $list = $this->create($query, $get)->getModels(); + $list = $query->asArray()->all(); // 总销量 sale_number // 单个销量 number 不知道要这个干嘛 // 总价 total_price @@ -313,7 +302,7 @@ class StatementAccountController extends BaseAdminController } return [ 'list' => array_values($result), - 'pageSize' => 10, + 'pageSize' => 1000, 'page' => 1, 'total' => count($result) ]; @@ -325,7 +314,7 @@ class StatementAccountController extends BaseAdminController /** * @doc-name 销量 */ - public function actionSaleNum($id = null, $start_time = '', $end_time = '') + public function actionSaleNum($id = null, $start_time = '', $end_time = '', $isDrug = false) { // 检查开始时间和结束时间是否已提供 @@ -345,7 +334,7 @@ class StatementAccountController extends BaseAdminController // 查询草药和成药的数量、进货价格、销售价格以及挂号收入 $cao_drug_num = Reconciliation::find()->alias('r')->where(['r.status' => 1, 'store_id' => $id, 'drug_type' => [1, 3]]) - ->andWhere($data ?? '')->groupBy('r.drug_id')->sum('number'); + ->andWhere($data ?? '')->sum('number'); $cheng_drug_num = Reconciliation::find()->alias('r')->where(['r.status' => 1, 'store_id' => $id, 'drug_type' => [2, 4]])->andWhere($data ?? '')->sum('number'); $cao_give_price = Reconciliation::find()->alias('r')->where(['r.status' => 1, 'store_id' => $id, 'drug_type' => [1, 3]])->andWhere($data ?? '')->sum('total_buy_price'); @@ -436,7 +425,7 @@ class StatementAccountController extends BaseAdminController Store::class => [ 'id', 'name', 'sale_number' => function ($s) use ($start_time, $end_time) { - return $this->actionSaleNum($s->id, $start_time, $end_time); + return $this->actionSaleNum($s->id, $start_time, $end_time, true); }, 'trans_fee' => function ($k) use ($start_time, $end_time) { return $this->actionStoreTransFee($k->id, 1, $start_time, $end_time); @@ -730,24 +719,32 @@ class StatementAccountController extends BaseAdminController 'or', ['<>', 'refund_status', '3'], ['<>', 'status', '4'], + ['<>', 'status', '5'], + ['<>', 'status', '9'], ])->andWhere($data ?? '')->sum('trans_expenses'); // 计算所有产品的加工费总和 $process_price = ProductOrder::find()->alias('p')->where(['store_id' => $admin->store_id, 'is_pay' => 1, 'is_settled' => 1])->andWhere([ 'or', ['<>', 'refund_status', '3'], ['<>', 'status', '4'], + ['<>', 'status', '5'], + ['<>', 'status', '9'], ])->andWhere($data ?? '')->sum('process_price'); // 计算所有产品的治疗费总和 $treatement_price = ProductOrder::find()->alias('p')->where(['store_id' => $admin->store_id, 'is_pay' => 1, 'is_settled' => 1])->andWhere([ 'or', ['<>', 'refund_status', '3'], ['<>', 'status', '4'], + ['<>', 'status', '5'], + ['<>', 'status', '9'], ])->andWhere($data ?? '')->sum('treatement_price'); // 计算所有代煎药的代煎费总和 $decoct_price_price = ProductOrder::find()->alias('p')->where(['is_decoct' => 1, 'store_id' => $admin->store_id, 'is_pay' => 1, 'is_settled' => 1])->andWhere([ 'or', ['<>', 'refund_status', '3'], - ['<>', 'status', '4'] + ['<>', 'status', '4'], + ['<>', 'status', '5'], + ['<>', 'status', '9'], ])->andWhere($data ?? '')->sum('decoct_price'); // 计算所有分账的总金额 $register_price = Ledger::find()->alias('re')->where(['user_id' => $admin->store_id, 'status' => 1, 'user_type' => 1, 'order_type' => 2])->andWhere($register_data ?? '')->sum('money'); @@ -817,26 +814,36 @@ class StatementAccountController extends BaseAdminController 'or', ['<>', 'refund_status', '3'], ['<>', 'status', '4'], + ['<>', 'status', '5'], + ['<>', 'status', '9'], ])->andWhere($data ?? '')->sum('trans_expenses'); $treatement_price = ProductOrder::find()->alias('p')->where(['is_pay' => 1, 'is_settled' => 1])->andWhere([ 'or', ['<>', 'refund_status', '3'], ['<>', 'status', '4'], + ['<>', 'status', '5'], + ['<>', 'status', '9'], ])->andWhere($data ?? '')->sum('treatement_price'); $process_price = ProductOrder::find()->alias('p')->where(['is_pay' => 1, 'is_settled' => 1])->andWhere([ 'or', ['<>', 'refund_status', '3'], ['<>', 'status', '4'], + ['<>', 'status', '5'], + ['<>', 'status', '9'], ])->andWhere($data ?? '')->sum('process_price'); $decoct_price_price = ProductOrder::find()->alias('p')->where(['is_pay' => 1, 'is_settled' => 1, 'is_decoct' => 1])->andWhere([ 'or', ['<>', 'refund_status', '3'], ['<>', 'status', '4'], + ['<>', 'status', '5'], + ['<>', 'status', '9'], ])->andWhere($data ?? '')->sum('decoct_price'); $total_price = ProductOrder::find()->alias('p')->where(['is_pay' => 1, 'is_settled' => 1])->andWhere([ 'or', ['<>', 'refund_status', '3'], ['<>', 'status', '4'], + ['<>', 'status', '5'], + ['<>', 'status', '9'], ])->andWhere($data ?? '')->sum('total_pay_price'); // 挂号金额 @@ -913,8 +920,8 @@ class StatementAccountController extends BaseAdminController $allSale = 0; $totalPrice = 0; foreach ($resData as $key => $value) { - $allSale = bcadd($allSale, $value->number, 0); - $totalPrice = bcadd($totalPrice, $value->total_price, 0); + $allSale += $value->number; + $totalPrice = bcadd($totalPrice, $value->total_price, 3); }