| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637 |
- <?php
- namespace addons\Mch\backend\controllers;
- use addons\Mch\common\models\Mch;
- use addons\Printer\common\models\Printer;
- use common\enums\DownloadEnum;
- use common\enums\ExpressEnum;
- use common\enums\MarketingTypeEnum;
- use common\enums\OrderStatusEnum;
- use common\enums\PayTypeEnum;
- use common\enums\RefundStatusEnum;
- use common\enums\RefundTypeEnum;
- use common\enums\ShippingTypeEnum;
- use common\enums\StatusEnum;
- use common\helpers\csv\CsvExportHelper;
- use common\models\common\CapitalLog;
- use common\models\common\Express;
- use common\models\common\MallSetting;
- use common\models\mall\MallAddons;
- use common\models\order\Order;
- use common\models\order\OrderAction;
- use common\models\order\OrderDetail;
- use common\models\order\OrderExpress;
- use common\models\order\OrderExpressLog;
- use common\models\user\User;
- use yii\helpers\Json;
- use common\models\elasticsearch\order\OrderAction as OrderActionEs;
- use common\models\order\OrderRefund;
- use common\models\user\UserLevel;
- class StoreOrderController extends BaseController
- {
- /**
- * @name:
- * @msg: 订单列表
- * @param {*}
- * @return {*}
- */
- public function actionIndex()
- {
- if (!\Yii::$app->request->isAjax) {
- return $this->render('/store-order/index');
- }
- if (\Yii::$app->request->isGet) {
- //商品列表筛选
- $get = \Yii::$app->request->get();
- $order_status_list = OrderStatusEnum::getMap();
- $payment_type_list = PayTypeEnum::getMap();
- $shipping_type_list = ShippingTypeEnum::getMap();
- $rules = [
- [['order_status'], 'in', 'range' => array_keys($order_status_list)],
- [['payment_type'], 'in', 'range' => array_keys($payment_type_list)],
- [['shipping_type'], 'in', 'range' => array_keys($shipping_type_list)],
- [['start', 'end'], 'datetime', 'format' => 'php:Y-m-d H:i:s'],
- [['order_no', 'mobile', 'order_id', 'marketing_type'], 'safe'],
- [['type', 'type_value', 'keyword'], 'string'],
- // ['mobile', 'match', 'pattern' => '/^1\d{10}$/', 'message' => '请输入正确的手机号码'],
- ];
- $res = \Yii::$app->services->validate->validate($get, $rules);
- if (!$res) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- // 查询参数
- $where[] = ['=', 'mall_id', $this->mall_id];
- $where[] = ['>=', 'status', StatusEnum::DISABLED];
- $where[] = ['store_id'=>0];
- if(isset($get['order_id']))$where[] = ['in', 'id', explode(',',$get['order_id'])];
- ($get['payment_type'] ?? false) && $where[] = ['=', 'payment_type', $get['payment_type']];
- ($get['shipping_type'] ?? false) && $where[] = ['=', 'shipping_type', $get['shipping_type']];
- if(isset($get['order_status'])&&$get['order_status'] != 999){
- $where[] = ['=', 'order_status', $get['order_status']];
- }
- ($get['order_no'] ?? false) && $where[] = ['=', 'order_no', $get['order_no']];
- ($get['start'] ?? false) && $where[] = ['>=', 'created_at', strtotime($get['start'])];
- ($get['end'] ?? false) && $where[] = ['<=', 'created_at', strtotime($get['end'])];
- if($get['type_value'] ?? false){
- switch($get['type']){
- case 'mobile':
- $uids = User::find()->select('id')->where(['like','mobile',$get['type_value'].'%',false])->column();
- !empty($uids) && $where[] = ['in', 'user_id', $uids];
- break;
- case 'user_id':
- $where[] = ['in', 'user_id', $get['type_value']];
- break;
- default:
- }
- }
- $where[]=['!=','mch_id',0];
- //查找多商户门店
- if (!empty($get['keyword'])) {
- $mch_info = Mch::lists([
- 'where' => [
- ['mall_id' => $this->mall_id],
- ['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]],
- ['or', ['like', 'store_name', $get['keyword']], ['like', 'shop_mobile', $get['keyword']]],
- ],
- ]);
- if (!empty($mch_info)) {
- $mch_ids = array_column($mch_info, 'id');
- $where[] = ['mch_id' => $mch_ids];
- } else {
- $where[] = ['mch_id' => []];
- }
- }
- if (!empty($get['marketing_type'])) {
- $where[] = ['marketing_type' => $get['marketing_type']];
- }
- $with = ['base_user', 'detail', 'mch'];
- $order = "id desc";
- $params = compact('where', 'with', 'order', 'alias');
- $page_data = Order::listPage($params);
- if ($page_data === false) return $this->error(Order::getStaticError());
- $compact_params = array_keys($page_data);
- extract($page_data);
- if(MallAddons::isInstall($this->mall_id,'Printer')){
- $mch_ids = array_column($page_data['list'],'mch_id');
- $printer_list = Printer::lists([
- 'where' => [
- ['mall_id'=> $this->mall_id],
- ['mch_id'=>$mch_ids],
- ['printer_type'=>3],
- ['status'=>StatusEnum::ENABLED]
- ],
- 'index'=>'mch_id'
- ]);
- }
- foreach ($list as &$order) {
- $order_expresses = OrderExpress::getOrderExpresses([['order_id' => $order['id']]]);
- foreach ($order['detail'] as &$detail) {
- // 物流信息
- $detail['express'] = '';
- foreach ($order_expresses as $record) {
- $order_detail_ids = empty($record['order_detail_ids']) ? [] : json_decode($record['order_detail_ids'], true);
- if (is_string($order_detail_ids)) $order_detail_ids = [];
- if (in_array($detail['id'], $order_detail_ids)) {
- $detail['express'] = $record['express_name'] . ' | ' . $record['express_no'];
- if ($record['shipping_type'] == 0) $detail['express'] = '--';
- }
- }
- }
- $order['Printer']['is_show_printer'] = 0;
- if(isset($printer_list[$order['mch_id']])){
- $order['Printer']['is_show_printer'] = 1;
- }
- }
- $export_list = Order::fieldsList();
- $export_list['mch_id'] = '商户名称';
- $marketing_type_map = MarketingTypeEnum::getMap();
- return $this->success('操作成功', compact($compact_params, 'order_status_list', 'payment_type_list', 'shipping_type_list', 'export_list', 'marketing_type_map'));
- }
- if(\Yii::$app->request->post('flag') == 'EXPORT'){
- $post = \Yii::$app->request->post();
- $post['mall_id'] = $this->mall_id;
- $post['mch_id'] = -1;
- $filename = '商户订单列表-' . date('YmdHis').'_'.rand(10000,99999);
- $res = CsvExportHelper::exportDownLoadCenter($this->mall_id,$filename,DownloadEnum::TYPE_ORDERS,Order::class,'exportHandle',$post, 0);
- if ($res === false) return $this->error('加入导出任务失败'.CsvExportHelper::getStaticError());
- return $this->success('添加导出任务成功,任务完成后请在下载中心进行下载!');
- }
- }
- /**
- * @name:
- * @msg: 订单详情
- * @param {*}
- * @return {*}
- */
- public function actionDetail()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isGet) {
- //商品列表筛选
- $get = \Yii::$app->request->get();
- $order_status_list = OrderStatusEnum::getMap();
- $payment_type_list = PayTypeEnum::getMap();
- $shipping_type_list = ShippingTypeEnum::getMap();
- $rules = [[['id'], 'required']];
- $res = \Yii::$app->services->validate->validate($get, $rules);
- $where = [['mall_id' => $this->mall_id]];
- $where[] = ['=', 'id', $get['id']];
- $where[] = ['>=', 'status', StatusEnum::DISABLED];
- $with = [
- 'base_user',
- 'express',
- 'express_log',
- 'detail'
- ];
- $params = compact('where', 'with');
- $order = Order::getOne($where, true, $with);
- if ($order === false) return $this->error(Order::getStaticError());
- $express_log = [];
- if ($order['express_log']) {
- foreach ($order['express_log'] as $item) {
- $item['status'] = ExpressEnum::getStatusMap($item['express_status']);
- $express_log[$item['order_express_id']] = $item;
- }
- }
- if (!empty($order['express'])) {
- foreach ($order['express'] as &$key) {
- if (!empty($express_log[$key['id']])) {
- $express_list = Json::decode($express_log[$key['id']]['list']);
- $key['now_state'] = $express_log[$key['id']]['status'];
- $key['express_log'] = is_null($express_list) ? '' : array_reverse($express_list['Traces']);
- }
- }
- }
- if (!empty($order['detail'])) {
- foreach ($order['detail'] as &$detail) {
- if (!empty($detail['attr_groups_format'])) {
- $attr_groups_format = json_decode($detail['attr_groups_format'], true);
- $attr_list = $attr_groups_format[$detail['sign_id']];
- $attr_group_name_list = array_column($attr_list, 'attr_group_name');
- $attr_name_list = array_column($attr_list, 'attr_name');
- $detail['attr_list'] = [];
- foreach ($attr_group_name_list as $index => $attr_group_name) {
- $detail['attr_list'][] = $attr_group_name . ':' . $attr_name_list[$index];
- }
- }
- }
- }
- $temp_step_arr = OrderStatusEnum::setpArrMap($order['order_status']); // 订单状态跟踪
- $step_arr = [];
- if(!empty($temp_step_arr)){
- foreach ($temp_step_arr as $k=>$v){
- if(!in_array($v['field'],['deposite_pay_time','final_payment_time'])){
- $step_arr[] = $v;
- }
- }
- }
- $order_action = OrderAction::getOrderAction([['order_id' => $get['id']]]);
- $marketing_type_map = MarketingTypeEnum::getMap();
- return $this->success('操作成功', compact('order', 'order_status_list', 'payment_type_list', 'shipping_type_list', 'step_arr', 'order_action', 'marketing_type_map'));
- }
- }
- return $this->render($this->action->id);
- }
- /**
- * @name:
- * @msg: 修改订单价格
- * @param {*}
- * @return {*}
- */
- public function actionChangePrice()
- {
- // 商品操作
- $form = \Yii::$app->request->post();
- $rules = [[['id', 'shipping_money'], 'required'], [['id'], 'integer'], [['shipping_money'], 'number'], ['detail', 'safe']];
- $res = \Yii::$app->services->validate->validate($form, $rules);
- if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- $form['mall_id'] = $this->mall['id'];
- $form['mch_id'] = $this->admin->mch_id;
- $form['operator_id'] = $this->admin->id;
- $form['operator_name'] = $this->admin->account;
- $res = Order::ChangePrice($form);
- if ($res === false) return $this->error(Order::getStaticError());
- return $this->success();
- }
- /**
- * @name:
- * @msg: 订单支付
- * @param {*}
- * @return {*}
- */
- public function actionPay()
- {
- // 商品操作
- $form = \Yii::$app->request->post();
- $rules = [[['id'], 'required'], [['id'], 'integer']];
- $res = \Yii::$app->services->validate->validate($form, $rules);
- if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- $form['mall_id'] = $this->mall['id'];
- $form['mch_id'] = $this->admin->mch_id;
- $form['operator_id'] = $this->admin->id;
- $form['operator_name'] = $this->admin->account;
- $res = Order::pay($form, PayTypeEnum::OFFLINE);
- if ($res === false) return $this->error(Order::getStaticError());
- return $this->success();
- }
- /**
- * @name:
- * @msg: 关闭订单
- * @param {*}
- * @return {*}
- */
- public function actionClose()
- {
- // 商品操作
- $form = \Yii::$app->request->post();
- $rules = [[['id'], 'required'], [['id'], 'integer']];
- $res = \Yii::$app->services->validate->validate($form, $rules);
- if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- $form['mall_id'] = $this->mall['id'];
- $form['mch_id'] = $this->admin->mch_id;
- $form['operator_id'] = $this->admin->id;
- $form['operator_name'] = $this->admin->account;
- $res = Order::close($form);
- if ($res === false) return $this->error(Order::getStaticError());
- return $this->success();
- }
- public function actionDel()
- {
- // 商品操作
- $form = \Yii::$app->request->post();
- $rules = [[['id'], 'required'], [['id'], 'integer']];
- $res = \Yii::$app->services->validate->validate($form, $rules);
- if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- $form['mall_id'] = $this->mall_id;
- $form['mch_id'] = $this->admin->mch_id;
- $form['operator_id'] = $this->admin->id;
- $form['operator_name'] = $this->admin->account;
- $form['is_admin'] = 1;
- $res = Order::del($form);
- if ($res === false) return $this->error(Order::getStaticError());
- return $this->success();
- }
- /**
- * @name:
- * @msg: 修改订单备注
- * @param {*}
- * @return {*}
- */
- public function actionRemark()
- {
- $form = \Yii::$app->request->post();
- $rules = [[['id'], 'required'], [['id'], 'integer'], [['remark', 'seller_remark'], 'string']];
- $res = \Yii::$app->services->validate->validate($form, $rules);
- if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- $form['mall_id'] = $this->mall['id'];
- $form['mch_id'] = $this->admin->mch_id;
- $form['operator_id'] = $this->admin->id;
- $form['operator_name'] = $this->admin->account;
- $res = Order::remark($form);
- if ($res === false) return $this->error(Order::getStaticError());
- return $this->success();
- }
- /**
- * @name:
- * @msg: 修改订单收货地址
- * @param {*}
- * @return {*}
- */
- public function actionChangeAddress()
- {
- $form = \Yii::$app->request->post();
- $rules = [
- [['id', 'receiver_name', 'mobile', 'province', 'city', 'area', 'address', 'region_name'], 'required'],
- [['id', 'province', 'city', 'area', 'zip'], 'integer'],
- [['address', 'region_name', 'receiver_name', 'mobile'], 'string']
- ];
- $res = \Yii::$app->services->validate->validate($form, $rules);
- if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- $form['mall_id'] = $this->mall['id'];
- $form['mch_id'] = $this->admin->mch_id;
- $form['operator_id'] = $this->admin->id;
- $form['operator_name'] = $this->admin->account;
- $form['is_admin'] = 1;
- $res = Order::changeAddress($form);
- if ($res === false) return $this->error(Order::getStaticError());
- return $this->success();
- }
- /**
- * @name:
- * @msg: 发货
- * @param {*}
- * @return {*}
- */
- public function actionShipping()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isGet) {
- // 获取订单发货信息
- $jd_mch_code = MallSetting::conf($this->mall_id, 'logistics.jd_mch_code');
- $express_list = Express::getExpresses([], [], true, '*');
- return $this->success('请求成功', compact('express_list', 'jd_mch_code'));
- } else {
- // 发货
- $form = \Yii::$app->request->post();
- $rules = [
- [['shipping_type', 'id'], 'required'],
- [['express_id', 'shipping_type', 'id'], 'integer'],
- [['express_name', 'express_no', 'memo'], 'string'],
- [['order_detail_ids'], 'each', 'rule' => ['integer']],
- [['shipping_change', 'customer_name'], 'safe']
- ];
- $res = \Yii::$app->services->validate->validate($form, $rules);
- if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- $form['mall_id'] = $this->mall_id;
- $form['mch_id'] = $this->admin->mch_id;
- $form['operator_id'] = $this->admin->id;
- $form['operator_name'] = $this->admin->account;
- if (empty($form['shipping_change'])) {
- $res = OrderExpress::delivery($form); // 发货
- } else {
- $res = OrderExpress::shippingChange($form); // 修改物流
- }
- if ($res === false) return $this->error(OrderExpress::getStaticError());
- return $this->success('发货/修改物流成功');
- }
- }
- }
- /**
- * 收货
- * @param $id
- * @param string $member_id
- * @throws UnprocessableEntityHttpException
- * @throws \yii\web\NotFoundHttpException
- */
- public function actionTakeDelivery()
- {
- // 商品操作
- $form = \Yii::$app->request->post();
- $rules = [[['id'], 'required'], [['id'], 'integer']];
- $res = \Yii::$app->services->validate->validate($form, $rules);
- if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- $form['mall_id'] = $this->mall['id'];
- $form['mch_id'] = $this->admin->mch_id;
- $form['operator_id'] = $this->admin->id;
- $form['operator_name'] = $this->admin->account;
- $res = Order::takeDelivery($form);
- if ($res === false) return $this->error(Order::getStaticError());
- return $this->success();
- }
- /**
- * @name:
- * @msg: 订单操作日志
- * @param {*}
- * @return {*}
- */
- public function actionOrderAction()
- {
- try {
- $request = \Yii::$app->request;
- if ($request->isAjax) {
- if ($request->isGet) {
- $params = \Yii::$app->request->get();
- $params['where'] = ['mall_id' => $this->mall_id];
- $params['is_page'] = true;
- $params['order'] = 'created_at desc';
- $list = OrderActionEs::getList($params);
- return $this->success('ok', $list);
- }
- }
- } catch (\Exception $e) {
- return $this->error($e->getMessage(), []);
- }
- return $this->render($this->action->id);
- }
- /**
- * @name:
- * @msg: 订单完成
- * @param {*}
- * @return {*}
- */
- public function actionSalesOrder()
- {
- // 商品操作
- $form = \Yii::$app->request->post();
- $rules = [[['id'], 'required'], [['id'], 'integer']];
- $res = \Yii::$app->services->validate->validate($form, $rules);
- if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- $form['mall_id'] = $this->mall_id;
- $form['operator_id'] = $this->admin->id;
- $form['operator_name'] = $this->admin->account;
- $res = Order::complete($form);
- if ($res == false) return $this->error('操作订单失败:' . Order::getStaticError());
- return $this->success('操作成功');
- }
- /**
- * @name:
- * @msg: 分润明细
- * @param {*}
- * @return {*}
- */
- public function actionCommissionAndScoreList()
- {
- $params = \Yii::$app->request->get();
- $wallet_type = 'commission';
- if (!empty($params['wallet_type'])) $wallet_type = $params['wallet_type'];
- $condition['where'] = [['order_id' => $params['order_id']]];
- $condition['select'] = 'id';
- $order_detail_list = OrderDetail::lists($condition);
- $order_detail_ids = array_column($order_detail_list, 'id');
- $condition = [
- 'where' => [
- ['source_table' => 'order_detail'],
- ['source_table_id' => $order_detail_ids]
- ],
- ];
- CapitalLog::$capitalType = "{$wallet_type}";
- $list = CapitalLog::getList($condition, 0);
- $level = UserLevel::find()->select("name,level")->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])->asArray()->all();
- $level_data = array_column($level, 'name', 'level');
- CapitalLog::$capitalType = "{$wallet_type}_frozen";
- $condition['where'][] = ['status' => 0];
- $frozen_list = CapitalLog::getList($condition, 1);
- $list = array_merge($list, $frozen_list);
- return $this->success('操作成功', ['list' => $list, 'user_level' => $level_data]);
- }
- /**
- * @name:
- * @msg: 售后订单列表
- * @param {*}
- * @return {*}
- */
- public function actionRefundList()
- {
- if (!\Yii::$app->request->isAjax) {
- return $this->render('/store-order/refund');
- }
- if (\Yii::$app->request->isGet) {
- //商品列表筛选
- $get = \Yii::$app->request->get();
- $refund_status_list = RefundStatusEnum::getMap();
- $refund_type_list = RefundTypeEnum::getMap();
- $rules = [
- [['is_feedback'], 'integer'],
- [['keyword', 'order_no', 'type'], 'string'],
- [['type', 'order_no', 'keyword', 'refund_status'], 'safe'],
- ];
- $res = \Yii::$app->services->validate->validate($get, $rules);
- if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- $where[] = ['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED];
- $where[] = ['!=', 'mch_id', 0];
- // 搜索查询
- !empty($get['order_no']) && $where[] = ['in', 'order_id', OrderRefund::getOidByOrderNo($this->mall_id, $get['order_no'])];
- if (isset($get['refund_status'])) {
- $where[] = ['=', 'refund_status', $get['refund_status']];
- } else {
- $where[] = ['in', 'refund_status', [RefundStatusEnum::APPLY, RefundStatusEnum::HANDEL, RefundStatusEnum::FINISH, RefundStatusEnum::RETURN_GOODS, RefundStatusEnum::EXCHANGE_GOODS, RefundStatusEnum::REFUSE]];
- }
- if (!empty($get['type']) && !empty($get['keyword'])) $where[] = OrderRefund::searchByKeyword($this->mall_id, $get['type'], $get['keyword']);
- $with = ['base_user', 'orderDetail', 'order'];
- $order = "id desc";
- $params = compact('where', 'with', 'order');
- $page_data = OrderRefund::listPage($params, false, true);
- if ($page_data === false) return $this->error(OrderRefund::getStaticError());
- $compact_params = array_keys($page_data);
- extract($page_data);
- foreach ($list as &$order) {
- foreach ($order['orderDetail'] as &$detail) {
- if (!empty($detail['attr_groups_format'])) {
- //规格
- $attr_groups_format = Json::decode($detail['attr_groups_format'], true);
- $attr_list = $attr_groups_format[$detail['sign_id']];
- $attr_group_name_list = array_column($attr_list, 'attr_group_name');
- $attr_name_list = array_column($attr_list, 'attr_name');
- $detail['attr_list'] = [];
- foreach ($attr_group_name_list as $index => $attr_group_name) {
- $detail['attr_list'][] = $attr_group_name . ':' . $attr_name_list[$index];
- }
- }
- }
- }
- return $this->success('操作成功', compact($compact_params, 'refund_status_list', 'refund_type_list'));
- }
- }
- /**
- * @name:
- * @msg: 售后订单详情
- * @param {*}
- * @return {*}
- */
- public function actionRefundDetail()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isGet) {
- //商品列表筛选
- $get = \Yii::$app->request->get();
- $order_status_list = OrderStatusEnum::getMap();
- $payment_type_list = PayTypeEnum::getMap();
- $feedback_type_list = OrderStatusEnum::getFeedbackMap();
- $address_list = \Yii::$app->services->setting->mall->get($this->mall_id, 'return_address.return_address');
- $address_list = $address_list ? json_decode($address_list, true) : [];
- $rules = [[['id'], 'required']];
- $res = \Yii::$app->services->validate->validate($get, $rules);
- if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- $where = [['mall_id' => $this->mall_id]];
- $where[] = ['id' => $get['id']];
- $where[] = ['>=', 'status', StatusEnum::DISABLED];
- $with = ['base_user', 'order', 'orderDetail', 'marketing', 'step'];
- $refund = OrderRefund::getOne($where, true, $with);
- if ($refund === false) return $this->error(OrderRefund::getStaticError());
- foreach ($refund['orderDetail'] as $key => $detail) {
- if (!empty($detail['attr_groups_format'])) {
- $attr_groups_format = Json::decode($detail['attr_groups_format'], true);
- $attr_list = $attr_groups_format[$detail['sign_id']];
- $attr_group_name_list = array_column($attr_list, 'attr_group_name');
- $attr_name_list = array_column($attr_list, 'attr_name');
- $detail['attr_list'] = [];
- }
- }
- // 返还优惠内容
- if (!empty($refund['marketing'])) {
- $discount = [];
- $marketing = $refund['marketing'];
- if (!empty($marketing['deduct_score'])) {
- $score_name = \Yii::$app->services->setting->mall->get($this->mall_id, 'score.score_name');
- $discount[] = floatval($marketing['deduct_score']) . $score_name;
- }
- $refund['discount'] = implode('+', $discount);
- }
- $step_status = $refund['step'][0]['step_status'] ?? 0;
- $step_arr = RefundStatusEnum::stepNumArr(in_array($step_status, [RefundStatusEnum::STEP_NEGATIVE_1, RefundStatusEnum::STEP_NEGATIVE_2]) ? 1 : $refund['type']); // 进度条
- $step_text = RefundStatusEnum::getStepStatusText($step_status);
- return $this->success('操作成功', compact('refund', 'order_status_list', 'payment_type_list', 'feedback_type_list', 'step_arr', 'address_list', 'step_text'));
- }
- }
- return $this->render('/store-order/refund-detail');
- }
- }
|