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