| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\admin\controllers;
- use app\constants\OptionSetting;
- use app\jobs\LgCashJob;
- use app\models\Cash;
- use app\models\DeliveryInfo;
- use app\models\District;
- use app\models\Lg;
- use app\models\LocalDeliveryCash;
- use app\models\LocalDeliveryCourier;
- use app\models\LocalDeliveryCourierComment;
- use app\models\LocalDeliveryCourierCommentExt;
- use app\models\LocalDeliveryCourierTag;
- use app\models\LocalDeliveryLog;
- use app\models\Option;
- use app\models\Order;
- use app\models\Store;
- use app\models\User;
- use app\models\WechatConfig;
- use app\modules\admin\models\CourierForm;
- use app\modules\admin\models\DeliveryOrderForm;
- use app\modules\admin\models\FreightForm;
- use app\utils\Alipay\Alipay;
- use app\utils\LgApi;
- use app\utils\Notice\NoticeSend;
- use Spatie\SimpleExcel\SimpleExcelWriter;
- use yii\helpers\Json;
- /**
- * @file LocalDeliveryController
- * @editor Created by vscode
- * @author WPing丶
- * @date 2023/06/29
- * @time 09:14:30
- *
- * 备注:同城配送
- */
- class LocalDeliveryController extends BaseController
- {
- /**
- * 模块名:actionGetCourier
- * 代码描述:获取配送员列表
- * 作者:WPing丶
- * 请求方式:GET
- * 创建时间:2023/06/29 9:15:54
- * @param int id
- * @param string str
- * @param bool bool
- */
- public function actionGetCourier()
- {
- $param = get_params();
- $form = new CourierForm();
- $form->scenario = $form::SCENARIO_LIST;
- $form->attributes = $param;
- return $this->asJson($form->searchCourier());
- }
- /**
- * 模块名:actionAddCourier
- * 代码描述:新增配送员
- * 作者:WPing丶
- * 请求方式:GET
- * 创建时间:2023/06/25 15:51:06
- * @param int id
- * @param string str
- * @param bool bool
- */
- public function actionAddCourier()
- {
- $param = post_params();
- $form = new CourierForm();
- $form->scenario = $form::SCENARIO_ADD;
- $form->attributes = $param;
- $res = $form->saveCourier();
- return $this->asJson($res);
- }
- /**
- * 模块名:actionEditCourier
- * 代码描述:编辑配送员
- * 作者:WPing丶
- * 请求方式:GET
- * 创建时间:2023/06/25 14:27:38
- * @param int id
- * @param string str
- * @param bool bool
- */
- public function actionEditCourier()
- {
- $param = post_params();
- $form = new CourierForm();
- $form->scenario = $form::SCENARIO_EDIT;
- $form->attributes = $param;
- $res = $form->saveCourier();
- return $this->asJson($res);
- }
- /**
- * 模块名:actionDelCourier
- * 代码描述:删除配送员
- * 作者:WPing丶
- * 请求方式:GET
- * 创建时间:2023/06/25 19:59:22
- * @param int id
- * @param string str
- * @param bool bool
- */
- public function actionDelCourier()
- {
- //主键id用key标识并进行获取
- $param = get_params('key');
- $form = new CourierForm();
- $form->scenario = $form::SCENARIO_DEL;
- $form->id = $param;
- $res = $form->delCourier();
- return $this->asJson($res);
- }
- /**
- * 模块名:actionDelCourier
- * 代码描述:审核配送员
- * 作者:WPing丶
- * 请求方式:GET
- * 创建时间:2023/06/25 19:59:22
- * @param int id
- * @param string str
- * @param bool bool
- */
- public function actionApplyCourier()
- {
- //主键id用key标识并进行获取
- $param = get_params('key');
- $state = get_params('state');
- $form = new CourierForm();
- // $form->scenario = $form::SCENARIO_APPLY;
- $form->id = $param;
- $form->state = $state;
- $res = $form->applyCourier();
- return $this->asJson($res);
- }
- /**
- * 模块名:actionGetFreight
- * 代码描述:获取计价规则列表
- * 作者:WPing丶
- * 请求方式:GET
- * 创建时间:2023/06/29 9:15:54
- * @param int id
- * @param string str
- * @param bool bool
- */
- public function actionGetFreight()
- {
- $param = get_params();
- $form = new FreightForm();
- $form->scenario = $form::SCENARIO_LIST;
- $form->attributes = $param;
- $form->store_id = get_store_id();
- return $this->asJson($form->searchFreight(input_params('type', 0)));
- }
- /**
- * 模块名:actionAddFreight
- * 代码描述:新增计价规则
- * 作者:WPing丶
- * 请求方式:GET
- * 创建时间:2023/06/25 15:51:06
- * @param int id
- * @param string str
- * @param bool bool
- */
- public function actionAddFreight()
- {
- $param = post_params();
- $form = new FreightForm();
- $form->scenario = $form::SCENARIO_ADD;
- $form->attributes = $param;
- $form->store_id = get_store_id();
- $res = $form->saveFreight(input_params('type', 0));
- return $this->asJson($res);
- }
- /**
- * 模块名:actionEditFreight
- * 代码描述:编辑计价规则
- * 作者:WPing丶
- * 请求方式:GET
- * 创建时间:2023/06/25 14:27:38
- * @param int id
- * @param string str
- * @param bool bool
- */
- public function actionEditFreight()
- {
- $param = post_params();
- $form = new FreightForm();
- $form->scenario = $form::SCENARIO_EDIT;
- $form->attributes = $param;
- $form->store_id = get_store_id();
- $res = $form->saveFreight(input_params('type', 0));
- return $this->asJson($res);
- }
- /**
- * 模块名:actionDelFreight
- * 代码描述:删除计价规则
- * 作者:WPing丶
- * 请求方式:GET
- * 创建时间:2023/06/25 19:59:22
- * @param int id
- * @param string str
- * @param bool bool
- */
- public function actionDelFreight()
- {
- //主键id用key标识并进行获取
- $param = get_params('key');
- $form = new FreightForm();
- $form->scenario = $form::SCENARIO_DEL;
- $form->id = $param;
- $res = $form->delFreight();
- return $this->asJson($res);
- }
- /**
- * 模块名:actionDelFreight
- * 代码描述:启用or关闭计价规则
- * 作者:WPing丶
- * 请求方式:GET
- * 创建时间:2023/06/25 19:59:22
- * @param int id
- * @param string str
- * @param bool bool
- */
- public function actionApplyFreight()
- {
- //主键id用key标识并进行获取
- $param = get_params('key');
- $is_enable = get_params('is_enable');
- $is_scan = get_params('is_scan');
- $form = new FreightForm();
- // $form->scenario = $form::SCENARIO_APPLY;
- $form->id = $param;
- $form->is_enable = $is_enable;
- $form->is_scan = $is_scan;
- $res = $form->applyFreight();
- return $this->asJson($res);
- }
- /**
- * 模块名:actionSetting
- * 代码描述:基础设置
- * 作者:WPing丶
- * 请求方式:GET
- * 创建时间:2023/07/01 10:48:17
- * @param int id
- * @param string str
- * @param bool bool
- */
- public function actionGetSetting()
- {
- $store_id = get_store_id();
- $values = Option::find()->where([
- 'store_id' => $store_id,
- 'group' => OptionSetting::LOCAL_DELIVERY_GROUP_NAME, 'name' => OptionSetting::LOCAL_DELIVERY_SETTING
- ])->select('value')->One();
- if ($values) {
- $data = json_decode($values->value, true);
- } else {
- $data = null;
- }
- return $this->asJson(['code' => 0, 'msg' => 'success', 'data' => $data]);
- }
- /**
- * 模块名:actionSetSetting
- * 代码描述:编辑基础设置
- * 作者:WPing丶
- * 请求方式:GET
- * 创建时间:2023/07/01 10:48:17
- * @param int id
- * @param string str
- * @param bool bool
- */
- public function actionSetSetting($store_id = 0)
- {
- $store_id = $store_id ?: get_store_id();
- $localDeliveryOption = Option::findOne([
- 'store_id' => $store_id, 'group' => OptionSetting::LOCAL_DELIVERY_GROUP_NAME,
- 'name' => OptionSetting::LOCAL_DELIVERY_SETTING
- ]);
- if (!$localDeliveryOption) {
- $localDeliveryOption = new Option();
- }
- $data = post_params();
- if (!is_numeric($data['min_money']) || !is_numeric($data['cash_max_day'])) {
- return $this->asJson(['code' => 1, 'msg' => '金额字段请输入数字']);
- }
- $data = [
- 'send_type' => [
- 'text' => '发单方式',
- 'value' => $data['send_type']
- ],
- 'delivery_type' => [
- 'text' => '骑手绑定模式',
- 'value' => 'store'//$data['delivery_type']
- ],
- 'default_time' => [
- 'text' => '配送默认时间',
- 'value' => $data['default_time']
- ],
- 'default_cost' => [
- 'text' => '骑手佣金',
- 'value' => $data['default_cost']
- ],
- 'pay_type' => [
- 'text' => '提现方式',
- 'value' => $data['pay_type']
- ],
- 'min_money' => [
- 'text' => '最小提现额度',
- 'value' => $data['min_money']
- ],
- 'cash_max_day' => [
- 'text' => '每天最大提现额度',
- 'value' => $data['cash_max_day']
- ],
- 'cash_service_charge' => [
- 'text' => '提现手续费',
- 'value' => floatval($data['cash_service_charge'])
- ],
- 'confirm_type' => [
- 'text' => '送达即签收',
- 'value' => $data['confirm_type']
- ],
- ];
- //商盟固定store_id
- $localDeliveryOption->store_id = $store_id;
- $localDeliveryOption->group = OptionSetting::LOCAL_DELIVERY_GROUP_NAME;
- $localDeliveryOption->name = OptionSetting::LOCAL_DELIVERY_SETTING;
- $localDeliveryOption->value = json_encode($data);
- if (!$localDeliveryOption->isNewRecord) {
- $localDeliveryOption->updated_at = time();
- }
- if (!$localDeliveryOption->save()) {
- foreach ($localDeliveryOption->errors as $error) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => $error,
- ]);
- }
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => '保存成功'
- ]);
- }
- /**
- * 模块名:actionGetOrderList
- * 代码描述:获取同城订单列表
- * 作者:WPing丶
- * 请求方式:GET
- * 创建时间:2023/07/05 14:25:32
- */
- public function actionGetOrderList()
- {
- $param = get_params();
- $form = new DeliveryOrderForm();
- $form->attributes = $param;
- return $this->asJson($form->search());
- }
- /**
- * 模块名:actionSendOrder
- * 代码描述:订单分配配送员
- * 作者:WPing丶
- * 请求方式:GET
- * 创建时间:2023/07/06 09:23:59
- */
- public function actionSendOrder()
- {
- $order_id = get_params('order_id'); //订单ID
- $rider_id = get_params('rider_id'); //骑手ID
- $courier = LocalDeliveryCourier::findOne(['id' => $rider_id, 'is_delete' => 0, 'state' => 2, 'status' => 1]);
- if (!$courier) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '骑手不存在或已离线,请重新选择',
- ]);
- }
- $now_num = DeliveryInfo::find()->alias('di')
- ->leftJoin(['o' => Order::tableName()], 'di.order_no = o.order_no')
- ->where(['o.trade_status' => 2, 'is_local' => 1, 'rider_id' => $rider_id])
- ->count();
- if ($courier->max_num != 0 && $now_num >= $courier->max_num) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '骑手(' . $courier->real_name . ')当前配送订单已达到上限,请分配其他骑手',
- ]);
- }
- $t = \Yii::$app->db->beginTransaction(); //开始事务
- $order = Order::findOne($order_id);
- $delivery_info = DeliveryInfo::findOne(['order_no' => $order->order_no]);
- $delivery_info->rider_id = $rider_id;
- $delivery_info->rider_name = $courier->real_name;
- $delivery_info->rider_mobile = $courier->mobile;
- $delivery_info->local_status = DeliveryInfo::LOCAL_STATUS_WAITING;
- if (!$delivery_info->save()) {
- $t->rollBack(); //事务回滚
- return $this->asJson([
- 'code' => 1,
- 'msg' => current($delivery_info->getFirstErrors()),
- ]);
- }
- $order->send_time = time();
- $order->trade_status = 2;
- if (!$order->save()) {
- $t->rollBack(); //事务回滚
- return $this->asJson([
- 'code' => 1,
- 'msg' => current($delivery_info->getFirstErrors()),
- ]);
- }
- $t->commit(); //事务执行
- return $this->asJson([
- 'code' => 0,
- 'msg' => '操作成功',
- ]);
- }
- /**
- * 模块名:actionCashList
- * 代码描述:提现记录
- * 作者:WPing丶
- * 请求方式:POST
- * 创建时间:2023/07/11 11:04:47
- * @param int id
- * @param string str
- * @param bool bool
- */
- public function actionCashList()
- {
- $store_id = get_store_id();
- $status = get_params('status');
- $query = LocalDeliveryCash::find()->where(['is_delete' => 0]);
- if ($status > -1) { //状态,0:待审核,1:待打款,2:审核驳回, 3:已打款
- $query->andWhere(['status' => $status]);
- }
- if ($store_id > 0) {
- $query->andWhere(['store_id' => $store_id]);
- }
- $query->orderBy('id DESC');
- $pagination = pagination_make($query);
- $list = $pagination['list'];
- foreach ($list as &$value) {
- $value['created_at'] = $value['created_at'] > 0 ? date('Y-m-d H:i:s', $value['created_at']) : '';
- $value['updated_at'] = $value['updated_at'] > 0 ? date('Y-m-d H:i:s', $value['updated_at']) : '';
- $value['pay_time'] = $value['pay_time'] > 0 ? date('Y-m-d H:i:s', $value['pay_time']) : '';
- $value['apply_time'] = $value['apply_time'] > 0 ? date('Y-m-d H:i:s', $value['apply_time']) : '';
- $value['actual_price'] = sprintf("%.2f", ($value['price'] - $value['service_charge']));
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'data' => $list,
- 'pageNo' => $pagination['pageNo'],
- 'totalCount' => $pagination['totalCount']
- ]
- ]);
- }
- /**
- * 模块名:actionConfirm
- * 代码描述:提现审核
- * 作者:WPing丶
- * 请求方式:GET
- * 创建时间:2023/07/12 14:47:15
- * @param int id 记录ID
- * @param int status 1=通过 2=拒绝 3=确认打款
- */
- public function actionAudit()
- {
- $id = get_params('id');
- $status = get_params('status');
- $cash = LocalDeliveryCash::find()->where(['is_delete' => 0, 'id' => $id])->andWhere(['or',['status' => LocalDeliveryCash::CASH_STATUS_WAIT],['status' => LocalDeliveryCash::CASH_STATUS_PASS]])->one();
- if (!$cash) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '记录不存在'
- ]);
- }
- // 拒绝
- if ($status == LocalDeliveryCash::CASH_STATUS_FAIL) {
- $t = \Yii::$app->db->beginTransaction(); //开始事务
- $log = LocalDeliveryLog::saveLog($cash->saas_user_id, $cash->price, 1, 1, 0, "提现驳回,返还佣金", 1);
- if (!$log) {
- $t->rollBack();
- return $this->asJson([
- 'code' => 1,
- 'msg' => '返还佣金失败'
- ]);
- }
- $cash->status = LocalDeliveryCash::CASH_STATUS_FAIL;
- $cash->apply_time = time();
- if (!$cash->save()) {
- $t->rollBack();
- return $this->asJson([
- 'code' => 1,
- 'msg' => implode(';', array_values($cash->firstErrors))
- ]);
- }
- $t->commit();
- return $this->asJson([
- 'code' => 0,
- 'msg' => '操作成功'
- ]);
- }
- // 通过
- if ($status == LocalDeliveryCash::CASH_STATUS_PASS) {
- $cash->status = LocalDeliveryCash::CASH_STATUS_PASS;
- $cash->apply_time = time();
- if (!$cash->save()) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => implode(';', array_values($cash->firstErrors))
- ]);
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => '操作成功'
- ]);
- }
- // 手动打款
- if ($status == LocalDeliveryCash::CASH_STATUS_REMIT) {
- $cash->status = LocalDeliveryCash::CASH_STATUS_REMIT;
- $cash->pay_time = time();
- $cash->pay_type = 2;
- if (!$cash->save()) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => implode(';', array_values($cash->firstErrors))
- ]);
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => '操作成功'
- ]);
- }elseif ($status == LocalDeliveryCash::CASH_STATUS_LG){
- if ($cash->type == 4){
- $user = User::findOne($cash->user_id);
- $saas = \app\models\SaasUser::findOne(['mobile' => $user->binding]);
- $lg_info = Lg::find()->where(['user_id'=>$saas->id,'status'=>1,'is_delete'=>0])->one();
- $lgApi = new LgApi($cash->store_id);
- //灵工提现
- $post_data = [
- 'store_id' => $cash->store_id,
- 'outTradeNo' => $cash->order_no,//唯一批次号
- 'accNo' => bcmul($cash->price,100),
- 'amt' => bcmul($cash->price,100),
- 'name' => $lg_info->name,
- 'certCard' => $lg_info->cert_card//身份证号
- ];
- $result = $lgApi->FlexiblePay($post_data);
- if (isset($result['status']) && $result['status'] == 999) {
- return $this->asJson($result);
- }
- $cash->status = 6;//灵工待打款
- $cash->save();
- //灵工提现接口调用后消息队列查询状态
- \queue_push(new LgCashJob(['id'=>$cash->id,'store_id'=>$cash->store_id,'type'=>12,'retry' => 5]), 60);
- return $this->asJson([
- 'code' => 0,
- 'msg' => '成功'
- ]);
- }
- }
- return $this->asJson([
- 'code' => 1,
- 'msg' => '操作异常'
- ]);
- }
- /**
- * 模块名:actionAccountLogList
- * 代码描述:佣金明细
- * 作者:WPing丶
- * 请求方式:GET
- * 创建时间:2023/07/12 09:03:52
- * @param int id
- * @param string str
- * @param bool bool
- */
- public function actionAccountLogList()
- {
- $start_time = get_params('start_time');
- $end_time = get_params('end_time');
- $type = get_params('type');
- $saas_user_id = get_params('saas_user_id');
- $query = LocalDeliveryLog::find()->alias('l')->where(['l.saas_user_id' => $saas_user_id]);
- if ($start_time) {
- $query->andWhere(['>=', 'l.created_at', strtotime($start_time . ' 00:00:00')]);
- }
- if ($end_time) {
- $query->andWhere(['<=', 'l.created_at', strtotime($end_time . ' 23:59:59')]);
- }
- if ($type > 0) {
- $query->andWhere(['l.type' => $type]);
- }
- $query->orderBy('l.id DESC');
- $pagination = pagination_make($query);
- $list = $pagination['list'];
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'data' => $list,
- 'pageNo' => $pagination['pageNo'],
- 'totalCount' => $pagination['totalCount']
- ],
- ]);
- }
- /**
- * 模块名:actionAccountLogList
- * 代码描述:骑手评价记录
- * 请求方式:GET
- * 创建时间:2024/03/19 09:35:52
- * @param string name
- * @param string start_time
- * @param string end_time
- */
- public function actionGetCourierComment() {
- $name = get_params('name');
- $start_time = get_params('start_time');
- $end_time = get_params('end_time');
- $store_id = get_store_id();
- $query = LocalDeliveryCourierComment::find()->alias('cc')
- ->leftJoin(['c' => LocalDeliveryCourier::tableName()], 'cc.rider_id = c.id')
- ->where(['c.is_delete' => 0, 'cc.store_id' => $store_id]);
- if ($name) {
- $query->andWhere(['LIKE', 'c.real_name', $name]);
- }
- if ($start_time) {
- $start_time = strtotime($start_time);
- $query->andWhere(['>=', 'cc.created_at', $start_time]);
- }
- if ($end_time) {
- $end_time = strtotime($end_time);
- $query->andWhere(['<=', 'cc.created_at', $end_time]);
- }
- $query->select('cc.id, c.real_name name, cc.star, cc.desc, cc.is_show, cc.created_at')->orderBy('id desc');
- $pagination = pagination_make($query);
- $list = $pagination['list'];
- foreach ($list as &$item) {
- $item['is_show'] = intval($item['is_show']);
- $item['created_at'] = date('Y-m-d H:i:s', $item['created_at']);
- $commentExt = LocalDeliveryCourierCommentExt::find()->where(['comment_id' => $item['id'], 'is_delete' => 0])->select('tag_id')->column();
- $content_arr = ['用户'.$item['star'].'星评价'];
- if (!empty($commentExt)) {
- $content_arr = LocalDeliveryCourierTag::find()->where(['id' => $commentExt])->select('tag')->column();
- }
- $item['desc'] = implode(' ', $content_arr);
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'data' => $list,
- 'pageNo' => $pagination['pageNo'],
- 'totalCount' => $pagination['totalCount']
- ],
- ]);
- }
- /**
- * 模块名:actionAccountLogList
- * 代码描述:修改骑手评价记录状态
- * 请求方式:GET
- * 创建时间:2024/03/19 09:35:52
- * @param string name
- * @param string start_time
- * @param string end_time
- */
- public function actionSetCourierCommentStatus() {
- $id = get_params('id');
- $is_show = get_params('is_show');
- $store_id = get_store_id();
- $localDeliveryCourierComment = LocalDeliveryCourierComment::findOne($id);
- if (empty($localDeliveryCourierComment)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '操作异常'
- ]);
- }
- if (!in_array($is_show, [0, 1])) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '操作异常'
- ]);
- }
- $localDeliveryCourierComment->is_show = $is_show;
- if (!$localDeliveryCourierComment->save()) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '操作失败' . json_encode($localDeliveryCourierComment->errors)
- ]);
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => '操作成功'
- ]);
- }
- //流水对账清单
- public function actionBillCheckList() {
- $isExport = get_params('isExport');
- $start_time = get_params('start_time');
- $end_time = get_params('end_time');
- $search_key = get_params('search_key');
- $query = DeliveryInfo::find()->alias('di')->leftJoin(['s' => Store::tableName()], 'di.store_id = s.id')
- ->where(['di.local_status' => 3, 'di.is_store_delivery_type' => 0, 'di.is_local' => 1, 'di.is_delete' => 0])->select([
- 'di.id',
- 'di.order_no',
- 'di.store_id',
- 'store_name' => 's.name',
- 'store_mobile' => 's.contact_tel',
- 'di.fee',
- 'di.rider_name',
- 'di.rider_mobile',
- 'di.confirm_time',
- ])->orderBy('id desc');
- if ($start_time) {
- $query->andWhere(['>=', 'confirm_time', strtotime($start_time)]);
- }
- if ($end_time) {
- $query->andWhere(['<=', 'confirm_time', strtotime($end_time)]);
- }
- if ($search_key) {
- $query->andWhere(['LIKE', 's.name', $search_key]);
- }
- if ($isExport) {
- $list = $query->asArray()->all();
- } else {
- $pagination = pagination_make($query);
- $list = $pagination['list'];
- }
- foreach ($list as $index => &$item) {
- $store = Store::findOne($item['store_id']);
- unset($list[$index]['store_id']);
- $item['store_name'] = $store->name ?: '';
- $item['store_mobile'] = $store->contact_tel;
- $order = Order::findOne(['order_no' => $item['order_no'], 'is_delete' => 0]);
- $item['created_at'] = date('Y-m-d H:i:s', $order->created_at);
- $item['delivery_time'] = date('Y-m-d H:i:s', $order->delivery_time);
- $item['confirm_time'] = date('Y-m-d H:i:s', $item['confirm_time']);
- }
- if ($isExport) {
- $export_field = [
- [
- 'id' => 'ID',
- 'order_no' => '订单号',
- 'store_name' => '商城名称',
- 'store_mobile' => '商城手机号',
- 'fee' => '配送费',
- 'rider_name' => '骑手名称',
- 'rider_mobile' => '骑手手机号',
- 'confirm_time' => '送达时间',
- 'created_at' => '下单时间',
- 'delivery_time' => '预计送达时间',
- ]
- ];
- $file_name = '财务列表';
- $data = array_merge($export_field, $list);
- return SimpleExcelWriter::streamDownload($file_name . time() . '.xlsx')
- ->noHeaderRow()
- ->addRows($data)
- ->toBrowser();
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => '',
- 'data' => [
- 'data' => $list,
- 'pageNo' => $pagination['pageNo'],
- 'totalCount' => $pagination['totalCount']
- ]
- ]);
- }
- }
|