| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765 |
- <?php
- namespace addons\Happiness\client\controllers;
- use addons\Printer\common\models\Printer;
- use addons\Store\common\enums\StoreEnum;
- use addons\Store\common\events\order\OrderRefundFinishEvent;
- use backend\modules\mall\services\RefundService;
- use common\enums\ApiStatusEnum;
- use common\enums\ExpressEnum;
- use common\enums\GoodsTypeEnum;
- use common\enums\MarketingTypeEnum;
- use common\enums\OrderSourceEnum;
- use common\enums\OrderStatusEnum;
- use common\enums\PayTypeEnum;
- use common\enums\RefundReasonEnum;
- use common\enums\RefundStatusEnum;
- use common\enums\RefundTypeEnum;
- use common\enums\ShippingTypeEnum;
- use common\enums\StatusEnum;
- use common\enums\UserWalletEnum;
- use common\helpers\LockHelper;
- use common\logic\order\OrderRefundLogic;
- use common\models\common\Express;
- use common\models\common\MallSetting;
- use common\models\goods\Goods;
- use common\models\mall\MallAddons;
- use common\models\order\Order;
- use common\models\order\OrderDetail;
- use common\models\order\OrderAction;
- use common\models\order\OrderExpress;
- use common\models\order\OrderRefund;
- use common\models\user\User;
- use Exception;
- use Yii;
- use yii\helpers\Json;
- use addons\Happiness\common\enums\HappinessEnum;
- use addons\Happiness\common\models\HappinessClerkLog;
- use addons\Happiness\common\models\HappinessOrder;
- use addons\Happiness\common\models\HappinessOrderRefund;
- use addons\Happiness\common\models\HappinessStore;
- use addons\Happiness\common\service\StoreService;
- use common\enums\AddonsEnum;
- use common\models\order\OrderMarketing;
- class OrderController extends BaseController
- {
- public $enableCsrfValidation = false;
- /**
- * 订单管理
- * @Author bing
- * @DateTime 2022-04-26 18:07:05
- * @return void
- * @copyright: Copyright (c) 2022 广东七件事集团
- */
- public function actionIndex()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isGet) {
- //商品列表筛选
- $get = Yii::$app->request->get();
- $isReserve = $get['is_reserve'] ?? 0;
-
- $order_status_list = HappinessEnum::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'], 'safe'],
- [['type', 'type_value'], 'string'],
- [['is_reserve'],'in', 'range' => [0,1]],
- // ['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[] = ['=', 'o.mall_id', $this->mall_id];
- $where[] = ['=', 'yo.store_id', $this->store_id];
- // $where[] = ['=', 'o.supplier_type', 0];
- $where[] = ['>=', 'o.status', StatusEnum::DISABLED];
- if ($isReserve) {
- $where[] = ['=', 'o.order_source', OrderSourceEnum::SOURCE_RESERVE];
- } else {
- $where[] = ['<>', 'o.order_source', OrderSourceEnum::SOURCE_RESERVE];
- }
- if (isset($get['order_id'])) $where[] = ['in', 'o.id', explode(',', $get['order_id'])];
- ($get['payment_type'] ?? false) && $where[] = ['=', 'o.payment_type', $get['payment_type']];
- ($get['shipping_type'] ?? false) && $where[] = ['=', 'o.shipping_type', $get['shipping_type']];
- if (isset($get['order_status']) && $get['order_status'] != 999) {
- $where[] = ['=', 'o.order_status', $get['order_status']];
- }
- ($get['order_no'] ?? false) && $where[] = ['=', 'o.order_no', $get['order_no']];
- ($get['start'] ?? false) && $where[] = ['>=', 'o.created_at', strtotime($get['start'])];
- ($get['end'] ?? false) && $where[] = ['<=', 'o.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', 'o.user_id', $uids];
- break;
- case 'user_id':
- $where[] = ['in', 'o.user_id', $get['type_value']];
- break;
- default:
- }
- }
- $alias = 'yo';
- $with = ['base_user', 'detail','reserve'];
- $order = "id desc";
- $join = [['LEFT JOIN', Order::tableName(). ' as o', "o.id = yo.order_id"]];
- $select = 'o.*,yo.store_id';
- $params = compact('where', 'with', 'order', 'alias', 'join', 'select');
- $page_data = HappinessOrder::listPage($params, false, true);
- if ($page_data === false) return $this->error(Goods::getStaticError());
- $compact_params = array_keys($page_data);
- $order_no_arr = array_column($page_data['list'],'order_no');
- $order_list = Order::lists(['where'=>[['order_no'=>$order_no_arr]],'index'=>'order_no','select'=>'id,order_no']);
- extract($page_data);
- $store_order_detail_ids = [];
- foreach ($page_data['list'] as $val){
- foreach ($val['detail'] as $value) {
- $store_order_detail_ids[]=$value['id'];
- }
- }
- $store_order_marketing_list = OrderMarketing::lists(['where'=>[['order_detail_id'=>$store_order_detail_ids]],'index'=>'order_detail_id']);
- $is_show_printer = 0;
- if(MallAddons::isInstall($this->mall_id,'Printer')){
- $res = Printer::lists([
- 'where' => [
- ['mall_id'=> $this->mall_id],
- ['store_id'=>$this->store_id],
- ['printer_type'=>2],
- ['status'=>StatusEnum::ENABLED]
- ]
- ]);
- if(!empty($res)) $is_show_printer = 1;
- }
- foreach ($list as &$order) {
- $order_expresses = OrderExpress::getOrderExpresses([['order_id' => $order['id']]]);
- $order['main_order_id'] = isset($order_list[$order['order_no']]['id']) ? $order_list[$order['order_no']]['id'] : 0;
- $order['Printer']['is_show_printer'] = $is_show_printer;
- $deduct_score = 0;
- $deduct_score_money = 0;
- 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'] = '--';
- }
- }
- if(!empty($store_order_marketing_list[$detail['id']])){
- $deduct_currency = json_decode($store_order_marketing_list[$detail['id']]['deduct_currency'],true);
- if(!empty($deduct_currency['score'])){
- $deduct_score+= $deduct_currency['score']['score'];
- $deduct_score_money+= $deduct_currency['score']['money'];
- }
- }
- }
- $order['score_deduct'] = '';
- if(!empty($deduct_score)&&!empty($deduct_score_money)){
- $deduct_score = bcadd($deduct_score,0,2);
- $deduct_score_money = bcadd($deduct_score_money,0,2);
- $order['score_deduct'] = "{$deduct_score}积分抵扣{$deduct_score_money}元";
- }
- $order['create_type_text'] = $order['create_type'] == 1 ? '线上下单' : '系统创建';
- }
- $marketing_type_map = MarketingTypeEnum::getMap();
- return $this->success('操作成功', compact($compact_params, 'order_status_list', 'payment_type_list', 'shipping_type_list', 'marketing_type_map'));
- }
- }
- return $this->render($this->action->id);
- }
- /**
- * 售后订单
- * @Author bing
- * @DateTime 2022-04-26 18:07:16
- * @return void
- * @copyright: Copyright (c) 2022 广东七件事集团
- */
- public function actionRefund()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isGet) {
- //商品列表筛选
- $get = Yii::$app->request->get();
- $refund_status_list = RefundStatusEnum::getMap();
- $refund_type_list = RefundTypeEnum::getMap();
- $rules = [
- [['is_feedback', 'goods_type'], '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 = [['o.mall_id' => $this->mall_id]];
- $where[] = ['=', 'yo.store_id', $this->store_id];
- $where[] = ['=', 'o.status', StatusEnum::ENABLED];
- if (!empty($get['goods_type'])) $where[] = ['o.goods_type' => $get['goods_type']];
- // 搜索查询
- !empty($get['order_no']) && $where[] = ['in', 'o.order_id', OrderRefund::getOidByOrderNo($this->mall_id, $get['order_no'])];
- if (isset($get['refund_status'])) {
- $where[] = ['=', 'o.refund_status', $get['refund_status']];
- } else {
- $where[] = ['in', 'o.refund_status', [RefundStatusEnum::APPLY, RefundStatusEnum::HANDEL, RefundStatusEnum::FINISH, RefundStatusEnum::RETURN_GOODS, RefundStatusEnum::EXCHANGE_GOODS, RefundStatusEnum::REFUSE]];
- }
- if (!empty($get['type']) && !empty($get['keyword'])) $where[] = HappinessOrderRefund::searchByKeyword($this->mall_id, $get['type'], $get['keyword']);
- $alias = 'yo';
- $with = ['base_user', 'orderDetail', 'order'];
- $order = "id desc";
- $join = [['LEFT JOIN', OrderRefund::tableName(). ' as o', "o.id = yo.refund_id"]];
- $select = 'o.*,yo.store_id';
- $params = compact('where', 'with', 'order', 'alias', 'join', 'select');
- $page_data = HappinessOrderRefund::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'));
- }
- }
- return $this->render($this->action->id, ['goods_type' => Json::encode(GoodsTypeEnum::getMap())]);
- }
- public function actionRefundDetail()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isGet) {
- //商品列表筛选
- $get = Yii::$app->request->get();
- $order_status_list = HappinessEnum::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) : [];
- $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'];
- $params = compact('where', 'with');
- $refund = OrderRefund::getOne($where, true, $with);
- if ($refund === false) return $this->error(Goods::getStaticError());
- $main_order = Order::findOne(['id'=>$refund['order_id']]);
- $store_order = HappinessOrder::findOne(['order_no'=>$main_order['order_no']??0]);
- // $store_order_credit = StoreOrderCredit::find()->where(['type'=>1,'order_id'=>$store_order['id']??0])
- // ->andWhere(['>','pay_time',0])->one();
- // $refund['orderDetail']['credit_money']= 0;
- // if(!empty($store_order_credit['extra'])){
- // $goods_id = $refund['orderDetail']['goods_id'];
- // $extra = json_decode($store_order_credit['extra'],true);
- // if(!empty($extra[$goods_id]['credit_money'])){
- // $refund['orderDetail']['goods_price'] = bcadd($refund['orderDetail']['goods_price'],$extra[$goods_id]['credit_money'],2);
- // $refund['orderDetail']['credit_money'] = $extra[$goods_id]['credit_money'];
- // }
- // }
- 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);
- // 五洲供应链判断是否能操作
- // 是否显示退货超期,撤销售后
- $is_show_revoce = (OrderRefund::findOne(['id' => $refund['id']]))->isReturnTimeoutOfRefund();
- $refund['option_limit'] = $refund['order']['order_source'] = 0;
- return $this->success('操作成功', compact('refund', 'order_status_list', 'payment_type_list', 'feedback_type_list', 'step_arr', 'address_list', 'step_text', 'is_show_revoce'));
- }
- }
- return $this->render($this->action->id);
- }
- /**
- * 订单详情
- * @Author bing
- * @DateTime 2021-09-06 14:09:56
- * @return void
- * @copyright: Copyright (c) 2020 广东七件事集团
- */
- public function actionDetail()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isGet) {
- //商品列表筛选
- $get = Yii::$app->request->get();
- $order_status_list = HappinessEnum::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[] = ['=', 'store_id', $this->store_id];
- $where[] = ['=', 'id', $get['id']];
- $where[] = ['>=', 'status', StatusEnum::DISABLED];
- $with = [
- 'base_user',
- 'detail',
- 'reserve',
- 'express',
- 'express_log',
- ];
- $params = compact('where', 'with');
- $order = Order::getOne($where, true, $with);
- if ($order === false) return $this->error(Goods::getStaticError());
- // $main_order = Order::getOne([['order_no'=>$order['order_no']]],true,['express','express_log']);
- $express_log = [];
- if ($order['express_log']) {
- foreach ($order['express_log'] as $item) {
- $item['status'] = ExpressEnum::getStatusMap($item['status']);
- $express_log[$item['order_express_id']] = $item;
- }
- }
- if (!empty($order['express'])) {
- foreach ($order['express'] as &$key) {
- if (isset($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']);
- }
- }
- }
- // $order['express'] = $main_order['express'] ?? [];
- 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];
- }
- }
- }
- }
- $shipping_type_text = ShippingTypeEnum::getShippingType($order['shipping_type']);
- $shipping_type_fields = ShippingTypeEnum::getShippingFields($order['shipping_type']);
- $step_arr = HappinessEnum::setpArrMap($order['order_status'], $shipping_type_text,$shipping_type_fields);// 订单状态跟踪
- $order_action = OrderAction::getOrderAction([['order_id' => $order['id']]]);
- $marketing_type_map = MarketingTypeEnum::getMap();
- $stepArr[] = ['title' => '买家下单', 'created_at' => '0', 'is_step' => 0];
- $stepArr[] = ['title' => '买家付款', 'created_at' => '0', 'is_step' => 0,];
- $stepArr[] = ['title' => $shipping_type_text, 'created_at' => '0', 'is_step' => 0,];
- $stepArr[] = ['title' => '交易完成', 'created_at' => '0', 'is_step' => 0,];
- if(!empty($step_arr)){
- foreach ($step_arr as $k=>$v){
- if(!in_array($v['field'],['deposite_pay_time','final_payment_time'])){
- if($order['shipping_type'] == ShippingTypeEnum::PICKUP){
- if($v['field'] == 'sign_time'){
- $step_arr[$k]['title'] = '买家自提';
- }
- }
- }
- }
- }
- //获取售后原因
- $refund_reason = RefundReasonEnum::getMap();
- $order['create_type_text'] = $order['create_type'] == 1 ? '线上下单' : '系统创建';
- $order['option_limit'] = intval($order['supplier_type'] == 4);
- return $this->success('操作成功', compact('order', 'stepArr', 'order_status_list', 'payment_type_list',
- 'shipping_type_list', 'step_arr', 'order_action', 'marketing_type_map', 'refund_reason'), ApiStatusEnum::CODE_SUCCESS, JSON_BIGINT_AS_STRING);
- }
- }
- return $this->render($this->action->id);
- }
- /**
- * 修改备注
- * @Author bing
- * @DateTime 2021-09-14 18:40:15
- * @return void
- * @copyright: Copyright (c) 2020 广东七件事集团
- */
- 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['store_id'] = $this->store_id;
- $form['operator_id'] = $this->admin->id ?? 0;
- $form['operator_name'] = $this->admin->account ?? '';
- $res = Order::remark($form);
- if ($res === false) return $this->error(Goods::getStaticError());
- return $this->success();
- }
- /**
- * 发货
- * @Author bing
- * @DateTime 2021-09-15 14:29:48
- * @return void
- * @copyright: Copyright (c) 2020 广东七件事集团
- */
- 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', 'memo_arr1', 'memo_arr2', 'memo_arr3'], '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['store_id'] = $this->store_id;
- $form['operator_id'] = $this->admin->id ?? 0;
- $form['operator_name'] = $this->admin->account ?? '';
- $form['memo'] = json_encode([$form['memo_arr1'],$form['memo_arr2'],$form['memo_arr3']],JSON_UNESCAPED_UNICODE);
- if (empty($form['shipping_change'])) {
- $res = HappinessOrder::OrderExpressDelivery($form,true);
- }
- if ($res === false) return $this->error(HappinessOrder::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['store_id'] = $this->store_id;
- $form['operator_id'] = $this->admin->id;
- $form['operator_name'] = $this->admin->account;
- $res = HappinessOrder::takeDelivery($form);
- if ($res === false) return $this->error(HappinessOrder::getStaticError());
- return $this->success();
- }
- /**
- * 完成订单
- * @param $id
- * @throws \yii\web\NotFoundHttpException
- */
- 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['store_id'] = $this->store_id;
- $form['operator_id'] = $this->admin->id ?? 0;
- $form['operator_name'] = $this->admin->account ?? '';
- $res = Order::complete($form);
- if ($res == false) return $this->error('操作订单失败:' . Order::getStaticError());
- return $this->success('操作成功');
- }
- /**
- * 修改收货地址
- * @Author bing
- * @DateTime 2021-09-14 18:40:15
- * @return void
- * @copyright: Copyright (c) 2020 广东七件事集团
- */
- 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['store_id'] = $this->store_id;
- $form['operator_id'] = $this->admin->id ?? 0;
- $form['operator_name'] = $this->admin->account ?? '';
- $form['is_store'] = 1;
- $res = Order::changeAddress($form);
- if ($res === false) return $this->error(Goods::getStaticError());
- return $this->success();
- }
- 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['store_id'] = $this->store_id;
- $form['operator_id'] = $this->admin->id ?? 0;
- $form['operator_name'] = $this->admin->account ?? '';
- $res = Order::close($form);
- if ($res === false) return $this->error(Goods::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['store_id'] = $this->store_id;
- $form['operator_id'] = $this->admin->id ?? 0;
- $form['operator_name'] = $this->admin->account ?? '';
- $res = Order::del($form);
- if ($res === false) return $this->error(Goods::getStaticError());
- return $this->success();
- }
- // 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['store_id'] = $this->store_id;
- // $form['operator_id'] = $this->admin->id ?? 0;
- // $form['operator_name'] = $this->admin->account ?? '';
- // $res = StoreOrder::pay($form, PayTypeEnum::OFFLINE);
- // if ($res === false) return $this->error(Goods::getStaticError());
- // return $this->success();
- // }
- /**
- * 售后处理
- * @Author: lun
- * @DateTime: 2021/10/12 0012 11:15
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|void
- */
- public function actionHandleRefund()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isPost) {
- //商品列表筛选
- $params = Yii::$app->request->post();
- $rules = [
- [['id', 'step_status'], 'required'],
- [['id', 'step_status', 'mobile', 'address_type'], 'integer'],
- [['saler_express', 'saler_express_no', 'address', 'consignee', 'refund_reason'], 'string'],
- [['saler_express', 'saler_express_no', 'address_type', 'customer_name'], 'safe'],
- ];
- $res = Yii::$app->services->validate->validate($params, $rules);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- // 退货地址
- $address = ['consignee' => $params['consignee'], 'mobile' => $params['mobile'], 'address' => $params['address']];
- // 换货物流信息
- $express = ['saler_express' => $params['saler_express'], 'saler_express_no' => $params['saler_express_no'], 'customer_name' => $params['customer_name']];
- $data = [
- 'id' => $params['id'],
- 'step_status' => $params['step_status'],
- 'address' => $address,
- 'express' => $express,
- 'refund_reason' => $params['refund_reason'] ?? '',
- 'is_store' => 1,
- 'operator_id' => $this->admin->id
- ];
- $logic = new OrderRefundLogic();
- $res = $logic->execute($this->mall_id, $data);
- if ($res == false) return $this->error($logic->getError());
- if (in_array($params['step_status'], [RefundStatusEnum::STEP_4, RefundStatusEnum::STEP_6]) && empty($params['is_async'])) {
- //触发订单售后完成
- $event = new OrderRefundFinishEvent($res['mall_id']);
- $data = [];
- $data['id'] = $res['id'];
- $data['source_table'] = 'order_detail';
- $data['source_table_id'] = $res['order_detail_id'];
- $data['step_status'] = $params['step_status'];
- Yii::$app->services->events->dispatch($event, $data, $event->listeners);
- }
- return $this->success('操作成功');
- }
- }
- }
- public function actionClerk(){
- $params = Yii::$app->request->post();
- $params['mall_id'] = $this->mall_id;
- $params['store_id'] = $this->store_id;
- // $params['clerk_code'] = $params['id'];
- $store = HappinessStore::findOne(['id'=>$this->store_id,'status'=>StatusEnum::ENABLED]);
- $params['clerk_id'] = (new StoreService(['mall_id' => $this->mall_id, 'store_id' => $this->store_id]))->getClerkIdByUserId($store['user_id']??0, true);
- $rse = HappinessClerkLog::setData($params);
- if($rse==false) return $this->error(HappinessClerkLog::getStaticError());
- return $this->success('操作成功');
- }
- public function actionReserve()
- {
- $is_show_username = Yii::$app->services->setting->mall->get($this->mall_id, 'order.is_show_username');
- return $this->render($this->action->id, ['is_show_username' => $is_show_username ?? 0]);
- }
- public function actionReserveDetail()
- {
- return $this->render($this->action->id, ['is_show_username' => $is_show_username ?? 0]);
- }
- /**
- * 撤销售后订单
- *
- * @return mixed
- */
- public function actionRevoceRefund(int $id)
- {
- $service = new RefundService(['mall_id' => $this->mall_id]);
- return $service->revoceRefund($id, ['is_store' => 1, 'operator_id' => $this->admin->id])
- ? $this->success('撤销售成功')
- : $this->error($service->getError());
- }
- public function actionGetOrderDetail()
- {
- $params = \Yii::$app->request->get();
- $res = \Yii::$app->services->validate->validate($params, [
- [['order_detail_id'], 'required'],
- ]);
- if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- $select = 'id,order_id,user_id,goods_name,sign_id,goods_attr_name,price,num,pic_url,goods_price,order_status,marketing_type,extra_info,adjust_money';
- $order_detail = OrderDetail::getOne([['id' => $params['order_detail_id']], 'mall_id' => $this->mall_id], 1, [], false, $select);
- if (empty($order_detail)) return $this->error('订单不存在');
- //价格等于商品价格加上修改价格
- $order_detail['goods_price'] = round($order_detail['goods_price'] + $order_detail['adjust_money'],2);
- return $this->success('操作成功',[ $order_detail]);
- }
- public function actionDoRefundSubmit()
- {
- $params = \Yii::$app->request->post();
- $res = \Yii::$app->services->validate->validate($params, [
- [['order_detail_id', 'reason', 'refund_price', 'settlement_method', 'balance_pre'], 'required'],
- [['shipping_status', 'pic_list', 'reason', 'refund_price', 'remark', 'type', 'user_id', 'settlement_method', 'balance_pre', 'main_order_detail_id'], 'safe'],
- ]);
- // if (empty($params['reason']))
- if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- $key = sprintf('DoRefundSubmit:%s', $params['user_id']);
- if (LockHelper::fLock($key)) return $this->error('请勿频繁请求');
- // 获取主商城订单详细
- $main_order_detail = OrderDetail::find()
- ->where(['mall_id' => $this->mall_id, 'id' => $params['order_detail_id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]])
- ->one();
- if (empty($main_order_detail)) return $this->error('订单不存在');
- $params['mall_id'] = $this->mall_id;
- $where = [
- ['=', 'order_detail_id', $main_order_detail['id']],
- ['=', 'user_id', $params['user_id']],
- ['=', 'mall_id', $this->mall_id],
- // ['=', 'store_id', $this->store_id],
- ['>', 'step_status', 0],
- ['<>', 'refund_status', RefundStatusEnum::REVOKE]
- ];
- $order_refund_model = OrderRefund::getOne($where, true);
- if ($order_refund_model) {
- LockHelper::unFLock($key);
- return $this->error('该订单商品已经申请过售后');
- }
- // 将申请修改为主商城信息
- $params['order_detail_id'] = $main_order_detail['id'];
- $res = OrderRefund::feedback($params);
- if ($res === false) {
- LockHelper::unFLock($key);
- return $this->error(Order::getStaticError());
- }
- $event = new \common\events\order\OrderRefundEvent();
- $event->mall_id = $this->mall_id;
- $order_detail['order_detail_id'] = $main_order_detail['id'];
- $order_detail['id'] = $res->id;
- $order_detail['operator_id'] = $this->admin->id;
- $order_detail['operator_name'] = $this->admin->account;
- $order_detail['is_admin'] = 1;
- $order_detail['admin_handler_refund'] = UserWalletEnum::ADMIN_HANDLER_REFUND;
- Yii::$app->services->events->dispatch($event, $order_detail, $event->listeners);
- LockHelper::unFLock($key);
- return $this->success('操作成功', ['id' => $res->id]);
- }
- }
|