request->isAjax) { if (\Yii::$app->request->isPost) { $data = \Yii::$app->request->post(); if($data['list_type'] == 'fill_order'){ $title = '代理商补货列表'; $class = CloudStockFillOrder::class; } else if ($data['list_type'] == 'diff_order') { $title = '价差礼包列表'; $class = CloudStockPriceDifferenceGiftPackageOrderService::class; } else if ($data['list_type'] == 'dispense_order') { $title = '代理商配货列表'; $class = CloudStockDispenseOrderService::class; }else{ $title = '用户买货订单列表'; $class = CloudStockBuyingOrder::class; } $filename = $title. '-' . date('YmdHis').'_'.rand(10000,99999); $data['mall_id'] = $this->mall_id; $res = CsvExportHelper::exportDownLoadCenter($this->mall_id,$filename,DownloadEnum::TYPE_CLOUD_STOCK,$class,'exportOrder',$data); if ($res === false) return $this->error('加入导出任务失败'.CsvExportHelper::getStaticError()); return $this->success('添加导出任务成功,任务完成后请在下载中心进行下载!'); }else{ $params = Yii::$app->request->get(); if (!empty($params['list_type']) && $params['list_type'] == 'diff_order') { $params['mall_id'] = $this->mall_id; $data = (new CloudStockPriceDifferenceGiftPackageOrderService(['mall_id' => $this->mall_id]))->index($params); return $this->success('操作成功', $data); } if (!empty($params['list_type']) && $params['list_type'] == 'dispense_order') { $params['mall_id'] = $this->mall_id; $data = (new CloudStockDispenseOrderService(['mall_id' => $this->mall_id]))->index($params); return $this->success('操作成功', $data); } $where[] = ['=', 'mall_id', $this->mall_id]; $where[] = ['in', 'status', [StatusEnum::DISABLED, StatusEnum::ENABLED]]; if (!empty($params['keyword'])) { $user_list = User::find()->where(['or', ['id' => $params['keyword']], ['nickname' => $params['keyword']], ['like', 'mobile', $params['keyword']]])->select('id')->asArray()->all(); $user_id_arr = array_column($user_list, 'id'); $where[] = ['user_id' => $user_id_arr]; } if (!empty($params['goods_name'])) { $goods_list = Goods::find()->where(['like', 'goods_name', $params['goods_name']])->select('id')->asArray()->all(); if ($goods_list) { $goods_id_arr = array_column($goods_list, 'id'); $where[] = ['goods_id' => $goods_id_arr]; } } if (!empty($params['payment_type'])) $where[] = ['=', 'payment_type', $params['payment_type'] ]; if (!empty($params['start'])) $where[] = ['>=', 'created_at', strtotime($params['start'])]; if (!empty($params['end'])) $where[] = ['<=', 'created_at', strtotime($params['end'])]; $params['order'] = 'id desc'; $params['with'] = ['user', 'order', 'orderDetail', 'goods']; if ($params['list_type'] == 'fill_order') { if (!empty($params['id'])) { $where[] = ['=', 'id', $params['id']]; } if (isset($params['is_pay']) && is_numeric($params['is_pay'])) { $where[] = ['=', 'is_pay', $params['is_pay']]; } $where[] = ['price_difference_order_id' => 0]; $params['where'] = $where; $params['with'] = ['user', 'goods']; $page_data = CloudStockFillOrder::listPage($params, false); $page_data['export_list'] = CloudStockFillOrder::fieldsLists(); if(!empty($page_data['list'])){ $trade_nos = array_column($page_data['list'],'trade_no'); $payment_trade_arr = PaymentTrade::lists(['where'=>[['out_trade_no'=>$trade_nos]],'index'=>'out_trade_no','select'=>'out_trade_no,pay_type as payment_type,rand_fee']); $fill_order_ids = []; $order_id_arr = array_column($page_data['list'], 'id'); $deduction_list = CloudStockDeductionDetail::lists([ 'where' => [ ['mall_id' => $this->mall_id], ['order_id' => $order_id_arr], ['order_type' => CloudStockEnum::STOCK_ORDER_TYPE_REPLENISH], ['changes_type' => CloudStockEnum::CHANGE_TYPE_DEDUTION_FILL] ], 'select' => 'user_id,order_id', ] ); $deduction_user_ids = array_column($deduction_list, 'user_id'); $deduction_user_id_arr = []; foreach ($deduction_list as $val) { $deduction_user_id_arr[$val['order_id']][] = $val['user_id']; } $user_list = User::lists([ 'where' => [ ['id' => $deduction_user_ids] ], 'index' => 'id', 'select' => 'id,nickname,mobile,avatar_url', ] ); $user_list[0] = ['id' => 0, 'nickname' => '平台', 'mobile' => '', 'avatar_url' => '',]; foreach ($page_data['list'] as $val){ if(empty($val['trade_no'])){ $fill_order_ids[]=$val['id']; } } if(!empty($fill_order_ids)){ $fill_order_relations = CloudStockFillOrderRelation::lists(['where'=>[['fill_order_id'=>$fill_order_ids]],'index'=>'fill_order_id','select'=>'fill_order_id,order_id']); $order_ids = array_column($fill_order_relations,'order_id'); $order_arr = Order::lists(['where'=>[['id'=>$order_ids]],'index'=>'id','select'=>'id,payment_type']); } foreach ($page_data['list'] as &$item){ if(!empty($item['trade_no'])){ $item['payment_type'] = $payment_trade_arr[$item['trade_no']]['payment_type']??''; $item['rand_fee'] = $payment_trade_arr[$item['trade_no']]['rand_fee']; }else{ if(isset($fill_order_relations[$item['id']])){ $order_id = $fill_order_relations[$item['id']]['order_id']; if(isset($order_arr)&&isset($order_arr[$order_id])){ $item['payment_type'] = $order_arr[$order_id]['payment_type']; } } } $item['from_user'] = []; if (isset($deduction_user_id_arr[$item['id']])) { foreach ($deduction_user_id_arr[$item['id']] as $uid) { if (!isset($user_list[$uid])) { continue; } $item['from_user'][] = [ 'id' => $uid, 'nickname' => $user_list[$uid]['nickname'], 'mobile' => $user_list[$uid]['mobile'], 'avatar_url' => $user_list[$uid]['avatar_url'], ]; } } } } } else { if (!empty($params['id'])) { $where[] = ['=', 'id', $params['id']]; } $params['where'] = $where; $params['with'] = ['user', 'order', 'orderDetail', 'goods']; $page_data = CloudStockBuyingOrder::listPage($params, false); if (!empty($page_data['list'])) { $order_id_arr = array_column($page_data['list'], 'id'); $deduction_list = CloudStockDeductionDetail::lists([ 'where' => [ ['order_id' => $order_id_arr], ['order_type' => CloudStockEnum::STOCK_ORDER_TYPE_USER] ], 'select' => 'user_id,order_id', ] ); $deduction_user_ids = array_column($deduction_list, 'user_id'); $deduction_user_id_arr = []; foreach ($deduction_list as $val) { $deduction_user_id_arr[$val['order_id']][] = $val['user_id']; } $user_list = User::lists([ 'where' => [ ['id' => $deduction_user_ids] ], 'index' => 'id', 'select' => 'id,nickname,mobile,avatar_url', ] ); $user_list[0] = [ 'id' => 0, 'nickname' => '平台', 'mobile' => '', 'avatar_url' => '' ]; } foreach ($page_data['list'] as &$item) { $item['from_user'] = []; if (isset($deduction_user_id_arr[$item['id']])) { foreach ($deduction_user_id_arr[$item['id']] as $uid) { if (!isset($user_list[$uid])) { continue; } $item['from_user'][] = [ 'id' => $uid, 'nickname' => $user_list[$uid]['nickname'], 'mobile' => $user_list[$uid]['mobile'], 'avatar_url' => $user_list[$uid]['avatar_url'], ]; } } } $page_data['export_list'] = CloudStockBuyingOrder::fieldsLists(); } $page_data['payment_type_list']= PayTypeEnum::getMap(); return $this->success('操作成功', $page_data); } } return $this->render('index', []); } public function actionInvite() { if (\Yii::$app->request->isAjax) { if (\Yii::$app->request->isPost) { $data = \Yii::$app->request->post(); $filename = '自取订单-' . date('YmdHis').'_'.rand(10000,99999); $data['mall_id'] = $this->mall_id; $res = CsvExportHelper::exportDownLoadCenter($this->mall_id,$filename,DownloadEnum::TYPE_CLOUD_STOCK,CloudStockAgentOrder::class,'exportOrder',$data); if ($res === false) return $this->error('加入导出任务失败'.CsvExportHelper::getStaticError()); return $this->success('添加导出任务成功,任务完成后请在下载中心进行下载!'); }else{ $params = Yii::$app->request->get(); $where[] = ['=', 'mall_id', $this->mall_id]; $where[] = ['in', 'status', [StatusEnum::DISABLED, StatusEnum::ENABLED]]; if (!empty($params['keyword'])) { $user_list = User::find()->where(['or', ['id' => $params['keyword']], ['like', 'mobile', $params['keyword']], ['like', 'nickname', $params['keyword']]])->select('id')->asArray()->all(); $user_id_arr = array_column($user_list, 'id'); $where[] = ['user_id' => $user_id_arr]; } if ($params['status'] != '') { if (abs($params['status']) == \addons\CloudStock\common\enums\CloudStockEnum::PICK_ORDER_STATUS4) { $where[] = ['=', 'send_status', \addons\CloudStock\common\enums\CloudStockEnum::PICK_ORDER_STATUS4]; $where[] = [$params['status'] > 0 ? '=' : '>', 'cancel_admin_id', 0]; } else { $where[] = ['=', 'send_status', $params['status']]; } } if (!empty($params['order_type'])) { $where[] = ['order_type' => $params['order_type']]; } if (!empty($params['express_no'])) { $where[] = ['=', 'express_no', $params['express_no']]; } if (!empty($params['out_trade_no'])) { $where[] = ['=', 'trade_no', $params['out_trade_no']]; } if (!empty($params['order_no'])) { $where[] = ['=', 'order_no', $params['order_no']]; } if (!empty($params['created_at'])) { $where[] = ['between', 'created_at', strtotime(reset($params['created_at'])), strtotime(end($params['created_at']))]; } if (isset($params['receiving_info']) && $params['receiving_info'] !== '') { $where[] = [ 'or', ['like', 'mobile', $params['receiving_info']], ['like', 'name', $params['receiving_info']] ]; } if (!empty($params['areaIds'])) { $where[] = [ 'or', ['province_id' => $params['areaIds']], ['city_id' => $params['areaIds']], ['district_id' => $params['areaIds']] ]; } $params['where'] = $where; $params['order'] = 'id desc'; $params['with'] = [ 'user', 'details' => function ($query) { $query ->with(['goods' => function ($query) { $query->select('id, cover_pic, goods_name'); }]); } ]; $page_data = CloudStockAgentOrder::listPage($params, false); if(!empty($page_data['list'])){ $express_codes = array_column($page_data['list'],'express_code'); $express_list = Express::getExpresses([['code'=>$express_codes]], [], true, '*'); $express_arr = array_column($express_list,'name','code'); $regionList = Region::find()->indexBy('id')->select('name')->column(); foreach ($page_data['list'] as &$item){ $item['express_name'] = $express_arr[$item['express_code']]??''; $item['order_type_text'] = $item['order_type'] == 1 ? "云仓自提" : "价差礼包自提"; $item['region_name'] = sprintf('%s %s %s', $regionList[$item['province_id']] ?? '', $regionList[$item['city_id']] ?? '', $regionList[$item['district_id']] ?? ''); } } $page_data['export_list'] = CloudStockAgentOrder::fieldsLists(); $send_status_map = CloudStockEnum::getAgentOrdetStatusMap(); $page_data['send_status_map'] = $send_status_map; $page_data['payment_type_list']= PayTypeEnum::getMap(); $page_data['payment_type_list'][0] = '免支付'; return $this->success('操作成功', $page_data); } } return $this->render('invite', []); } 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,CloudStockOrderBatchDeliveryError::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 = CloudStockOrderBatchDelivery::setData($this->mall_id, $params); if ($model == false) throw new \Exception(CloudStockOrderBatchDelivery::getStaticError()); //CloudStockAgentOrder::asyncBatchDelivery(['id' => $model->id]); // 提交到异步处理 Yii::$app->services->rabbitMq->push(RabbitMqEnum::EXCHANGE_ORDER, RabbitMqEnum::ORDER_QUEUE, ['id' => $model->id], CloudStockAgentOrder::class, 'asyncBatchDelivery'); return $this->success('提交成功,正在处理异步处理批量发货'); } catch (\Exception $e) { return $this->error('提交失败:' . $e->getMessage()); } }else{ $params = Yii::$app->request->get(); $rules = [ [['delivery_status'], 'integer'], [['start_time','end_time','operator_name'], 'string'], ]; $res = Yii::$app->services->validate->validate($params, $rules); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); // 条件组合 $where = [['mall_id' => $this->mall_id]]; $where[] = ['=', 'status', StatusEnum::ENABLED]; isset($params['start_time']) && isset($params['end_time']) && $where[] = ['between', 'created_at', strtotime($params['start_time']), strtotime($params['end_time'])]; isset($params['operator_name']) && $where[] = ['=', 'operator_name', $params['operator_name']]; isset($params['delivery_status']) && $where[] = ['=', 'delivery_status', $params['delivery_status']]; $with=[]; $order = "id desc"; $list_params = compact('where', 'with', 'order'); $list = CloudStockOrderBatchDelivery::listPage($list_params, false, true); if ($list === false) return $this->error(CloudStockOrderBatchDelivery::getStaticError()); return $this->success('操作成功', $list); } } return $this->render($this->action->id); } 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); } 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 = CloudStockOrderBatchDeliveryError::listPage($list_params, false, true); if ($list === false) return $this->error(CloudStockOrderBatchDeliveryError::getStaticError()); return $this->success('操作成功', $list); } } return $this->render($this->action->id); } public function actionExpressList() { $express_list = Express::getExpresses([], [], true, '*'); return $this->success('成功', $express_list); } public function actionDelivery() { if (\Yii::$app->request->isAjax) { $params = Yii::$app->request->post(); $params['send_status'] = CloudStockEnum::SEND_STATUS_1; unset($params['_csrf']); CloudStockAgentOrder::setData($this->mall_id, $params); return $this->success('发货成功'); } return $this->render('invite', []); } public function actionViewLogistics(){ try { $id = Yii::$app->request->get('id', ''); $traces = CloudStockAgentOrder::viewLogistics($id,$this->mall_id); $is_true = 0; if(!empty($traces)) $is_true = 1; return $this->success('',['traces'=>$traces,'is_true'=>$is_true]); }catch (\Exception $e){ return $this->error($e->getMessage()); } } public function actionCommissionAndScoreList(){ $params = Yii::$app->request->get(); $wallet_type = 'commission'; $level = UserLevel::find()->select("name,level")->where(['mall_id' => $this->mall_id,'status' => StatusEnum::ENABLED])->asArray()->all(); $level_data = array_column($level,'name','level'); $list = []; if(!empty($params['wallet_type'])) $wallet_type = $params['wallet_type']; $condition['select'] = 'id'; $condition = [ 'where'=>[ ['source_table'=>['cloud_stock_agent_order']], ['source_table_id'=>$params['order_id']] ], ]; CapitalLog::$capitalType = "{$wallet_type}"; $temp_list = CapitalLog::getList($condition,0); if(!empty($temp_list)) $list = array_merge($list,$temp_list); $level = UserLevel::find()->select("name,level")->where(['mall_id' => $this->mall_id,'status' => StatusEnum::ENABLED])->asArray()->all(); $level_data = array_column($level,'name','level'); CapitalLog::$capitalType = "{$wallet_type}_frozen"; $condition['where'][] = ['status'=>0]; $frozen_list = CapitalLog::getList($condition,1); if(!empty($frozen_list)) $list = array_merge($list,$frozen_list); return $this->success('操作成功',['list'=>$list,'user_level'=>$level_data]); } /** * 编辑卖家备注 * * @return void */ public function actionModifySellerRemark() { $params = Yii::$app->request->post(); $rules = [ [['id'], 'required'], [['id'], 'integer'], [['seller_remark'], 'string', 'max' => 255], ]; $res = Yii::$app->services->validate->validate($params, $rules); if ($res === false) { return $this->error(Yii::$app->services->validate->getErrorMessage()); } $service = new CloudStockAgentOrderService(['mall_id' => $this->mall_id]); if (!$service->modifyRemark($params['id'], $params['seller_remark'], true)) { $this->error($service->getError()); return; } $this->success(); } /** * 修改收货地址 * * @return void */ public function actionModifyAddress() { $params = Yii::$app->request->post(); $rules = [ [['id', 'name', 'mobile', 'address', 'province_id', 'city_id', 'district_id'], 'required'], [['id','province_id','city_id','district_id'], 'integer'], [['mobile'], 'number'], [['name'], 'string', 'max' => 125], [['address'], 'string', 'max' => 128], ]; $res = Yii::$app->services->validate->validate($params, $rules); if ($res === false) { return $this->error(Yii::$app->services->validate->getErrorMessage()); } $service = new CloudStockAgentOrderService(['mall_id' => $this->mall_id]); if (!$service->modifyAddress($params)) { $this->error($service->getError()); return; } $this->success(); } /** * 取消自提 * * @return void */ public function actionCancelAgentOrder() { $params = Yii::$app->request->post(); $rules = [ [['id'], 'required'], [['id'], 'integer'], ]; $res = Yii::$app->services->validate->validate($params, $rules); if ($res === false) { return $this->error(Yii::$app->services->validate->getErrorMessage()); } $service = new CloudStockAgentOrderService(['mall_id' => $this->mall_id, 'admin_id' => $this->admin->id]); if (!$service->cancelAgentOrder($params['id'])) { $this->error($service->getError()); return; } $this->success(); } }