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'] ] ]); } }