request->isAjax) { if (\Yii::$app->request->isGet) { //商品列表筛选 $get = Yii::$app->request->get(); $isReserve = $get['is_reserve'] ?? 0; if($isReserve){ $order_status_list = OrderStatusEnum::getReserveMap(); $order_status_list[3] = '服务中'; }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'], '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[] = ['=', 'mall_id', $this->mall_id]; $where[] = ['=', 'store_id', $this->store_id]; $where[] = ['=', 'supplier_type', 0]; $where[] = ['>=', 'status', StatusEnum::DISABLED]; if ($isReserve) { $where[] = ['=', 'order_source', OrderSourceEnum::SOURCE_RESERVE]; } else { $where[] = ['<>', 'order_source', OrderSourceEnum::SOURCE_RESERVE]; } if (isset($get['order_id'])) $where[] = ['in', 'id', explode(',', $get['order_id'])]; ($get['payment_type'] ?? false) && $where[] = ['=', 'payment_type', $get['payment_type']]; ($get['shipping_type'] ?? false) && $where[] = ['=', 'shipping_type', $get['shipping_type']]; if (isset($get['order_status']) && $get['order_status'] != 999) { if ($isReserve && $get['order_status'] == OrderStatusEnum::SING) { // 以前端栏目配置服务中即待验收其状态包括已提货 $where[] = ['in', 'order_status', [OrderStatusEnum::SING, OrderStatusEnum::TAKE_FINISH]]; } else { $where[] = ['=', 'order_status', $get['order_status']]; } } ($get['order_no'] ?? false) && $where[] = ['=', 'order_no', $get['order_no']]; ($get['start'] ?? false) && $where[] = ['>=', 'created_at', strtotime($get['start'])]; ($get['end'] ?? false) && $where[] = ['<=', 'created_at', strtotime($get['end'])]; if ($get['type_value'] ?? false) { switch ($get['type']) { case 'mobile': $uids = User::find()->select('id')->where(['like', 'mobile', $get['type_value'] . '%', false])->column(); !empty($uids) && $where[] = ['in', 'user_id', $uids]; break; case 'user_id': $where[] = ['in', 'user_id', $get['type_value']]; break; case 'consignee': case 'consignee_mobile': if ($get['type'] == 'consignee') { $where[] = ['like', 'receiver_name', $get['type_value'] . '%', false]; } else { $where[] = ['like', 'mobile', $get['type_value'] . '%', false]; } break; default: } } $with = ['base_user', 'detail','reserve']; $order = "id desc"; $params = compact('where', 'with', 'order'); $page_data = StoreOrder::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 = StoreOrderMarketing::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 ? '线上下单' : '系统创建'; } $export_list = StoreOrder::fieldsList(); if($isReserve){ $export_list['create_type'] = '创建方式'; } $marketing_type_map = MarketingTypeEnum::getMap(); return $this->success('操作成功', compact($compact_params, 'order_status_list', 'payment_type_list', 'shipping_type_list', 'export_list', 'marketing_type_map')); } if (\Yii::$app->request->post('flag') == 'EXPORT') { $post = \Yii::$app->request->post(); $post['mall_id'] = $this->mall_id; $post['store_id'] = $this->store_id; $filename = 'o2o门店订单列表-' . date('YmdHis') . '_' . rand(10000, 99999); $res = CsvExportHelper::exportDownLoadCenter($this->mall_id, $filename, DownloadEnum::TYPE_ORDERS, StoreOrder::class, 'exportHandle', $post,0,$this->store_id); if ($res === false) return $this->error('加入导出任务失败' . CsvExportHelper::getStaticError()); return $this->success('添加导出任务成功,任务完成后请在下载中心进行下载!'); } } 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 = [['mall_id' => $this->mall_id]]; $where[] = ['=', 'store_id', $this->store_id]; $where[] = ['=', 'status', StatusEnum::ENABLED]; if (!empty($get['goods_type'])) $where[] = ['goods_type' => $get['goods_type']]; // 搜索查询 !empty($get['order_no']) && $where[] = ['in', 'order_id', OrderRefund::getOidByOrderNo($this->mall_id, $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['type']) && !empty($get['keyword'])) $where[] = OrderRefund::searchByKeyword($this->mall_id, $get['type'], $get['keyword']); $with = ['base_user', 'orderDetail', 'order']; $order = "id desc"; $params = compact('where', 'with', 'order'); $page_data = OrderRefund::listPage($params, false, true); if ($page_data === false) return $this->error(OrderRefund::getStaticError()); $compact_params = array_keys($page_data); extract($page_data); foreach ($list as &$order) { foreach ($order['orderDetail'] as &$detail) { if (!empty($detail['attr_groups_format'])) { //规格 $attr_groups_format = Json::decode($detail['attr_groups_format'], true); $attr_list = $attr_groups_format[$detail['sign_id']]; $attr_group_name_list = array_column($attr_list, 'attr_group_name'); $attr_name_list = array_column($attr_list, 'attr_name'); $detail['attr_list'] = []; foreach ($attr_group_name_list as $index => $attr_group_name) { $detail['attr_list'][] = $attr_group_name . ':' . $attr_name_list[$index]; } } } 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']); } } } 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 = 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) : []; $address_list = StoreRefundAddress::lists([ 'where' => [ ['store_id' => $this->store_id], ['status' => StatusEnum::ENABLED] ], 'select'=>'address,mobile,name as consignee, refund_name', ]); $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], ['store_id' => $this->store_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()); $main_order = Order::findOne(['id'=>$refund['order_id']]); $store_order = StoreOrder::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($detail['goods_attr_name']) && !empty($detail['goods_attr_id'])) { if ($detail['order_source'] == 'Reserve') { // 服务订单 $attr_info = StoreGoodsExtra::getOne([['=', 'id', $detail['goods_attr_id']]],true, ['goods']); } else { $attr_info = StoreGoodsAttr::getOne([['=', 'id', $detail['goods_attr_id']]],true, ['goods']); } $detail['goods_attr_name'] = $attr_info ? $attr_info['name'] : ''; } } // 返还优惠内容 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'] == AddonsEnum::ADDONS_NAME_WUZHOU_CHAIN ? 1 : 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 2022-04-26 18:07:29 * @return void * @copyright: Copyright (c) 2022 广东七件事集团 */ public function actionPlatformOrder() { 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 = [ [['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'], // ['mobile', 'match', 'pattern' => '/^1\d{10}$/', 'message' => '请输入正确的手机号码'], ]; $res = Yii::$app->services->validate->validate($get, $rules); if (!$res) return $this->error(Yii::$app->services->validate->getErrorMessage()); $where[] = ['=', 'mall_id', $this->mall_id]; $where[] = ['=', 'store_id', $this->store_id]; $where[] = ['>', 'supplier_type', 0]; $where[] = ['>=', 'status', StatusEnum::DISABLED]; if (isset($get['order_id'])) $where[] = ['in', 'id', explode(',', $get['order_id'])]; ($get['payment_type'] ?? false) && $where[] = ['=', 'payment_type', $get['payment_type']]; ($get['shipping_type'] ?? false) && $where[] = ['=', 'shipping_type', $get['shipping_type']]; if (isset($get['order_status']) && $get['order_status'] != 999) { $where[] = ['=', 'order_status', $get['order_status']]; } ($get['order_no'] ?? false) && $where[] = ['=', 'order_no', $get['order_no']]; ($get['start'] ?? false) && $where[] = ['>=', 'created_at', strtotime($get['start'])]; ($get['end'] ?? false) && $where[] = ['<=', 'created_at', strtotime($get['end'])]; if ($get['type_value'] ?? false) { switch ($get['type']) { case 'mobile': $uids = User::find()->select('id')->where(['like', 'mobile', $get['type_value'] . '%', false])->column(); !empty($uids) && $where[] = ['in', 'user_id', $uids]; break; case 'user_id': $where[] = ['in', 'user_id', $get['type_value']]; break; default: } } $with = ['base_user', 'detail']; $order = "id desc"; $params = compact('where', 'with', 'order', 'alias'); $page_data = StoreOrder::listPage($params, false, true); if ($page_data === false) return $this->error(Goods::getStaticError()); $compact_params = array_keys($page_data); extract($page_data); foreach ($list as &$order) { $order_expresses = OrderExpress::getOrderExpresses([['order_id' => $order['id']]]); foreach ($order['detail'] as &$detail) { // 物流信息 $detail['express'] = ''; foreach ($order_expresses as $record) { $order_detail_ids = empty($record['order_detail_ids']) ? [] : json_decode($record['order_detail_ids'], true); if (is_string($order_detail_ids)) $order_detail_ids = []; if (in_array($detail['id'], $order_detail_ids)) { $detail['express'] = $record['express_name'] . ' | ' . $record['express_no']; if ($record['shipping_type'] == 0) $detail['express'] = '--'; } } } // 五洲供应链订单限制操作 $item['option_limit'] = 0; if ($item['supplier_type'] == StoreEnum::SELF_MALL_WUZHOU) $item['option_limit'] = 1; } $export_list = StoreOrder::fieldsList(); $marketing_type_map = MarketingTypeEnum::getMap(); return $this->success('操作成功', compact($compact_params, 'order_status_list', 'payment_type_list', 'shipping_type_list', 'export_list', 'marketing_type_map')); } if (\Yii::$app->request->post('flag') == 'EXPORT') { $post = \Yii::$app->request->post(); $post['mall_id'] = $this->mall_id; $filename = '订单列表-' . date('YmdHis') . '_' . rand(10000, 99999); $res = CsvExportHelper::exportDownLoadCenter($this->mall_id, $filename, DownloadEnum::TYPE_ORDERS, Order::class, 'exportHandle', $post); if ($res === false) return $this->error('加入导出任务失败' . CsvExportHelper::getStaticError()); return $this->success('添加导出任务成功,任务完成后请在下载中心进行下载!'); } } 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 = 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[] = ['=', 'store_id', $this->store_id]; $where[] = ['=', 'id', $get['id']]; $where[] = ['>=', 'status', StatusEnum::DISABLED]; $with = [ 'base_user', 'detail', 'reserve' ]; $params = compact('where', 'with'); $order = StoreOrder::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 ($main_order['express_log']) { foreach ($main_order['express_log'] as $item) { $item['status'] = ExpressEnum::getStatusMap($item['status']); $express_log[$item['order_express_id']] = $item; } } if (!empty($main_order['express'])) { foreach ($main_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]; } } if (empty($detail['goods_attr_name']) && !empty($detail['goods_attr_id'])) { if ($detail['order_source'] == 'Reserve') { // 服务订单 $attr_info = StoreGoodsExtra::getOne([['=', 'id', $detail['goods_attr_id']]],true, ['goods']); } else { $attr_info = StoreGoodsAttr::getOne([['=', 'id', $detail['goods_attr_id']]],true, ['goods']); } $detail['goods_attr_name'] = $attr_info ? $attr_info['name'] : ''; } } } $shipping_type_text = ShippingTypeEnum::getShippingType($order['shipping_type']); $shipping_type_fields = ShippingTypeEnum::getShippingFields($order['shipping_type']); $step_arr = StoreEnum::setpArrMap($order['order_status'], $shipping_type_text,$shipping_type_fields);// 订单状态跟踪 $order_action = OrderAction::getOrderAction([['order_id' => $main_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,]; $store = Store::getOne([['id' => $order['store_id']]], true); //获取售后原因 $refund_reason = RefundReasonEnum::getMap(); $order['create_type_text'] = $order['create_type'] == 1 ? '线上下单' : '系统创建'; $order['option_limit'] = intval($order['supplier_type'] == StoreEnum::SELF_MALL_WUZHOU); return $this->success('操作成功', compact('order', 'stepArr', 'order_status_list', 'payment_type_list', 'shipping_type_list', 'step_arr', 'order_action', 'marketing_type_map', 'store', '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 = StoreOrder::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 = StoreOrder::OrderExpressDelivery($form); } else { $res = StoreOrder::OrderExpressShippingChange($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['store_id'] = $this->store_id; $form['operator_id'] = $this->admin->id; $form['operator_name'] = $this->admin->account; $res = StoreOrder::takeDelivery($form); if ($res === false) return $this->error(Goods::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 = StoreOrder::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 = StoreOrder::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 = StoreOrder::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 = StoreOrder::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 actionCommissionAndScoreList(){ $params = Yii::$app->request->get(); $wallet_type = 'commission'; if(!empty($params['wallet_type'])) $wallet_type = $params['wallet_type']; $condition['where'] = [['order_id'=>$params['order_id']]]; $condition['select'] = 'id'; $order_detail_list = StoreOrderDetail::lists($condition); $order_detail_ids = array_column($order_detail_list,'id'); $store_order = StoreOrder::findOne($params['order_id']); $order = Order::findOne(['order_no'=>$store_order['order_no']]); $mall_order_detail_ids = []; if($order){ $condition['where'] = [['order_id' => $order['id']]]; $condition['select'] = 'id'; $mall_order_detail_list = OrderDetail::lists($condition); $mall_order_detail_ids = array_column($mall_order_detail_list, 'id'); } $condition = [ 'where' => [ [ 'or', [ 'and', ['source_table'=>['store_order_detail',StoreOrderDetail::tableName()]], ['source_table_id'=>$order_detail_ids] ], [ 'and', ['source_table' => [OrderDetail::tableName(),'order_detail']], ['source_table_id' => $mall_order_detail_ids] ] ] ], ]; CapitalLog::$capitalType = "{$wallet_type}"; $list = CapitalLog::getList($condition,0); $level = UserLevel::find()->select("name,level")->where(['mall_id' => $this->mall_id,'status' => StatusEnum::ENABLED])->asArray()->all(); $level_data = array_column($level,'name','level'); CapitalLog::$capitalType = "{$wallet_type}_frozen"; $condition['where'][] = ['status'=>0]; $frozen_list = CapitalLog::getList($condition,1); $list = array_merge($list,$frozen_list); return $this->success('操作成功',['list'=>$list,'user_level'=>$level_data]); } 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 = Store::findOne(['id'=>$this->store_id,'status'=>StatusEnum::ENABLED]); $storeService = new StoreService(); $storeService->mall_id = $this->mall_id; $storeService->store_id = $this->store_id; $params['clerk_id'] = $storeService->getClerkIdByUserId($store['user_id']??0, true); $rse = StoreClerkLog::setData($params); if($rse==false) return $this->error(StoreClerkLog::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]); } 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 = StoreOrder::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 = StoreOrderDetail::find()->where(['order_id' => $params['id']])->select('main_order_detail_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_store'] = 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, // 不需要手续费 'is_store' => 1, 'is_manual' => 1, 'operator_id' => $this->admin->id ]; $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(); } /** * 撤销售后订单 * * @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()); } /** * * @return mixed|string|void */ public function actionPrinter() { if (\Yii::$app->request->isAjax){ if (\Yii::$app->request->isPost){ $params = Yii::$app->request->post(); $rules = [ [['order_id'], 'required'], [['order_id'], 'integer'], [['order_type'], 'safe'], [['print_type'], 'required'], [['print_type'], 'integer'], ]; $res = Yii::$app->services->validate->validate($params, $rules); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $order_type = null; if(isset($params['order_type']))$order_type = $params['order_type']; $storeOrderInfo = StoreOrder::findOne($params['order_id']); $orderInfo = Order::findOne(['order_no' => $storeOrderInfo->order_no]); PrinterBase::async_handle(['order_id' => $orderInfo->id,'type' => PrintOrder::PRINT_TYPE_SYSTEM,'order_type'=>$order_type, 'print_type' => $params['print_type'], 'store_order_id' => $storeOrderInfo->id]); return $this->success('操作成功'); } } } 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, main_order_detail_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 = StoreOrderDetail::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 actionGetGoodsCommissionList(){ $params = Yii::$app->request->get(); $condition = [ 'where'=>[ ['source_table'=>[StoreOrder::tableName()]], ['source_table_id'=>$params['order_id']] ], ]; $list = []; $check_order_detail_refund = StoreOrderDetail::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', StoreOrderDetail::tableName()]], ['source_table_id' => $params['goods_id']], ['mall_id' => $this->mall_id], ['from_type' => ['Agent', 'Area', 'CloudStock', 'Achievement', 'Distribution']], ], ]; // $wallet_type = $params['wallet_type']; CapitalLog::$capitalType = "{$params['wallet_type']}"; $temp_list = CapitalLog::getList($condition,0); if(!empty($temp_list)) $list = array_merge($list,$temp_list); return $this->success('操作成功',['list'=>$list]); } 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['main_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]); } }