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 = Order::searchParams($this->mall_id, $get); $where[] = ['=', 'marketing_type', ScratchEnum::ADDONS_NAME]; $with = ['base_user', 'detail']; $order = "id desc"; $params = compact('where', 'with', 'order', 'alias'); $page_data = Order::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'] = '--'; } } } } $export_list = Order::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('index'); } /** * 订单改价 * @Author bing * @DateTime 2021-09-10 19:12:51 * @return void * @copyright: Copyright (c) 2020 广东七件事集团 */ 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 * @return void * @copyright: Copyright (c) 2020 广东七件事集团 */ 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(Goods::getStaticError()); return $this->success(); } /** * 关闭订单 * @Author bing * @DateTime 2021-09-10 19:12:23 * @return void * @copyright: Copyright (c) 2020 广东七件事集团 */ 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(Goods::getStaticError()); return $this->success(); } /** * 删除订单 * @Author bing * @DateTime 2021-09-10 19:12:23 * @return void * @copyright: Copyright (c) 2020 广东七件事集团 */ 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(Goods::getStaticError()); return $this->success(); } /** * 修改备注 * @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['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()); 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['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 * @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'], '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(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; $res = Order::takeDelivery($form); if ($res === false) return $this->error(Goods::getStaticError()); return $this->success(); } /** * 订单详情 * @Author bing * @DateTime 2021-09-06 14:09:56 * @return void * @copyright: Copyright (c) 2020 广东七件事集团 */ public function actionDetail() { return $this->render('detail'); } /** * 订单操作日志 * @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; $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'], '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[] = ['=', 'status', StatusEnum::ENABLED]; // 搜索查询 !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')); } } return $this->render($this->action->id); } /** * 售后详情 * @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', '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($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($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', 'mobile', 'address_type'], 'integer'], [['saler_express', 'saler_express_no', 'address', 'consignee'], '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, ]; $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'], 'required'], [['express_id'], '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()); // 提交到异步处理 Yii::$app->services->rabbitMq->push(RabbitMqEnum::EXCHANGE_ORDER, RabbitMqEnum::ORDER_QUEUE, ['id' => $model->id], OrderDeliveryListener::class, 'async_batch_handle'); $this->success('提交成功,正在处理异步处理批量发货'); } catch (Exception $e) { $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'; 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]); } /** * 下载批量发货模板 * @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 = ['订单号', '物流单号']; $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); } }