| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\admin\models;
- // use app\models\Form;
- // use app\models\Option;
- use app\jobs\CreatedCloudGoodsUpdate;
- use app\models\AgentFrontCentralizeGoods;
- use app\models\AgentFrontCentralizeGoodsExt;
- use app\models\AgentFrontCentralizeGoodsLog;
- use app\models\CloudGoodsUpdateLog;
- use app\models\District;
- use app\models\DriverMdBind;
- use app\models\Goods;
- use app\models\Md;
- use app\models\Purchase;
- use app\models\User;
- use app\modules\admin\models\agent\AgentForm;
- use app\utils\Notice\NoticeSend;
- use Yii;
- use Exception;
- use yii\base\Model;
- use app\models\Admin;
- use app\models\Supplier;
- use app\models\StoreCloud;
- use app\models\Store;
- use app\models\Cat;
- use yii\data\Pagination;
- use app\models\Option;
- //use linslin\yii2\curl;
- use app\models\Share;
- use yii\base\BaseObject;
- use yii\helpers\Json;
- use app\jobs\BatchDownGoodsJob;
- use app\constants\OptionSetting;
- use app\models\SaasUser;
- class PlatformForm extends Model
- {
- public $supplier_name;
- public $user_name;
- public $name;
- public $cat_id;
- public $id;
- public $password;
- public $tel;
- public $logo;
- public $type;
- public $certificate;
- public $id_card_reverse;
- public $id_card_front;
- public $page;
- public $limit;
- public $supplier_id; //云库供货商id
- public $cloud_user_id; //云库会员id
- public $price; //变动金额
- public $desc; //详情
- public $status; //状态
- public $cash_id; //提现ID
- public $pay_type; //打款方式 1 微信打款 2 支付宝打款 3 银行卡打款 4 其他
- public $service_charge; //手续费
- public $action_id; //云仓用户id
- public $user_id;
- public $cloud_store_id; //云仓商户id
- public $saas_user_id; // 联盟用户id
- public $saas_user_mobile; // 联盟用户id
- public $store_id; // 商城id
- public $avatar_url;
- public $email;
- public $sale_day;
- public $rate; //供货商费率
- public $parent_id;
- public $is_show;
- public $pic_url;
- public $sort;
- public $sale_sort;
- public $price_sort;
- public $is_distribution;
- public $no_distribution;
- public $ids;
- public $cloud_platform_list;
- public $is_enable;
- public $district_id;
- public $city_id;
- public $province_id;
- public $send_type;
- public $filter_goods_id;
- public $min_money;
- public $max_money;
- public $level;
- public $profit;
- public $agent_percent;
- public $agent_install_percent;
- public $agent_profit_default;
- public $list;
- public $order_no;
- public $start_time;
- public $end_time;
- public $sorting_start_time;
- public $sorting_end_time;
- public $could_mch_id;
- public $goods_id;
- public $attr;
- public $num;
- public $supplier_custom_form;
- public $shop_count;
- private $domain;
- public $channel_id;
- public $is_self;
- public $platform_negotiated_price;
- public $centralize_goods_type;//0线货 1团货
- public $goods_name;
- public $goods_no;
- public function __construct($config = [])
- {
- parent::__construct($config);
- $this->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;
- }
- }
|