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)], [['keyword','type'], 'string'], ]; $res = Yii::$app->services->validate->validate($param, $rules); if (!$res) return $this->error(Yii::$app->services->validate->getErrorMessage()); $where[] = ['mall_id' => $this->mall_id]; $where[] = ['store_id' => $this->store_id]; if (isset($param['order_status']) && $param['order_status'] != 999) { $where[] = ['order_status' => $param['order_status']]; } if (isset($param['keyword']) && $param['keyword']) { $keyword_order_no = $param['keyword']; $express = OrderExpress::findOne(['express_no' => $param['keyword']]); if($express){ $order = Order::findOne(['id' => $express->order_id,'mall_id' => $this->mall_id,'store_id' => $this->store_id]); $order && $keyword_order_no = $order->order_no; } $where[] = ['or', ['order_no' => $keyword_order_no], ['mobile' => $param['keyword']]]; } $where[] = ['=', 'supplier_type', 0]; $where[] = ['!=', 'marketing_type', 'SecondaryCard']; $where[] = ['>=', 'status', StatusEnum::DISABLED]; $with = ['base_user', 'detail']; $order = "id desc"; $params = compact('where', 'with', 'order'); $page_data = StoreOrder::listPage($params, false, true); if ($page_data === false) return $this->error(Goods::getStaticError()); foreach ($page_data['list'] as &$item){ $item['type'] =2; } $compact_params = array_keys($page_data); extract($page_data); //订单数量:未付款,待发货,待收货 $stat = StoreOrder::find()->select('count(id) as num ,order_status')->where(['mall_id' => $this->mall_id, 'store_id' => $this->store_id ])->groupBy('order_status')->asArray()->all(); $stat = array_column($stat, 'num', 'order_status'); //$stat_tab = []; $stat_tab[] = [ 'order_status' => 999, 'num' => 0 , 'order_status_text' => '全部' ]; foreach ($order_status_list as $key => $value) { if (!in_array($key, [OrderStatusEnum::NOT_PAY, OrderStatusEnum::PAY, OrderStatusEnum::SHIPMENTS])) continue; $stat_tab[] = [ 'order_status' => $key, 'num' => $stat[$key] ?? 0, 'order_status_text' => $value ]; } return $this->success('操作成功', compact($compact_params, 'order_status_list', 'payment_type_list', 'shipping_type_list', 'export_list', 'marketing_type_map','stat_tab')); } public function actionRefund() { $param = Yii::$app->request->get(); $refund_status_list = RefundStatusEnum::getMap(); $refund_type_list = RefundTypeEnum::getMap(); $rules = [ [['keyword'], 'string'], [['keyword', 'refund_status'], 'safe'], ]; $res = Yii::$app->services->validate->validate($param, $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 (isset($param['keyword']) && $param['keyword']) { //关键词 订单号:st202212161912558027820701 if (substr($param['keyword'], 0, 2) == 'st') { //商城订单号搜索,查询对应订单id $search_order = OrderRefund::getOidByOrderNo($this->mall_id, $param['order_no']); if ($search_order) { $where[] = ['in', 'order_id', $search_order]; } } else { preg_match('/^1\d{10}$/', $param['keyword'], $match); if ($match) { $where[] = OrderRefund::searchByKeyword($this->mall_id, 'mobile', $param['keyword']); } else { //快递单号查询不了 } } } if (isset($param['refund_status']) && $param['refund_status'] != 999 ) { if($param['refund_status'] == RefundStatusEnum::HANDEL){ //售后中 $where[] = ['in', 'refund_status', [ RefundStatusEnum::HANDEL, RefundStatusEnum::RETURN_GOODS, RefundStatusEnum::EXCHANGE_GOODS]]; }else{ $where[] = ['=', 'refund_status', $param['refund_status']]; } } else { $where[] = ['in', 'refund_status', [RefundStatusEnum::APPLY, RefundStatusEnum::HANDEL, RefundStatusEnum::FINISH, RefundStatusEnum::RETURN_GOODS, RefundStatusEnum::EXCHANGE_GOODS, RefundStatusEnum::REFUSE]]; } $with = ['base_user', 'orderDetail', 'order']; $select = 'id,order_id,order_detail_id,reason,remark,refund_price,refund_status,user_id'; $order = "id desc"; $params = compact('where', 'with', 'order', 'select'); $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]; } } } } //导航栏售后状态-数量 $stat = OrderRefund::find()->select('count(id) as num ,refund_status') ->where(['mall_id' => $this->mall_id, 'store_id' => $this->store_id ])->groupBy('refund_status')->asArray()->all(); $stat = array_column($stat, 'num', 'refund_status'); //$stat_tab = []; $stat_tab[] = [ 'refund_status' => 999, 'num' => 0 , 'refund_status_text' => '全部' ]; foreach ($refund_status_list as $key => $value) { if (!in_array($key, [RefundStatusEnum::APPLY, RefundStatusEnum::HANDEL, RefundStatusEnum::FINISH])) continue; $stat_tab[] = [ 'refund_status' => $key, 'num' => $stat[$key] ?? 0, 'refund_status_text' => $value ]; } return $this->success('操作成功', compact($compact_params, 'refund_status_list', 'refund_type_list', 'stat_tab')); } public function actionDetail() { $get = Yii::$app->request->get(); $rules = [[['id'], 'required']]; $res = Yii::$app->services->validate->validate($get, $rules); if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $order_status_list = OrderStatusEnum::getMap(); $payment_type_list = PayTypeEnum::getMap(); $shipping_type_list = ShippingTypeEnum::getMap(); $where = [['mall_id' => $this->mall_id]]; $where[] = ['=', 'id', $get['id']]; $where[] = ['=', 'store_id', $this->store_id]; $where[] = ['>=', 'status', StatusEnum::DISABLED]; $with = [ 'base_user', 'detail' ]; $params = compact('where', 'with'); $order = StoreOrder::getOne($where, true, $with); if ($order === false) return $this->error(StoreOrder::getStaticError()); $main_order = Order::getOne([['order_no'=>$order['order_no']]],true,['express','express_log']); $express_log = []; $order['order_type_text'] = '普通订单'; //佣金分红 $order['commission_total'] = 0; //服务费 $order['service_fee'] = 0; //商家实收: $order['amount_received'] = 0; $store_commission = StoreCommission::findOne(['store_id'=>$this->store_id,'order_no' =>$order['order_no']]); if($store_commission){ $order['service_fee'] = $store_commission->service_charge; $order['commission_total'] = $store_commission->addons_bonus; $order['amount_received'] = $store_commission->amount_received; } $order_setting = Yii::$app->services->setting->mall->get($this->mall_id, 'order'); $order['payment_expire_time'] = $order_setting['payment_expire_time'] ?? 30; $order['auto_receiving_time'] = $order_setting['auto_receiving_time'] ?? 14; if (!empty($order['detail'])) { foreach ($order['detail'] as &$detail) { if (!empty($detail['attr_groups_format'])) { $attr_groups_format = json_decode($detail['attr_groups_format'], true); $attr_list = $attr_groups_format[$detail['sign_id']]; $attr_group_name_list = array_column($attr_list, 'attr_group_name'); $attr_name_list = array_column($attr_list, 'attr_name'); $detail['attr_list'] = []; foreach ($attr_group_name_list as $index => $attr_group_name) { $detail['attr_list'][] = $attr_group_name . ':' . $attr_name_list[$index]; } } } } $shipping_type_text = ShippingTypeEnum::getShippingType($order['shipping_type']); $step_arr = StoreEnum::setpArrMap($order['order_status'], $shipping_type_text);// 订单状态跟踪 $order_action = OrderAction::getOrderAction([['order_id' => $main_order['id']]]); $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); $order['show_clerk_button'] = $order['order_status'] == OrderStatusEnum::TAKE ? 1:0; // 订单物流备注 $memoInfo = OrderExpress::find()->where(['order_id' => $main_order['id']])->select("memo")->asArray()->one(); $order['memo'] = $memoInfo['memo'] ?? ''; return $this->success('操作成功', compact('order', 'stepArr', 'order_status_list', 'payment_type_list', 'shipping_type_list', 'step_arr', 'order_action', 'store')); } public function actionRefundDetail() { $get = Yii::$app->request->get(); $rules = [[['id'], 'required']]; $res = Yii::$app->services->validate->validate($get, $rules); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $order_status_list = OrderStatusEnum::getMap(); $address_list = StoreRefundAddress::lists([ 'where' => [ ['store_id' => $this->store_id], ['status' => StatusEnum::ENABLED] ], 'select' => 'address,mobile,name, refund_name as consignee', ]); $where = [['mall_id' => $this->mall_id], ['store_id' => $this->store_id]]; $where[] = ['=', 'id', $get['id']]; $where[] = ['>=', 'status', StatusEnum::DISABLED]; $with = ['base_user', 'order', 'orderDetail', 'marketing', 'step']; $params = compact('where', 'with'); $refund = OrderRefund::getOne($where, true, $with); if ($refund === false) return $this->error(OrderRefund::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($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_status_map = RefundStatusEnum::getStepStatusText(); $refund_type_text = RefundTypeEnum::getMap(); $refund_status_map = RefundStatusEnum::getMap(); $refund['type_text'] = $refund_type_text[$refund['type']] ?? ''; $refund['refund_status_text'] = $refund_status_map[$refund['refund_status']] ?? ''; //关闭时间 $refund['finish_at'] = 0; if($refund['status'] == RefundStatusEnum::FINISH){ //售后完成 $refund['finish_at'] = $refund['updated_at']; } return $this->success('操作成功', compact('refund', 'order_status_list', 'step_arr', 'address_list', 'step_status_map','refund_status_map')); } /** * 售后列表 * @Author: lun * @DateTime: 2023/2/14 0014 16:07 * @Copyright: copyright (c) 2021 广东七件事集团 * @return mixed|void */ public function actionRefundList() { $params = \Yii::$app->request->get(); $where[] = ['mall_id' => $this->mall_id]; $where[] = ['store_id' => $this->store_id]; $params['order'] = 'id desc'; $params['where'] = $where; $params['with'] = ['step', 'orderDetail']; $list = OrderRefund::listPage($params); if($list['list']){ foreach($list['list'] as $k=>$v){ $goods_unit = Goods::getOne([['=','id',$v['orderDetail']['goods_id']]],false,'','','unit')['unit']; $list['list'][$k]['orderDetail']['unit'] = $goods_unit; } } $list['mall_name'] = $this->store['store_name']; $list['refund_status_text'] = RefundStatusEnum::getMap(); return $this->success('操作成功 ', $list); } public function actionCashierLog() { $request = Yii::$app->request; try { if ($request->isGet) { $get = $request->get(); $res = Yii::$app->services->validate->validate($get, [ [['keyword', 'order_no', 'start_time', 'end_time'], 'string'], [['page', 'limit'], 'integer'] ]); if (!$res) throw new Exception(Yii::$app->services->validate->getErrorMessage()); $get['user_id'] = $this->user_id; $list = (new StoreOrderService(['mall_id' => $this->mall_id, 'store_id' => $this->store_id]))->getCashierLog($get); return $this->success('获取成功', $list); } } catch (\Exception $e) { return $this->error($e->getMessage()); } } }