| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754 |
- <?php
- namespace backend\modules\mall\controllers;
- use addons\Community\common\service\HeadService;
- use addons\QiJuhe\common\models\OrderRefundModel;
- use addons\Community\common\models\CommunityGoodsSetting;
- use addons\ScoreExpansion\common\enums\ScoreExpansionEnum;
- use addons\ScoreExpansion\common\models\ScoreExpansion;
- use common\enums\AddonsEnum;
- use common\components\export\CsvTool;
- use common\enums\DownloadEnum;
- use common\enums\ExpressEnum;
- use common\enums\GlobalFuncEnum;
- use common\enums\GoodsTypeEnum;
- use common\enums\MarketingTypeEnum;
- use common\enums\OrderCommentEnum;
- use common\enums\OrderSourceEnum;
- use common\enums\OrderStatusEnum;
- use common\enums\RabbitMqEnum;
- use common\enums\RefundStatusEnum;
- use common\enums\RefundTypeEnum;
- use common\enums\ShippingTypeEnum;
- use backend\controllers\MallController;
- use backend\modules\mall\services\RefundService as MallRefundService;
- use common\enums\PayTypeEnum;
- use common\enums\StatusEnum;
- use common\events\order\OrderLeaveEvent;
- use common\events\order\OrderRemarkEvent;
- use common\events\order\ShippingValidateEvent;
- use common\globals\GlobalInvoke;
- use common\helpers\LockHelper;
- use common\listeners\order\OrderDeliveryListener;
- use common\logic\order\OrderRefundLogic;
- use common\models\common\Addons;
- use common\models\common\CapitalLog;
- use common\models\common\Download;
- use common\models\common\Express;
- use common\models\common\GlobalVarMap;
- use common\models\common\MallSetting;
- use common\models\common\PaymentRefund;
- use common\models\common\PaymentTrade;
- use common\models\common\PaymentTradeOrder;
- use common\models\elasticsearch\order\OrderAction as OrderActionEs;
- use common\models\goods\Goods;
- use common\models\goods\GoodsAttr;
- use common\models\goods\GoodsReserveSku;
- use common\models\mall\MallAddons;
- use common\models\order\Order;
- use common\models\order\OrderAction;
- use common\models\order\OrderBatchDelivery;
- use common\models\order\OrderBatchDeliveryError;
- use common\models\order\OrderDetail;
- use common\models\order\OrderExpress;
- use common\models\order\OrderExpressLog;
- use common\models\order\OrderExtra;
- use common\models\order\OrderMarketing;
- use common\models\order\OrderRefund;
- use common\models\order\OrderRefundStep;
- use common\models\user\DigitalLog;
- use common\models\user\UserLevel;
- use common\models\order\OrderInvoice;
- use Exception;
- use Yii;
- use yii\helpers\Json;
- use common\helpers\csv\CsvExportHelper;
- use common\models\order\OrderUserHandle;
- use common\models\user\User;
- use common\enums\ApiStatusEnum;
- use common\enums\RefundReasonEnum;
- use common\events\data\backend\GetOrderListEvent;
- use addons\ValetOrder\common\models\ValetOrder;
- use addons\QiDingDong\common\service\RefundService;
- use addons\ServicePointAppointment\common\service\OrderService;
- use common\enums\UserWalletEnum;
- use common\events\mall\OrderGetExpressEvent;
- use services\common\UserWalletService;
- use backend\modules\mall\services\OrderService as MallOrderService;
- /**
- * 商品订单控制器
- *
- * @Author bing
- * @DateTime 2021-09-06 14:11:55
- * @copyright: Copyright (c) 2020 广东七件事集团
- */
- class OrderController extends MallController
- {
- // 预约订单
- 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]);
- }
- /**
- * 预约订单详情
- * @return string
- */
- public function actionReserveDetail()
- {
- return $this->render($this->action->id);
- }
- public function actionIndex()
- {
- date_default_timezone_set('PRC');
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isGet) {
- //商品列表筛选
- $get = Yii::$app->request->get();
- $isReserve = $get['is_reserve'] ?? 0;
- if($isReserve){
- $order_status_list = OrderStatusEnum::getReserveMap();
- }else{
- $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', 'province', 'is_use_coupon'], 'safe'],
- [['type', 'type_value', 'marketing_type', 'cate_id', 'not_marketing_type'], '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 = Order::searchParams($this->mall_id, $get);
- $with = ['base_user', 'detail','reserve', 'extra'];
- $order = "id desc";
- $params = compact('where', 'with', 'order');
- $page_data = Order::listPage($params, false, true);
- if ($page_data === false) return $this->error(Goods::getStaticError());
- if (!empty($page_data['list'])) {
- $shippingValidateEventEvent = new ShippingValidateEvent($this->mall_id);
- $shippingValidateEventEvent->setOrderIds(array_column($page_data['list'], 'id') ?: []);
- Yii::$app->services->events->dispatch($shippingValidateEventEvent);
- $user_handle_ids = OrderUserHandle::lists([
- 'where' => [
- ['order_id' => array_column($page_data['list'], 'id') ?? []],
- ['order_status' => OrderStatusEnum::ACCOMPLISH],
- ['mall_id' => $this->mall_id]
- ],
- 'select' => 'order_id',
- ]);
- $user_handle_ids = array_column($user_handle_ids, 'order_id') ?? [];
- foreach ($page_data['list'] as &$order) {
- $order['show_botton'] = true;
- $order_expresses = OrderExpress::getOrderExpresses([['order_id' => $order['id']]]);
- $order['is_user_handle_finish'] = in_array($order['id'], $user_handle_ids) ? 1 : 0;
- //获取留言
- $order['leave'] = $order['extra']['message'] ?? '';
- // 判断是否无需物流信息
- $order['need_not_express'] = true;
- $order['is_allow_shipping'] = $shippingValidateEventEvent->getIsAllow($order['id'])['isAllow'];
- foreach ($order['detail'] as &$detail) {
- // 获取商品信息
- $goodsInfo = Goods::getOne([['=', 'mall_id', $this->mall_id], ['=', 'id', $detail['goods_id']]], false, '', '', 'unit,goods_type, freight_type');
- $detail['goods_unit'] = $goodsInfo['unit'];
- $is_community_enable = false;
- // 判断是否是社区团购
- if (MallAddons::isInstall($this->mall_id, 'Community')) {
- $is_community_enable = CommunityGoodsSetting::getEnable($this->mall_id, $detail['goods_id']);
- }
- if (!empty($goodsInfo['freight_type']) || $is_community_enable) $order['need_not_express'] = false;
- $order['is_virtual'] = $detail['is_virtual'];
- // 物流信息
- $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($detail['goods_attr_name']) && $detail['goods_attr_id']){
- if ($isReserve) {
- $attr_info = GoodsReserveSku::getOne([['=','id',$detail['goods_attr_id']]],true,['goods']);
- } else {
- $attr_info = GoodsAttr::getOne([['=','id',$detail['goods_attr_id']]],true,['goods']);
- }
- $detail['goods_attr_name'] = $attr_info ? $attr_info['name'] : '';
- $detail['pic_url'] = !empty($attr_info['pic_url']) ? $attr_info['pic_url'] : (!empty($attr_info['goods']['cover_pic']) ? $attr_info['goods']['cover_pic'] : $detail['pic_url']);
- }
- }
- }
- }
- $page_data['list'] = GlobalInvoke::exec(GlobalFuncEnum::BACKEND_ORDER_LIST, $this->mall_id, [
- 'order' => $page_data['list'], 'mall_id' => $this->mall_id
- ]) ?:$page_data['list'];
- // 获取插件内容
- $event = new GetOrderListEvent($this->mall_id, $page_data['list']);
- Yii::$app->services->events->dispatch($event);
- $page_data['list'] = $event->getResultList();
- $export_list = Order::fieldsList();
- $marketing_type_map = MarketingTypeEnum::getMap();
- $marketing_type_map['order_user_handle_finish'] = '放弃退换货';
- $marketing_type_map[OrderSourceEnum::SOURCE_CLOUD_PRESCRIPTION] = OrderSourceEnum::getMap()[OrderSourceEnum::SOURCE_CLOUD_PRESCRIPTION];
- $sum_where = $where;
- array_unshift($sum_where, 'AND');
- $total_area_money = (float)Order::find()->where($sum_where)->sum('pay_money');
- $page_data['total_area_money'] = $total_area_money;
- $page_data['total_order_count'] = (int)Order::find()->where($sum_where)->count();
- $compact_params = array_keys($page_data);
- extract($page_data);
- $addons_commission_arr = GlobalInvoke::exec(GlobalInvoke::INVOKE_COMMISSION_TYPE, $this->mall_id, ['mall_id' => $this->mall_id]);
- //判断积分拓客插件有没有安装
- //获取商城已安装插件列表
- $valid_addons = MallAddons::getValidAddons($this->mall_id);
- if (in_array(AddonsEnum::ADDONS_NAME_SCORE_EXPANSION, $valid_addons)){
- $ScoreExpansionArr = (new ScoreExpansion())->getGoodsModeCommssionType();
- foreach($ScoreExpansionArr as $type){
- $addons_commission_arr[AddonsEnum::ADDONS_NAME_SCORE_EXPANSION][]= $type;
- }
- }
- //判断积分拓客插件有没有安装end
- $commission_type = [
- ['name' => 'commission', 'label' => '佣金'], ['name' => 'score', 'label' => '积分']
- ];
- foreach ($addons_commission_arr as $item){
- foreach($item as $v){
- $commission_type[] = $v;
- }
- }
- $down = Download::getOne([
- ['mall_id'=>$this->mall_id],
- ['type'=>DownloadEnum::TYPE_ORDERS],
- ['like','name','订单列表'.'%',false]
- ],true,[],'id desc');
- $fields = [];
- if(!empty($down)){
- $down['params'] = json_decode($down['params'],true);
- $fields = $down['params']['fields'];
- }
- $print_url = \Yii::$app->request->hostInfo . '/print.html';
- return $this->success('操作成功', compact($compact_params, 'fields','order_status_list', 'payment_type_list',
- 'shipping_type_list','export_list','marketing_type_map', 'commission_type','valid_addons', 'print_url'), ApiStatusEnum::CODE_SUCCESS, JSON_BIGINT_AS_STRING);
- }
- if (\Yii::$app->request->post('flag') == 'EXPORT') {
- $post = \Yii::$app->request->post();
- $post['mall_id'] = $this->mall_id;
- $post['store_id'] = 0;
- $post['mch_id'] = 0;
- $filename = '订单列表-' . date('YmdHis') . '_' . rand(10000, 99999);
- $res = CsvExportHelper::exportDownLoadOrder($this->mall_id, $filename, DownloadEnum::TYPE_ORDERS, Order::class, 'exportHandle', $post);
- if ($res === false) return $this->error('加入导出任务失败' . CsvExportHelper::getStaticError());
- return $this->success('添加导出任务成功,任务完成后请在下载中心进行下载!');
- }
- }
- $is_show_username = Yii::$app->services->setting->mall->get($this->mall_id,'order.is_show_username');
- $is_compliance = Yii::$app->services->mall->isOpenComplianceMode($this->mall_id);
- $is_electronic_bill = MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_ELECTRONIC_BILL) == 0 ? false : true;
- $is_electronic_bill_setting = \Yii::$app->services->setting->addons->get($this->mall_id, AddonsEnum::ADDONS_NAME_ELECTRONIC_BILL, 'basic');
- return $this->render($this->action->id,['is_show_username'=>$is_show_username??0, 'is_compliance' => $is_compliance, 'is_electronic_bill' => ($is_electronic_bill && !empty($is_electronic_bill_setting['is_enable']))]);
- }
- /**
- * 订单改价
- * @Author bing
- * @DateTime 2021-09-10 19:12:51
- * @copyright: Copyright (c) 2020 广东七件事集团
- * @return void
- */
- 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(Goods::getStaticError());
- return $this->success();
- }
- /**
- * 支付订单
- * @Author bing
- * @DateTime 2021-09-10 19:12:23
- * @copyright: Copyright (c) 2020 广东七件事集团
- * @return void
- */
- 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;
- $form['is_admin'] = 1;
- $service = new MallOrderService(['mall_id' => $this->mall_id]);
- $res = $service->adminPay($form);
- if ($res === false) return $this->error($service->getError());
- return $this->success();
- }
- /**
- * 关闭订单
- * @Author bing
- * @DateTime 2021-09-10 19:12:23
- * @copyright: Copyright (c) 2020 广东七件事集团
- * @return void
- */
- 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;
- $form['is_admin'] = 1;
- $res = Order::close($form);
- if ($res === false) return $this->error(Goods::getStaticError());
- return $this->success();
- }
- /**
- * 删除订单
- * @Author bing
- * @DateTime 2021-09-10 19:12:23
- * @copyright: Copyright (c) 2020 广东七件事集团
- * @return void
- */
- 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());
- if(!is_array($form['id'])){
- $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());
- }else{
- foreach ($form['id'] as $id){
- $params = [];
- $params['mall_id'] = $this->mall_id;
- $params['mch_id'] = $this->admin->mch_id;
- $params['operator_id'] = $this->admin->id;
- $params['operator_name'] = $this->admin->account;
- $params['id'] = $id;
- $params['is_admin'] = 1;
- $res = Order::del($params);
- if ($res === false) return $this->error(Order::getStaticError());
- }
- }
- return $this->success();
- }
- /**
- * 修改备注
- * @Author bing
- * @DateTime 2021-09-14 18:40:15
- * @copyright: Copyright (c) 2020 广东七件事集团
- * @return void
- */
- 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(Goods::getStaticError());
- // 事件
- $event = new OrderRemarkEvent($form['mall_id']);
- $form['operator_id'] = $this->admin->id;
- $form['is_admin'] = 1;
- Yii::$app->services->events->dispatch($event,$form,$event->listeners);
- return $this->success();
- }
- /**
- * 修改收货地址
- * @Author bing
- * @DateTime 2021-09-14 18:40:15
- * @copyright: Copyright (c) 2020 广东七件事集团
- * @return void
- */
- 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(Goods::getStaticError());
- return $this->success();
- }
- /**
- * 发货
- * @Author bing
- * @DateTime 2021-09-15 14:29:48
- * @copyright: Copyright (c) 2020 广东七件事集团
- * @return void
- */
- 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', 'send_nums'], '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;
- $form['is_admin'] = 1;
- $form['memo'] = json_encode([$form['memo_arr1'],$form['memo_arr2'],$form['memo_arr3']],JSON_UNESCAPED_UNICODE);
- if (empty($form['shipping_change'])) {
- $res = OrderExpress::delivery($form); // 发货
- } else {
- $res = OrderExpress::shippingChange($form); // 修改物流
- }
- if ($res === false) return $this->error(Goods::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;
- $form['is_admin'] = 1;
- $res = Order::takeDelivery($form);
- if ($res === false) return $this->error(Goods::getStaticError());
- return $this->success();
- }
- /**
- * @notes:取消发货
- * @return mixed|null
- * @author: lun
- * @Time: 2022/10/27 10:20
- */
- public function actionCancelShipment()
- {
- // 商品操作
- $form = Yii::$app->request->post();
- $rules = [[['id', 'order_id'], 'required'], [['id', 'order_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 = OrderExpress::cancelExpress($form, true);
- if ($res === false) return $this->error(Order::getStaticError());
- return $this->success();
- }
- /**
- * 订单详情
- * @Author bing
- * @DateTime 2021-09-06 14:09:56
- * @copyright: Copyright (c) 2020 广东七件事集团
- * @return void
- */
- 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',
- 'reserve'
- ];
- $params = compact('where', 'with');
- $order = Order::getOne($where, true, $with);
- if ($order === false) return $this->error(Goods::getStaticError());
- $express_log = [];
- if ($order['express_log']) {
- $time = time();
- $hour = Yii::$app->services->setting->mall->get($this->mall_id, 'logistics.update'); // 获取更新物流时间设置
- if (empty($hour) && is_array($hour)) $hour = 8; // 默认8小时更新一次
- foreach ($order['express_log'] as $key => $item) {
- $item['status'] = ExpressEnum::getStatusMap($item['status']);
- // 检查物流是否已完成,未完成且距离上次修改时间超过一个小时
- if ($item['table_express_status'] == StatusEnum::DISABLED && $item['updated_at'] + $hour * 3600 < $time) {
- $item['list'] = OrderExpressLog::execExpressLog($this->mall_id, $item);
- }
- $express_log[$item['order_express_id']] = $item;
- }
- }
- if (!empty($order['express'])) {
- $request_type = Yii::$app->services->setting->mall->get($this->mall_id, 'logistics.request_type');
- foreach ($order['express'] as &$key) {
- if (isset($express_log[$key['id']])) {
- $express_list = $express_log[$key['id']]['list'] ? Json::decode($express_log[$key['id']]['list']) : null;
- $key['now_state'] = $express_log[$key['id']]['status'];
- // 因为七件事订单物流和快递鸟数据不一致,所以需要处理
- if ($request_type == 1) {
- $key['express_log'] = is_null($express_list) ? '' : array_reverse($express_list['Traces']);
- } else {
- $key['express_log'] = is_null($express_list) ? '' : $express_list['Traces'];
- }
- }
- $key['nums'] = json_decode($key['nums'], true) ?: [];
- }
- }
- // 获取插件物流信息
- $event = new OrderGetExpressEvent($this->mall_id, $order['express'], $order['id'], $order['order_source']);
- Yii::$app->services->events->dispatch($event);
- $order['express'] = $event->getResultList($express_log);
- if (!empty($order['detail'])) {
- // 获取订单营销赠扣信息
- $orderDetailIds = array_column($order['detail'], 'id');
- $orderMarketing = OrderMarketing::find()
- ->where(['status' => StatusEnum::ENABLED, 'order_detail_id' => $orderDetailIds])
- ->indexBy('order_detail_id')->asArray()->all();
- foreach ($order['detail'] as &$detail) {
- $detail['score_money'] = $orderMarketing[$detail['id']]['score_money'] ?? 0; // 积分抵扣金额
- $order['total_num'] += $detail['num'];
- 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];
- }
- }
- $order['is_virtual'] = $detail['is_virtual'];
- if (empty($detail['goods_attr_name']) && !empty($detail['goods_attr_id'])) {
- if ($detail['order_source'] == 'Reserve') { // 服务订单
- $attr_info = GoodsReserveSku::getOne([['=', 'id', $detail['goods_attr_id']]],true, ['goods']);
- } else {
- $attr_info = GoodsAttr::getOne([['=', 'id', $detail['goods_attr_id']]],true, ['goods']);
- }
- $detail['goods_attr_name'] = $attr_info ? $attr_info['name'] : '';
- }
- }
- }
- $step_arr = OrderStatusEnum::setpArrMap($order['is_virtual'] ? -99 : $order['order_status']); // 订单状态跟踪
- $order_action = OrderAction::getOrderAction([['order_id' => $get['id']]]);
- $marketing_type_map = MarketingTypeEnum::getMap();
- //修改支付out_trade_no
- if ($order['pay_status']&& empty($order['out_trade_no'])) {
- $order['out_trade_no'] = PaymentTradeOrder::getOutTradeNoOfOrderNo($order['order_no']);
- }
- $order['show_botton'] = true;
- // 公共调用
- $order = GlobalInvoke::exec(GlobalInvoke::ORDER_DETAIL, $this->mall_id, [
- 'order' => $order,
- 'mall_id' => $this->mall_id,
- ]) ?: $order;
- //云盟店订单
- if (!$order['show_botton']) {
- foreach ($step_arr as $key => $value) {
- if ($value['field'] == 'consign_time') {
- if ($order['shipping_type'] == 2) {
- $step_arr[$key]['title'] = '买家自提';
- $step_arr[$key]['field'] = 'sign_time';
- } else if ($order['shipping_type'] == 3){
- $step_arr[$key]['title'] = '门店配送';
- $step_arr[$key]['field'] = 'sign_time';
- }
- }
- }
- }
- // 查询交易单号
- $trade_id = PaymentTradeOrder::find()
- ->where(['order_no' => $order['order_no']])
- ->select('trade_id')
- ->orderBy('id desc')
- ->scalar();
- $paymentTrade = PaymentTrade::find()
- ->where(['id'=>$trade_id])
- ->with(['paidItem'])
- ->asArray()
- ->one();
- $order['payment'] = $paymentTrade;
- if(empty($order['out_trade_no'])){
- $order['out_trade_no'] = $paymentTrade ? $paymentTrade['out_trade_no'] : '';
- }
- $order_user_handle = OrderUserHandle::find()->where(['order_id' => $order['id'], 'order_status' => OrderStatusEnum::ACCOMPLISH])->select('id')->scalar();
- $order['is_user_handle_finish'] = $order_user_handle ? 1 : 0;
- // 获取留言
- $leave = OrderExtra::getInfo(['=', 'order_id', $order['id']], 'message');
- $order['leave'] = $leave['message'] ?? '';
- //获取售后原因
- $refund_reason = RefundReasonEnum::getMap();
- //return $this->success('操作成功', compact('order', 'order_status_list', 'payment_type_list', 'shipping_type_list', 'step_arr', 'order_action','marketing_type_map'));
- return $this->success('操作成功', compact('order', '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);
- }
- /**
- * 订单操作日志
- * @return mixed|string|void
- */
- 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);
- }
- /**
- * 完成订单
- * @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['operator_id'] = $this->admin->id;
- $form['operator_name'] = $this->admin->account;
- $form['is_admin'] = 1;
- $res = Order::complete($form);
- if ($res == false) return $this->error('操作订单失败:' . Order::getStaticError());
- return $this->success('操作成功');
- }
- /**
- * 售后订单列表
- * @Author: lun
- * @DateTime: 2021/10/8 0008 17:53
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|string|void
- */
- 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', 'refund_type'], '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],['mch_id' =>0],['store_id' => 0]];
- $where[] = ['=', 'status', StatusEnum::ENABLED];
- $where[] = ['!=', 'order_detail_id', 0];
- if (!empty($get['refund_type'])) $where[] = ['=', 'type', $get['refund_type']];
- if (!empty($get['order_no'])) {
- $where[]=[
- 'OR',
- ['in', 'order_id', OrderRefund::getVagueOrderNo($this->mall_id,$get['order_no'])],
- ['like', 'order_no', $get['order_no']]
- ];
- }
- if (isset($get['refund_status'])) {
- $where[] = ['in', 'refund_status', explode(',', $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['goods_type'])) $where[] = ['goods_type' => $get['goods_type']];
- if (!empty($get['type']) && !empty($get['keyword'])) $where[] = OrderRefund::searchByKeyword($this->mall_id, $get['type'], $get['keyword']);
- $with = ['base_user', 'orderDetail', 'order', 'lastStep' => function ($query) {
- $query->select('id, order_refund_id, created_at');
- }];
- $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) {
- $order['goods_unit'] = Goods::getOne([['=', 'mall_id', $this->mall_id], ['=', 'id', $order['orderDetail']['goods_id']]], false, '', '', 'unit')['unit'];
- 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];
- }
- }
- }
- if (!empty($order['order'])) {
- $extraInfo = $order['order']['extra_info'];
- if (!empty($extraInfo['head_id']) && MallAddons::isInstall($this->mall_id, 'Community')) {
- $order['order']['community_addons_data'] = (new HeadService())->pickupInfo($order['mall_id'], $extraInfo['head_id']);
- }
- }
- }
- $export_list = OrderRefund::fieldsList();
- $commission_type = $this->getCommissionType();
- return $this->success('操作成功', compact($compact_params, 'refund_status_list', 'refund_type_list', 'export_list', 'commission_type'));
- }
- if (\Yii::$app->request->post('flag') == 'EXPORT') {
- $post = \Yii::$app->request->post();
- $post['mall_id'] = $this->mall_id;
- $filename = '售后订单列表-' . date('YmdHis') . '_' . rand(10000, 99999);
- $res = CsvExportHelper::exportDownLoadCenter($this->mall_id, $filename, DownloadEnum::TYPE_ORDERS, OrderRefund::class, 'exportHandle', $post);
- if ($res === false) return $this->error('加入导出任务失败' . CsvExportHelper::getStaticError());
- return $this->success('添加导出任务成功,任务完成后请在下载中心进行下载!');
- }
- }
- return $this->render($this->action->id, ['goods_type' => Json::encode(GoodsTypeEnum::getMap())]);
- }
- public function actionBatchRefund()
- {
- $post = Yii::$app->request->post();
- if (empty($post['refund_ids'])) return $this->error('请选择需要操作操作的订单!');
- $order_ids = explode(',', $post['refund_ids']);
- $orderRefundList = OrderRefund::find()->select("id,type")->where(['in', 'id', $order_ids])->all();
- $not_matching_ids = [];// 不是仅支付的订单
- $refund_type_list = RefundTypeEnum::getMap();
- foreach ($orderRefundList as $item) {
- if ($item->type != RefundTypeEnum::MONEY) {
- $not_matching_ids[] = $item->id;
- }
- }
- if (!empty($not_matching_ids)) {// 拥有不可退款条件
- $not_matching_ids = implode(',', $not_matching_ids);
- $message = '批量操作中ID:' . trim($not_matching_ids, ',') . '。不符合' . $refund_type_list[RefundTypeEnum::MONEY] . '条件,请重新选择!';
- return $this->error($message);
- }
- //批量操作时进行锁
- $key = "order_refund:batch_refund_lock_" . md5($post['refund_ids']);
- if (LockHelper::fLock($key, 60)) {
- return $this->error("暂时无法操作,请稍后在尝试!");
- }
- Yii::$app->redis->setex($key, 180, 1);
- // 退货地址
- $address = ['consignee' => $post['consignee'],'mobile' => $post['mobile'],'address' => $post['address']];
- // 换货物流信息
- $express = ['saler_express' => $post['saler_express'],'saler_express_no' => $post['saler_express_no'],'customer_name' => $post['customer_name']];
- try {
- $params = [];
- foreach ($orderRefundList as $item) {
- $data = [
- 'id' => $item->id,
- 'step_status' => RefundStatusEnum::STEP_6,
- 'address' => $address,
- 'express' => $express,
- 'refund_reason' => $post['refund_reason'] ?? '',
- ];
- $params['data'][] = $data;
- }
- $params['mall_id'] = $this->mall_id;
- $params['redis_key'] = $key;
- OrderRefund::batchRefundSync($params);
- } catch (Exception $e) {
- }
- return $this->success('售后申请成功,请耐心等候!');
- }
- /**
- * 售后详情
- * @Author: lun
- * @DateTime: 2021/10/9 0009 11:57
- * @Copyright: copyright (c) 2021 广东七件事集团
- */
- 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' => function ($query) {
- $query->select('*');
- }, 'orderDetail', 'marketing', 'step'];
- $params = compact('where', 'with');
- $refund = OrderRefund::getOne($where, true, $with);
- if ($refund === false) return $this->error(Goods::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($detail['goods_attr_name']) && !empty($detail['goods_attr_id'])) {
- if ($detail['order_source'] == 'Reserve') { // 服务订单
- $attr_info = GoodsReserveSku::getOne([['=', 'id', $detail['goods_attr_id']]],true, ['goods']);
- } else {
- $attr_info = GoodsAttr::getOne([['=', 'id', $detail['goods_attr_id']]],true, ['goods']);
- }
- $detail['goods_attr_name'] = $attr_info ? $attr_info['name'] : '';
- }
- }
- // 公共调用订单详情
- $refund['order'] = GlobalInvoke::exec(GlobalInvoke::ORDER_DETAIL, $this->mall_id, [
- 'order' => $refund['order'],
- 'mall_id' => $this->mall_id,
- ]) ?: $refund['order'];
- // 返还优惠内容
- if (!empty($refund['marketing'])) {
- $discount = [];
- $marketing = $refund['marketing'];
- if (!empty($marketing['deduct_score'])) {
- if($refund['order']['marketing_type'] == AddonsEnum::ADDONS_NAME_FUN_MALL){
- $deduct_currency = (array)json_decode($marketing['deduct_currency'], true);
- if(isset($deduct_currency['midou_cy'])) $discount[] = floatval($deduct_currency['midou_cy']['midou_cy']) . $deduct_currency['midou_cy']['name'];
- }elseif($refund['order']['marketing_type'] == AddonsEnum::ADDONS_NAME_DIGITAL_MALL){
- $deduct_currency = (array)json_decode($marketing['deduct_currency'], true);
- if(isset($deduct_currency['digital'])) $discount[] = floatval($deduct_currency['digital']['digital']) . $deduct_currency['digital']['name'];
- }else{
- $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);
- //退款金额方式
- $refund['payment_refund_type'] = '';
- if($refund['is_refund']){
- $payment_refund = PaymentRefund::findOne(['trade_order_no' => $refund['order']['order_no']]);
- $refund['payment_refund_type'] = !empty($payment_refund) && $payment_refund->pay_type != PayTypeEnum::BALANCE ? '原路返回' : '退回余额';
- }
- // 组合支付
- $trade = PaymentTrade::findOne(['out_trade_no' => $refund['order']['out_trade_no']]);
- $trade && $trade->isMixedPay() && $refund['refund_items'] = array_map(function ($item) {
- return $item->toArray();
- }, $trade->getRefundFeeList($refund['id']));
-
- $order_detail = OrderDetail::findOne(['id' => $refund['order_detail_id']]);
- $goods = Goods::findOne(['id' => $order_detail->goods_id])->toArray();
- $refund_status_list = RefundStatusEnum::getMap();
- $q_refund = null;
- if ($goods['goods_source'] == 'QiJuhe') {
- $q_refund = OrderRefundModel::find()->where(['order_refund_id' => $refund['id']])->orderBy('id desc')->asArray()->one();
- }
- // 是否显示退货超期,撤销售后
- $is_show_revoce = (OrderRefund::findOne(['id' => $refund['id']]))->isReturnTimeoutOfRefund();
- return $this->success('操作成功', compact('refund', 'order_status_list', 'payment_type_list', 'feedback_type_list', 'step_arr', 'address_list',
- 'step_text', 'is_show_revoce', 'goods', 'refund_status_list', 'q_refund'));
- }
- }
- return $this->render($this->action->id);
- }
- /**
- * 售后处理
- * @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','address_type'], 'integer'],
- [['saler_express','saler_express_no','address','consignee','refund_reason','mobile'], 'string'],
- [['saler_express','saler_express_no','address_type','customer_name', 'balance_pre', 'score_pre', 'digital_pre','admin_handler_refund','refund_price','refund_remark'], 'safe'],
- ];
- // //模拟数据
- // $params['balance_pre'] = 100;
- // $params['admin_handler_refund'] = 1;
- if ($params['step_status'] == RefundStatusEnum::STEP_NEGATIVE_1 && empty($params['refund_reason'])) {
- return $this->error('请输入拒绝理由');
- }
- $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'],
- 'refund_price' => $params['refund_price']??0,
- 'refund_remark' => $params['refund_remark']??'',
- 'address' => $address,
- 'express' => $express,
- 'refund_reason' => $params['refund_reason'] ?? '',
- 'operator_id' => $this->admin->id,
- 'is_admin' => 1
- ];
- if (!empty($params['balance_pre']) || is_numeric($params['balance_pre'])) $data['refund_pre'] = $params['balance_pre'];
- if (!empty($params['score_pre']) || is_numeric($params['score_pre'])) $data['score_pre'] = $params['score_pre'];
- if (!empty($params['digital_pre']) || is_numeric($params['digital_pre'])) $data['digital_pre'] = $params['digital_pre'];
- if ($params['admin_handler_refund'] == 1) $data['admin_handler_refund'] = UserWalletEnum::ADMIN_HANDLER_REFUND;
- // print_r($params);exit;
- $logic = new OrderRefundLogic();
- $res = $logic->execute($this->mall_id, $data);
- if ($res == false) return $this->error($logic->getError());
- return $this->success('操作成功');
- }
- }
- }
- /**
- * 批量发货页面
- * @Author: lun
- * @DateTime: 2021/11/30 0030 18:51
- * @Copyright: copyright (c) 2021 广东七件事集团
- */
- public function actionBatchDelivery()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isPost) {
- $params = Yii::$app->request->post();
- // 失败订单导出
- if(\Yii::$app->request->post('flag') == 'EXPORT'){
- $rules = [[['batch_delivery_id'], 'required'], [['batch_delivery_id'], 'integer']];
- $res = Yii::$app->services->validate->validate($params, $rules);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $download['mall_id'] = $this->mall_id;
- $download['batch_delivery_id'] = $params['batch_delivery_id'];
- $filename = '批量发货失败-' . date('YmdHis').'_'.rand(10000,99999);
- $res = CsvExportHelper::exportDownLoadCenter($this->mall_id,$filename,DownloadEnum::TYPE_ORDERS,OrderBatchDeliveryError::class,'exportHandle',$download);
- if ($res === false) return $this->error('加入导出任务失败'.CsvExportHelper::getStaticError());
- return $this->success('添加导出任务成功,任务完成后请在下载中心进行下载!');
- }
- $rules = [
- [['express_id','express_name','delivery_file', 'isByGoods'], 'required'],
- [['express_id', 'isByGoods'], 'integer'],
- [['delivery_file','express_name'], 'string'],
- ];
- $res = Yii::$app->services->validate->validate($params, $rules);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- try {
- $params['operator_id'] = $this->admin->id;
- $params['operator_name'] = $this->admin->account;
- $model = OrderBatchDelivery::setData($this->mall_id, $params);
- if ($model == false) throw new Exception(OrderBatchDelivery::getStaticError());
- // 提交到异步处理
- $isByGoods = !in_array($params['isByGoods'], [0, 1]) ? 0 : $params['isByGoods'];
- $handleAction = ['async_batch_handle', 'async_batch_handle_by_goods'][(int)$isByGoods];
- Yii::$app->services->rabbitMq->push(RabbitMqEnum::EXCHANGE_ORDER, RabbitMqEnum::ORDER_QUEUE, ['id' => $model->id], OrderDeliveryListener::class, $handleAction);
- return $this->success('提交成功,正在处理异步处理批量发货');
- } catch (Exception $e) {
- return $this->error('提交失败:' . $e->getMessage());
- }
- }else{
- $params = Yii::$app->request->get();
- $rules = [
- [['delivery_status'], 'integer'],
- [['start_time','end_time','operator_name'], 'string'],
- ];
- $res = Yii::$app->services->validate->validate($params, $rules);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- // 条件组合
- $where = [['mall_id' => $this->mall_id]];
- $where[] = ['=', 'status', StatusEnum::ENABLED];
- isset($params['start_time']) && isset($params['end_time']) && $where[] = ['between', 'created_at', strtotime($params['start_time']), strtotime($params['end_time'])];
- isset($params['operator_name']) && $where[] = ['=', 'operator_name', $params['operator_name']];
- isset($params['delivery_status']) && $where[] = ['=', 'delivery_status', $params['delivery_status']];
- $order = "id desc";
- $list_params = compact('where', 'with', 'order');
- $list = OrderBatchDelivery::listPage($list_params, false, true);
- if ($list === false) return $this->error(OrderBatchDelivery::getStaticError());
- return $this->success('操作成功', $list);
- }
- }
- return $this->render($this->action->id);
- }
- public function actionCommissionAndScoreList(){
- $params = Yii::$app->request->get();
- $wallet_type = 'commission';
- $level = UserLevel::find()->select("name,level")->where(['mall_id' => $this->mall_id,'status' => StatusEnum::ENABLED])->asArray()->all();
- $level_data = array_column($level,'name','level');
- $list = [];
- if(!empty($params['wallet_type'])) $wallet_type = $params['wallet_type'];
- if(!in_array($wallet_type, ['score', 'commission'])){
- $list['list'] = [];
- $list['list'] = GlobalInvoke::exec(GlobalFuncEnum::ONE_CAPITAL_LOG_LIST, $this->mall_id, [
- 'list' => $list['list'], 'mall_id' => $this->mall_id, 'wallet_type' => $wallet_type, 'order_id' => $params['order_id']
- ]) ?:$list['list'];
- return $this->success('操作成功',['list'=> $list['list'], 'user_level'=> $level_data]);
- }
- $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::tableName()]],
- ['source_table_id'=>$params['order_id']]
- ],
- ];
- CapitalLog::$capitalType = "{$wallet_type}";
- $extra_list = CapitalLog::getList($condition,0);
- if(!empty($extra_list)) $list = $extra_list;
- $condition = [
- 'where'=>[
- ['source_table'=>['order_detail',OrderDetail::tableName()]],
- ['source_table_id'=>$order_detail_ids]
- ],
- ];
- CapitalLog::$capitalType = "{$wallet_type}";
- $temp_list = CapitalLog::getList($condition,0);
- if(!empty($temp_list)) $list = array_merge($list,$temp_list);
- $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);
- if(!empty($frozen_list)) $list = array_merge($list,$frozen_list);
- return $this->success('操作成功',['list'=>$list,'user_level'=>$level_data]);
- }
- /**
- * 下载批量发货模板
- * @Author: lun
- * @DateTime: 2021/12/1 0001 14:24
- * @Copyright: copyright (c) 2021 广东七件事集团
- */
- public function actionDownloadDeliveryTemplate()
- {
- $csv = new CsvTool();
- $csv->filename = '批量发货模板';
- $csv->file_dirname = DownloadEnum::getTypeStorageDirMap(DownloadEnum::TYPE_ORDERS);
- $csv->export_mode = CsvTool::EXPORT_MODE_SYNC;
- $csv->header = $this->request->get('isByGoods') ? ['订单号', '物流单号', '商品名称', '商品数量'] : ['订单号', '物流单号'];
- $csv->export(true);
- }
- /**
- * 批量发货错误原因列表
- * @Author: lun
- * @DateTime: 2021/12/2 0002 14:58
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|string|void
- */
- public function actionBatchDeliveryError()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isGet) {
- $params = Yii::$app->request->get();
- $rules = [
- [['delivery_id'], 'required'],
- [['delivery_id'], 'integer'],
- ];
- $res = Yii::$app->services->validate->validate($params, $rules);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- // 条件组合
- $where = [['mall_id' => $this->mall_id],['batch_delivery_id' => $params['delivery_id']],['=', 'status', StatusEnum::ENABLED]];
- $order = "id desc";
- $select = "id,order_no,express_no,content";
- $list_params = compact('where', 'select', 'order');
- $list = OrderBatchDeliveryError::listPage($list_params, false, true);
- if ($list === false) return $this->error(OrderBatchDeliveryError::getStaticError());
- return $this->success('操作成功', $list);
- }
- }
- return $this->render($this->action->id);
- }
- /**
- * 申请售后-换货-后台确认收货,售后完成
- * @Author: hua
- * @DateTime: 2021/10/9 15:52
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|void
- */
- public function actionRefundTakeDelivery()
- {
- $params = \Yii::$app->request->post();
- $res = \Yii::$app->services->validate->validate($params, [
- [['id'], 'required'],
- ]);
- if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- $params['mall_id'] = $this->mall_id;
- $res = OrderRefundStep::refundTakeDelivery($params);
- if ($res === false) return $this->error(OrderRefundStep::getStaticError());
- return $this->success('操作成功');
- }
- /**
- * @Author: 广东七件事 ganxiaohao
- * @Date: 2020-05-15
- * @Time: 9:58
- * @Note:开票记录
- * @return string|\yii\web\Response
- */
- public function actionInvoice()
- {
- if (\Yii::$app->request->post('flag') == 'EXPORT') {
- $post = \Yii::$app->request->post();
- $post['mall_id'] = $this->mall_id;
- $filename = '开票记录-' . date('YmdHis') . '_' . rand(10000, 99999);
- $res = CsvExportHelper::exportDownLoadCenter($this->mall_id, $filename, DownloadEnum::TYPE_ORDERS, OrderInvoice::class, 'exportHandle', $post);
- if ($res === false) return $this->error('加入导出任务失败' . CsvExportHelper::getStaticError());
- return $this->success('添加导出任务成功,任务完成后请在下载中心进行下载!');
- }
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isGet) {
- $get = \Yii::$app->request->get();
- $params['order'] = 'id desc';
- $params['alias'] = 'b';
- $params['joinWith'] = ['user'];
- if (!empty($get['keyword'])) {
- $user_ids = User::find()
- ->where(['mall_id'=>$this->mall_id])->andWhere([
- 'or',
- ['like', 'nickname', $get['keyword']],
- ['like', 'mobile', $get['keyword']]
- ])->select('id')->asArray()->column();
- $params['where'][] = ['in', 'b.user_id', $user_ids];
- }
- if (!empty($get['user_id'])) {
- $params['where'][] = ['=', 'b.user_id', $get['user_id']];
- }
- if (!empty($get['order_no'])) {
- $params['where'][] = ['=', 'b.order_no', $get['order_no']];
- }
- if ($get['head_type'] != -1) {
- $params['where'][] = ['=', 'b.head_type', $get['head_type']];
- }
- if ($get['invoice_status'] != -1) {
- $params['where'][] = ['=', 'b.invoice_status', $get['invoice_status']];
- }
- $params['where'][] = ['=', 'b.mall_id', $this->mall_id];
- $params['order'] = ['id' => SORT_DESC];
- $params['limit'] = 10;
- $list = OrderInvoice::listPage($params);
- $list['export_list'] = OrderInvoice::exportFieldsList();
- return $this->success('操作成功',$list,ApiStatusEnum::CODE_SUCCESS,JSON_UNESCAPED_UNICODE);
- }
- if (\Yii::$app->request->isPost) {
- $post = \Yii::$app->request->post();
- $invoice = OrderInvoice::findOne($post['id']);
- if(empty($invoice)) return $this->error('数据异常!');
- $invoice->invoice_status = $post['status'];
- $invoice->remark = $post['remark'];
- if(!$invoice->save()) return $this->error('操作失败');
- return $this->success('操作成功');
- }
- }
- return $this->render('invoice');
- }
- /**
- * 手动退款
- * @return mixed|null
- */
- public function actionManualRefund()
- {
- $params = \Yii::$app->request->post();
- $res = \Yii::$app->services->validate->validate($params, [
- [['id', 'refund_amount', 'reason'], 'required'],
- ]);
- if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- try {
- $order = Order::findOne(['id' => $params['id']]);
- if (empty($order)) throw new Exception('订单不存在');
- if ($order->order_source != OrderSourceEnum::SOURCE_RESERVE) throw new Exception('当前订单类型不支持手动退款');
- if (empty($order->pay_status)) throw new Exception('当前订单未支付');
- if ($order->order_status < OrderStatusEnum::PAY) throw new Exception('当前订单状态不支持退款');
- $order_detail_id = OrderDetail::find()->where(['order_id' => $params['id']])->select('id')->scalar();
- // 执行退款
- $params = [
- 'order_detail_id' => $order_detail_id,
- 'reason' => $params['reason'],
- 'remark' => '',
- 'type' => RefundTypeEnum::MONEY,
- 'refund_price' => bcmul($params['refund_amount'], 1, 2),
- 'user_id' => $order->user_id,
- 'mall_id' => $order->mall_id,
- ];
- $res = OrderRefund::feedback($params);
- if ($res === false) throw new \Exception(Order::getStaticError());
- $event = new \common\events\order\OrderRefundEvent();
- $event->mall_id = $order->mall_id;
- $order_detail['order_detail_id'] = $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['is_manual'] = 1;
- Yii::$app->services->events->dispatch($event, $order_detail, $event->listeners);
- // 执行退款操作
- // 退货地址
- $address = ['consignee' => '','mobile' => '','address' => ''];
- // 换货物流信息
- $express = ['saler_express' => '','saler_express_no' => '','customer_name' => ''];
- $data = [
- 'id' => $res->id,
- 'step_status' => RefundStatusEnum::STEP_6, // 直接打款操作
- 'address' => $address,
- 'express' => $express,
- 'refund_reason' => '',
- 'not_dec_fee' => StatusEnum::ENABLED, // 不需要手续费
- 'operator_id' => $this->admin->id,
- 'is_admin' => 1,
- 'is_manual' => 1,
- ];
- $logic = new OrderRefundLogic();
- $res = $logic->execute($this->mall_id, $data);
- if (!$res) throw new \Exception($logic->getError());
- } catch (Exception $e) {
- return $this->error($e->getMessage());
- }
- return $this->success();
- }
- /**
- * 订单批量留言或备注
- * @params order_ids 操作订单id
- * @params order_type 操作类型
- * @params content 数据内容
- * @return void
- */
- public function actionOrderBatch()
- {
- $post = Yii::$app->request->post();
- $rules = [[['order_ids'], 'required'], [['content', 'order_type', 'order_ids', 'user_id', 'is_batch_message'], 'string']];
- $res = Yii::$app->services->validate->validate($post, $rules);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $message = '';
- switch ($post['order_type']) {
- case OrderCommentEnum::BATCH_REMARKS:// 批量备注
- $res = Order::batchRemark($post);
- $message = '备注';
- // 事件
- $orderIds = explode(',', $post['order_ids']);
- $event = new OrderRemarkEvent($this->mall_id);
- foreach ($orderIds as $orderId) {
- $eventData['operator_id'] = $this->admin->id;
- $eventData['seller_remark'] = $post['content'] ?? 0;
- $eventData['is_admin'] = 1;
- $eventData['is_batch'] = 1;
- $eventData['id'] = $orderId;
- Yii::$app->services->events->dispatch($event,$eventData,$event->listeners);
- }
- break;
- case OrderCommentEnum::BATCH_LEAVE:// 批量留言
- $res = OrderExtra::batchLeave($post);
- $message = '留言';
- // 事件
- $orderIds = explode(',', $post['order_ids']);
- $event = new OrderLeaveEvent($this->mall_id);
- foreach ($orderIds as $orderId) {
- $eventData['operator_id'] = $this->admin->id;
- $eventData['message'] = $post['content'] ?? 0;
- $eventData['is_admin'] = 1;
- $eventData['is_batch'] = (int)!empty($post['is_batch_message']);
- $eventData['id'] = $orderId;
- Yii::$app->services->events->dispatch($event,$eventData,$event->listeners);
- }
- break;
- default:
- break;
- }
- if ($res === false) return $this->error(Order::getStaticError());
- return $this->success($message . "操作成功");
- }
- /**
- * 撤销售后订单
- *
- * @return mixed
- */
- public function actionRevoceRefund(int $id)
- {
- $service = new MallRefundService(['mall_id' => $this->mall_id]);
- return $service->revoceRefund($id, ['is_admin' => 1, 'operator_id' => $this->admin->id])
- ? $this->success('撤销售成功')
- : $this->error($service->getError());
- }
- /**
- * 返回售后订单菜单是否需要显示小红点
- *
- * @return void
- */
- public function actionOrderRefundIsShowRedDot()
- {
- $this->success('success', [
- 'is_show' => (bool)OrderRefund::find()
- ->where([
- 'mall_id' => $this->mall_id,
- 'mch_id' => 0,
- 'store_id' => 0,
- 'refund_status' => [
- RefundStatusEnum::APPLY,
- RefundStatusEnum::HANDEL,
- RefundStatusEnum::RETURN_GOODS,
- RefundStatusEnum::EXCHANGE_GOODS,
- ],
- 'status' => StatusEnum::ENABLED,
- ])
- ->count()
- ]);
- }
- public function actionGetGoodsCommissionList(){
- $params = Yii::$app->request->get();
- $condition = [
- 'where'=>[
- ['source_table'=>[Order::tableName()]],
- ['source_table_id'=>$params['order_id']]
- ],
- ];
- $list = [];
- $check_order_detail_refund = OrderDetail::findOne(['order_id' => $params['order_id'], 'is_feedback' => 2]);
- if (empty($check_order_detail_refund)) {
- CapitalLog::$capitalType = "{$params['wallet_type']}";
- $extra_list = CapitalLog::getList($condition,0);
- if(!empty($extra_list)) $list = $extra_list;
- }
- $condition = [
- 'where' => [
- ['source_table' => ['order_detail', OrderDetail::tableName()]],
- ['source_table_id' => $params['goods_id']],
- ['mall_id' => $this->mall_id],
- ['from_type' => ['Agent', 'Area', 'CloudStock', 'Achievement', 'Distribution', 'EqualSubsidy', 'PerformanceDividend']],
- ],
- ];
- // $wallet_type = $params['wallet_type'];
- CapitalLog::$capitalType = "{$params['wallet_type']}";
- $temp_list = CapitalLog::getList($condition,0);
- if(!empty($temp_list)) {
- foreach ($temp_list as &$item) {
- $item['type'] = 'commission';
- }
- $list = array_merge($list,$temp_list);
- }
- $params['wallet_type'] = 'score';
- CapitalLog::$capitalType = "{$params['wallet_type']}";
- $temp_list = CapitalLog::getList($condition,0);
- if (!empty($temp_list)) {
- foreach ($temp_list as &$item) {
- $item['type'] = 'score';
- }
- $list = array_merge($list, $temp_list);
- }
- $digital_list = DigitalLog::lists([
- 'where' => array_merge($condition['where'], [['status' => CapitalLog::STATUS_SEND], ['send_status' => DigitalLog::SEND_STATUS_NORMAL]]),
- 'with' => ['user']
- ]);
- if ($digital_list) {
- $from_type_arr = array_column($digital_list, 'from_type');
- $addons_list = Addons::lists(['where' => [['name' => $from_type_arr]], 'index' => 'name', 'select' => 'name,title']);
- $capital_type_map = GlobalVarMap::getEnumMapByType('CapitalTypeMap', $digital_list[0]['mall_id']);
- foreach ($digital_list as &$item) {
- $item['from_type_text'] = $addons_list[$item['from_type']]['title'] ?? '';
- $item['capital_type_text'] = $capital_type_map[$item['capital_type']] ?? '';
- $item['type'] = 'digital';
- $item['nickname'] = $item['user']['nickname'];
- $item['mobile'] = $item['user']['mobile'];
- $item['level'] = $item['user']['level'];
- $item['avatar_url'] = $item['user']['avatar_url'];
- unset($item['user']);
- }
- $list = array_merge($list, $digital_list);
- }
- return $this->success('操作成功',['list'=>$list]);
- }
- 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 = GlobalInvoke::exec(GlobalInvoke::ORDER_REFUND_SUBMIT, $this->mall_id, [
- 'order_detail' => $order_detail,
- 'mall_id' => $this->mall_id,
- ]) ?: $order_detail;
- //价格等于商品价格加上修改价格
- $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', 'score_pre', 'digital_pre'], 'required'],
- [['shipping_status', 'pic_list', 'reason', 'refund_price', 'remark', 'type', 'user_id', 'settlement_method', 'balance_pre', 'score_pre', 'digital_pre'], '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('请勿频繁请求');
- // 判断是否安装了代客下单
- if (MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_VALET_ORDER)) {
- // 判断当前订单是否为代客下单订单
- if (!empty(ValetOrder::find()->where(['mall_id' => $this->mall_id])
- ->andWhere(['order_id' => OrderDetail::find()->where(['id' => $params['order_detail_id']])->select('order_id')->scalar()])
- ->select('id')->scalar())) {
- $config = \Yii::$app->services->setting->addons->get($this->mall_id, AddonsEnum::ADDONS_NAME_VALET_ORDER, 'basic');
- // 如果插件是开启状态,且可售后是关闭状态
- if (!empty($config['is_enable']) && empty($config['is_enable_order_refund'])) {
- LockHelper::unFLock($key);
- return $this->error("代客下单订单不可申请退款/售后");
- }
- }
- }
- if (MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_SERVICE_POINT_APPOINTMENT) &&
- (new OrderService())->isReserveByOrderDetailId($this->mall_id, $params['order_detail_id'])) { // 服务点预约
- LockHelper::unFLock($key);
- return $this->error('预约订单含有预约后不可进行售后');
- }
- // 企叮咚
- if (MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_QI_DING_DONG)) {
- if (!RefundService::hasPic($params['order_detail_id'], $params['pic_list'])) {
- LockHelper::unFLock($key);
- return $this->error('图片不能为空');
- }
- }
- // $params['user_id'] = $params['user_id'];
- $params['mall_id'] = $this->mall_id;
- $where = [
- ['=', 'order_detail_id', $params['order_detail_id']],
- ['=', 'user_id', $params['user_id']],
- ['=', 'mall_id', $this->mall_id],
- ['>', 'step_status', 0],
- ['in', 'status', [StatusEnum::ENABLED, StatusEnum::DISABLED]],
- ['<>', 'refund_status', RefundStatusEnum::REVOKE]
- ];
- $order_refund_model = OrderRefund::getOne($where, true);
- if ($order_refund_model) {
- LockHelper::unFLock($key);
- return $this->error('该订单商品已经申请过售后');
- }
- $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'] = $params['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]);
- }
- /**
- * 获取订单所有状态
- * @Author:lun
- * @Date:2024-08-29 16:10
- * @Copyright:copyright(c)2024 广东七件事集团
- * @return mixed|void|null
- */
- public function actionGetOrderStatus()
- {
- $request = Yii::$app->request;
- if ($request->isAjax && $request->isGet) {
- $response = [
- 'order_status_map' => OrderStatusEnum::getMap(),
- 'payment_type_map' => PayTypeEnum::getMap(),
- 'shipping_type_map' => ShippingTypeEnum::getMap(),
- 'marketing_type_map' => MarketingTypeEnum::getMap(),
- 'refund_status_map' => RefundStatusEnum::getMap(),
- 'refund_type_map' => RefundTypeEnum::getMap(),
- ];
- return $this->success('操作成功', $response);
- }
- }
- /**
- * 获取分润明细弹窗需要展示的tab
- *
- * @return array[]
- * @throws \yii\db\Exception
- */
- protected function getCommissionType()
- {
- $addons_commission_arr = GlobalInvoke::exec(GlobalInvoke::INVOKE_COMMISSION_TYPE, $this->mall_id, ['mall_id' => $this->mall_id]);
- //判断积分拓客插件有没有安装
- //获取商城已安装插件列表
- $valid_addons = MallAddons::getValidAddons($this->mall_id);
- if (in_array(AddonsEnum::ADDONS_NAME_SCORE_EXPANSION, $valid_addons)){
- $ScoreExpansionArr = (new ScoreExpansion())->getGoodsModeCommssionType();
- foreach($ScoreExpansionArr as $type){
- $addons_commission_arr[AddonsEnum::ADDONS_NAME_SCORE_EXPANSION][]= $type;
- }
- }
- //判断积分拓客插件有没有安装end
- $commission_type = [
- ['name' => 'commission', 'label' => '佣金'], ['name' => 'score', 'label' => '积分']
- ];
- foreach ($addons_commission_arr as $item){
- foreach($item as $v){
- $commission_type[] = $v;
- }
- }
- return $commission_type;
- }
- /**
- * 分润明细数据(根据order_detail_id)
- *
- * @return mixed|null
- */
- public function actionCommissionAndScoreListByOrderDetailId(){
- $params = Yii::$app->request->get();
- $wallet_type = 'commission';
- $level = UserLevel::find()->select("name,level")->where(['mall_id' => $this->mall_id,'status' => StatusEnum::ENABLED])->asArray()->all();
- $level_data = array_column($level,'name','level');
- $list = [];
- if(!empty($params['wallet_type'])) $wallet_type = $params['wallet_type'];
- if(!in_array($wallet_type, ['score', 'commission'])){
- $list['list'] = [];
- $list['list'] = GlobalInvoke::exec(GlobalFuncEnum::ONE_CAPITAL_LOG_LIST, $this->mall_id, [
- 'list' => $list['list'], 'mall_id' => $this->mall_id, 'wallet_type' => $wallet_type,
- 'order_id' => $params['order_id'],'order_detail_id' => $params['order_detail_id']
- ]) ?:$list['list'];
- return $this->success('操作成功',['list'=> $list['list'], 'user_level'=> $level_data]);
- }
- $condition = [
- 'where'=>[
- ['source_table'=>[Order::tableName()]],
- ['source_table_id'=>$params['order_id']]
- ],
- ];
- CapitalLog::$capitalType = "{$wallet_type}";
- $extra_list = CapitalLog::getList($condition,0);
- if(!empty($extra_list)) $list = $extra_list;
- $condition = [
- 'where'=>[
- ['source_table' => ['order_detail',OrderDetail::tableName()]],
- ['source_table_id' => $params['order_detail_id']]
- ],
- ];
- CapitalLog::$capitalType = "{$wallet_type}";
- $temp_list = CapitalLog::getList($condition,0);
- if(!empty($temp_list)) $list = array_merge($list,$temp_list);
- $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, -1]];
- $frozen_list = CapitalLog::getList($condition,1);
- if(!empty($frozen_list)) $list = array_merge($list,$frozen_list);
- return $this->success('操作成功',['list'=>$list,'user_level'=>$level_data]);
- }
- /**
- * 发货时验证物流号是否已经发过了
- *
- * @return void
- */
- public function actionCheckOrderExpressNo()
- {
- // 发货
- $params = Yii::$app->request->get();
- $rules = [
- [['express_no', 'id'], 'required'],
- [['id'], 'integer'],
- [['express_no'], 'string'],
- ];
- $res = Yii::$app->services->validate->validate($params, $rules);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $service = new \backend\modules\mall\services\OrderService(['mall_id' => $this->mall_id]);
- return $this->success('操作成功', ['is_exists' => $service->checkOrderExpressNo($params)]);
- }
- }
|