domain = (new OptionSetting)->getCloudDomainName(); } /** * @return array the validation rules. */ public function rules() { return [ [['certificate', 'id_card_reverse','id_card_front','logo','desc','avatar_url', 'pic_url'], 'string', 'max' => 255], [['name', 'user_name', 'password', 'supplier_name', 'cloud_platform_list', 'saas_user_mobile', 'order_no', 'centralize_goods_type', 'goods_name', 'goods_no'], 'string', 'max'=>32], [['filter_goods_id', 'ids', 'min_money', 'max_money', 'email', 'start_time', 'end_time', 'sorting_start_time', 'sorting_end_time', 'attr', 'supplier_custom_form'], 'string'], [['tel','price','service_charge', 'id', 'sale_day', 'rate', 'sort', 'profit', 'level', 'agent_percent', 'agent_install_percent', 'agent_profit_default', 'shop_count', 'platform_negotiated_price'],'number'], [['action_id','user_id','pay_type','cash_id','type','page','limit','cloud_user_id','cloud_store_id','status', 'parent_id', 'is_show', 'is_enable', 'saas_user_id', 'store_id', 'district_id', 'city_id', 'province_id', 'send_type', 'could_mch_id', 'goods_id', 'num', 'channel_id', 'is_self'],'integer'], [['sale_sort', 'price_sort', 'cat_id', 'is_distribution', 'no_distribution', 'supplier_id', 'list'], 'safe'], ]; } //创建会员 public function storeUserAdd(){ if (!$this->validate()) { return $this->getErrorSummary(false)[0]; } $cloud_store_token = get_platform_token(); if (!$cloud_store_token) { return [ 'code' => 1, 'msg' => '网络问题请重试', ]; } $store_user_add_url = "/cloud/user/storeUserAdd"; $store_user_add_data['access_token'] = $cloud_store_token; $store_user_add_data['name'] = $this->name; $store_user_add_data['pwd'] = $this->password; $store_user_add_data['tel'] = $this->tel; $store_user_add_data['email'] = $this->email; $store_user_add_data['type'] = $this->type; $store_user_add_data['avatar_url'] = $this->avatar_url; $storeInfo = cloud_post($this->domain.$store_user_add_url,$store_user_add_data); $storeInfo = json_decode($storeInfo,true); if($storeInfo['code'] != 0){ $code = 1; return $this->outPutData($code,$storeInfo['msg']); }else{ return $this->outPutData($storeInfo['code'],$storeInfo['msg'],$storeInfo['data']); } } //充值列表 public function storeGetRechargeList(){ if (!$this->validate()) { return $this->getErrorSummary(false)[0]; } $cloud_store_token = get_platform_token(); if (!$cloud_store_token) { return [ 'code' => 1, 'msg' => '网络问题请重试', ]; } $store_get_recharge_list_url = "/cloud/user/storegetRechargeList"; $store_get_recharge_list_data = []; $store_get_recharge_list_data['access_token'] = $cloud_store_token; //获取供货商的token信息 $store_get_recharge_list_data['page'] = $this->page; //默认为 1 $store_get_recharge_list_data['limit'] = $this->limit; //默认20 if($this->tel) $store_get_recharge_list_data['tel'] = $this->tel; //电话 if($this->name) $store_get_recharge_list_data['name'] = $this->name; //名称 $storeGetRechargeListInfo = cloud_post($this->domain.$store_get_recharge_list_url,$store_get_recharge_list_data); $storeGetRechargeListInfo = json_decode($storeGetRechargeListInfo,true); if($storeGetRechargeListInfo['code'] != 0){ $code = 1;//失败 return $this->outPutData($code,$storeGetRechargeListInfo['msg']); }else{ $msg = "获取成功"; return $this->outPutData($storeGetRechargeListInfo['code'],$msg,$storeGetRechargeListInfo['data']); } } //关联供应商 public function setCloudPlatform(){ if (!$this->validate()) { return $this->getErrorSummary(false)[0]; } $store_cloud = StoreCloud::find()->where(['cloud_store_id' => $this->cloud_store_id,"is_delete" => 0])->one(); if(!$store_cloud) { $code = 1;//失败 $msg = "店铺不存在"; return $this->outPutData($code,$msg); } $store_cloud->cloud_platform_list = $this->cloud_platform_list; $save = $store_cloud->save(); if($save){ return $this->outPutData(0, '操作成功'); }else{ return $this->outPutData(1, '操作失败'); } } //编辑用户 public function storeMchEdit(){ // if (!$this->validate()) { // return $this->getErrorSummary(false)[0]; // } $store_cloud = StoreCloud::findOne(['cloud_store_id' => $this->cloud_store_id, "is_delete" => 0]); if(!$store_cloud) { $code = 1;//失败 $msg = "会员不存在"; return $this->outPutData($code,$msg); } $item = StoreCloud::find()->where(['name' => trim($this->user_name), 'is_delete' => 0])->andWhere(['<>', 'id', $store_cloud->id])->one(); if ($item) { return [ 'code' => 1, 'msg' => '云仓账户已存在', ]; } $purchase = Purchase::findOne(['name' => trim($this->user_name), 'is_delete' => 0, 'status' => 0]); if ($purchase && (int)$purchase->status === 0) { return [ 'code' => 1, 'msg' => '有相同名称账户正在审核中', ]; } // $store_cloud->name = $this->name; $store_cloud->name = $this->user_name; if (!empty(trim($this->password))) { $store_cloud->password = $this->password; } // $store_cloud->logo = $this->logo; // $store_cloud->tel = $this->tel; // $store_cloud->type = $this->type; // $store_cloud->certificate = $this->certificate; // $store_cloud->id_card_reverse = $this->id_card_reverse; // $store_cloud->id_card_front = $this->id_card_front; $cloud_store_token = get_platform_token(); if (!$cloud_store_token) { return [ 'code' => 1, 'msg' => '网络问题请重试', ]; } $store_mch_edit_url = "/cloud/user/storeMchEdit"; $store_mch_edit_data = []; $store_mch_edit_data['access_token'] = $cloud_store_token; //获取供货商的token信息 $store_mch_edit_data['name'] = $this->user_name; if (!empty(trim($this->password))) { $store_mch_edit_data['pwd'] = $this->password; } // $store_mch_edit_data['logo'] = $this->logo; // $store_mch_edit_data['tel'] = $this->tel; // $store_mch_edit_data['type'] = $this->type; // $store_mch_edit_data['certificate'] = $this->certificate; // $store_mch_edit_data['id_card_reverse'] = $this->id_card_reverse; // $store_mch_edit_data['id_card_front'] = $this->id_card_front; // $store_mch_edit_data['mch_id'] = $this->cloud_store_id; //商户id $store_mch_edit_data['user_id'] = $store_cloud->cloud_user_id; $t = Yii::$app->db->beginTransaction(); $store_cloud->save(); $storeMchEditInfo = cloud_post($this->domain.$store_mch_edit_url,$store_mch_edit_data); $storeMchEditInfo = json_decode($storeMchEditInfo,true); if($storeMchEditInfo['code'] != 0){ $t->rollBack(); $code = 1;//失败 return $this->outPutData($code,$storeMchEditInfo['msg']); }else{ $t->commit(); return $this->outPutData($storeMchEditInfo['code'],$storeMchEditInfo['msg']); } } //删除商户 public function storeMchDel(){ if (!$this->validate()) { return $this->getErrorSummary(false)[0]; } $cloud_store_token = get_platform_token(); if (!$cloud_store_token) { return [ 'code' => 1, 'msg' => '网络问题请重试', ]; } $store_mch_del_url = "/cloud/user/storeMchDel"; $store_mch_del_data = []; $store_mch_del_data['access_token'] = $cloud_store_token; //获取供货商的token信息 $store_mch_del_data['mch_id'] = $this->cloud_store_id; //默认为 1 $store_cloud = StoreCloud::find()->where(['cloud_store_id' => $this->cloud_store_id,"is_delete" => 0])->one(); $t = Yii::$app->db->beginTransaction(); if(!$store_cloud){ // $code = 1;//失败 // $msg = "用户不存在"; // return $this->outPutData($code,$msg); } else { $store_cloud->is_delete = 1; $store_cloud->deleted_at = time(); $store_cloud->save(); $purchase = Purchase::findOne(['store_cloud_id' => $store_cloud->id]); if ($purchase) { $purchase->is_delete = 1; $purchase->save(); } } $storeMchDelInfo = cloud_post($this->domain.$store_mch_del_url,$store_mch_del_data); $storeMchDelInfo = json_decode($storeMchDelInfo,true); if($storeMchDelInfo['code'] != 0){ $t->rollBack(); $code = 1;//失败 return $this->outPutData($code,$storeMchDelInfo['msg']); }else{ $t->commit(); return $this->outPutData($storeMchDelInfo['code'],$storeMchDelInfo['msg']); } } //商户列表 public function storeMchList(){ if (!$this->validate()) { return $this->getErrorSummary(false)[0]; } $cloud_store_token = get_platform_token(); if (!$cloud_store_token) { return [ 'code' => 1, 'msg' => '网络问题请重试', ]; } $store_mch_list_url = "/cloud/user/storeMchList"; $store_mch_list_data = []; $store_mch_list_data['access_token'] = $cloud_store_token; //获取供货商的token信息 if ($this->name) { $store_mch_list_data['name'] = $this->name; $store_ids = Store::find()->where(['LIKE', 'name', $this->name])->andWhere(['is_delete' => 0]) ->select('id')->column(); if (!empty($store_ids)) { $store_cloud_id = StoreCloud::find()->where(['store_id' => $store_ids, 'is_delete' => 0])->andWhere(['>', 'cloud_store_id', 0]) ->select('cloud_store_id')->column(); if (!empty($store_cloud_id)) { $store_mch_list_data['ids'] = implode(',', $store_cloud_id); } } } if ($this->tel) { $store_mch_list_data['tel'] = $this->tel; } if ($this->channel_id) { $store_mch_list_data['channel_id'] = $this->channel_id; } if ($this->level) { $store_mch_list_data['level'] = $this->level; } $store_mch_list_data['page'] = $this->page; //默认为 1 $store_mch_list_data['limit'] = $this->limit; //默认20 if($this->tel) $store_mch_list_data['tel'] = $this->tel; //电话 if($this->name) $store_mch_list_data['name'] = $this->name; //名称 $storeMchListInfo = cloud_post($this->domain.$store_mch_list_url,$store_mch_list_data); $storeMchListInfo = json_decode($storeMchListInfo,true); if($storeMchListInfo['code'] != 0){ $code = 1;//失败 return $this->outPutData($code,$storeMchListInfo['msg']); }else{ $data = []; foreach ($storeMchListInfo['data']['list'] as $key => $item) { $data[$key]['can_distribution'] = 0; $data[$key]['store_id'] = 0; $data[$key]['is_enable'] = 0; $data[$key]['saas_user_id'] = 0; $data[$key]['store_cloud_id'] = 0; $data[$key]['type'] = 0; $data[$key]['logo'] = ''; $data[$key]['cloud_platform_list'] = ''; $data[$key]['store_name'] = ''; $data[$key]['store_logo'] = ''; $data[$key]['category_id'] = 0; $data[$key]['user_name'] = $item['name']; $data[$key]['user_avatar'] = $item['logo']; $data[$key]['can_recharge'] = 1; $store_cloud = StoreCloud::findOne(['cloud_store_id' => $item['id']]); if ($store_cloud) { $data[$key]['can_distribution'] = (string)$store_cloud->can_distribution; $data[$key]['store_id'] = $store_cloud->store_id; if ($data[$key]['store_id']) { $store = Store::findOne($data[$key]['store_id']); if ($store) { $data[$key]['store_name'] = $store->name; $data[$key]['store_logo'] = $store->logo; $data[$key]['category_id'] = $store->category_id; if($data[$key]['category_id'] > 0){ $catInfo = Cat::find()->where(['id' => $data[$key]['category_id'], 'is_delete' => 0])->one(); if( isset($catInfo->name) ){ $data[$key]['category_name'] = $catInfo->name; } } } } $data[$key]['is_enable'] = intval($store_cloud->is_enable); $data[$key]['saas_user_id'] = $store_cloud->saas_user_id; $data[$key]['store_cloud_id'] = $store_cloud->id; $data[$key]['type'] = intval($store_cloud->type); $data[$key]['logo'] = $store_cloud->logo; $data[$key]['cloud_platform_list'] = $store_cloud->cloud_platform_list; if ($store_cloud->saas_user_id) { $saasUser = SaasUser::findOne($store_cloud->saas_user_id); if ($saasUser) { // $data[$key]['user_name'] = $saasUser->name; $data[$key]['user_avatar'] = $saasUser->avatar; } } } $data[$key]['id'] = $item['id']; $data[$key]['cloud_store'] = $item; } $storeMchListInfo['data']['list'] = $data; $msg = "获取成功"; $this->name = null; $user_channel = $this->userGoodsChannel(1); $channel_list = []; if ($user_channel['code'] === 0) { $channel_list = $user_channel['data']['list']; } $storeMchListInfo['data']['channel_list'] = $channel_list; return $this->outPutData($storeMchListInfo['code'],$msg,$storeMchListInfo['data']); } } public function storeMchEnable() { try { $store_cloud = StoreCloud::findOne(['cloud_store_id' => $this->id]); if (empty($store_cloud)) { throw new \Exception("未找到数据"); } if (in_array((int)$this->is_enable, [0, 1])) { $store_cloud->is_enable = (int)$this->is_enable; if (!$store_cloud->save()) { throw new \Exception(json_encode($store_cloud->errors)); } return [ 'code' => 0, 'msg' => "修改成功" ]; } throw new \Exception("操作失败"); } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //商户列表 public function newStoreMchList(){ if (!$this->validate()) { return $this->getErrorSummary(false)[0]; } $cloud_store_token = get_platform_token(); if (!$cloud_store_token) { return [ 'code' => 1, 'msg' => '网络问题请重试', ]; } $store_mch_list_url = "/cloud/user/storeInfo"; $store_mch_list_data = []; $store_mch_list_data['access_token'] = $cloud_store_token; //获取供货商的token信息 $query = StoreCloud::find()->alias('c') ->leftJoin(["s"=>Store::tableName()],'c.store_id=s.id') ->leftJoin(['su' => SaasUser::tableName()], 'c.saas_user_id = su.id') ->where(['c.is_delete'=>0])->andWhere(['>','c.cloud_store_id',0]); if ($this->name) { $query->andWhere(['OR', ['like', 'c.name', $this->name], ['like', 's.name', $this->name]]); } if ((int)$this->is_enable !== -1) { $query->andWhere(['c.is_enable' => (int)$this->is_enable]); } if ($this->tel) { $query->andWhere(['like', 'c.tel', $this->tel]); } $count = $query->count(); $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $this->limit, 'page' => $this->page - 1]); $list = $query->limit($pagination->limit)->offset($pagination->offset)->orderBy('c.cloud_store_id DESC')->asArray() ->select('c.id store_cloud_id, c.can_distribution, c.store_id, c.is_enable,c.saas_user_id,c.cloud_store_id id, c.type,c.logo,c.cloud_platform_list,s.name store_name,s.logo store_logo,s.category_id,su.name as user_name,su.avatar as user_avatar')->all(); foreach($list as $key=>&$val){ if($val['category_id']>0){ $catInfo = Cat::find()->where(['id'=>$val['category_id'],'is_delete'=>0])->one(); if( isset($catInfo->name) ){ $list[$key]['category_name'] = $catInfo->name; } } $store_mch_list_data['id'] = $val['id']; $cloudInfo = cloud_post($this->domain.$store_mch_list_url,$store_mch_list_data); $storeMchListInfo = json_decode($cloudInfo,true); if($storeMchListInfo && $storeMchListInfo['code'] == 0){ $storeMchListInfo['data']['data']['type'] = $val['type']; $list[$key]['cloud_store'] = $storeMchListInfo['data']['data']; } else { $list[$key]['cloud_store'] = []; } if ((int)$val['saas_user_id'] === 0) { $val['user_avatar'] = $list[$key]['cloud_store']['logo']; $val['user_name'] = $list[$key]['cloud_store']['name']; } $val['is_enable'] *= 1; $val['can_recharge'] = 1; } $msg = "获取成功"; $data = []; $data['count'] = $count; $data['limit'] = $this->limit; $data['page'] = $this->page; $data['list'] = $list; $channel_list = []; $user_channel = $this->userGoodsChannel(1); if ($user_channel['code'] === 0) { $channel_list = $user_channel['data']['list']; } $data['channel_list'] = $channel_list; $code = 0; return $this->outPutData($code,$msg,$data); } //商户充值 public function storeSubmitRecharge(){ if (!$this->validate()) { return $this->getErrorSummary(false)[0]; } $storeCloud = StoreCloud::findOne(['cloud_store_id' => $this->id, 'is_delete' => 0]); if (!$storeCloud) { return [ 'code' => 1, 'msg' => '商户未找到', ]; } $cloud_store_token = get_platform_token(); if (!$cloud_store_token) { return [ 'code' => 1, 'msg' => '网络问题请重试', ]; } $store_submit_recharge_url = "/cloud/user/storeSubmitRecharge"; $store_submit_recharge_data = []; $store_submit_recharge_data['access_token'] = $cloud_store_token; //获取供货商的token信息 $store_submit_recharge_data['action_id'] = $storeCloud->cloud_store_id; $store_submit_recharge_data['price'] = number_format($this->price, 2,".",""); $storeSubmitRechargeInfo = cloud_post($this->domain.$store_submit_recharge_url,$store_submit_recharge_data); $storeSubmitRechargeInfo = json_decode($storeSubmitRechargeInfo,true); if($storeSubmitRechargeInfo['code'] != 0){ $code = 1;//失败 return $this->outPutData($code,$storeSubmitRechargeInfo['msg']); }else{ return $this->outPutData($storeSubmitRechargeInfo['code'],$storeSubmitRechargeInfo['msg']); } } //创建商户 public function storeMchAdd() { if (!$this->validate()) { return $this->getErrorSummary(false)[0]; } if (!$this->saas_user_id) { return [ 'code' => 1, 'msg' => '缺少必要参数', ]; } if (!in_array($this->type, [0, 1, 2])) { return [ 'code' => 1, 'msg' => '商户类型不正确', ]; } if ($this->type > 0 && !$this->store_id) { return [ 'code' => 1, 'msg' => '缺少必要参数', ]; } if (empty(trim($this->user_name))) { return [ 'code' => 1, 'msg' => '请填写云仓账户', ]; } if (empty(trim($this->password)) && !$this->id) { return [ 'code' => 1, 'msg' => '请填写云仓账户密码', ]; } $saasUser = SaasUser::findOne($this->saas_user_id); if (!$saasUser) { return [ 'code' => 1, 'msg' => '用户未找到', ]; } if ($this->saas_user_mobile) { $res = preg_match("/^1[3456789]\d{9}$/", $this->saas_user_mobile); if (!$res) { return [ 'code' => 1, 'msg' => '手机号格式错误', ]; } if (empty($saasUser->mobile)) { $saasUser->mobile = $this->saas_user_mobile; $saasUser->save(); } } $item = StoreCloud::find() ->where(['is_delete' => 0]) ->andWhere([ 'or', ['saas_user_id' => $this->saas_user_id], ['store_id' => $this->store_id] ])->one(); if ($item) { return [ 'code' => 1, 'msg' => '该' . ($item->store_id == $this->store_id && $item->store_id > 0 ? '商城' : '用户') . '已经绑定过了', ]; } $item = StoreCloud::find()->where(['name' => trim($this->user_name), 'is_delete' => 0])->andWhere(['<>', 'id', $this->id])->one(); if ($item) { return [ 'code' => 1, 'msg' => '云仓账户已存在', ]; } //获取平台token $cloud_token = get_platform_token(); if (!$cloud_token) { return [ 'code' => 1, 'msg' => '网络问题请重试', ]; } $purchase = Purchase::findOne(['AND', ['saas_user_id' => $this->saas_user_id, 'is_delete' => 0], ['<>', 'status', 2]]); if ($purchase && (int)$purchase->status === 0) { return [ 'code' => 1, 'msg' => '当前用户已经在审核申请中,请前往审核', ]; } $purchase = Purchase::findOne(['name' => trim($this->user_name), 'is_delete' => 0, 'status' => 0]); if ($purchase) { return [ 'code' => 1, 'msg' => '有相同名称账户正在审核中', ]; } $domain = $this->domain; $url = "/cloud/purchase/createPurchase"; $data['access_token'] = $cloud_token; $data['name'] = $this->user_name;//$purchase->name ?: $saasUser->name; $data['logo'] = $saasUser->avatar; $data['tel'] = $purchase->mobile ?: $saasUser->mobile; if (!empty(trim($this->password))) { $data['pwd'] = $this->password;//$purchase->mobile ?:$saasUser->mobile; } $result = cloud_post($domain . $url, $data); $result = json_decode($result, true); if ((int)$result['code'] > 0) { return [ 'code' => 1, 'msg' => $result['msg'], ]; } $mch_id = $result['data']['mch_id']; $user_id = $result['data']['user_id']; $storeCloud = new StoreCloud(); $storeCloud->store_id = $this->store_id ?: 0; $storeCloud->cloud_user_id = $user_id; $storeCloud->cloud_store_id = $mch_id; $storeCloud->saas_user_id = $this->saas_user_id; $storeCloud->name = $this->user_name;//$purchase->name ?: $saasUser->name; if (!empty(trim($this->password))) { $storeCloud->password = $this->password;//$purchase->mobile ?:$saasUser->mobile; } $storeCloud->logo = $saasUser->avatar; $storeCloud->type = $this->type; $storeCloud->tel = $purchase->mobile ?:$saasUser->mobile; $storeCloud->created_at = time(); $storeCloud->province_id = $this->province_id; $storeCloud->city_id = $this->city_id; $storeCloud->district_id = $this->district_id; if ($storeCloud->save()) { if ($storeCloud->store_id) { $admin = Admin::findOne(['type' => 'store', 'type_id' => $storeCloud->store_id, 'is_delete' => 0]); if ($admin) { $admin->mobile = $saasUser->mobile; $admin->save(); } } return [ 'code' => 0, 'msg' => '操作成功', ]; } return [ 'code' => 1, 'msg' => '操作失败', ]; } //查询余额记录 public function storeGetBalanceLog(){ if (!$this->validate()) { return $this->getErrorSummary(false)[0]; } $cloud_token = get_platform_token(); if (!$cloud_token) { return [ 'code' => 1, 'msg' => '网络问题请重试', ]; } $get_balance_log_url = "/cloud/user/storeGetBalanceLog"; $get_balance_log_data = []; $get_balance_log_data['access_token'] = $cloud_token; //获取供货商的token信息 $get_balance_log_data['page'] = $this->page; //默认为 1 $get_balance_log_data['limit'] = $this->limit; //默认20 $get_balance_log_data['tel'] = $this->tel; //电话 $get_balance_log_data['name'] = $this->name; //名称 $get_balance_log_data['status'] = $this->status; //1商户 2 供货商 //增加区域代理功能 $admin = get_admin(); $admin_id = $admin->id; if ($admin->username == 'admin') { $admin_id = null; } if ($this->status === 2) { $query = Supplier::find()->where(['is_delete' => 0]); $str = 'cloud_supplier_id'; } else { $query = StoreCloud::find()->where(['is_delete' => 0, 'is_enable' => 1]); $str = 'cloud_store_id'; } if ($admin_id) { $admin_model = Admin::findOne($admin_id); $area_level = $admin_model->area_level; if($area_level == 1){ $query->andWhere( ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id, 'district_id' => $admin_model->district_id]); } elseif ($area_level == 2){ $query->andWhere( ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id]); } elseif ($area_level == 3){ $query->andWhere(['province_id' => $admin_model->province_id]); } $this->ids = $query->select($str)->column(); if ($this->ids) { $get_balance_log_data['ids'] = implode(',', $this->ids); } else { return $this->outPutData(0,'获取成功', [ 'list' => [] ]); } } $getBalanceLogInfo = cloud_post($this->domain.$get_balance_log_url,$get_balance_log_data); $getBalanceLogInfo = json_decode($getBalanceLogInfo,true); if($getBalanceLogInfo['code'] != 0){ $code = 1;//失败 return $this->outPutData($code,$getBalanceLogInfo['msg']); }else{ return $this->outPutData($getBalanceLogInfo['code'],'获取成功',$getBalanceLogInfo['data']); } } //供货商提现列表 public function storeGetCashList(){ if (!$this->validate()) { return $this->getErrorSummary(false)[0]; } $cloud_token = get_platform_token(); if (!$cloud_token) { return [ 'code' => 1, 'msg' => '网络问题请重试', ]; } $supplier_cash_list_url = "/cloud/user/storegetCashList"; $supplier_cash_list_data = []; $supplier_cash_list_data['access_token'] = $cloud_token; //获取供货商的token信息 $supplier_cash_list_data['page'] = $this->page; //默认为 1 $supplier_cash_list_data['limit'] = $this->limit; //默认20 $supplier_cash_list_data['status'] = $this->status; //提现状态 0 待审核 1 已处理 2 已拒绝 -1 全部 $admin = get_admin(); $admin_id = $admin->id; if ($admin->username == 'admin') { $admin_id = null; } if ($admin_id) { $admin_model = Admin::findOne($admin_id); $area_level = $admin_model->area_level; $query = Supplier::find()->where(['is_delete' => 0]); if($area_level == 1){ $query->andWhere( ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id, 'district_id' => $admin_model->district_id]); } elseif ($area_level == 2){ $query->andWhere( ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id]); } elseif ($area_level == 3){ $query->andWhere(['province_id' => $admin_model->province_id]); } $ids = $query->select('cloud_supplier_id')->column(); if ($ids) { if(is_array($ids)){ $ids = implode(',', $ids); } $supplier_cash_list_data['supplier_id'] = $ids; } } if($this->tel) $supplier_cash_list_data['tel'] = $this->tel; //电话 if($this->name) $supplier_cash_list_data['name'] = $this->name; //名称 if($this->cloud_user_id) $supplier_cash_list_data['user_id'] = $this->cloud_user_id; //用户ID 非供货商或商户ID $supplierCashListInfo = cloud_post($this->domain.$supplier_cash_list_url,$supplier_cash_list_data); $supplierCashListInfo = json_decode($supplierCashListInfo,true); if($supplierCashListInfo['code'] != 0){ $code = 1;//失败 return $this->outPutData($code,$supplierCashListInfo['msg']); }else{ return $this->outPutData($supplierCashListInfo['code'],'获取成功',$supplierCashListInfo['data']); } } //供货商提现列表 public function balanceCashList(){ if (!$this->validate()) { return $this->getErrorSummary(false)[0]; } $cloud_token = get_platform_token(); if (!$cloud_token) { return [ 'code' => 1, 'msg' => '网络问题请重试', ]; } $supplier_cash_list_url = "/cloud/user/balanceCashList"; $supplier_cash_list_data = []; $supplier_cash_list_data['access_token'] = $cloud_token; //获取供货商的token信息 $supplier_cash_list_data['page'] = $this->page; //默认为 1 $supplier_cash_list_data['limit'] = $this->limit; //默认20 if($this->tel) $supplier_cash_list_data['tel'] = $this->tel; //电话 if($this->name) $supplier_cash_list_data['name'] = $this->name; //名称 $admin = get_admin(); $admin_id = $admin->id; if ($admin->username == 'admin') { $admin_id = null; } if ($admin_id) { $admin_model = Admin::findOne($admin_id); $area_level = $admin_model->area_level; $query = Supplier::find()->where(['is_delete' => 0]); if($area_level == 1){ $query->andWhere( ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id, 'district_id' => $admin_model->district_id]); } elseif ($area_level == 2){ $query->andWhere( ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id]); } elseif ($area_level == 3){ $query->andWhere(['province_id' => $admin_model->province_id]); } $ids = $query->select('cloud_supplier_id')->column(); if ($ids) { $ids = implode(',', $ids); $supplier_cash_list_data['supplier_id'] = $ids; } else { return $this->outPutData(0,'获取成功', [ 'list' => [] ]); } } if($this->cloud_user_id) $supplier_cash_list_data['user_id'] = $this->cloud_user_id; //用户ID 非供货商或商户ID $supplierCashListInfo = cloud_post($this->domain.$supplier_cash_list_url,$supplier_cash_list_data); $supplierCashListInfo = json_decode($supplierCashListInfo,true); if($supplierCashListInfo['code'] != 0){ $code = 1;//失败 return $this->outPutData($code,$supplierCashListInfo['msg']); }else{ return $this->outPutData($supplierCashListInfo['code'],'获取成功',$supplierCashListInfo['data']); } } //供货商提现处理 public function storeActionSupplierCash(){ if (!$this->validate()) { return $this->getErrorSummary(false)[0]; } $cloud_token = get_platform_token(); if (!$cloud_token) { return [ 'code' => 1, 'msg' => '网络问题请重试', ]; } $action_supplier_cash_url = "/cloud/user/storeActionSupplierCash"; $action_supplier_cash_data = []; $action_supplier_cash_data['access_token'] = $cloud_token; //获取供货商的token信息 $action_supplier_cash_data['cash_id'] = $this->cash_id; //提现ID $action_supplier_cash_data['pay_type'] = $this->pay_type; //打款方式 1 微信打款 2 支付宝打款 3 银行卡打款 4 其他 $action_supplier_cash_data['status'] = $this->status; //1 同意 2 拒绝 $action_supplier_cash_data['service_charge'] = $this->service_charge; //手续费 $actionSupplierCashInfo = cloud_post($this->domain.$action_supplier_cash_url,$action_supplier_cash_data); $actionSupplierCashInfo = json_decode($actionSupplierCashInfo,true); if($actionSupplierCashInfo['code'] != 0){ $code = 1;//失败 return $this->outPutData($code,$actionSupplierCashInfo['msg']); }else{ return $this->outPutData($actionSupplierCashInfo['code'],$actionSupplierCashInfo['msg']); } } //获取商品列表 public function goodsInfo(){ if (!$this->id && !$this->ids) { return $this->getErrorSummary(false)[0]; } $goods_list_url = "/cloud/user/userGetGoodsList"; $cloud_token = get_platform_token(); if (!$cloud_token) { return [ 'code' => 1, 'msg' => '网络问题请重试', ]; } $goods_list_data = []; $goods_list_data['access_token'] = $cloud_token; //获取供货商的token信息 $goods_list_data['page'] = $this->page; //默认为 1 $goods_list_data['limit'] = $this->limit; //默认20 if($this->id) $goods_list_data['id'] = $this->id; //商品名称 if($this->ids) $goods_list_data['ids'] = $this->ids; //商品名称 $goods_list_data['is_self'] = $this->is_self ?: 0; $goodsListInfo = cloud_post($this->domain.$goods_list_url,$goods_list_data); $goodsListInfo = json_decode($goodsListInfo,true); if($goodsListInfo['code'] != 0){ $code = 1;//失败 return $this->outPutData($code,$goodsListInfo['msg']); }else{ return $this->outPutData($goodsListInfo['code'],"获取成功",$goodsListInfo['data']); } } //获取商品列表 public function goodsList(){ if (!$this->validate()) { return $this->getErrorSummary(false)[0]; } $goods_list_url = "/cloud/user/userGetGoodsList"; $cloud_token = get_platform_token(); if (!$cloud_token) { return [ 'code' => 1, 'msg' => '网络问题请重试', ]; } $goods_list_data = []; $goods_list_data['access_token'] = $cloud_token; //获取供货商的token信息 $goods_list_data['page'] = $this->page; //默认为 1 $goods_list_data['limit'] = $this->limit; //默认20 $admin = get_admin(); $admin_id = $admin->id; if ($admin->username == 'admin') { $admin_id = null; } if ($this->type !== 1) { if ($admin_id) { $admin_model = Admin::findOne($admin_id); $area_level = $admin_model->area_level; // $query = Supplier::find()->where(['is_delete' => 0]); // if($area_level == 1){ // $query->andWhere( // ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id, 'district_id' => $admin_model->district_id]); // } elseif ($area_level == 2){ // $query->andWhere( // ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id]); // } elseif ($area_level == 3){ // $query->andWhere(['province_id' => $admin_model->province_id]); // } // $supplier_id = $query->select('cloud_supplier_id')->column(); // if ($supplier_id) { // $this->supplier_id = implode(',', $supplier_id); // } else { // return $this->outPutData(0,"获取成功", [ // 'list' => [] // ]); // } } } if($this->supplier_id) $goods_list_data['supplier_id'] = $this->supplier_id; //查询供货商 if ($this->supplier_name) { $supplier_id_arr = Supplier::find()->where(['is_delete' => 0])->andWhere(['LIKE', 'supplier_name', $this->supplier_name])->select('cloud_supplier_id')->column(); if ($supplier_id_arr) { if ($this->supplier_id) { $supplier_id_ = explode(',', $this->supplier_id); $supplier_id_arr = array_merge($supplier_id_, $supplier_id_arr); } $goods_list_data['supplier_id'] = implode(',', $supplier_id_arr); } } $store_id = get_store_id(); $store_cloud = StoreCloud::findOne(['store_id' => $store_id, 'is_delete' => 0]); $cloud_store_id = $store_cloud->cloud_store_id; if($this->name) $goods_list_data['name'] = $this->name; //商品名称 //@todo669 if($this->cat_id) $goods_list_data['cat_id'] = $this->cat_id; if($this->id) $goods_list_data['id'] = $this->id; //商品名称 if($this->ids) $goods_list_data['ids'] = $this->ids; //商品名称 if($this->status) $goods_list_data['status'] = $this->status; //-1 全部 0 下架 1 上架 $goods_list_data['sort'] = isset($this->sort) ? $this->sort : 1; if($this->sale_sort) $goods_list_data['sale_sort'] = $this->sale_sort; if($this->price_sort) $goods_list_data['price_sort'] = $this->price_sort; if($this->is_distribution) $goods_list_data['is_distribution'] = $this->is_distribution; if($this->send_type) $goods_list_data['send_type'] = $this->send_type; if($this->filter_goods_id) $goods_list_data['filter_goods_id'] = $this->filter_goods_id; if($this->min_money) $goods_list_data['min_money'] = $this->min_money; if($this->max_money) $goods_list_data['max_money'] = $this->max_money; //传递云仓mch_id获取供货渠道比例 $goods_list_data['mch_id'] = $cloud_store_id; $goodsListInfo = cloud_post($this->domain.$goods_list_url,$goods_list_data); $goodsListInfo = json_decode($goodsListInfo,true); if($goodsListInfo['code'] != 0){ $code = 1;//失败 return $this->outPutData($code,$goodsListInfo['msg']); }else{ //获取议价比 // $content = Option::get('cloud', 0, 'saas'); // $content = json_decode($content['value'], true); $content = Store::find()->where(['id' => get_store_id()])->select('rate')->asArray()->one(); $rate = $content['rate']; //填充 if (!empty($goodsListInfo['data']['list'])) { foreach ($goodsListInfo['data']['list'] as &$item) { $sale_price_type = Option::get('sale_price_type', get_store_id(), 'store')['value']; $item['sale_price'] = intval($sale_price_type) === 0 ? bcadd($item['platform_negotiated_price'], bcmul($item['platform_negotiated_price'], ($rate / 100), 2), 2) : $item['original_price']; if (!empty($item['attrs'])) { $item['attrs'] = json_decode($item['attrs'], true); if (!empty($item['attrs'])) { foreach ($item['attrs'] as &$attr_item) { if (!$attr_item['pic']) { $attr_item['pic'] = $item['pic_url']; } //生成零售价 $sale_price_type = Option::get('sale_price_type', get_store_id(), 'store')['value']; $sale_price = intval($sale_price_type) === 0 ? bcadd($attr_item['platform_negotiated_price'], bcmul($attr_item['platform_negotiated_price'], ($rate / 100), 2), 2) : $attr_item['original_price']; $attr_item = array_merge($attr_item, ['sale_price' => $sale_price, 'rate' => $rate]); //查询详情 * 供货渠道折扣 $attr_item['channel_platform_price'] = bcmul($sale_price, bcdiv($goodsListInfo['data']['channel_rate'], 10, 2), 2); } } $item['attrs'] = json_encode($item['attrs'], JSON_UNESCAPED_UNICODE); } $item['channel_platform_price'] = bcmul($item['sale_price'], bcdiv($goodsListInfo['data']['channel_rate'], 10, 2), 2); } } return $this->outPutData($goodsListInfo['code'],"获取成功",$goodsListInfo['data']); } } //获取商品审核列表 public function goodsAuditList(){ if (!$this->validate()) { return $this->getErrorSummary(false)[0]; } $goods_list_url = "/cloud/user/userGetGoodsAuditList"; $cloud_token = get_platform_token(); if (!$cloud_token) { return [ 'code' => 1, 'msg' => '网络问题请重试', ]; } $goods_list_data = []; $goods_list_data['access_token'] = $cloud_token; //获取供货商的token信息 $goods_list_data['page'] = $this->page; //默认为 1 $goods_list_data['limit'] = $this->limit; //默认20 $admin = get_admin(); $admin_id = $admin->id; if ($admin->username == 'admin') { $admin_id = null; } if ($admin_id) { $admin_model = Admin::findOne($admin_id); $area_level = $admin_model->area_level; $query = Supplier::find()->where(['is_delete' => 0]); if($area_level == 1){ $query->andWhere( ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id, 'district_id' => $admin_model->district_id]); } elseif ($area_level == 2){ $query->andWhere( ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id]); } elseif ($area_level == 3){ $query->andWhere(['province_id' => $admin_model->province_id]); } $supplier_id = $query->select('cloud_supplier_id')->column(); if ($supplier_id) { $this->supplier_id = implode(',', $supplier_id); } else { return $this->outPutData(0,"获取成功",[ 'list' => [] ]); } } if($this->supplier_id) $goods_list_data['supplier_id'] = $this->supplier_id; if($this->cat_id) $goods_list_data['cat_id'] = $this->cat_id; if($this->name) $goods_list_data['name'] = $this->name; //商品名称 if($this->status) $goods_list_data['status'] = $this->status; //0未审核 1成功 2拒绝 if($this->supplier_name) $goods_list_data['supplier_name'] = $this->supplier_name; $goodsListInfo = cloud_post($this->domain.$goods_list_url,$goods_list_data); $goodsListInfo = json_decode($goodsListInfo,true); if($goodsListInfo['code'] != 0){ $code = 1;//失败 return $this->outPutData($code,$goodsListInfo['msg']); }else{ if ($admin_id && empty($this->supplier_id)) { $goodsListInfo['data'] = ['list' => []]; } return $this->outPutData($goodsListInfo['code'],"获取成功",$goodsListInfo['data']); } } //操作余额 public function setBalance(){ if (!$this->validate()) { return $this->getErrorSummary(false)[0]; } $balance_url = "/cloud/user/storeSetBalance"; $cloud_token = get_platform_token(); if (!$cloud_token) { return [ 'code' => 1, 'msg' => '网络问题请重试', ]; } $balance_data = []; $balance_data['access_token'] = $cloud_token; $balance_data['action_id'] = $this->action_id; //商户、供货商Id $balance_data['type'] = $this->type; //0 减少 1 增加 $balance_data['status'] = $this->status; //0 用户 1 商户 2 供货商 0 暂时不考虑 $balance_data['desc'] = $this->desc; //备注 $balance_data['price'] = number_format($this->price, 2,".",""); //变动金额 $balanceInfo = cloud_post($this->domain.$balance_url,$balance_data); $balanceInfo = json_decode($balanceInfo,true); if($balanceInfo['code'] != 0){ $code = 1; //失败 return $this->outPutData($code,$balanceInfo['msg']); }else{ return $this->outPutData($balanceInfo['code'],$balanceInfo['msg']); } } //删除供货商 public function delSupplier(){ $del_url = "/cloud/user/storeSupplierDel"; $cloud_token = get_platform_token(); if (!$cloud_token) { return [ 'code' => 1, 'msg' => '网络问题请重试', ]; } $t = Yii::$app->db->beginTransaction(); $supplier = Supplier::find()->where(['cloud_supplier_id' => $this->supplier_id ,'is_delete' => 0])->one(); $admin = Admin::find()->where(['type'=> Admin::ADMIN_TYPE_SUPPLIER,'type_id'=>$supplier->attributes['id'] ,'is_delete' => 0 ])->one(); if ($supplier) { $supplier->is_delete = 1; $supplier->deleted_at = time(); if(!$supplier->save()){ $t->rollBack(); $code = 1; //失败 $msg = '删除失败,请重试'; return $this->outPutData($code,$msg); } } if ($admin) { $admin->is_delete = 1; if(!$admin->save()){ $t->rollBack(); $code = 1; //失败 $msg = '删除失败,请重试'; return $this->outPutData($code,$msg); } } $del_data = []; $del_data['access_token'] = $cloud_token; $del_data['supplier_id'] = $this->supplier_id; $delInfo = cloud_post($this->domain.$del_url,$del_data); $delInfo = json_decode($delInfo,true); if($delInfo['code'] != 0){ $t->rollBack(); $code = 1; //失败 return $this->outPutData($code,$delInfo['msg']); }else{ $t->commit(); return $this->outPutData($delInfo['code'],$delInfo['msg']); } } //编辑供货商 public function editSupplier(){ $supplier = Supplier::find()->where(['cloud_supplier_id' => $this->id])->one(); if (empty($supplier)) { $code = 1; $msg = '查询不到数据,请稍后重试'; return $this->outPutData($code,$msg); } $supplier->name = $this->name; !empty($this->password) && $supplier->password = $this->password; $supplier->logo = $this->logo; $supplier->phone = $this->tel; $supplier->supplier_name = $this->supplier_name; $supplier->type = $this->type; $supplier->sale_day = $this->sale_day; $supplier->certificate = $this->certificate; $supplier->id_card_reverse = $this->id_card_reverse; $supplier->id_card_front = $this->id_card_front; $supplier->updated_at = time(); $supplier->status = (int)$this->status; $supplier->phone = $this->tel; $supplier->district_id = $this->district_id; $supplier->city_id = $this->city_id; $supplier->province_id = $this->province_id; $supplier->rate = $this->rate; if(!$supplier->save()) { $code = 1; $msg = '修改失败,请重试'; return $this->outPutData($code,$msg); } $edit_url = "/cloud/user/storeSupplierEdit"; $cloud_token = get_platform_token(); if (!$cloud_token) { return [ 'code' => 1, 'msg' => '网络问题请重试', ]; } $supplier_data['access_token'] = $cloud_token; $supplier_data['name'] = $this->name; !empty($this->password) && $supplier_data['pwd'] = $this->password; $supplier_data['logo'] = $this->logo; $supplier_data['supplier_name'] = $this->supplier_name; $supplier_data['tel'] = $this->tel; $supplier_data['email'] = $this->email; $supplier_data['type'] = $this->type; $supplier_data['certificate'] = $this->certificate; $supplier_data['id_card_reverse'] = $this->id_card_reverse; $supplier_data['id_card_front'] = $this->id_card_front; $supplier_data['updated_at'] = time(); $supplier_data['sale_day'] = $this->sale_day; if ($this->rate) { $supplier_data['rate'] = $this->rate; } $supplier_data['status'] = (int)$this->status; $supplier_data['user_id'] = $supplier->cloud_user_id; $supplier_data['supplier_id'] = $this->id; \Yii::error($supplier_data, "供货商信息"); $editInfo = cloud_post($this->domain.$edit_url,$supplier_data); $editInfo = json_decode($editInfo,true); if (!empty($this->password)) { $admin = Admin::findOne(['type' => "supplier" , 'type_id' => $supplier->id]); $admin->password = \Yii::$app->security->generatePasswordHash($this->password); if (!$admin->save()) { return $this->outPutData(1,"管理员信息保存失败"); }; } if($editInfo['code'] != 0){ $code = 1; return $this->outPutData($code,$editInfo['msg']); }else{ return $this->outPutData($editInfo['code'],$editInfo['msg']); } } //修改供货商状态 public function setSupplierStatus(){ $del_url = "/cloud/user/storeSupplierDel"; $cloud_token = get_platform_token(); if (!$cloud_token) { return [ 'code' => 1, 'msg' => '网络问题请重试', ]; } $t = Yii::$app->db->beginTransaction(); $supplier = Supplier::find()->where(['cloud_supplier_id' => $this->supplier_id ,'is_delete' => 0])->andWhere(['<>', 'status', '1'])->one(); if ($supplier && in_array($this->status, [1, 2])) { $supplier->status = $this->status; $supplier->updated_at = time(); if(!$supplier->save()){ $t->rollBack(); $code = 1; //失败 $msg = '操作失败,请重试'; return $this->outPutData($code,$msg); } } $del_data['access_token'] = $cloud_token; $del_data['supplier_id'] = $this->supplier_id; $del_data['status'] = (int)$this->status; $del_data['type'] = 1; $delInfo = cloud_post($this->domain.$del_url,$del_data); $delInfo = json_decode($delInfo,true); if($delInfo['code'] != 0){ $t->rollBack(); $code = 1; //失败 return $this->outPutData($code,$delInfo['msg']); }else{ $t->commit(); $res = NoticeSend::AgentExamine($supplier->id, 1); if (isset($res['code']) && $res['code'] !== 0) { debug_log($res, 'sms.log'); } return $this->outPutData($delInfo['code'],$delInfo['msg']); } } //供货商列表 public function listSupplier(){ if (!\Yii::$app->isSaas()) { return [ 'code' => 0 ]; } $list_url = "/cloud/user/storeSupplierList"; $cloud_token = get_platform_token(); if (!$cloud_token) { return [ 'code' => 0, 'msg' => '网络问题请重试', ]; } //注册云台的平台用户 $list_data = []; $list_data['access_token'] = $cloud_token; $list_data['page'] = $this->page; $list_data['limit'] = $this->limit; $list_data['status'] = $this->status; $admin = get_admin(); $admin_id = $admin->id; if ($admin->username == 'admin') { $admin_id = null; } if ($admin->type === Admin::ADMIN_TYPE_DEFAULT) { $admin_id = null; } if ($admin->type === Admin::ADMIN_TYPE_GOODS_AGENT) { // $form = new AgentForm(); // $result = $form->getSupplier($admin->id); // if ($result['code'] === 0) { // $this->ids = $result['data']; // } else { // return $result; // } } if ($admin_id) { $admin_model = Admin::findOne($admin_id); $area_level = $admin_model->area_level; $query = Supplier::find()->where(['is_delete' => 0]); if($area_level == 1){ $query->andWhere( ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id, 'district_id' => $admin_model->district_id]); } elseif ($area_level == 2){ $query->andWhere( ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id]); } elseif ($area_level == 3){ $query->andWhere(['province_id' => $admin_model->province_id]); } $ids = $query->select('cloud_supplier_id')->column(); if ($ids) { $this->ids = $ids; } else { return $this->outPutData(0, '获取成功', [ 'list' => [] ]); } } if ($this->tel) $list_data['tel'] = $this->tel; if ($this->name) $list_data['supplier_name'] = $this->name; if ($this->ids) { if(is_array($this->ids)){ $this->ids = implode(',', $this->ids); } $list_data['ids'] = $this->ids; $list_url = "/cloud/user/storeSupplierListByIds"; } //获取云仓数据 $listInfo = cloud_post($this->domain.$list_url,$list_data); $listInfo = json_decode($listInfo,true); //获取数据库数据 if($listInfo['code'] != 0){ $code = 0; return $this->outPutData($code,$listInfo['msg']); }else{ $code = 0; $msg = "获取成功"; foreach ($listInfo['data']['list'] as &$item) { $supplier = Supplier::find()->where(['is_delete' => 0, 'cloud_supplier_id' => $item['id']]) ->select("district_id, province_id, city_id")->asArray()->one(); $item['district_id'] = $supplier['district_id'] ?: ''; $item['province_id'] = $supplier['province_id'] ?: ''; $item['city_id'] = $supplier['city_id'] ?: ''; $item['supplier_info'] = Supplier::find()->select(['id', 'supplier_name', 'logo', 'custom_form'])->where(['cloud_supplier_id' => $item['id']])->one(); } return $this->outPutData($code,$msg,$listInfo['data']); } } //审核商品 public function auditHandle() { try { $list_url = "/cloud/user/userGetGoodsAuditHandle"; $cloud_token = get_platform_token(); if (!$cloud_token) { return [ 'code' => 1, 'msg' => '网络问题请重试', ]; } //注册云台的平台用户 $list_data = []; $list_data['access_token'] = $cloud_token; $list_data['status'] = $this->status; $list_data['desc'] = $this->desc; $list_data['id'] = $this->id ?? 0; $list_data['ids'] = $this->ids; if ($this->name) $list_data['name'] = $this->name; //获取云仓数据 $listInfo = cloud_post($this->domain.$list_url,$list_data); $listInfo = json_decode($listInfo,true); //获取数据库数据 if($listInfo['code'] != 0){ $code = 1; return $this->outPutData($code,$listInfo['msg']); }else{ $code = 0; $msg = "获取成功"; if ((int)$this->status === 1 && $listInfo['data']) { $cloud_goods_id = $listInfo['data']; $form = new GoodsForm(); //找出商品未审核或者未更新的产品 $CloudGoodsUpdateLog = CloudGoodsUpdateLog::find()->where(['cloud_goods_id' => $cloud_goods_id])->asArray()->all(); foreach ($CloudGoodsUpdateLog as $value) { //直接通过审核(目前只有点击审核通过时才会调用此事件) $item = CloudGoodsUpdateLog::findOne($value['id']); $item->is_audit = 1; $item->updated_at = time(); $item->save(); //判断是否开启自动更新 $cloud_is_update = Option::get('cloud_is_update', $value['store_id'], 'store')['value']; if ((int)$cloud_is_update > 0) { //更新产品逻辑 if ($value['goods_id']) { $StoreCloud = StoreCloud::findOne(['store_id' => $value['store_id'], 'is_delete' => 0, 'is_enable' => 1]); $form->id = $value['cloud_goods_id']; $form->store_id =$value['store_id']; $goodsInfo = $form->saveCloudGoods(); $merchantForm = new MerchantForm(); $merchantForm->token_stroe_cloud_id = $StoreCloud->id; $result = $merchantForm->mchGoodsImport($goodsInfo['cloudBindInfo'], $goodsInfo['goods_id'], $value['store_id']); if ((int)$result['code'] !== 0) { return $result; } } } } } return $this->outPutData($code,$msg,$listInfo['data']); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //创建云仓账号 public function createSupplier() { if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0] ]; } $admin = new Admin(); if (Admin::findOne(['username' => $this->name, 'is_delete' => 0])) { $code = 1; $msg = '登陆账号已经存在'; return $this->outPutData($code,$msg); } // if ($this->tel) { // if (Admin::findOne(['mobile' => $this->tel, 'is_delete' => 0])) { // $code = 1; // $msg = '手机号已经存在'; // return $this->outPutData($code,$msg); // } // } //获取平台token $cloud_token = get_platform_token(); if (!$cloud_token) { return [ 'code' => 1, 'msg' => '平台未申请云仓账户', ]; } $member_url = "/cloud/user/storeUserAdd"; $check_member_url = "/cloud/user/storeUserList"; $supplier_url = "/cloud/user/storeSupplierAdd"; $check_supplier_url = "/cloud/user/storeSupplierList"; //注册云台的平台用户 $check_supplier_data = $check_member_data = $member_data = $supplier_data = []; //注册云台的平台用户 $check_member_data['access_token'] = $cloud_token; $check_member_data['name'] = $this->name; $checkMemberInfo = cloud_post($this->domain.$check_member_url,$check_member_data); if(!$checkMemberInfo){ $code = 1; $msg = "创建失败"; return $this->outPutData($code,$msg); } $checkMemberInfo = json_decode($checkMemberInfo,true); if($checkMemberInfo['code'] == 0 && isset($checkMemberInfo['data']['list'][0]['id']) && $checkMemberInfo['data']['list'][0]['id']>0){ $memberInfo['data'] = $checkMemberInfo['data']['list'][0]; $memberInfo['data']['user_id'] = $checkMemberInfo['data']['list'][0]['id']; }else{ $member_data['access_token'] = $cloud_token; $member_data['name'] = $this->name; $member_data['pwd'] = $this->password; $member_data['tel'] = $this->tel; $member_data['email'] = $this->email; $member_data['avatar_url'] = $this->logo; $memberInfo = cloud_post($this->domain.$member_url,$member_data); $memberInfo = json_decode($memberInfo,true); if($memberInfo['code'] != 0){ $code = 1; return $this->outPutData($code,$memberInfo['msg']); } } $check_supplier_data['access_token'] = $cloud_token; $check_supplier_data['name'] = $this->name; $checkSupplierInfo = cloud_post($this->domain.$check_supplier_url,$check_supplier_data); if(!$checkSupplierInfo){ $code = 1; $msg = "创建供货商失败"; return $this->outPutData($code,$msg); } $content = Option::get('cloud', 0, 'saas')['value']; if ($content) { $content = json_decode($content, true); } $checkSupplierInfo = json_decode($checkSupplierInfo,true); if($checkSupplierInfo['code'] == 0 && isset($checkSupplierInfo['data']['list'][0]['id']) && $checkSupplierInfo['data']['list'][0]['id']>0){ $supplierInfo['data'] = $checkSupplierInfo['data']['list'][0]; $supplierInfo['data']['supplier_id'] = $checkSupplierInfo['data']['list'][0]['id']; }else{ //注册云台的供货商账户 $supplier_data['access_token'] = $cloud_token; $supplier_data['user_id'] = $memberInfo['data']['user_id']; $supplier_data['supplier_name'] = $this->supplier_name; $supplier_data['name'] = $this->name; $supplier_data['logo'] = $this->logo; $supplier_data['tel'] = $this->tel; $supplier_data['type'] = $this->type; $supplier_data['status'] = 0; $supplier_data['certificate'] = $this->certificate; $supplier_data['id_card_reverse'] = $this->id_card_reverse; $supplier_data['id_card_front'] = $this->id_card_front; $supplier_data['sale_day'] = !empty($this->sale_day) ? $this->sale_day : ($content['sale_day'] ?: 0); if ($this->rate) { $supplier_data['rate'] = $this->rate; } $supplierInfo = cloud_post($this->domain.$supplier_url,$supplier_data); $supplierInfo = json_decode($supplierInfo,true); if($supplierInfo['code'] != 0){ $code = 1; return $this->outPutData($code,$supplierInfo['msg']); } } //写入本地数据库 开始 $t = Yii::$app->db->beginTransaction(); $admin->username = $this->name; $admin->mobile = $this->tel; $admin->password = Yii::$app->security->generatePasswordHash($this->password); $admin->type = Admin::ADMIN_TYPE_SUPPLIER; $admin->save(); if ($admin->attributes['id'] <= 0){ $t->rollBack(); $code = 1; $msg = '创建云仓用户失败'; return $this->outPutData($code,$msg); } $supplier = new Supplier(); $supplier->name = $this->name; $supplier->password = $this->password; $supplier->supplier_name = $this->supplier_name; if ($this->supplier_name == '胜天半子') { $supplier->is_stbz = 1; } $supplier->logo = $this->logo; $supplier->phone = $this->tel; $supplier->type = $this->type; $supplier->status = 0; $supplier->certificate = $this->certificate; $supplier->id_card_reverse = $this->id_card_reverse; $supplier->id_card_front = $this->id_card_front; $supplier->created_at = time(); $supplier->admin_id = $admin->attributes['id']; $supplier->cloud_user_id = $memberInfo['data']['user_id']; $supplier->cloud_supplier_id = $supplierInfo['data']['supplier_id']; // $supplier->sale_day = $this->sale_day; $supplier->sale_day = !empty($this->sale_day) ? $this->sale_day : ($content['sale_day'] ?: 0); $supplier->saas_user_id = $this->saas_user_id ?: 0; $supplier->district_id = $this->district_id; $supplier->city_id = $this->city_id; $supplier->province_id = $this->province_id; $supplier->rate = $this->rate; $supplier->custom_form = $this->supplier_custom_form; $supplier_token = get_cloud_token($this->name,$this->password); if($supplier_token['taken']) { $supplier->access_token = $supplier_token['taken']; $supplier->access_token_time = time(); } $supplier->save(); if ($supplier->attributes['id']<=0){ $t->rollBack(); $code = 1; $msg = '创建云仓用户失败'; return $this->outPutData($code,$msg); } $admin->type_id = $supplier->attributes['id']; //设置关系 $admin->save(); $t->commit(); //写入本地数据库 结束 $code = 0; $msg = '注册成功'; return $this->outPutData($code,$msg, ['cloud_supplier_id' => $supplier->cloud_supplier_id]); } public function saveGoodsCat() { try { //获取平台token $cloud_token = get_platform_token(); if (!$cloud_token) { return [ 'code' => 1, 'msg' => '网络问题请重试', ]; } $saveGoodsCateUrl = "/cloud/user/saveCat"; $saveGoodsCateData['access_token'] = $cloud_token; $saveGoodsCateData['parent_id'] = $this->parent_id; $saveGoodsCateData['is_show'] = $this->is_show; $saveGoodsCateData['name'] = $this->name; $saveGoodsCateData['pic_url'] = $this->pic_url; $saveGoodsCateData['sort'] = $this->sort ?: 100; $saveGoodsCateData['id'] = $this->id; if (isset($this->shop_count)) { $saveGoodsCateData['shop_count'] = $this->shop_count; } $saveGoodsCateInfo = cloud_post($this->domain.$saveGoodsCateUrl,$saveGoodsCateData); $saveGoodsCateInfo = json_decode($saveGoodsCateInfo,true); if($saveGoodsCateInfo['code'] != 0){ throw new \Exception($saveGoodsCateInfo['msg']); } return $this->outPutData(0, $saveGoodsCateInfo['msg']); } catch (\Exception $e) { return $this->outPutData(1, $e->getMessage()); } } public function getGoodsCatList() { try { //获取平台token $cloud_token = get_platform_token(); if (!$cloud_token) { return [ 'code' => 1, 'msg' => '网络问题请重试', ]; } $getGoodsCateUrl = "/cloud/user/getCatList"; $getGoodsCateData['access_token'] = $cloud_token; $getGoodsCateData['is_show'] = $this->is_show ?: 0; $getGoodsCateInfo = cloud_post($this->domain.$getGoodsCateUrl,$getGoodsCateData); $getGoodsCateInfo = json_decode($getGoodsCateInfo,true); if($getGoodsCateInfo['code'] != 0){ throw new \Exception($getGoodsCateInfo['msg']); } return $this->outPutData(0, $getGoodsCateInfo['msg'], $getGoodsCateInfo['data']); } catch (\Exception $e) { return $this->outPutData(1, $e->getMessage()); } } public function catChange() { try { //获取平台token $cloud_token = get_platform_token(); if (!$cloud_token) { return [ 'code' => 1, 'msg' => '网络问题请重试', ]; } $getGoodsCateUrl = "/cloud/user/catChange"; $getGoodsCateData['access_token'] = $cloud_token; $getGoodsCateData['parent_id'] = $this->parent_id ?: 0; $getGoodsCateData['id'] = $this->id ?: 0; $getGoodsCateData['list'] = $this->list ?? ''; $getGoodsCateInfo = cloud_post($this->domain.$getGoodsCateUrl,$getGoodsCateData); $getGoodsCateInfo = json_decode($getGoodsCateInfo,true); if($getGoodsCateInfo['code'] != 0){ throw new \Exception($getGoodsCateInfo['msg']); } return $this->outPutData(0, $getGoodsCateInfo['msg'], $getGoodsCateInfo['data']); } catch (\Exception $e) { return $this->outPutData(1, $e->getMessage()); } } public function getCatListChildren() { try { //获取平台token $cloud_token = get_platform_token(); if (!$cloud_token) { return [ 'code' => 1, 'msg' => '网络问题请重试', ]; } $getGoodsCateUrl = "/cloud/user/getCatListChildren"; $getGoodsCateData['access_token'] = $cloud_token; $getGoodsCateData['parent_id'] = $this->parent_id; $getGoodsCateInfo = cloud_post($this->domain.$getGoodsCateUrl,$getGoodsCateData); $getGoodsCateInfo = json_decode($getGoodsCateInfo,true); if($getGoodsCateInfo['code'] != 0){ throw new \Exception($getGoodsCateInfo['msg']); } return $this->outPutData(0, $getGoodsCateInfo['msg'], $getGoodsCateInfo['data']); } catch (\Exception $e) { return $this->outPutData(1, $e->getMessage()); } } public function getGoodsCatName() { try { //获取平台token $cloud_token = get_platform_token(); if (!$cloud_token) { return [ 'code' => 1, 'msg' => '网络问题请重试', ]; } $getGoodsCateUrl = "/cloud/user/getCatList"; $getGoodsCateData['access_token'] = $cloud_token; $getGoodsCateData['is_show'] = $this->is_show ?: 0; $getGoodsCateInfo = cloud_post($this->domain.$getGoodsCateUrl,$getGoodsCateData); $getGoodsCateInfo = json_decode($getGoodsCateInfo,true); if($getGoodsCateInfo['code'] != 0){ throw new \Exception($getGoodsCateInfo['msg']); } return $this->outPutData(0, $getGoodsCateInfo['msg'], $getGoodsCateInfo['data_name']); } catch (\Exception $e) { return $this->outPutData(1, $e->getMessage()); } } //删除 public function goodsCatDel() { try { //获取平台token $cloud_token = get_platform_token(); if (!$cloud_token) { return [ 'code' => 1, 'msg' => '网络问题请重试', ]; } $getGoodsCateUrl = "/cloud/user/catDel"; $getGoodsCateData['access_token'] = $cloud_token; $getGoodsCateData['ids'] = $this->ids; $getGoodsCateData['type'] = $this->type; $getGoodsCateInfo = cloud_post($this->domain.$getGoodsCateUrl,$getGoodsCateData); $getGoodsCateInfo = json_decode($getGoodsCateInfo,true); if($getGoodsCateInfo['code'] != 0){ throw new \Exception($getGoodsCateInfo['msg']); } return $this->outPutData(0, $getGoodsCateInfo['msg']); } catch (\Exception $e) { return $this->outPutData(1, $e->getMessage()); } } //更改配送单状态 //用户下单->店铺转单到供货商->供货商生成集采配送单->供货商发货->仓库收货->仓库投篮【生成分拣单,给分拣单里面加产品】->分拣完成->根据分拣单生成线路配送单 public function setDistributionStatus() { $t = \Yii::$app->db->beginTransaction(); try { //获取平台token $cloud_token = get_platform_token(); if (!$cloud_token) { return [ 'code' => 1, 'msg' => '网络问题请重试', ]; } //配货单收货 if (intval($this->status) === 2) { $ids = explode(',', $this->ids); foreach ($ids as $id_item) { $form = new SupplierForm(); $result = $form->agentOrderDistributionList($id_item, 1); if (!$result['code']) { foreach ($result['data']['data'] as $data_item) { foreach ($data_item['mch_goods'] as $mch_goods_item) { foreach ($mch_goods_item['mch_order'] as $mch_order_item) { $md_id = $mch_order_item['md_id']; $driverMdBind = DriverMdBind::findOne(['md_id' => $md_id, 'is_delete' => 0]); if (!$driverMdBind) { throw new \Exception('当前门店未绑定线路 不可收货'); } foreach ($mch_order_item['md_order'] as $md_order_item) { $goods_attr = json_decode($md_order_item['goods_attr'], true); $attr_id = array_column($goods_attr['attr_list'], 'attr_id'); sort($attr_id); $agentFrontCentralizeGoods = AgentFrontCentralizeGoods::findOne([ 'cloud_goods_id' => $md_order_item['goods_id'], 'attr' => json_encode($attr_id), 'centralize_goods_type' => $md_order_item['centralize_goods_type'], 'front_admin_id' => get_admin()->id, 'status' => AgentFrontCentralizeGoods::STATUS_SORTING ]); if (!$agentFrontCentralizeGoods) { $agentFrontCentralizeGoods = new AgentFrontCentralizeGoods(); $agentFrontCentralizeGoods->front_admin_id = get_admin()->id; $agentFrontCentralizeGoods->cloud_goods_id = $md_order_item['goods_id']; $agentFrontCentralizeGoods->attr = json_encode($attr_id); $agentFrontCentralizeGoods->attr_info = $md_order_item['goods_attr']; $agentFrontCentralizeGoods->goods_no = $md_order_item['goods_no']; $agentFrontCentralizeGoods->goods_name = $md_order_item['goods_name']; $agentFrontCentralizeGoods->pic_url = $md_order_item['pic_url']; $agentFrontCentralizeGoods->centralize_goods_type = $md_order_item['centralize_goods_type']; $agentFrontCentralizeGoods->supplier_id = $data_item['supplier_id']; } $agentFrontCentralizeGoods->goods_num += $md_order_item['goods_num']; if (!$agentFrontCentralizeGoods->save()) { throw new \Exception(implode(';', array_values($agentFrontCentralizeGoods->firstErrors))); } //判断是否重复插入 $agentFrontCentralizeGoodsLog = AgentFrontCentralizeGoodsLog::findOne([ 'centralize_goods_id' => $agentFrontCentralizeGoods->id, 'cloud_order_id' => $md_order_item['order_id'], 'md_id' => $mch_order_item['md_id'] ]); if ($agentFrontCentralizeGoodsLog) { throw new \Exception('重复插入数据'); } $agentFrontCentralizeGoodsExt = AgentFrontCentralizeGoodsExt::findOne([ 'centralize_goods_id' => $agentFrontCentralizeGoods->id, 'md_id' => $mch_order_item['md_id'], 'status' => AgentFrontCentralizeGoodsExt::STATUS_WAIT_SORTING ]); if (!$agentFrontCentralizeGoodsExt) { $agentFrontCentralizeGoodsExt = new AgentFrontCentralizeGoodsExt(); $agentFrontCentralizeGoodsExt->goods_num = 0; } $agentFrontCentralizeGoodsExt->centralize_goods_id = $agentFrontCentralizeGoods->id; // $agentFrontCentralizeGoodsExt->cloud_order_id = $md_order_item['order_id']; $agentFrontCentralizeGoodsExt->md_id = $mch_order_item['md_id']; $agentFrontCentralizeGoodsExt->goods_num += $md_order_item['goods_num']; if (!$agentFrontCentralizeGoodsExt->save()) { throw new \Exception(implode(';', array_values($agentFrontCentralizeGoodsExt->firstErrors))); } //判断是否重复插入 $agentFrontCentralizeGoodsLog = new AgentFrontCentralizeGoodsLog(); $agentFrontCentralizeGoodsLog->centralize_goods_id = $agentFrontCentralizeGoods->id; $agentFrontCentralizeGoodsLog->cloud_order_id = $md_order_item['order_id']; $agentFrontCentralizeGoodsLog->md_id = $mch_order_item['md_id']; $agentFrontCentralizeGoodsLog->save(); if (!$agentFrontCentralizeGoodsLog->save()) { throw new \Exception(implode(';', array_values($agentFrontCentralizeGoodsLog->firstErrors))); } } } } } } } } $getGoodsCateUrl = "/cloud/user/setDistributionStatus"; $getGoodsCateData['access_token'] = $cloud_token; $getGoodsCateData['ids'] = $this->ids; $getGoodsCateData['status'] = $this->status; $getGoodsCateData['admin_id'] = get_admin()->id; $getGoodsCateInfo = cloud_post($this->domain.$getGoodsCateUrl,$getGoodsCateData); $getGoodsCateInfo = json_decode($getGoodsCateInfo,true); if($getGoodsCateInfo['code'] != 0){ debug_log(['getGoodsCateInfo' => $getGoodsCateInfo], 'setDistributionStatus.log'); } $t->commit(); return $this->outPutData(0, $getGoodsCateInfo['msg']); } catch (\Exception $e) { debug_log([ 'message' => $e->getMessage(), 'line' => $e->getLine(), 'file' => $e->getFile() ], 'setDistributionStatus.log'); $t->rollBack(); return $this->outPutData(1, $e->getMessage()); } } //会员等级列表 public function userLevelSearch () { try { //获取平台token $cloud_token = get_platform_token(); if (!$cloud_token) { return [ 'code' => 1, 'msg' => '网络问题请重试', ]; } $getGoodsCateUrl = "/cloud/user/userLevelSearch"; $getGoodsCateData['access_token'] = $cloud_token; $getGoodsCateData['name'] = $this->name; $getGoodsCateData['page'] = $this->page; $getGoodsCateData['limit'] = $this->limit; //$getGoodsCateData['status'] = (int)$this->status; $getGoodsCateInfo = cloud_post($this->domain.$getGoodsCateUrl,$getGoodsCateData); $getGoodsCateInfo = json_decode($getGoodsCateInfo,true); if($getGoodsCateInfo['code'] != 0){ throw new \Exception($getGoodsCateInfo['msg']); } return $this->outPutData(0, $getGoodsCateInfo['msg'], $getGoodsCateInfo['data']); } catch (\Exception $e) { return $this->outPutData(1, $e->getMessage()); } } //会员等级列表 public function setUserLevelStatus () { try { //获取平台token $cloud_token = get_platform_token(); if (!$cloud_token) { return [ 'code' => 1, 'msg' => '网络问题请重试', ]; } $getGoodsCateUrl = "/cloud/user/setUserLevelStatus"; $getGoodsCateData['access_token'] = $cloud_token; $getGoodsCateData['id'] = $this->id; $getGoodsCateData['status'] = $this->status; $getGoodsCateInfo = cloud_post($this->domain.$getGoodsCateUrl,$getGoodsCateData); $getGoodsCateInfo = json_decode($getGoodsCateInfo,true); if($getGoodsCateInfo['code'] != 0){ throw new \Exception($getGoodsCateInfo['msg']); } return $this->outPutData(0, $getGoodsCateInfo['msg']); } catch (\Exception $e) { return $this->outPutData(1, $e->getMessage()); } } //会员等级列表 public function setUserLevel () { try { //获取平台token $cloud_token = get_platform_token(); if (!$cloud_token) { return [ 'code' => 1, 'msg' => '网络问题请重试', ]; } $status = $this->status ?? 1; $getGoodsCateUrl = "/cloud/user/setUserLevel"; $getGoodsCateData['access_token'] = $cloud_token; $getGoodsCateData['level'] = (int)$this->level; $getGoodsCateData['name'] = $this->name; $getGoodsCateData['profit'] = $this->profit; $getGoodsCateData['price'] = $this->price; $getGoodsCateData['status'] = (int)$status; $getGoodsCateData['id'] = (int)$this->id; $getGoodsCateInfo = cloud_post($this->domain.$getGoodsCateUrl,$getGoodsCateData); $getGoodsCateInfo = json_decode($getGoodsCateInfo,true); if($getGoodsCateInfo['code'] != 0){ throw new \Exception($getGoodsCateInfo['msg']); } return $this->outPutData(0, $getGoodsCateInfo['msg']); } catch (\Exception $e) { return $this->outPutData(1, $e->getMessage()); } } public function setAgentGoodsPercent() { try { //获取平台token $cloud_token = get_platform_token(); if (!$cloud_token) { return [ 'code' => 1, 'msg' => '网络问题请重试', ]; } $status = $this->status ?? 1; $getGoodsCateUrl = "/cloud/user/setAgentGoodsPercent"; $getGoodsCateData['access_token'] = $cloud_token; $getGoodsCateData['id'] = (int)$this->id; $getGoodsCateData['agent_percent'] = $this->agent_percent; $getGoodsCateData['agent_install_percent'] = $this->agent_install_percent; $getGoodsCateData['agent_profit_default'] = (int)$this->agent_profit_default; $getGoodsCateInfo = cloud_post($this->domain.$getGoodsCateUrl,$getGoodsCateData); $getGoodsCateInfo = json_decode($getGoodsCateInfo,true); if($getGoodsCateInfo['code'] != 0){ throw new \Exception($getGoodsCateInfo['msg']); } return $this->outPutData(0, $getGoodsCateInfo['msg']); } catch (\Exception $e) { return $this->outPutData(1, $e->getMessage()); } } public function getUserLevel() { try { if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; } //获取平台token $cloud_token = get_platform_token(); $getGoodsCateUrl = "/cloud/user/getUserLevel"; $getGoodsCateData['access_token'] = $cloud_token; $getGoodsCateData['status'] = $this->status ?? 0; $getGoodsCateInfo = cloud_post($this->domain.$getGoodsCateUrl,$getGoodsCateData); $getGoodsCateInfo = json_decode($getGoodsCateInfo,true); if($getGoodsCateInfo['code'] != 0){ throw new \Exception($getGoodsCateInfo['msg']); } return $getGoodsCateInfo; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } public function setMchLevel() { try { if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; } //获取平台token $cloud_token = get_platform_token(); $getGoodsCateUrl = "/cloud/user/setMchLevel"; $getGoodsCateData['access_token'] = $cloud_token; $getGoodsCateData['id'] = $this->id; $getGoodsCateData['mch_id'] = $this->cloud_store_id; $getGoodsCateInfo = cloud_post($this->domain.$getGoodsCateUrl,$getGoodsCateData); $getGoodsCateInfo = json_decode($getGoodsCateInfo,true); if($getGoodsCateInfo['code'] != 0){ throw new \Exception($getGoodsCateInfo['msg']); } return $getGoodsCateInfo; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } public function getSortingOrder($id = 0) { try { //获取平台token $cloud_token = get_platform_token(); if (!$cloud_token) { throw new \Exception('网络问题请重试'); } $getGoodsCateData = []; //搜索店铺名称 $name = $this->name; $mch_id = ''; if ($name) { $store_id = Store::find()->where(['AND', ['is_delete' => 0], ['LIKE', 'name', $name]])->select('id')->column(); $mch_id = StoreCloud::find()->where(['store_id' => $store_id, 'is_delete' => 0])->select('cloud_store_id')->column(); array_push($mch_id, -1); if ($mch_id) { $mch_id = implode(',', $mch_id); } } $getGoodsCateUrl = "/cloud/user/getSortingOrder"; $getGoodsCateData['access_token'] = $cloud_token; $getGoodsCateData['admin_id'] = get_admin()->id; $getGoodsCateData['status'] = $this->status; $getGoodsCateData['order_no'] = $this->order_no; $getGoodsCateData['start_time'] = $this->start_time; $getGoodsCateData['end_time'] = $this->end_time; $getGoodsCateData['sorting_start_time'] = $this->sorting_start_time; $getGoodsCateData['sorting_end_time'] = $this->sorting_end_time; $getGoodsCateData['page'] = get_params('pageNo', get_params('page', 1)); $getGoodsCateData['limit'] = get_params('pageSize', get_params('limit', 10)); $getGoodsCateData['mch_id'] = $mch_id; $getGoodsCateData['id'] = $id; $getGoodsCateInfo = cloud_post($this->domain.$getGoodsCateUrl,$getGoodsCateData); $getGoodsCateInfo = json_decode($getGoodsCateInfo,true); if($getGoodsCateInfo['code'] != 0){ throw new \Exception($getGoodsCateInfo['msg']); } foreach ($getGoodsCateInfo['data']['list'] as &$item) { $item['store_name'] = '云仓店铺'; $item['store_address'] = '-'; $item['store_mobile'] = '-'; $store_cloud = StoreCloud::findOne(['cloud_store_id' => $item['mch_id'], 'is_delete' => 0]); if ($store_cloud) { $store = Store::findOne($store_cloud->store_id); $item['store_name'] = $store->name ?? $item['store_name']; $admin = Admin::findOne(['type_id' => $store->id, 'type' => 'store', 'is_delete' => 0]); //店铺信息 if ($admin) { $district = District::find()->where(['id' => [$admin->province_id, $admin->city_id, $admin->district_id]])->select('name')->column(); $item['store_mobile'] = $admin->mobile; $item['store_address'] = implode('/', $district) . ($admin->address ?: ''); } } $item['md_info'] = null; if ($item['md_id'] > 0) { $md_info = Md::findOne($item['md_id']); $item['md_info'] = [ 'logo' => $md_info->cover_url ?? '', 'name' => $md_info->name ?? '', 'tel' => $md_info->mobile ?? '', ]; } } return $this->outPutData(0, $getGoodsCateInfo['msg'], $getGoodsCateInfo['data']); } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //修改分拣单状态 // public function setSortingStatus() { // $t = \Yii::$app->db->beginTransaction(); // try { // $cloud_token = get_platform_token(); // $id = $this->id; // //分拣 // $orderToLine = DriverForm::orderToLine($id, get_admin()->id); // if($orderToLine['code'] != 0){ // throw new \Exception($orderToLine['msg']); // } // $getGoodsCateUrl = "/cloud/user/setSortingOrder"; // $getGoodsCateData['access_token'] = $cloud_token; // $getGoodsCateData['admin_id'] = get_admin()->id; // $getGoodsCateData['id'] = $id; // $getGoodsCateInfo = cloud_post($this->domain.$getGoodsCateUrl,$getGoodsCateData); // $getGoodsCateInfo = json_decode($getGoodsCateInfo,true); // if($getGoodsCateInfo['code'] != 0){ // throw new \Exception($getGoodsCateInfo['msg']); // } // $t->commit(); // return $this->outPutData(0, $getGoodsCateInfo['msg']); // } catch (\Exception $e) { // $t->rollBack(); // return [ // 'code' => 1, // 'msg' => $e->getMessage() // ]; // } // } //云仓库存详情 public function getCloudPreviewNumInfo(){ //获取平台token $cloud_token = get_platform_token(); $supplier_order_list_data = []; $supplier_order_list_url = "/cloud/user/getCloudPreviewNumInfo"; $supplier_order_list_data['access_token'] = $cloud_token; $supplier_order_list_data['mch_id'] = $this->could_mch_id; if (!$supplier_order_list_data['mch_id']) { $store_id = $this->store_id; $storeCloud = StoreCloud::findOne(['store_id' => $store_id,'is_delete'=>0]); $supplier_order_list_data['mch_id'] = $storeCloud->cloud_store_id ?? 0; } $supplier_order_list_data['name'] = $this->name; $supplier_order_list_data['page'] = input_params('pageNo') ?: $this->page; //默认为 1 $supplier_order_list_data['limit'] = $this->limit; //默认20 $supplierOrderListInfo = cloud_post($this->domain.$supplier_order_list_url,$supplier_order_list_data); $supplierOrderListInfo = json_decode($supplierOrderListInfo,true); if($supplierOrderListInfo['code'] != 0){ $code = 1; //失败 return $this->outPutData($code,$supplierOrderListInfo['msg']); }else{ if ($supplierOrderListInfo['data']['mch_info']) { $mch_id = $supplierOrderListInfo['data']['mch_info']['mch_id']; $store_cloud = StoreCloud::findOne(['cloud_store_id' => $mch_id, 'is_delete' => 0]); $supplierOrderListInfo['data']['mch_info']['store_name'] = '-'; if ($store_cloud) { $supplierOrderListInfo['data']['mch_info']['store_name'] = Store::findOne(['id' => $store_cloud->store_id, 'is_delete' => 0])->name ?? '-'; } $user_info = StoreCloud::find()->alias('c') ->leftJoin(['su' => SaasUser::tableName()], 'c.saas_user_id = su.id') ->where(['c.is_delete' => 0, 'c.cloud_store_id' => $mch_id])->select('su.avatar, su.name')->asArray()->one(); if ($user_info) { $supplierOrderListInfo['data']['mch_info']['name'] = $user_info['name'] ?: $supplierOrderListInfo['data']['mch_info']['name']; $supplierOrderListInfo['data']['mch_info']['logo'] = $user_info['avatar'] ?: $supplierOrderListInfo['data']['mch_info']['logo']; } } return $supplierOrderListInfo; } } //云仓库存详情 public function getCloudPreviewNumLog(){ //获取平台token $cloud_token = get_platform_token(); $supplier_order_list_data = []; $supplier_order_list_url = "/cloud/user/getCloudPreviewNumLog"; $supplier_order_list_data['access_token'] = $cloud_token; $supplier_order_list_data['id'] = $this->id; $supplier_order_list_data['order_no'] = $this->order_no; $supplier_order_list_data['start_time'] = $this->start_time; $supplier_order_list_data['end_time'] = $this->end_time; $supplier_order_list_data['page'] = input_params('pageNo') ?: $this->page; //默认为 1 $supplier_order_list_data['limit'] = $this->limit; //默认20 $supplierOrderListInfo = cloud_post($this->domain.$supplier_order_list_url,$supplier_order_list_data); $supplierOrderListInfo = json_decode($supplierOrderListInfo,true); if($supplierOrderListInfo['code'] != 0){ $code = 1; //失败 return $this->outPutData($code,$supplierOrderListInfo['msg']); }else{ if ($supplierOrderListInfo['data']['mch_info']) { $mch_id = $supplierOrderListInfo['data']['mch_info']['mch_id']; $store_cloud = StoreCloud::findOne(['cloud_store_id' => $mch_id, 'is_delete' => 0]); $supplierOrderListInfo['data']['mch_info']['store_name'] = '-'; if ($store_cloud) { $supplierOrderListInfo['data']['mch_info']['store_name'] = Store::findOne(['id' => $store_cloud->store_id, 'is_delete' => 0])->name ?? '-'; } $user_info = StoreCloud::find()->alias('c') ->leftJoin(['su' => SaasUser::tableName()], 'c.saas_user_id = su.id') ->where(['c.is_delete' => 0, 'c.cloud_store_id' => $mch_id])->select('su.avatar, su.name')->asArray()->one(); if ($user_info) { $supplierOrderListInfo['data']['mch_info']['name'] = $user_info['name'] ?: $supplierOrderListInfo['data']['mch_info']['name']; $supplierOrderListInfo['data']['mch_info']['logo'] = $user_info['avatar'] ?: $supplierOrderListInfo['data']['mch_info']['logo']; } } return $supplierOrderListInfo; } } //添加云仓库存商品 public function addCloudPreviewGoods(){ //获取平台token $cloud_token = get_platform_token(); $supplier_order_list_data = []; $supplier_order_list_url = "/cloud/user/addCloudPreviewGoods"; $supplier_order_list_data['access_token'] = $cloud_token; $supplier_order_list_data['goods_id'] = $this->goods_id; $supplier_order_list_data['attr'] = $this->attr; $supplier_order_list_data['mch_id'] = $this->id; $supplier_order_list_data['num'] = $this->num; $supplierOrderListInfo = cloud_post($this->domain.$supplier_order_list_url,$supplier_order_list_data); $supplierOrderListInfo = json_decode($supplierOrderListInfo,true); if($supplierOrderListInfo['code'] != 0){ $code = 1; //失败 return $this->outPutData($code,$supplierOrderListInfo['msg']); }else{ return $supplierOrderListInfo; } } //修改云仓库存数量 public function setPreviewGoodsNum(){ //获取平台token $cloud_token = get_platform_token(); $supplier_order_list_data = []; $supplier_order_list_url = "/cloud/user/setPreviewGoodsNum"; $supplier_order_list_data['access_token'] = $cloud_token; $supplier_order_list_data['id'] = $this->id; $supplier_order_list_data['type'] = $this->type; $supplier_order_list_data['desc'] = $this->desc; $supplier_order_list_data['num'] = $this->num; $supplierOrderListInfo = cloud_post($this->domain.$supplier_order_list_url,$supplier_order_list_data); $supplierOrderListInfo = json_decode($supplierOrderListInfo,true); if($supplierOrderListInfo['code'] != 0){ $code = 1; //失败 return $this->outPutData($code,$supplierOrderListInfo['msg']); }else{ return $supplierOrderListInfo; } } //云仓库存详情 public function getCloudPreviewGoodsList(){ //获取平台token $cloud_token = get_platform_token(); $supplier_order_list_data = []; $supplier_order_list_url = "/cloud/user/getCloudPreviewGoodsList"; $supplier_order_list_data['access_token'] = $cloud_token; $supplier_order_list_data['page'] = input_params('pageNo') ?: $this->page; //默认为 1 $supplier_order_list_data['limit'] = $this->limit; //默认20 $supplierOrderListInfo = cloud_post($this->domain.$supplier_order_list_url,$supplier_order_list_data); $supplierOrderListInfo = json_decode($supplierOrderListInfo,true); if($supplierOrderListInfo['code'] != 0){ $code = 1; //失败 return $this->outPutData($code,$supplierOrderListInfo['msg']); }else{ return $supplierOrderListInfo; } } //增加供货渠道 public function addUserGoodsChannel() { $t = \Yii::$app->db->beginTransaction(); try { $cloud_token = get_platform_token(); $id = $this->id; $name = $this->name; $status = $this->status; $rate = $this->rate; if (!in_array($status, [0, 1])) { throw new \Exception('状态错误'); } $goodsChannelData = []; $goodsChannelUrl = "/cloud/user/goodsChannelSave"; $goodsChannelData['access_token'] = $cloud_token; $goodsChannelData['id'] = $id; $goodsChannelData['name'] = $name; $goodsChannelData['status'] = $status; $goodsChannelData['rate'] = $rate; $goodsChannelResult = cloud_post($this->domain . $goodsChannelUrl, $goodsChannelData); $goodsChannelResult = json_decode($goodsChannelResult, true); if ($goodsChannelResult['code']) { throw new \Exception($goodsChannelResult['msg']); } //参数示例 $t->commit(); return $goodsChannelResult; } catch (\Exception $e) { $t->rollBack(); return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //供货渠道列表 public function userGoodsChannel($no_page = 0) { try { $cloud_token = get_platform_token(); $status = $this->status; $name = $this->name; $start_time = $this->start_time; $end_time = $this->end_time; if (!in_array($status, [-1, 0, 1])) { throw new \Exception('状态错误'); } $goodsChannelData = []; $goodsChannelUrl = "/cloud/user/goodsChannelList"; $goodsChannelData['access_token'] = $cloud_token; $goodsChannelData['status'] = $status;//0禁用 1启用 -1全部 $goodsChannelData['name'] = $name;//供货渠道名称 $goodsChannelData['start_time'] = $start_time;//供货渠道创建开始时间 $goodsChannelData['end_time'] = $end_time;//供货渠道创建结束时间 $goodsChannelData['page'] = $this->page; $goodsChannelData['limit'] = $this->limit; $goodsChannelData['no_page'] = $no_page;//无分页情况 $goodsChannelResult = cloud_post($this->domain . $goodsChannelUrl, $goodsChannelData); $goodsChannelResult = json_decode($goodsChannelResult, true); if ($goodsChannelResult['code']) { throw new \Exception($goodsChannelResult['msg']); } return $goodsChannelResult; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //供货渠道删除 public function userGoodsChannelStatus() { $t = \Yii::$app->db->beginTransaction(); try { $cloud_token = get_platform_token(); $ids = $this->ids; $status = $this->status; $goodsChannelData = []; $goodsChannelUrl = "/cloud/user/goodsChannelStatus"; $goodsChannelData['access_token'] = $cloud_token; $goodsChannelData['ids'] = $ids; $goodsChannelData['status'] = $status;//0禁用 1启用 2删除 $goodsChannelResult = cloud_post($this->domain . $goodsChannelUrl, $goodsChannelData); $goodsChannelResult = json_decode($goodsChannelResult, true); if ($goodsChannelResult['code']) { throw new \Exception($goodsChannelResult['msg']); } $t->commit(); return $goodsChannelResult; } catch (\Exception $e) { $t->rollBack(); return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //设置云仓用户供货渠道 public function setUserGoodsChannel() { $cloud_token = get_platform_token(); $goodsChannelData = []; $goodsChannelUrl = "/cloud/user/setUserGoodsChannel"; $goodsChannelData['access_token'] = $cloud_token; $goodsChannelData['mch_id'] = $this->id; $goodsChannelData['channel_id'] = $this->channel_id;//0禁用 1启用 2删除 $goodsChannelResult = cloud_post($this->domain . $goodsChannelUrl, $goodsChannelData); return json_decode($goodsChannelResult, true); } //云仓用户修改店铺 public function setCloudUserStore() { try { $cloud_store_id = $this->id; $store_id = $this->store_id; $store_cloud = StoreCloud::findOne(['cloud_store_id' => $cloud_store_id, 'is_delete' => 0]); $cloud_user_id = $store_cloud->cloud_user_id; if ($store_cloud) { $old_store_id = $store_cloud->store_id; $other_store = StoreCloud::find()->where(['store_id' => $store_id, 'is_delete' => 0])->andWhere(['<>', 'id', $store_cloud->id]) ->asArray()->one(); if ($other_store) { throw new \Exception('有其他云仓账户绑定该商城'); } StoreCloud::updateAll(['store_id' => 0], ['store_id' => $store_id, 'is_delete' => 0]); $store_cloud->store_id = $store_id; if (!$store_cloud->save()) { throw new \Exception(json_encode($store_cloud->errors, JSON_UNESCAPED_UNICODE)); } if (intval($old_store_id) !== intval($store_id)) { $this->delUserCloudGoodsBind($cloud_user_id, $old_store_id); } return [ 'code' => 0, 'msg' => '修改成功' ]; } throw new \Exception('查询云仓账户信息失败'); } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //修复更换云仓店铺后 店铺没有云仓商品问题 public function delUserCloudGoodsBind($cloud_user_id, $old_store_id) { try { //获取平台token $cloud_token = get_platform_token(); if (!$cloud_token) { return [ 'code' => 1, 'msg' => '网络问题请重试', ]; } $store_cloud = StoreCloud::findOne(['cloud_user_id' => $cloud_user_id, 'is_delete' => 0]); if (empty($store_cloud)) { return [ 'code' => 1, 'msg' => '云仓用户查询失败', ]; } $delGoodsBindUrl = "/cloud/user/delUserCloudGoodsBind"; $delGoodsBindData['access_token'] = $cloud_token; $delGoodsBindData['user_id'] = $cloud_user_id; $delGoodsBindInfo = cloud_post($this->domain . $delGoodsBindUrl, $delGoodsBindData); $delGoodsBindInfo = json_decode($delGoodsBindInfo, true); if($delGoodsBindInfo['code'] != 0){ throw new \Exception($delGoodsBindInfo['msg']); } $bind_goods_id = $delGoodsBindInfo['data']; if (!empty($bind_goods_id)) { Goods::updateAll(['is_delete' => 1], ['is_delete' => 0, 'store_id' => $old_store_id, 'cloud_goods_id' => $bind_goods_id]); } return $this->outPutData(0, $delGoodsBindInfo['msg']); } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //云仓库存详情 public function setPlatformNegotiatedPrice($service_charge_rate){ //获取平台token $cloud_token = get_platform_token(); $supplier_order_list_data = []; $supplier_order_list_url = "/cloud/user/setPlatformNegotiatedPrice"; $supplier_order_list_data['access_token'] = $cloud_token; $supplier_order_list_data['platform_negotiated_rate'] = $service_charge_rate; $supplierOrderListInfo = cloud_post($this->domain.$supplier_order_list_url,$supplier_order_list_data); $supplierOrderListInfo = json_decode($supplierOrderListInfo,true); if($supplierOrderListInfo['code'] != 0){ $code = 1; //失败 return $this->outPutData($code,$supplierOrderListInfo['msg']); }else{ return $supplierOrderListInfo; } } //设置平台协议价 public function setGoodsPlatformNegotiatedPrice() { //获取平台token $cloud_token = get_platform_token(); $set_goods_platform_negotiated_price_data = []; $set_goods_platform_negotiated_price_url = "/cloud/user/setGoodsPlatformNegotiatedPrice"; $set_goods_platform_negotiated_price_data['access_token'] = $cloud_token; $set_goods_platform_negotiated_price_data['goods_id'] = $this->goods_id; $set_goods_platform_negotiated_price_data['attr'] = $this->attr; $set_goods_platform_negotiated_price_data['platform_negotiated_price'] = $this->platform_negotiated_price; $set_goods_platform_negotiated_price_info = cloud_post($this->domain . $set_goods_platform_negotiated_price_url, $set_goods_platform_negotiated_price_data); $set_goods_platform_negotiated_price_info = json_decode($set_goods_platform_negotiated_price_info, true); if ($set_goods_platform_negotiated_price_info['code'] != 0) { $code = 1; //失败 return $this->outPutData($code, $set_goods_platform_negotiated_price_info['msg']); } else { return $set_goods_platform_negotiated_price_info; } } public function getCloudProfitList() { $cloud_token = get_platform_token(); $set_goods_platform_negotiated_price_data = []; $set_goods_platform_negotiated_price_url = "/cloud/user/getCloudProfitList"; $set_goods_platform_negotiated_price_data['access_token'] = $cloud_token; $set_goods_platform_negotiated_price_data['order_no'] = $this->order_no; $set_goods_platform_negotiated_price_data['supplier_name'] = $this->supplier_name; $set_goods_platform_negotiated_price_data['store_name'] = $this->name; $set_goods_platform_negotiated_price_data['start_time'] = $this->start_time; $set_goods_platform_negotiated_price_data['end_time'] = $this->end_time; $set_goods_platform_negotiated_price_data['limit'] = $this->limit; $set_goods_platform_negotiated_price_data['page'] = $this->page; $set_goods_platform_negotiated_price_info = cloud_post($this->domain . $set_goods_platform_negotiated_price_url, $set_goods_platform_negotiated_price_data); $set_goods_platform_negotiated_price_info = json_decode($set_goods_platform_negotiated_price_info, true); if ($set_goods_platform_negotiated_price_info['code'] != 0) { $code = 1; //失败 return $this->outPutData($code, $set_goods_platform_negotiated_price_info['msg']); } else { return $set_goods_platform_negotiated_price_info; } } public function setCloudUrl() { try { $cloud_token = get_platform_token(); // $id = $this->id; $data_url = "/cloud/user/setCloudUrl"; $data['access_token'] = $cloud_token; // $data['old_url'] = $this->old_url; $data['url'] = \Yii::$app->request->hostName; $getGoodsCateInfo = cloud_post($this->domain.$data_url,$data); $getGoodsCateInfo = json_decode($getGoodsCateInfo,true); if($getGoodsCateInfo['code'] != 0){ throw new \Exception($getGoodsCateInfo['msg']); } return $this->outPutData(0, $getGoodsCateInfo['msg']); } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //返回数据 private function outPutData($code,$msg,$data=[]){ $putData = []; $putData['code'] = $code; $putData['msg'] = $msg; if($data) $putData['data'] = $data; if($msg == 'token不能为空'){ $putData['code'] = -1; } return $putData; } }