PlatformForm.php 121 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\admin\models;
  8. // use app\models\Form;
  9. // use app\models\Option;
  10. use app\jobs\CreatedCloudGoodsUpdate;
  11. use app\models\AgentFrontCentralizeGoods;
  12. use app\models\AgentFrontCentralizeGoodsExt;
  13. use app\models\AgentFrontCentralizeGoodsLog;
  14. use app\models\CloudGoodsUpdateLog;
  15. use app\models\District;
  16. use app\models\DriverMdBind;
  17. use app\models\Goods;
  18. use app\models\Md;
  19. use app\models\Purchase;
  20. use app\models\User;
  21. use app\modules\admin\models\agent\AgentForm;
  22. use app\utils\Notice\NoticeSend;
  23. use Yii;
  24. use Exception;
  25. use yii\base\Model;
  26. use app\models\Admin;
  27. use app\models\Supplier;
  28. use app\models\StoreCloud;
  29. use app\models\Store;
  30. use app\models\Cat;
  31. use yii\data\Pagination;
  32. use app\models\Option;
  33. //use linslin\yii2\curl;
  34. use app\models\Share;
  35. use yii\base\BaseObject;
  36. use yii\helpers\Json;
  37. use app\jobs\BatchDownGoodsJob;
  38. use app\constants\OptionSetting;
  39. use app\models\SaasUser;
  40. class PlatformForm extends Model
  41. {
  42. public $supplier_name;
  43. public $user_name;
  44. public $name;
  45. public $cat_id;
  46. public $id;
  47. public $password;
  48. public $tel;
  49. public $logo;
  50. public $type;
  51. public $certificate;
  52. public $id_card_reverse;
  53. public $id_card_front;
  54. public $page;
  55. public $limit;
  56. public $supplier_id; //云库供货商id
  57. public $cloud_user_id; //云库会员id
  58. public $price; //变动金额
  59. public $desc; //详情
  60. public $status; //状态
  61. public $cash_id; //提现ID
  62. public $pay_type; //打款方式 1 微信打款 2 支付宝打款 3 银行卡打款 4 其他
  63. public $service_charge; //手续费
  64. public $action_id; //云仓用户id
  65. public $user_id;
  66. public $cloud_store_id; //云仓商户id
  67. public $saas_user_id; // 联盟用户id
  68. public $saas_user_mobile; // 联盟用户id
  69. public $store_id; // 商城id
  70. public $avatar_url;
  71. public $email;
  72. public $sale_day;
  73. public $rate; //供货商费率
  74. public $parent_id;
  75. public $is_show;
  76. public $pic_url;
  77. public $sort;
  78. public $sale_sort;
  79. public $price_sort;
  80. public $is_distribution;
  81. public $no_distribution;
  82. public $ids;
  83. public $cloud_platform_list;
  84. public $is_enable;
  85. public $district_id;
  86. public $city_id;
  87. public $province_id;
  88. public $send_type;
  89. public $filter_goods_id;
  90. public $min_money;
  91. public $max_money;
  92. public $level;
  93. public $profit;
  94. public $agent_percent;
  95. public $agent_install_percent;
  96. public $agent_profit_default;
  97. public $list;
  98. public $order_no;
  99. public $start_time;
  100. public $end_time;
  101. public $sorting_start_time;
  102. public $sorting_end_time;
  103. public $could_mch_id;
  104. public $goods_id;
  105. public $attr;
  106. public $num;
  107. public $supplier_custom_form;
  108. public $shop_count;
  109. private $domain;
  110. public $channel_id;
  111. public $is_self;
  112. public $platform_negotiated_price;
  113. public $centralize_goods_type;//0线货 1团货
  114. public $goods_name;
  115. public $goods_no;
  116. public function __construct($config = [])
  117. {
  118. parent::__construct($config);
  119. $this->domain = (new OptionSetting)->getCloudDomainName();
  120. }
  121. /**
  122. * @return array the validation rules.
  123. */
  124. public function rules()
  125. {
  126. return [
  127. [['certificate', 'id_card_reverse','id_card_front','logo','desc','avatar_url', 'pic_url'], 'string', 'max' => 255],
  128. [['name', 'user_name', 'password', 'supplier_name', 'cloud_platform_list', 'saas_user_mobile', 'order_no', 'centralize_goods_type', 'goods_name', 'goods_no'], 'string', 'max'=>32],
  129. [['filter_goods_id', 'ids', 'min_money', 'max_money', 'email', 'start_time', 'end_time', 'sorting_start_time', 'sorting_end_time', 'attr', 'supplier_custom_form'], 'string'],
  130. [['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'],
  131. [['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'],
  132. [['sale_sort', 'price_sort', 'cat_id', 'is_distribution', 'no_distribution', 'supplier_id', 'list'], 'safe'],
  133. ];
  134. }
  135. //创建会员
  136. public function storeUserAdd(){
  137. if (!$this->validate()) {
  138. return $this->getErrorSummary(false)[0];
  139. }
  140. $cloud_store_token = get_platform_token();
  141. if (!$cloud_store_token) {
  142. return [
  143. 'code' => 1,
  144. 'msg' => '网络问题请重试',
  145. ];
  146. }
  147. $store_user_add_url = "/cloud/user/storeUserAdd";
  148. $store_user_add_data['access_token'] = $cloud_store_token;
  149. $store_user_add_data['name'] = $this->name;
  150. $store_user_add_data['pwd'] = $this->password;
  151. $store_user_add_data['tel'] = $this->tel;
  152. $store_user_add_data['email'] = $this->email;
  153. $store_user_add_data['type'] = $this->type;
  154. $store_user_add_data['avatar_url'] = $this->avatar_url;
  155. $storeInfo = cloud_post($this->domain.$store_user_add_url,$store_user_add_data);
  156. $storeInfo = json_decode($storeInfo,true);
  157. if($storeInfo['code'] != 0){
  158. $code = 1;
  159. return $this->outPutData($code,$storeInfo['msg']);
  160. }else{
  161. return $this->outPutData($storeInfo['code'],$storeInfo['msg'],$storeInfo['data']);
  162. }
  163. }
  164. //充值列表
  165. public function storeGetRechargeList(){
  166. if (!$this->validate()) {
  167. return $this->getErrorSummary(false)[0];
  168. }
  169. $cloud_store_token = get_platform_token();
  170. if (!$cloud_store_token) {
  171. return [
  172. 'code' => 1,
  173. 'msg' => '网络问题请重试',
  174. ];
  175. }
  176. $store_get_recharge_list_url = "/cloud/user/storegetRechargeList";
  177. $store_get_recharge_list_data = [];
  178. $store_get_recharge_list_data['access_token'] = $cloud_store_token; //获取供货商的token信息
  179. $store_get_recharge_list_data['page'] = $this->page; //默认为 1
  180. $store_get_recharge_list_data['limit'] = $this->limit; //默认20
  181. if($this->tel) $store_get_recharge_list_data['tel'] = $this->tel; //电话
  182. if($this->name) $store_get_recharge_list_data['name'] = $this->name; //名称
  183. $storeGetRechargeListInfo = cloud_post($this->domain.$store_get_recharge_list_url,$store_get_recharge_list_data);
  184. $storeGetRechargeListInfo = json_decode($storeGetRechargeListInfo,true);
  185. if($storeGetRechargeListInfo['code'] != 0){
  186. $code = 1;//失败
  187. return $this->outPutData($code,$storeGetRechargeListInfo['msg']);
  188. }else{
  189. $msg = "获取成功";
  190. return $this->outPutData($storeGetRechargeListInfo['code'],$msg,$storeGetRechargeListInfo['data']);
  191. }
  192. }
  193. //关联供应商
  194. public function setCloudPlatform(){
  195. if (!$this->validate()) {
  196. return $this->getErrorSummary(false)[0];
  197. }
  198. $store_cloud = StoreCloud::find()->where(['cloud_store_id' => $this->cloud_store_id,"is_delete" => 0])->one();
  199. if(!$store_cloud) {
  200. $code = 1;//失败
  201. $msg = "店铺不存在";
  202. return $this->outPutData($code,$msg);
  203. }
  204. $store_cloud->cloud_platform_list = $this->cloud_platform_list;
  205. $save = $store_cloud->save();
  206. if($save){
  207. return $this->outPutData(0, '操作成功');
  208. }else{
  209. return $this->outPutData(1, '操作失败');
  210. }
  211. }
  212. //编辑用户
  213. public function storeMchEdit(){
  214. // if (!$this->validate()) {
  215. // return $this->getErrorSummary(false)[0];
  216. // }
  217. $store_cloud = StoreCloud::findOne(['cloud_store_id' => $this->cloud_store_id, "is_delete" => 0]);
  218. if(!$store_cloud) {
  219. $code = 1;//失败
  220. $msg = "会员不存在";
  221. return $this->outPutData($code,$msg);
  222. }
  223. $item = StoreCloud::find()->where(['name' => trim($this->user_name), 'is_delete' => 0])->andWhere(['<>', 'id', $store_cloud->id])->one();
  224. if ($item) {
  225. return [
  226. 'code' => 1,
  227. 'msg' => '云仓账户已存在',
  228. ];
  229. }
  230. $purchase = Purchase::findOne(['name' => trim($this->user_name), 'is_delete' => 0, 'status' => 0]);
  231. if ($purchase && (int)$purchase->status === 0) {
  232. return [
  233. 'code' => 1,
  234. 'msg' => '有相同名称账户正在审核中',
  235. ];
  236. }
  237. // $store_cloud->name = $this->name;
  238. $store_cloud->name = $this->user_name;
  239. if (!empty(trim($this->password))) {
  240. $store_cloud->password = $this->password;
  241. }
  242. // $store_cloud->logo = $this->logo;
  243. // $store_cloud->tel = $this->tel;
  244. // $store_cloud->type = $this->type;
  245. // $store_cloud->certificate = $this->certificate;
  246. // $store_cloud->id_card_reverse = $this->id_card_reverse;
  247. // $store_cloud->id_card_front = $this->id_card_front;
  248. $cloud_store_token = get_platform_token();
  249. if (!$cloud_store_token) {
  250. return [
  251. 'code' => 1,
  252. 'msg' => '网络问题请重试',
  253. ];
  254. }
  255. $store_mch_edit_url = "/cloud/user/storeMchEdit";
  256. $store_mch_edit_data = [];
  257. $store_mch_edit_data['access_token'] = $cloud_store_token; //获取供货商的token信息
  258. $store_mch_edit_data['name'] = $this->user_name;
  259. if (!empty(trim($this->password))) {
  260. $store_mch_edit_data['pwd'] = $this->password;
  261. }
  262. // $store_mch_edit_data['logo'] = $this->logo;
  263. // $store_mch_edit_data['tel'] = $this->tel;
  264. // $store_mch_edit_data['type'] = $this->type;
  265. // $store_mch_edit_data['certificate'] = $this->certificate;
  266. // $store_mch_edit_data['id_card_reverse'] = $this->id_card_reverse;
  267. // $store_mch_edit_data['id_card_front'] = $this->id_card_front;
  268. // $store_mch_edit_data['mch_id'] = $this->cloud_store_id; //商户id
  269. $store_mch_edit_data['user_id'] = $store_cloud->cloud_user_id;
  270. $t = Yii::$app->db->beginTransaction();
  271. $store_cloud->save();
  272. $storeMchEditInfo = cloud_post($this->domain.$store_mch_edit_url,$store_mch_edit_data);
  273. $storeMchEditInfo = json_decode($storeMchEditInfo,true);
  274. if($storeMchEditInfo['code'] != 0){
  275. $t->rollBack();
  276. $code = 1;//失败
  277. return $this->outPutData($code,$storeMchEditInfo['msg']);
  278. }else{
  279. $t->commit();
  280. return $this->outPutData($storeMchEditInfo['code'],$storeMchEditInfo['msg']);
  281. }
  282. }
  283. //删除商户
  284. public function storeMchDel(){
  285. if (!$this->validate()) {
  286. return $this->getErrorSummary(false)[0];
  287. }
  288. $cloud_store_token = get_platform_token();
  289. if (!$cloud_store_token) {
  290. return [
  291. 'code' => 1,
  292. 'msg' => '网络问题请重试',
  293. ];
  294. }
  295. $store_mch_del_url = "/cloud/user/storeMchDel";
  296. $store_mch_del_data = [];
  297. $store_mch_del_data['access_token'] = $cloud_store_token; //获取供货商的token信息
  298. $store_mch_del_data['mch_id'] = $this->cloud_store_id; //默认为 1
  299. $store_cloud = StoreCloud::find()->where(['cloud_store_id' => $this->cloud_store_id,"is_delete" => 0])->one();
  300. $t = Yii::$app->db->beginTransaction();
  301. if(!$store_cloud){
  302. // $code = 1;//失败
  303. // $msg = "用户不存在";
  304. // return $this->outPutData($code,$msg);
  305. } else {
  306. $store_cloud->is_delete = 1;
  307. $store_cloud->deleted_at = time();
  308. $store_cloud->save();
  309. $purchase = Purchase::findOne(['store_cloud_id' => $store_cloud->id]);
  310. if ($purchase) {
  311. $purchase->is_delete = 1;
  312. $purchase->save();
  313. }
  314. }
  315. $storeMchDelInfo = cloud_post($this->domain.$store_mch_del_url,$store_mch_del_data);
  316. $storeMchDelInfo = json_decode($storeMchDelInfo,true);
  317. if($storeMchDelInfo['code'] != 0){
  318. $t->rollBack();
  319. $code = 1;//失败
  320. return $this->outPutData($code,$storeMchDelInfo['msg']);
  321. }else{
  322. $t->commit();
  323. return $this->outPutData($storeMchDelInfo['code'],$storeMchDelInfo['msg']);
  324. }
  325. }
  326. //商户列表
  327. public function storeMchList(){
  328. if (!$this->validate()) {
  329. return $this->getErrorSummary(false)[0];
  330. }
  331. $cloud_store_token = get_platform_token();
  332. if (!$cloud_store_token) {
  333. return [
  334. 'code' => 1,
  335. 'msg' => '网络问题请重试',
  336. ];
  337. }
  338. $store_mch_list_url = "/cloud/user/storeMchList";
  339. $store_mch_list_data = [];
  340. $store_mch_list_data['access_token'] = $cloud_store_token; //获取供货商的token信息
  341. if ($this->name) {
  342. $store_mch_list_data['name'] = $this->name;
  343. $store_ids = Store::find()->where(['LIKE', 'name', $this->name])->andWhere(['is_delete' => 0])
  344. ->select('id')->column();
  345. if (!empty($store_ids)) {
  346. $store_cloud_id = StoreCloud::find()->where(['store_id' => $store_ids, 'is_delete' => 0])->andWhere(['>', 'cloud_store_id', 0])
  347. ->select('cloud_store_id')->column();
  348. if (!empty($store_cloud_id)) {
  349. $store_mch_list_data['ids'] = implode(',', $store_cloud_id);
  350. }
  351. }
  352. }
  353. if ($this->tel) {
  354. $store_mch_list_data['tel'] = $this->tel;
  355. }
  356. if ($this->channel_id) {
  357. $store_mch_list_data['channel_id'] = $this->channel_id;
  358. }
  359. if ($this->level) {
  360. $store_mch_list_data['level'] = $this->level;
  361. }
  362. $store_mch_list_data['page'] = $this->page; //默认为 1
  363. $store_mch_list_data['limit'] = $this->limit; //默认20
  364. if($this->tel) $store_mch_list_data['tel'] = $this->tel; //电话
  365. if($this->name) $store_mch_list_data['name'] = $this->name; //名称
  366. $storeMchListInfo = cloud_post($this->domain.$store_mch_list_url,$store_mch_list_data);
  367. $storeMchListInfo = json_decode($storeMchListInfo,true);
  368. if($storeMchListInfo['code'] != 0){
  369. $code = 1;//失败
  370. return $this->outPutData($code,$storeMchListInfo['msg']);
  371. }else{
  372. $data = [];
  373. foreach ($storeMchListInfo['data']['list'] as $key => $item) {
  374. $data[$key]['can_distribution'] = 0;
  375. $data[$key]['store_id'] = 0;
  376. $data[$key]['is_enable'] = 0;
  377. $data[$key]['saas_user_id'] = 0;
  378. $data[$key]['store_cloud_id'] = 0;
  379. $data[$key]['type'] = 0;
  380. $data[$key]['logo'] = '';
  381. $data[$key]['cloud_platform_list'] = '';
  382. $data[$key]['store_name'] = '';
  383. $data[$key]['store_logo'] = '';
  384. $data[$key]['category_id'] = 0;
  385. $data[$key]['user_name'] = $item['name'];
  386. $data[$key]['user_avatar'] = $item['logo'];
  387. $data[$key]['can_recharge'] = 1;
  388. $store_cloud = StoreCloud::findOne(['cloud_store_id' => $item['id']]);
  389. if ($store_cloud) {
  390. $data[$key]['can_distribution'] = (string)$store_cloud->can_distribution;
  391. $data[$key]['store_id'] = $store_cloud->store_id;
  392. if ($data[$key]['store_id']) {
  393. $store = Store::findOne($data[$key]['store_id']);
  394. if ($store) {
  395. $data[$key]['store_name'] = $store->name;
  396. $data[$key]['store_logo'] = $store->logo;
  397. $data[$key]['category_id'] = $store->category_id;
  398. if($data[$key]['category_id'] > 0){
  399. $catInfo = Cat::find()->where(['id' => $data[$key]['category_id'], 'is_delete' => 0])->one();
  400. if( isset($catInfo->name) ){
  401. $data[$key]['category_name'] = $catInfo->name;
  402. }
  403. }
  404. }
  405. }
  406. $data[$key]['is_enable'] = intval($store_cloud->is_enable);
  407. $data[$key]['saas_user_id'] = $store_cloud->saas_user_id;
  408. $data[$key]['store_cloud_id'] = $store_cloud->id;
  409. $data[$key]['type'] = intval($store_cloud->type);
  410. $data[$key]['logo'] = $store_cloud->logo;
  411. $data[$key]['cloud_platform_list'] = $store_cloud->cloud_platform_list;
  412. if ($store_cloud->saas_user_id) {
  413. $saasUser = SaasUser::findOne($store_cloud->saas_user_id);
  414. if ($saasUser) {
  415. // $data[$key]['user_name'] = $saasUser->name;
  416. $data[$key]['user_avatar'] = $saasUser->avatar;
  417. }
  418. }
  419. }
  420. $data[$key]['id'] = $item['id'];
  421. $data[$key]['cloud_store'] = $item;
  422. }
  423. $storeMchListInfo['data']['list'] = $data;
  424. $msg = "获取成功";
  425. $this->name = null;
  426. $user_channel = $this->userGoodsChannel(1);
  427. $channel_list = [];
  428. if ($user_channel['code'] === 0) {
  429. $channel_list = $user_channel['data']['list'];
  430. }
  431. $storeMchListInfo['data']['channel_list'] = $channel_list;
  432. return $this->outPutData($storeMchListInfo['code'],$msg,$storeMchListInfo['data']);
  433. }
  434. }
  435. public function storeMchEnable()
  436. {
  437. try {
  438. $store_cloud = StoreCloud::findOne(['cloud_store_id' => $this->id]);
  439. if (empty($store_cloud)) {
  440. throw new \Exception("未找到数据");
  441. }
  442. if (in_array((int)$this->is_enable, [0, 1])) {
  443. $store_cloud->is_enable = (int)$this->is_enable;
  444. if (!$store_cloud->save()) {
  445. throw new \Exception(json_encode($store_cloud->errors));
  446. }
  447. return [
  448. 'code' => 0,
  449. 'msg' => "修改成功"
  450. ];
  451. }
  452. throw new \Exception("操作失败");
  453. } catch (\Exception $e) {
  454. return [
  455. 'code' => 1,
  456. 'msg' => $e->getMessage()
  457. ];
  458. }
  459. }
  460. //商户列表
  461. public function newStoreMchList(){
  462. if (!$this->validate()) {
  463. return $this->getErrorSummary(false)[0];
  464. }
  465. $cloud_store_token = get_platform_token();
  466. if (!$cloud_store_token) {
  467. return [
  468. 'code' => 1,
  469. 'msg' => '网络问题请重试',
  470. ];
  471. }
  472. $store_mch_list_url = "/cloud/user/storeInfo";
  473. $store_mch_list_data = [];
  474. $store_mch_list_data['access_token'] = $cloud_store_token; //获取供货商的token信息
  475. $query = StoreCloud::find()->alias('c')
  476. ->leftJoin(["s"=>Store::tableName()],'c.store_id=s.id')
  477. ->leftJoin(['su' => SaasUser::tableName()], 'c.saas_user_id = su.id')
  478. ->where(['c.is_delete'=>0])->andWhere(['>','c.cloud_store_id',0]);
  479. if ($this->name) {
  480. $query->andWhere(['OR', ['like', 'c.name', $this->name], ['like', 's.name', $this->name]]);
  481. }
  482. if ((int)$this->is_enable !== -1) {
  483. $query->andWhere(['c.is_enable' => (int)$this->is_enable]);
  484. }
  485. if ($this->tel) {
  486. $query->andWhere(['like', 'c.tel', $this->tel]);
  487. }
  488. $count = $query->count();
  489. $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $this->limit, 'page' => $this->page - 1]);
  490. $list = $query->limit($pagination->limit)->offset($pagination->offset)->orderBy('c.cloud_store_id DESC')->asArray()
  491. ->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();
  492. foreach($list as $key=>&$val){
  493. if($val['category_id']>0){
  494. $catInfo = Cat::find()->where(['id'=>$val['category_id'],'is_delete'=>0])->one();
  495. if( isset($catInfo->name) ){
  496. $list[$key]['category_name'] = $catInfo->name;
  497. }
  498. }
  499. $store_mch_list_data['id'] = $val['id'];
  500. $cloudInfo = cloud_post($this->domain.$store_mch_list_url,$store_mch_list_data);
  501. $storeMchListInfo = json_decode($cloudInfo,true);
  502. if($storeMchListInfo && $storeMchListInfo['code'] == 0){
  503. $storeMchListInfo['data']['data']['type'] = $val['type'];
  504. $list[$key]['cloud_store'] = $storeMchListInfo['data']['data'];
  505. } else {
  506. $list[$key]['cloud_store'] = [];
  507. }
  508. if ((int)$val['saas_user_id'] === 0) {
  509. $val['user_avatar'] = $list[$key]['cloud_store']['logo'];
  510. $val['user_name'] = $list[$key]['cloud_store']['name'];
  511. }
  512. $val['is_enable'] *= 1;
  513. $val['can_recharge'] = 1;
  514. }
  515. $msg = "获取成功";
  516. $data = [];
  517. $data['count'] = $count;
  518. $data['limit'] = $this->limit;
  519. $data['page'] = $this->page;
  520. $data['list'] = $list;
  521. $channel_list = [];
  522. $user_channel = $this->userGoodsChannel(1);
  523. if ($user_channel['code'] === 0) {
  524. $channel_list = $user_channel['data']['list'];
  525. }
  526. $data['channel_list'] = $channel_list;
  527. $code = 0;
  528. return $this->outPutData($code,$msg,$data);
  529. }
  530. //商户充值
  531. public function storeSubmitRecharge(){
  532. if (!$this->validate()) {
  533. return $this->getErrorSummary(false)[0];
  534. }
  535. $storeCloud = StoreCloud::findOne(['cloud_store_id' => $this->id, 'is_delete' => 0]);
  536. if (!$storeCloud) {
  537. return [
  538. 'code' => 1,
  539. 'msg' => '商户未找到',
  540. ];
  541. }
  542. $cloud_store_token = get_platform_token();
  543. if (!$cloud_store_token) {
  544. return [
  545. 'code' => 1,
  546. 'msg' => '网络问题请重试',
  547. ];
  548. }
  549. $store_submit_recharge_url = "/cloud/user/storeSubmitRecharge";
  550. $store_submit_recharge_data = [];
  551. $store_submit_recharge_data['access_token'] = $cloud_store_token; //获取供货商的token信息
  552. $store_submit_recharge_data['action_id'] = $storeCloud->cloud_store_id;
  553. $store_submit_recharge_data['price'] = number_format($this->price, 2,".","");
  554. $storeSubmitRechargeInfo = cloud_post($this->domain.$store_submit_recharge_url,$store_submit_recharge_data);
  555. $storeSubmitRechargeInfo = json_decode($storeSubmitRechargeInfo,true);
  556. if($storeSubmitRechargeInfo['code'] != 0){
  557. $code = 1;//失败
  558. return $this->outPutData($code,$storeSubmitRechargeInfo['msg']);
  559. }else{
  560. return $this->outPutData($storeSubmitRechargeInfo['code'],$storeSubmitRechargeInfo['msg']);
  561. }
  562. }
  563. //创建商户
  564. public function storeMchAdd()
  565. {
  566. if (!$this->validate()) {
  567. return $this->getErrorSummary(false)[0];
  568. }
  569. if (!$this->saas_user_id) {
  570. return [
  571. 'code' => 1,
  572. 'msg' => '缺少必要参数',
  573. ];
  574. }
  575. if (!in_array($this->type, [0, 1, 2])) {
  576. return [
  577. 'code' => 1,
  578. 'msg' => '商户类型不正确',
  579. ];
  580. }
  581. if ($this->type > 0 && !$this->store_id) {
  582. return [
  583. 'code' => 1,
  584. 'msg' => '缺少必要参数',
  585. ];
  586. }
  587. if (empty(trim($this->user_name))) {
  588. return [
  589. 'code' => 1,
  590. 'msg' => '请填写云仓账户',
  591. ];
  592. }
  593. if (empty(trim($this->password)) && !$this->id) {
  594. return [
  595. 'code' => 1,
  596. 'msg' => '请填写云仓账户密码',
  597. ];
  598. }
  599. $saasUser = SaasUser::findOne($this->saas_user_id);
  600. if (!$saasUser) {
  601. return [
  602. 'code' => 1,
  603. 'msg' => '用户未找到',
  604. ];
  605. }
  606. if ($this->saas_user_mobile) {
  607. $res = preg_match("/^1[3456789]\d{9}$/", $this->saas_user_mobile);
  608. if (!$res) {
  609. return [
  610. 'code' => 1,
  611. 'msg' => '手机号格式错误',
  612. ];
  613. }
  614. if (empty($saasUser->mobile)) {
  615. $saasUser->mobile = $this->saas_user_mobile;
  616. $saasUser->save();
  617. }
  618. }
  619. $item = StoreCloud::find()
  620. ->where(['is_delete' => 0])
  621. ->andWhere([
  622. 'or',
  623. ['saas_user_id' => $this->saas_user_id],
  624. ['store_id' => $this->store_id]
  625. ])->one();
  626. if ($item) {
  627. return [
  628. 'code' => 1,
  629. 'msg' => '该' . ($item->store_id == $this->store_id && $item->store_id > 0 ? '商城' : '用户') . '已经绑定过了',
  630. ];
  631. }
  632. $item = StoreCloud::find()->where(['name' => trim($this->user_name), 'is_delete' => 0])->andWhere(['<>', 'id', $this->id])->one();
  633. if ($item) {
  634. return [
  635. 'code' => 1,
  636. 'msg' => '云仓账户已存在',
  637. ];
  638. }
  639. //获取平台token
  640. $cloud_token = get_platform_token();
  641. if (!$cloud_token) {
  642. return [
  643. 'code' => 1,
  644. 'msg' => '网络问题请重试',
  645. ];
  646. }
  647. $purchase = Purchase::findOne(['AND', ['saas_user_id' => $this->saas_user_id, 'is_delete' => 0], ['<>', 'status', 2]]);
  648. if ($purchase && (int)$purchase->status === 0) {
  649. return [
  650. 'code' => 1,
  651. 'msg' => '当前用户已经在审核申请中,请前往审核',
  652. ];
  653. }
  654. $purchase = Purchase::findOne(['name' => trim($this->user_name), 'is_delete' => 0, 'status' => 0]);
  655. if ($purchase) {
  656. return [
  657. 'code' => 1,
  658. 'msg' => '有相同名称账户正在审核中',
  659. ];
  660. }
  661. $domain = $this->domain;
  662. $url = "/cloud/purchase/createPurchase";
  663. $data['access_token'] = $cloud_token;
  664. $data['name'] = $this->user_name;//$purchase->name ?: $saasUser->name;
  665. $data['logo'] = $saasUser->avatar;
  666. $data['tel'] = $purchase->mobile ?: $saasUser->mobile;
  667. if (!empty(trim($this->password))) {
  668. $data['pwd'] = $this->password;//$purchase->mobile ?:$saasUser->mobile;
  669. }
  670. $result = cloud_post($domain . $url, $data);
  671. $result = json_decode($result, true);
  672. if ((int)$result['code'] > 0) {
  673. return [
  674. 'code' => 1,
  675. 'msg' => $result['msg'],
  676. ];
  677. }
  678. $mch_id = $result['data']['mch_id'];
  679. $user_id = $result['data']['user_id'];
  680. $storeCloud = new StoreCloud();
  681. $storeCloud->store_id = $this->store_id ?: 0;
  682. $storeCloud->cloud_user_id = $user_id;
  683. $storeCloud->cloud_store_id = $mch_id;
  684. $storeCloud->saas_user_id = $this->saas_user_id;
  685. $storeCloud->name = $this->user_name;//$purchase->name ?: $saasUser->name;
  686. if (!empty(trim($this->password))) {
  687. $storeCloud->password = $this->password;//$purchase->mobile ?:$saasUser->mobile;
  688. }
  689. $storeCloud->logo = $saasUser->avatar;
  690. $storeCloud->type = $this->type;
  691. $storeCloud->tel = $purchase->mobile ?:$saasUser->mobile;
  692. $storeCloud->created_at = time();
  693. $storeCloud->province_id = $this->province_id;
  694. $storeCloud->city_id = $this->city_id;
  695. $storeCloud->district_id = $this->district_id;
  696. if ($storeCloud->save()) {
  697. if ($storeCloud->store_id) {
  698. $admin = Admin::findOne(['type' => 'store', 'type_id' => $storeCloud->store_id, 'is_delete' => 0]);
  699. if ($admin) {
  700. $admin->mobile = $saasUser->mobile;
  701. $admin->save();
  702. }
  703. }
  704. return [
  705. 'code' => 0,
  706. 'msg' => '操作成功',
  707. ];
  708. }
  709. return [
  710. 'code' => 1,
  711. 'msg' => '操作失败',
  712. ];
  713. }
  714. //查询余额记录
  715. public function storeGetBalanceLog(){
  716. if (!$this->validate()) {
  717. return $this->getErrorSummary(false)[0];
  718. }
  719. $cloud_token = get_platform_token();
  720. if (!$cloud_token) {
  721. return [
  722. 'code' => 1,
  723. 'msg' => '网络问题请重试',
  724. ];
  725. }
  726. $get_balance_log_url = "/cloud/user/storeGetBalanceLog";
  727. $get_balance_log_data = [];
  728. $get_balance_log_data['access_token'] = $cloud_token; //获取供货商的token信息
  729. $get_balance_log_data['page'] = $this->page; //默认为 1
  730. $get_balance_log_data['limit'] = $this->limit; //默认20
  731. $get_balance_log_data['tel'] = $this->tel; //电话
  732. $get_balance_log_data['name'] = $this->name; //名称
  733. $get_balance_log_data['status'] = $this->status; //1商户 2 供货商
  734. //增加区域代理功能
  735. $admin = get_admin();
  736. $admin_id = $admin->id;
  737. if ($admin->username == 'admin') {
  738. $admin_id = null;
  739. }
  740. if ($this->status === 2) {
  741. $query = Supplier::find()->where(['is_delete' => 0]);
  742. $str = 'cloud_supplier_id';
  743. } else {
  744. $query = StoreCloud::find()->where(['is_delete' => 0, 'is_enable' => 1]);
  745. $str = 'cloud_store_id';
  746. }
  747. if ($admin_id) {
  748. $admin_model = Admin::findOne($admin_id);
  749. $area_level = $admin_model->area_level;
  750. if($area_level == 1){
  751. $query->andWhere(
  752. ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id, 'district_id' => $admin_model->district_id]);
  753. } elseif ($area_level == 2){
  754. $query->andWhere(
  755. ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id]);
  756. } elseif ($area_level == 3){
  757. $query->andWhere(['province_id' => $admin_model->province_id]);
  758. }
  759. $this->ids = $query->select($str)->column();
  760. if ($this->ids) {
  761. $get_balance_log_data['ids'] = implode(',', $this->ids);
  762. } else {
  763. return $this->outPutData(0,'获取成功', [
  764. 'list' => []
  765. ]);
  766. }
  767. }
  768. $getBalanceLogInfo = cloud_post($this->domain.$get_balance_log_url,$get_balance_log_data);
  769. $getBalanceLogInfo = json_decode($getBalanceLogInfo,true);
  770. if($getBalanceLogInfo['code'] != 0){
  771. $code = 1;//失败
  772. return $this->outPutData($code,$getBalanceLogInfo['msg']);
  773. }else{
  774. return $this->outPutData($getBalanceLogInfo['code'],'获取成功',$getBalanceLogInfo['data']);
  775. }
  776. }
  777. //供货商提现列表
  778. public function storeGetCashList(){
  779. if (!$this->validate()) {
  780. return $this->getErrorSummary(false)[0];
  781. }
  782. $cloud_token = get_platform_token();
  783. if (!$cloud_token) {
  784. return [
  785. 'code' => 1,
  786. 'msg' => '网络问题请重试',
  787. ];
  788. }
  789. $supplier_cash_list_url = "/cloud/user/storegetCashList";
  790. $supplier_cash_list_data = [];
  791. $supplier_cash_list_data['access_token'] = $cloud_token; //获取供货商的token信息
  792. $supplier_cash_list_data['page'] = $this->page; //默认为 1
  793. $supplier_cash_list_data['limit'] = $this->limit; //默认20
  794. $supplier_cash_list_data['status'] = $this->status; //提现状态 0 待审核 1 已处理 2 已拒绝 -1 全部
  795. $admin = get_admin();
  796. $admin_id = $admin->id;
  797. if ($admin->username == 'admin') {
  798. $admin_id = null;
  799. }
  800. if ($admin_id) {
  801. $admin_model = Admin::findOne($admin_id);
  802. $area_level = $admin_model->area_level;
  803. $query = Supplier::find()->where(['is_delete' => 0]);
  804. if($area_level == 1){
  805. $query->andWhere(
  806. ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id, 'district_id' => $admin_model->district_id]);
  807. } elseif ($area_level == 2){
  808. $query->andWhere(
  809. ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id]);
  810. } elseif ($area_level == 3){
  811. $query->andWhere(['province_id' => $admin_model->province_id]);
  812. }
  813. $ids = $query->select('cloud_supplier_id')->column();
  814. if ($ids) {
  815. if(is_array($ids)){
  816. $ids = implode(',', $ids);
  817. }
  818. $supplier_cash_list_data['supplier_id'] = $ids;
  819. }
  820. }
  821. if($this->tel) $supplier_cash_list_data['tel'] = $this->tel; //电话
  822. if($this->name) $supplier_cash_list_data['name'] = $this->name; //名称
  823. if($this->cloud_user_id) $supplier_cash_list_data['user_id'] = $this->cloud_user_id; //用户ID 非供货商或商户ID
  824. $supplierCashListInfo = cloud_post($this->domain.$supplier_cash_list_url,$supplier_cash_list_data);
  825. $supplierCashListInfo = json_decode($supplierCashListInfo,true);
  826. if($supplierCashListInfo['code'] != 0){
  827. $code = 1;//失败
  828. return $this->outPutData($code,$supplierCashListInfo['msg']);
  829. }else{
  830. return $this->outPutData($supplierCashListInfo['code'],'获取成功',$supplierCashListInfo['data']);
  831. }
  832. }
  833. //供货商提现列表
  834. public function balanceCashList(){
  835. if (!$this->validate()) {
  836. return $this->getErrorSummary(false)[0];
  837. }
  838. $cloud_token = get_platform_token();
  839. if (!$cloud_token) {
  840. return [
  841. 'code' => 1,
  842. 'msg' => '网络问题请重试',
  843. ];
  844. }
  845. $supplier_cash_list_url = "/cloud/user/balanceCashList";
  846. $supplier_cash_list_data = [];
  847. $supplier_cash_list_data['access_token'] = $cloud_token; //获取供货商的token信息
  848. $supplier_cash_list_data['page'] = $this->page; //默认为 1
  849. $supplier_cash_list_data['limit'] = $this->limit; //默认20
  850. if($this->tel) $supplier_cash_list_data['tel'] = $this->tel; //电话
  851. if($this->name) $supplier_cash_list_data['name'] = $this->name; //名称
  852. $admin = get_admin();
  853. $admin_id = $admin->id;
  854. if ($admin->username == 'admin') {
  855. $admin_id = null;
  856. }
  857. if ($admin_id) {
  858. $admin_model = Admin::findOne($admin_id);
  859. $area_level = $admin_model->area_level;
  860. $query = Supplier::find()->where(['is_delete' => 0]);
  861. if($area_level == 1){
  862. $query->andWhere(
  863. ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id, 'district_id' => $admin_model->district_id]);
  864. } elseif ($area_level == 2){
  865. $query->andWhere(
  866. ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id]);
  867. } elseif ($area_level == 3){
  868. $query->andWhere(['province_id' => $admin_model->province_id]);
  869. }
  870. $ids = $query->select('cloud_supplier_id')->column();
  871. if ($ids) {
  872. $ids = implode(',', $ids);
  873. $supplier_cash_list_data['supplier_id'] = $ids;
  874. } else {
  875. return $this->outPutData(0,'获取成功', [
  876. 'list' => []
  877. ]);
  878. }
  879. }
  880. if($this->cloud_user_id) $supplier_cash_list_data['user_id'] = $this->cloud_user_id; //用户ID 非供货商或商户ID
  881. $supplierCashListInfo = cloud_post($this->domain.$supplier_cash_list_url,$supplier_cash_list_data);
  882. $supplierCashListInfo = json_decode($supplierCashListInfo,true);
  883. if($supplierCashListInfo['code'] != 0){
  884. $code = 1;//失败
  885. return $this->outPutData($code,$supplierCashListInfo['msg']);
  886. }else{
  887. return $this->outPutData($supplierCashListInfo['code'],'获取成功',$supplierCashListInfo['data']);
  888. }
  889. }
  890. //供货商提现处理
  891. public function storeActionSupplierCash(){
  892. if (!$this->validate()) {
  893. return $this->getErrorSummary(false)[0];
  894. }
  895. $cloud_token = get_platform_token();
  896. if (!$cloud_token) {
  897. return [
  898. 'code' => 1,
  899. 'msg' => '网络问题请重试',
  900. ];
  901. }
  902. $action_supplier_cash_url = "/cloud/user/storeActionSupplierCash";
  903. $action_supplier_cash_data = [];
  904. $action_supplier_cash_data['access_token'] = $cloud_token; //获取供货商的token信息
  905. $action_supplier_cash_data['cash_id'] = $this->cash_id; //提现ID
  906. $action_supplier_cash_data['pay_type'] = $this->pay_type; //打款方式 1 微信打款 2 支付宝打款 3 银行卡打款 4 其他
  907. $action_supplier_cash_data['status'] = $this->status; //1 同意 2 拒绝
  908. $action_supplier_cash_data['service_charge'] = $this->service_charge; //手续费
  909. $actionSupplierCashInfo = cloud_post($this->domain.$action_supplier_cash_url,$action_supplier_cash_data);
  910. $actionSupplierCashInfo = json_decode($actionSupplierCashInfo,true);
  911. if($actionSupplierCashInfo['code'] != 0){
  912. $code = 1;//失败
  913. return $this->outPutData($code,$actionSupplierCashInfo['msg']);
  914. }else{
  915. return $this->outPutData($actionSupplierCashInfo['code'],$actionSupplierCashInfo['msg']);
  916. }
  917. }
  918. //获取商品列表
  919. public function goodsInfo(){
  920. if (!$this->id && !$this->ids) {
  921. return $this->getErrorSummary(false)[0];
  922. }
  923. $goods_list_url = "/cloud/user/userGetGoodsList";
  924. $cloud_token = get_platform_token();
  925. if (!$cloud_token) {
  926. return [
  927. 'code' => 1,
  928. 'msg' => '网络问题请重试',
  929. ];
  930. }
  931. $goods_list_data = [];
  932. $goods_list_data['access_token'] = $cloud_token; //获取供货商的token信息
  933. $goods_list_data['page'] = $this->page; //默认为 1
  934. $goods_list_data['limit'] = $this->limit; //默认20
  935. if($this->id) $goods_list_data['id'] = $this->id; //商品名称
  936. if($this->ids) $goods_list_data['ids'] = $this->ids; //商品名称
  937. $goods_list_data['is_self'] = $this->is_self ?: 0;
  938. $goodsListInfo = cloud_post($this->domain.$goods_list_url,$goods_list_data);
  939. $goodsListInfo = json_decode($goodsListInfo,true);
  940. if($goodsListInfo['code'] != 0){
  941. $code = 1;//失败
  942. return $this->outPutData($code,$goodsListInfo['msg']);
  943. }else{
  944. return $this->outPutData($goodsListInfo['code'],"获取成功",$goodsListInfo['data']);
  945. }
  946. }
  947. //获取商品列表
  948. public function goodsList(){
  949. if (!$this->validate()) {
  950. return $this->getErrorSummary(false)[0];
  951. }
  952. $goods_list_url = "/cloud/user/userGetGoodsList";
  953. $cloud_token = get_platform_token();
  954. if (!$cloud_token) {
  955. return [
  956. 'code' => 1,
  957. 'msg' => '网络问题请重试',
  958. ];
  959. }
  960. $goods_list_data = [];
  961. $goods_list_data['access_token'] = $cloud_token; //获取供货商的token信息
  962. $goods_list_data['page'] = $this->page; //默认为 1
  963. $goods_list_data['limit'] = $this->limit; //默认20
  964. $admin = get_admin();
  965. $admin_id = $admin->id;
  966. if ($admin->username == 'admin') {
  967. $admin_id = null;
  968. }
  969. if ($this->type !== 1) {
  970. if ($admin_id) {
  971. $admin_model = Admin::findOne($admin_id);
  972. $area_level = $admin_model->area_level;
  973. // $query = Supplier::find()->where(['is_delete' => 0]);
  974. // if($area_level == 1){
  975. // $query->andWhere(
  976. // ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id, 'district_id' => $admin_model->district_id]);
  977. // } elseif ($area_level == 2){
  978. // $query->andWhere(
  979. // ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id]);
  980. // } elseif ($area_level == 3){
  981. // $query->andWhere(['province_id' => $admin_model->province_id]);
  982. // }
  983. // $supplier_id = $query->select('cloud_supplier_id')->column();
  984. // if ($supplier_id) {
  985. // $this->supplier_id = implode(',', $supplier_id);
  986. // } else {
  987. // return $this->outPutData(0,"获取成功", [
  988. // 'list' => []
  989. // ]);
  990. // }
  991. }
  992. }
  993. if($this->supplier_id) $goods_list_data['supplier_id'] = $this->supplier_id;
  994. //查询供货商
  995. if ($this->supplier_name) {
  996. $supplier_id_arr = Supplier::find()->where(['is_delete' => 0])->andWhere(['LIKE', 'supplier_name', $this->supplier_name])->select('cloud_supplier_id')->column();
  997. if ($supplier_id_arr) {
  998. if ($this->supplier_id) {
  999. $supplier_id_ = explode(',', $this->supplier_id);
  1000. $supplier_id_arr = array_merge($supplier_id_, $supplier_id_arr);
  1001. }
  1002. $goods_list_data['supplier_id'] = implode(',', $supplier_id_arr);
  1003. }
  1004. }
  1005. $store_id = get_store_id();
  1006. $store_cloud = StoreCloud::findOne(['store_id' => $store_id, 'is_delete' => 0]);
  1007. $cloud_store_id = $store_cloud->cloud_store_id;
  1008. if($this->name) $goods_list_data['name'] = $this->name; //商品名称
  1009. //@todo669
  1010. if($this->cat_id) $goods_list_data['cat_id'] = $this->cat_id;
  1011. if($this->id) $goods_list_data['id'] = $this->id; //商品名称
  1012. if($this->ids) $goods_list_data['ids'] = $this->ids; //商品名称
  1013. if($this->status) $goods_list_data['status'] = $this->status; //-1 全部 0 下架 1 上架
  1014. $goods_list_data['sort'] = isset($this->sort) ? $this->sort : 1;
  1015. if($this->sale_sort) $goods_list_data['sale_sort'] = $this->sale_sort;
  1016. if($this->price_sort) $goods_list_data['price_sort'] = $this->price_sort;
  1017. if($this->is_distribution) $goods_list_data['is_distribution'] = $this->is_distribution;
  1018. if($this->send_type) $goods_list_data['send_type'] = $this->send_type;
  1019. if($this->filter_goods_id) $goods_list_data['filter_goods_id'] = $this->filter_goods_id;
  1020. if($this->min_money) $goods_list_data['min_money'] = $this->min_money;
  1021. if($this->max_money) $goods_list_data['max_money'] = $this->max_money;
  1022. //传递云仓mch_id获取供货渠道比例
  1023. $goods_list_data['mch_id'] = $cloud_store_id;
  1024. $goodsListInfo = cloud_post($this->domain.$goods_list_url,$goods_list_data);
  1025. $goodsListInfo = json_decode($goodsListInfo,true);
  1026. if($goodsListInfo['code'] != 0){
  1027. $code = 1;//失败
  1028. return $this->outPutData($code,$goodsListInfo['msg']);
  1029. }else{
  1030. //获取议价比
  1031. // $content = Option::get('cloud', 0, 'saas');
  1032. // $content = json_decode($content['value'], true);
  1033. $content = Store::find()->where(['id' => get_store_id()])->select('rate')->asArray()->one();
  1034. $rate = $content['rate'];
  1035. //填充
  1036. if (!empty($goodsListInfo['data']['list'])) {
  1037. foreach ($goodsListInfo['data']['list'] as &$item) {
  1038. $sale_price_type = Option::get('sale_price_type', get_store_id(), 'store')['value'];
  1039. $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'];
  1040. if (!empty($item['attrs'])) {
  1041. $item['attrs'] = json_decode($item['attrs'], true);
  1042. if (!empty($item['attrs'])) {
  1043. foreach ($item['attrs'] as &$attr_item) {
  1044. if (!$attr_item['pic']) {
  1045. $attr_item['pic'] = $item['pic_url'];
  1046. }
  1047. //生成零售价
  1048. $sale_price_type = Option::get('sale_price_type', get_store_id(), 'store')['value'];
  1049. $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'];
  1050. $attr_item = array_merge($attr_item, ['sale_price' => $sale_price, 'rate' => $rate]);
  1051. //查询详情 * 供货渠道折扣
  1052. $attr_item['channel_platform_price'] = bcmul($sale_price, bcdiv($goodsListInfo['data']['channel_rate'], 10, 2), 2);
  1053. }
  1054. }
  1055. $item['attrs'] = json_encode($item['attrs'], JSON_UNESCAPED_UNICODE);
  1056. }
  1057. $item['channel_platform_price'] = bcmul($item['sale_price'], bcdiv($goodsListInfo['data']['channel_rate'], 10, 2), 2);
  1058. }
  1059. }
  1060. return $this->outPutData($goodsListInfo['code'],"获取成功",$goodsListInfo['data']);
  1061. }
  1062. }
  1063. //获取商品审核列表
  1064. public function goodsAuditList(){
  1065. if (!$this->validate()) {
  1066. return $this->getErrorSummary(false)[0];
  1067. }
  1068. $goods_list_url = "/cloud/user/userGetGoodsAuditList";
  1069. $cloud_token = get_platform_token();
  1070. if (!$cloud_token) {
  1071. return [
  1072. 'code' => 1,
  1073. 'msg' => '网络问题请重试',
  1074. ];
  1075. }
  1076. $goods_list_data = [];
  1077. $goods_list_data['access_token'] = $cloud_token; //获取供货商的token信息
  1078. $goods_list_data['page'] = $this->page; //默认为 1
  1079. $goods_list_data['limit'] = $this->limit; //默认20
  1080. $admin = get_admin();
  1081. $admin_id = $admin->id;
  1082. if ($admin->username == 'admin') {
  1083. $admin_id = null;
  1084. }
  1085. if ($admin_id) {
  1086. $admin_model = Admin::findOne($admin_id);
  1087. $area_level = $admin_model->area_level;
  1088. $query = Supplier::find()->where(['is_delete' => 0]);
  1089. if($area_level == 1){
  1090. $query->andWhere(
  1091. ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id, 'district_id' => $admin_model->district_id]);
  1092. } elseif ($area_level == 2){
  1093. $query->andWhere(
  1094. ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id]);
  1095. } elseif ($area_level == 3){
  1096. $query->andWhere(['province_id' => $admin_model->province_id]);
  1097. }
  1098. $supplier_id = $query->select('cloud_supplier_id')->column();
  1099. if ($supplier_id) {
  1100. $this->supplier_id = implode(',', $supplier_id);
  1101. } else {
  1102. return $this->outPutData(0,"获取成功",[
  1103. 'list' => []
  1104. ]);
  1105. }
  1106. }
  1107. if($this->supplier_id) $goods_list_data['supplier_id'] = $this->supplier_id;
  1108. if($this->cat_id) $goods_list_data['cat_id'] = $this->cat_id;
  1109. if($this->name) $goods_list_data['name'] = $this->name; //商品名称
  1110. if($this->status) $goods_list_data['status'] = $this->status; //0未审核 1成功 2拒绝
  1111. if($this->supplier_name) $goods_list_data['supplier_name'] = $this->supplier_name;
  1112. $goodsListInfo = cloud_post($this->domain.$goods_list_url,$goods_list_data);
  1113. $goodsListInfo = json_decode($goodsListInfo,true);
  1114. if($goodsListInfo['code'] != 0){
  1115. $code = 1;//失败
  1116. return $this->outPutData($code,$goodsListInfo['msg']);
  1117. }else{
  1118. if ($admin_id && empty($this->supplier_id)) {
  1119. $goodsListInfo['data'] = ['list' => []];
  1120. }
  1121. return $this->outPutData($goodsListInfo['code'],"获取成功",$goodsListInfo['data']);
  1122. }
  1123. }
  1124. //操作余额
  1125. public function setBalance(){
  1126. if (!$this->validate()) {
  1127. return $this->getErrorSummary(false)[0];
  1128. }
  1129. $balance_url = "/cloud/user/storeSetBalance";
  1130. $cloud_token = get_platform_token();
  1131. if (!$cloud_token) {
  1132. return [
  1133. 'code' => 1,
  1134. 'msg' => '网络问题请重试',
  1135. ];
  1136. }
  1137. $balance_data = [];
  1138. $balance_data['access_token'] = $cloud_token;
  1139. $balance_data['action_id'] = $this->action_id; //商户、供货商Id
  1140. $balance_data['type'] = $this->type; //0 减少 1 增加
  1141. $balance_data['status'] = $this->status; //0 用户 1 商户 2 供货商 0 暂时不考虑
  1142. $balance_data['desc'] = $this->desc; //备注
  1143. $balance_data['price'] = number_format($this->price, 2,".",""); //变动金额
  1144. $balanceInfo = cloud_post($this->domain.$balance_url,$balance_data);
  1145. $balanceInfo = json_decode($balanceInfo,true);
  1146. if($balanceInfo['code'] != 0){
  1147. $code = 1; //失败
  1148. return $this->outPutData($code,$balanceInfo['msg']);
  1149. }else{
  1150. return $this->outPutData($balanceInfo['code'],$balanceInfo['msg']);
  1151. }
  1152. }
  1153. //删除供货商
  1154. public function delSupplier(){
  1155. $del_url = "/cloud/user/storeSupplierDel";
  1156. $cloud_token = get_platform_token();
  1157. if (!$cloud_token) {
  1158. return [
  1159. 'code' => 1,
  1160. 'msg' => '网络问题请重试',
  1161. ];
  1162. }
  1163. $t = Yii::$app->db->beginTransaction();
  1164. $supplier = Supplier::find()->where(['cloud_supplier_id' => $this->supplier_id ,'is_delete' => 0])->one();
  1165. $admin = Admin::find()->where(['type'=> Admin::ADMIN_TYPE_SUPPLIER,'type_id'=>$supplier->attributes['id'] ,'is_delete' => 0 ])->one();
  1166. if ($supplier) {
  1167. $supplier->is_delete = 1;
  1168. $supplier->deleted_at = time();
  1169. if(!$supplier->save()){
  1170. $t->rollBack();
  1171. $code = 1; //失败
  1172. $msg = '删除失败,请重试';
  1173. return $this->outPutData($code,$msg);
  1174. }
  1175. }
  1176. if ($admin) {
  1177. $admin->is_delete = 1;
  1178. if(!$admin->save()){
  1179. $t->rollBack();
  1180. $code = 1; //失败
  1181. $msg = '删除失败,请重试';
  1182. return $this->outPutData($code,$msg);
  1183. }
  1184. }
  1185. $del_data = [];
  1186. $del_data['access_token'] = $cloud_token;
  1187. $del_data['supplier_id'] = $this->supplier_id;
  1188. $delInfo = cloud_post($this->domain.$del_url,$del_data);
  1189. $delInfo = json_decode($delInfo,true);
  1190. if($delInfo['code'] != 0){
  1191. $t->rollBack();
  1192. $code = 1; //失败
  1193. return $this->outPutData($code,$delInfo['msg']);
  1194. }else{
  1195. $t->commit();
  1196. return $this->outPutData($delInfo['code'],$delInfo['msg']);
  1197. }
  1198. }
  1199. //编辑供货商
  1200. public function editSupplier(){
  1201. $supplier = Supplier::find()->where(['cloud_supplier_id' => $this->id])->one();
  1202. if (empty($supplier)) {
  1203. $code = 1;
  1204. $msg = '查询不到数据,请稍后重试';
  1205. return $this->outPutData($code,$msg);
  1206. }
  1207. $supplier->name = $this->name;
  1208. !empty($this->password) && $supplier->password = $this->password;
  1209. $supplier->logo = $this->logo;
  1210. $supplier->phone = $this->tel;
  1211. $supplier->supplier_name = $this->supplier_name;
  1212. $supplier->type = $this->type;
  1213. $supplier->sale_day = $this->sale_day;
  1214. $supplier->certificate = $this->certificate;
  1215. $supplier->id_card_reverse = $this->id_card_reverse;
  1216. $supplier->id_card_front = $this->id_card_front;
  1217. $supplier->updated_at = time();
  1218. $supplier->status = (int)$this->status;
  1219. $supplier->phone = $this->tel;
  1220. $supplier->district_id = $this->district_id;
  1221. $supplier->city_id = $this->city_id;
  1222. $supplier->province_id = $this->province_id;
  1223. $supplier->rate = $this->rate;
  1224. if(!$supplier->save()) {
  1225. $code = 1;
  1226. $msg = '修改失败,请重试';
  1227. return $this->outPutData($code,$msg);
  1228. }
  1229. $edit_url = "/cloud/user/storeSupplierEdit";
  1230. $cloud_token = get_platform_token();
  1231. if (!$cloud_token) {
  1232. return [
  1233. 'code' => 1,
  1234. 'msg' => '网络问题请重试',
  1235. ];
  1236. }
  1237. $supplier_data['access_token'] = $cloud_token;
  1238. $supplier_data['name'] = $this->name;
  1239. !empty($this->password) && $supplier_data['pwd'] = $this->password;
  1240. $supplier_data['logo'] = $this->logo;
  1241. $supplier_data['supplier_name'] = $this->supplier_name;
  1242. $supplier_data['tel'] = $this->tel;
  1243. $supplier_data['email'] = $this->email;
  1244. $supplier_data['type'] = $this->type;
  1245. $supplier_data['certificate'] = $this->certificate;
  1246. $supplier_data['id_card_reverse'] = $this->id_card_reverse;
  1247. $supplier_data['id_card_front'] = $this->id_card_front;
  1248. $supplier_data['updated_at'] = time();
  1249. $supplier_data['sale_day'] = $this->sale_day;
  1250. if ($this->rate) {
  1251. $supplier_data['rate'] = $this->rate;
  1252. }
  1253. $supplier_data['status'] = (int)$this->status;
  1254. $supplier_data['user_id'] = $supplier->cloud_user_id;
  1255. $supplier_data['supplier_id'] = $this->id;
  1256. \Yii::error($supplier_data, "供货商信息");
  1257. $editInfo = cloud_post($this->domain.$edit_url,$supplier_data);
  1258. $editInfo = json_decode($editInfo,true);
  1259. if (!empty($this->password)) {
  1260. $admin = Admin::findOne(['type' => "supplier" , 'type_id' => $supplier->id]);
  1261. $admin->password = \Yii::$app->security->generatePasswordHash($this->password);
  1262. if (!$admin->save()) {
  1263. return $this->outPutData(1,"管理员信息保存失败");
  1264. };
  1265. }
  1266. if($editInfo['code'] != 0){
  1267. $code = 1;
  1268. return $this->outPutData($code,$editInfo['msg']);
  1269. }else{
  1270. return $this->outPutData($editInfo['code'],$editInfo['msg']);
  1271. }
  1272. }
  1273. //修改供货商状态
  1274. public function setSupplierStatus(){
  1275. $del_url = "/cloud/user/storeSupplierDel";
  1276. $cloud_token = get_platform_token();
  1277. if (!$cloud_token) {
  1278. return [
  1279. 'code' => 1,
  1280. 'msg' => '网络问题请重试',
  1281. ];
  1282. }
  1283. $t = Yii::$app->db->beginTransaction();
  1284. $supplier = Supplier::find()->where(['cloud_supplier_id' => $this->supplier_id ,'is_delete' => 0])->andWhere(['<>', 'status', '1'])->one();
  1285. if ($supplier && in_array($this->status, [1, 2])) {
  1286. $supplier->status = $this->status;
  1287. $supplier->updated_at = time();
  1288. if(!$supplier->save()){
  1289. $t->rollBack();
  1290. $code = 1; //失败
  1291. $msg = '操作失败,请重试';
  1292. return $this->outPutData($code,$msg);
  1293. }
  1294. }
  1295. $del_data['access_token'] = $cloud_token;
  1296. $del_data['supplier_id'] = $this->supplier_id;
  1297. $del_data['status'] = (int)$this->status;
  1298. $del_data['type'] = 1;
  1299. $delInfo = cloud_post($this->domain.$del_url,$del_data);
  1300. $delInfo = json_decode($delInfo,true);
  1301. if($delInfo['code'] != 0){
  1302. $t->rollBack();
  1303. $code = 1; //失败
  1304. return $this->outPutData($code,$delInfo['msg']);
  1305. }else{
  1306. $t->commit();
  1307. $res = NoticeSend::AgentExamine($supplier->id, 1);
  1308. if (isset($res['code']) && $res['code'] !== 0) {
  1309. debug_log($res, 'sms.log');
  1310. }
  1311. return $this->outPutData($delInfo['code'],$delInfo['msg']);
  1312. }
  1313. }
  1314. //供货商列表
  1315. public function listSupplier(){
  1316. if (!\Yii::$app->isSaas()) {
  1317. return [
  1318. 'code' => 0
  1319. ];
  1320. }
  1321. $list_url = "/cloud/user/storeSupplierList";
  1322. $cloud_token = get_platform_token();
  1323. if (!$cloud_token) {
  1324. return [
  1325. 'code' => 0,
  1326. 'msg' => '网络问题请重试',
  1327. ];
  1328. }
  1329. //注册云台的平台用户
  1330. $list_data = [];
  1331. $list_data['access_token'] = $cloud_token;
  1332. $list_data['page'] = $this->page;
  1333. $list_data['limit'] = $this->limit;
  1334. $list_data['status'] = $this->status;
  1335. $admin = get_admin();
  1336. $admin_id = $admin->id;
  1337. if ($admin->username == 'admin') {
  1338. $admin_id = null;
  1339. }
  1340. if ($admin->type === Admin::ADMIN_TYPE_DEFAULT) {
  1341. $admin_id = null;
  1342. }
  1343. if ($admin->type === Admin::ADMIN_TYPE_GOODS_AGENT) {
  1344. // $form = new AgentForm();
  1345. // $result = $form->getSupplier($admin->id);
  1346. // if ($result['code'] === 0) {
  1347. // $this->ids = $result['data'];
  1348. // } else {
  1349. // return $result;
  1350. // }
  1351. }
  1352. if ($admin_id) {
  1353. $admin_model = Admin::findOne($admin_id);
  1354. $area_level = $admin_model->area_level;
  1355. $query = Supplier::find()->where(['is_delete' => 0]);
  1356. if($area_level == 1){
  1357. $query->andWhere(
  1358. ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id, 'district_id' => $admin_model->district_id]);
  1359. } elseif ($area_level == 2){
  1360. $query->andWhere(
  1361. ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id]);
  1362. } elseif ($area_level == 3){
  1363. $query->andWhere(['province_id' => $admin_model->province_id]);
  1364. }
  1365. $ids = $query->select('cloud_supplier_id')->column();
  1366. if ($ids) {
  1367. $this->ids = $ids;
  1368. } else {
  1369. return $this->outPutData(0, '获取成功', [
  1370. 'list' => []
  1371. ]);
  1372. }
  1373. }
  1374. if ($this->tel) $list_data['tel'] = $this->tel;
  1375. if ($this->name) $list_data['supplier_name'] = $this->name;
  1376. if ($this->ids) {
  1377. if(is_array($this->ids)){
  1378. $this->ids = implode(',', $this->ids);
  1379. }
  1380. $list_data['ids'] = $this->ids;
  1381. $list_url = "/cloud/user/storeSupplierListByIds";
  1382. }
  1383. //获取云仓数据
  1384. $listInfo = cloud_post($this->domain.$list_url,$list_data);
  1385. $listInfo = json_decode($listInfo,true);
  1386. //获取数据库数据
  1387. if($listInfo['code'] != 0){
  1388. $code = 0;
  1389. return $this->outPutData($code,$listInfo['msg']);
  1390. }else{
  1391. $code = 0;
  1392. $msg = "获取成功";
  1393. foreach ($listInfo['data']['list'] as &$item) {
  1394. $supplier = Supplier::find()->where(['is_delete' => 0, 'cloud_supplier_id' => $item['id']])
  1395. ->select("district_id, province_id, city_id")->asArray()->one();
  1396. $item['district_id'] = $supplier['district_id'] ?: '';
  1397. $item['province_id'] = $supplier['province_id'] ?: '';
  1398. $item['city_id'] = $supplier['city_id'] ?: '';
  1399. $item['supplier_info'] = Supplier::find()->select(['id', 'supplier_name', 'logo', 'custom_form'])->where(['cloud_supplier_id' => $item['id']])->one();
  1400. }
  1401. return $this->outPutData($code,$msg,$listInfo['data']);
  1402. }
  1403. }
  1404. //审核商品
  1405. public function auditHandle()
  1406. {
  1407. try {
  1408. $list_url = "/cloud/user/userGetGoodsAuditHandle";
  1409. $cloud_token = get_platform_token();
  1410. if (!$cloud_token) {
  1411. return [
  1412. 'code' => 1,
  1413. 'msg' => '网络问题请重试',
  1414. ];
  1415. }
  1416. //注册云台的平台用户
  1417. $list_data = [];
  1418. $list_data['access_token'] = $cloud_token;
  1419. $list_data['status'] = $this->status;
  1420. $list_data['desc'] = $this->desc;
  1421. $list_data['id'] = $this->id ?? 0;
  1422. $list_data['ids'] = $this->ids;
  1423. if ($this->name) $list_data['name'] = $this->name;
  1424. //获取云仓数据
  1425. $listInfo = cloud_post($this->domain.$list_url,$list_data);
  1426. $listInfo = json_decode($listInfo,true);
  1427. //获取数据库数据
  1428. if($listInfo['code'] != 0){
  1429. $code = 1;
  1430. return $this->outPutData($code,$listInfo['msg']);
  1431. }else{
  1432. $code = 0;
  1433. $msg = "获取成功";
  1434. if ((int)$this->status === 1 && $listInfo['data']) {
  1435. $cloud_goods_id = $listInfo['data'];
  1436. $form = new GoodsForm();
  1437. //找出商品未审核或者未更新的产品
  1438. $CloudGoodsUpdateLog = CloudGoodsUpdateLog::find()->where(['cloud_goods_id' => $cloud_goods_id])->asArray()->all();
  1439. foreach ($CloudGoodsUpdateLog as $value) {
  1440. //直接通过审核(目前只有点击审核通过时才会调用此事件)
  1441. $item = CloudGoodsUpdateLog::findOne($value['id']);
  1442. $item->is_audit = 1;
  1443. $item->updated_at = time();
  1444. $item->save();
  1445. //判断是否开启自动更新
  1446. $cloud_is_update = Option::get('cloud_is_update', $value['store_id'], 'store')['value'];
  1447. if ((int)$cloud_is_update > 0) {
  1448. //更新产品逻辑
  1449. if ($value['goods_id']) {
  1450. $StoreCloud = StoreCloud::findOne(['store_id' => $value['store_id'], 'is_delete' => 0, 'is_enable' => 1]);
  1451. $form->id = $value['cloud_goods_id'];
  1452. $form->store_id =$value['store_id'];
  1453. $goodsInfo = $form->saveCloudGoods();
  1454. $merchantForm = new MerchantForm();
  1455. $merchantForm->token_stroe_cloud_id = $StoreCloud->id;
  1456. $result = $merchantForm->mchGoodsImport($goodsInfo['cloudBindInfo'], $goodsInfo['goods_id'], $value['store_id']);
  1457. if ((int)$result['code'] !== 0) {
  1458. return $result;
  1459. }
  1460. }
  1461. }
  1462. }
  1463. }
  1464. return $this->outPutData($code,$msg,$listInfo['data']);
  1465. }
  1466. } catch (\Exception $e) {
  1467. return [
  1468. 'code' => 1,
  1469. 'msg' => $e->getMessage()
  1470. ];
  1471. }
  1472. }
  1473. //创建云仓账号
  1474. public function createSupplier()
  1475. {
  1476. if (!$this->validate()) {
  1477. return [
  1478. 'code' => 1,
  1479. 'msg' => $this->getErrorSummary(false)[0]
  1480. ];
  1481. }
  1482. $admin = new Admin();
  1483. if (Admin::findOne(['username' => $this->name, 'is_delete' => 0])) {
  1484. $code = 1;
  1485. $msg = '登陆账号已经存在';
  1486. return $this->outPutData($code,$msg);
  1487. }
  1488. // if ($this->tel) {
  1489. // if (Admin::findOne(['mobile' => $this->tel, 'is_delete' => 0])) {
  1490. // $code = 1;
  1491. // $msg = '手机号已经存在';
  1492. // return $this->outPutData($code,$msg);
  1493. // }
  1494. // }
  1495. //获取平台token
  1496. $cloud_token = get_platform_token();
  1497. if (!$cloud_token) {
  1498. return [
  1499. 'code' => 1,
  1500. 'msg' => '平台未申请云仓账户',
  1501. ];
  1502. }
  1503. $member_url = "/cloud/user/storeUserAdd";
  1504. $check_member_url = "/cloud/user/storeUserList";
  1505. $supplier_url = "/cloud/user/storeSupplierAdd";
  1506. $check_supplier_url = "/cloud/user/storeSupplierList";
  1507. //注册云台的平台用户
  1508. $check_supplier_data = $check_member_data = $member_data = $supplier_data = [];
  1509. //注册云台的平台用户
  1510. $check_member_data['access_token'] = $cloud_token;
  1511. $check_member_data['name'] = $this->name;
  1512. $checkMemberInfo = cloud_post($this->domain.$check_member_url,$check_member_data);
  1513. if(!$checkMemberInfo){
  1514. $code = 1;
  1515. $msg = "创建失败";
  1516. return $this->outPutData($code,$msg);
  1517. }
  1518. $checkMemberInfo = json_decode($checkMemberInfo,true);
  1519. if($checkMemberInfo['code'] == 0 && isset($checkMemberInfo['data']['list'][0]['id']) && $checkMemberInfo['data']['list'][0]['id']>0){
  1520. $memberInfo['data'] = $checkMemberInfo['data']['list'][0];
  1521. $memberInfo['data']['user_id'] = $checkMemberInfo['data']['list'][0]['id'];
  1522. }else{
  1523. $member_data['access_token'] = $cloud_token;
  1524. $member_data['name'] = $this->name;
  1525. $member_data['pwd'] = $this->password;
  1526. $member_data['tel'] = $this->tel;
  1527. $member_data['email'] = $this->email;
  1528. $member_data['avatar_url'] = $this->logo;
  1529. $memberInfo = cloud_post($this->domain.$member_url,$member_data);
  1530. $memberInfo = json_decode($memberInfo,true);
  1531. if($memberInfo['code'] != 0){
  1532. $code = 1;
  1533. return $this->outPutData($code,$memberInfo['msg']);
  1534. }
  1535. }
  1536. $check_supplier_data['access_token'] = $cloud_token;
  1537. $check_supplier_data['name'] = $this->name;
  1538. $checkSupplierInfo = cloud_post($this->domain.$check_supplier_url,$check_supplier_data);
  1539. if(!$checkSupplierInfo){
  1540. $code = 1;
  1541. $msg = "创建供货商失败";
  1542. return $this->outPutData($code,$msg);
  1543. }
  1544. $content = Option::get('cloud', 0, 'saas')['value'];
  1545. if ($content) {
  1546. $content = json_decode($content, true);
  1547. }
  1548. $checkSupplierInfo = json_decode($checkSupplierInfo,true);
  1549. if($checkSupplierInfo['code'] == 0 && isset($checkSupplierInfo['data']['list'][0]['id']) && $checkSupplierInfo['data']['list'][0]['id']>0){
  1550. $supplierInfo['data'] = $checkSupplierInfo['data']['list'][0];
  1551. $supplierInfo['data']['supplier_id'] = $checkSupplierInfo['data']['list'][0]['id'];
  1552. }else{
  1553. //注册云台的供货商账户
  1554. $supplier_data['access_token'] = $cloud_token;
  1555. $supplier_data['user_id'] = $memberInfo['data']['user_id'];
  1556. $supplier_data['supplier_name'] = $this->supplier_name;
  1557. $supplier_data['name'] = $this->name;
  1558. $supplier_data['logo'] = $this->logo;
  1559. $supplier_data['tel'] = $this->tel;
  1560. $supplier_data['type'] = $this->type;
  1561. $supplier_data['status'] = 0;
  1562. $supplier_data['certificate'] = $this->certificate;
  1563. $supplier_data['id_card_reverse'] = $this->id_card_reverse;
  1564. $supplier_data['id_card_front'] = $this->id_card_front;
  1565. $supplier_data['sale_day'] = !empty($this->sale_day) ? $this->sale_day : ($content['sale_day'] ?: 0);
  1566. if ($this->rate) {
  1567. $supplier_data['rate'] = $this->rate;
  1568. }
  1569. $supplierInfo = cloud_post($this->domain.$supplier_url,$supplier_data);
  1570. $supplierInfo = json_decode($supplierInfo,true);
  1571. if($supplierInfo['code'] != 0){
  1572. $code = 1;
  1573. return $this->outPutData($code,$supplierInfo['msg']);
  1574. }
  1575. }
  1576. //写入本地数据库 开始
  1577. $t = Yii::$app->db->beginTransaction();
  1578. $admin->username = $this->name;
  1579. $admin->mobile = $this->tel;
  1580. $admin->password = Yii::$app->security->generatePasswordHash($this->password);
  1581. $admin->type = Admin::ADMIN_TYPE_SUPPLIER;
  1582. $admin->save();
  1583. if ($admin->attributes['id'] <= 0){
  1584. $t->rollBack();
  1585. $code = 1;
  1586. $msg = '创建云仓用户失败';
  1587. return $this->outPutData($code,$msg);
  1588. }
  1589. $supplier = new Supplier();
  1590. $supplier->name = $this->name;
  1591. $supplier->password = $this->password;
  1592. $supplier->supplier_name = $this->supplier_name;
  1593. if ($this->supplier_name == '胜天半子') {
  1594. $supplier->is_stbz = 1;
  1595. }
  1596. $supplier->logo = $this->logo;
  1597. $supplier->phone = $this->tel;
  1598. $supplier->type = $this->type;
  1599. $supplier->status = 0;
  1600. $supplier->certificate = $this->certificate;
  1601. $supplier->id_card_reverse = $this->id_card_reverse;
  1602. $supplier->id_card_front = $this->id_card_front;
  1603. $supplier->created_at = time();
  1604. $supplier->admin_id = $admin->attributes['id'];
  1605. $supplier->cloud_user_id = $memberInfo['data']['user_id'];
  1606. $supplier->cloud_supplier_id = $supplierInfo['data']['supplier_id'];
  1607. // $supplier->sale_day = $this->sale_day;
  1608. $supplier->sale_day = !empty($this->sale_day) ? $this->sale_day : ($content['sale_day'] ?: 0);
  1609. $supplier->saas_user_id = $this->saas_user_id ?: 0;
  1610. $supplier->district_id = $this->district_id;
  1611. $supplier->city_id = $this->city_id;
  1612. $supplier->province_id = $this->province_id;
  1613. $supplier->rate = $this->rate;
  1614. $supplier->custom_form = $this->supplier_custom_form;
  1615. $supplier_token = get_cloud_token($this->name,$this->password);
  1616. if($supplier_token['taken']) {
  1617. $supplier->access_token = $supplier_token['taken'];
  1618. $supplier->access_token_time = time();
  1619. }
  1620. $supplier->save();
  1621. if ($supplier->attributes['id']<=0){
  1622. $t->rollBack();
  1623. $code = 1;
  1624. $msg = '创建云仓用户失败';
  1625. return $this->outPutData($code,$msg);
  1626. }
  1627. $admin->type_id = $supplier->attributes['id']; //设置关系
  1628. $admin->save();
  1629. $t->commit();
  1630. //写入本地数据库 结束
  1631. $code = 0;
  1632. $msg = '注册成功';
  1633. return $this->outPutData($code,$msg, ['cloud_supplier_id' => $supplier->cloud_supplier_id]);
  1634. }
  1635. public function saveGoodsCat()
  1636. {
  1637. try {
  1638. //获取平台token
  1639. $cloud_token = get_platform_token();
  1640. if (!$cloud_token) {
  1641. return [
  1642. 'code' => 1,
  1643. 'msg' => '网络问题请重试',
  1644. ];
  1645. }
  1646. $saveGoodsCateUrl = "/cloud/user/saveCat";
  1647. $saveGoodsCateData['access_token'] = $cloud_token;
  1648. $saveGoodsCateData['parent_id'] = $this->parent_id;
  1649. $saveGoodsCateData['is_show'] = $this->is_show;
  1650. $saveGoodsCateData['name'] = $this->name;
  1651. $saveGoodsCateData['pic_url'] = $this->pic_url;
  1652. $saveGoodsCateData['sort'] = $this->sort ?: 100;
  1653. $saveGoodsCateData['id'] = $this->id;
  1654. if (isset($this->shop_count)) {
  1655. $saveGoodsCateData['shop_count'] = $this->shop_count;
  1656. }
  1657. $saveGoodsCateInfo = cloud_post($this->domain.$saveGoodsCateUrl,$saveGoodsCateData);
  1658. $saveGoodsCateInfo = json_decode($saveGoodsCateInfo,true);
  1659. if($saveGoodsCateInfo['code'] != 0){
  1660. throw new \Exception($saveGoodsCateInfo['msg']);
  1661. }
  1662. return $this->outPutData(0, $saveGoodsCateInfo['msg']);
  1663. } catch (\Exception $e) {
  1664. return $this->outPutData(1, $e->getMessage());
  1665. }
  1666. }
  1667. public function getGoodsCatList()
  1668. {
  1669. try {
  1670. //获取平台token
  1671. $cloud_token = get_platform_token();
  1672. if (!$cloud_token) {
  1673. return [
  1674. 'code' => 1,
  1675. 'msg' => '网络问题请重试',
  1676. ];
  1677. }
  1678. $getGoodsCateUrl = "/cloud/user/getCatList";
  1679. $getGoodsCateData['access_token'] = $cloud_token;
  1680. $getGoodsCateData['is_show'] = $this->is_show ?: 0;
  1681. $getGoodsCateInfo = cloud_post($this->domain.$getGoodsCateUrl,$getGoodsCateData);
  1682. $getGoodsCateInfo = json_decode($getGoodsCateInfo,true);
  1683. if($getGoodsCateInfo['code'] != 0){
  1684. throw new \Exception($getGoodsCateInfo['msg']);
  1685. }
  1686. return $this->outPutData(0, $getGoodsCateInfo['msg'], $getGoodsCateInfo['data']);
  1687. } catch (\Exception $e) {
  1688. return $this->outPutData(1, $e->getMessage());
  1689. }
  1690. }
  1691. public function catChange()
  1692. {
  1693. try {
  1694. //获取平台token
  1695. $cloud_token = get_platform_token();
  1696. if (!$cloud_token) {
  1697. return [
  1698. 'code' => 1,
  1699. 'msg' => '网络问题请重试',
  1700. ];
  1701. }
  1702. $getGoodsCateUrl = "/cloud/user/catChange";
  1703. $getGoodsCateData['access_token'] = $cloud_token;
  1704. $getGoodsCateData['parent_id'] = $this->parent_id ?: 0;
  1705. $getGoodsCateData['id'] = $this->id ?: 0;
  1706. $getGoodsCateData['list'] = $this->list ?? '';
  1707. $getGoodsCateInfo = cloud_post($this->domain.$getGoodsCateUrl,$getGoodsCateData);
  1708. $getGoodsCateInfo = json_decode($getGoodsCateInfo,true);
  1709. if($getGoodsCateInfo['code'] != 0){
  1710. throw new \Exception($getGoodsCateInfo['msg']);
  1711. }
  1712. return $this->outPutData(0, $getGoodsCateInfo['msg'], $getGoodsCateInfo['data']);
  1713. } catch (\Exception $e) {
  1714. return $this->outPutData(1, $e->getMessage());
  1715. }
  1716. }
  1717. public function getCatListChildren()
  1718. {
  1719. try {
  1720. //获取平台token
  1721. $cloud_token = get_platform_token();
  1722. if (!$cloud_token) {
  1723. return [
  1724. 'code' => 1,
  1725. 'msg' => '网络问题请重试',
  1726. ];
  1727. }
  1728. $getGoodsCateUrl = "/cloud/user/getCatListChildren";
  1729. $getGoodsCateData['access_token'] = $cloud_token;
  1730. $getGoodsCateData['parent_id'] = $this->parent_id;
  1731. $getGoodsCateInfo = cloud_post($this->domain.$getGoodsCateUrl,$getGoodsCateData);
  1732. $getGoodsCateInfo = json_decode($getGoodsCateInfo,true);
  1733. if($getGoodsCateInfo['code'] != 0){
  1734. throw new \Exception($getGoodsCateInfo['msg']);
  1735. }
  1736. return $this->outPutData(0, $getGoodsCateInfo['msg'], $getGoodsCateInfo['data']);
  1737. } catch (\Exception $e) {
  1738. return $this->outPutData(1, $e->getMessage());
  1739. }
  1740. }
  1741. public function getGoodsCatName()
  1742. {
  1743. try {
  1744. //获取平台token
  1745. $cloud_token = get_platform_token();
  1746. if (!$cloud_token) {
  1747. return [
  1748. 'code' => 1,
  1749. 'msg' => '网络问题请重试',
  1750. ];
  1751. }
  1752. $getGoodsCateUrl = "/cloud/user/getCatList";
  1753. $getGoodsCateData['access_token'] = $cloud_token;
  1754. $getGoodsCateData['is_show'] = $this->is_show ?: 0;
  1755. $getGoodsCateInfo = cloud_post($this->domain.$getGoodsCateUrl,$getGoodsCateData);
  1756. $getGoodsCateInfo = json_decode($getGoodsCateInfo,true);
  1757. if($getGoodsCateInfo['code'] != 0){
  1758. throw new \Exception($getGoodsCateInfo['msg']);
  1759. }
  1760. return $this->outPutData(0, $getGoodsCateInfo['msg'], $getGoodsCateInfo['data_name']);
  1761. } catch (\Exception $e) {
  1762. return $this->outPutData(1, $e->getMessage());
  1763. }
  1764. }
  1765. //删除
  1766. public function goodsCatDel()
  1767. {
  1768. try {
  1769. //获取平台token
  1770. $cloud_token = get_platform_token();
  1771. if (!$cloud_token) {
  1772. return [
  1773. 'code' => 1,
  1774. 'msg' => '网络问题请重试',
  1775. ];
  1776. }
  1777. $getGoodsCateUrl = "/cloud/user/catDel";
  1778. $getGoodsCateData['access_token'] = $cloud_token;
  1779. $getGoodsCateData['ids'] = $this->ids;
  1780. $getGoodsCateData['type'] = $this->type;
  1781. $getGoodsCateInfo = cloud_post($this->domain.$getGoodsCateUrl,$getGoodsCateData);
  1782. $getGoodsCateInfo = json_decode($getGoodsCateInfo,true);
  1783. if($getGoodsCateInfo['code'] != 0){
  1784. throw new \Exception($getGoodsCateInfo['msg']);
  1785. }
  1786. return $this->outPutData(0, $getGoodsCateInfo['msg']);
  1787. } catch (\Exception $e) {
  1788. return $this->outPutData(1, $e->getMessage());
  1789. }
  1790. }
  1791. //更改配送单状态
  1792. //用户下单->店铺转单到供货商->供货商生成集采配送单->供货商发货->仓库收货->仓库投篮【生成分拣单,给分拣单里面加产品】->分拣完成->根据分拣单生成线路配送单
  1793. public function setDistributionStatus()
  1794. {
  1795. $t = \Yii::$app->db->beginTransaction();
  1796. try {
  1797. //获取平台token
  1798. $cloud_token = get_platform_token();
  1799. if (!$cloud_token) {
  1800. return [
  1801. 'code' => 1,
  1802. 'msg' => '网络问题请重试',
  1803. ];
  1804. }
  1805. //配货单收货
  1806. if (intval($this->status) === 2) {
  1807. $ids = explode(',', $this->ids);
  1808. foreach ($ids as $id_item) {
  1809. $form = new SupplierForm();
  1810. $result = $form->agentOrderDistributionList($id_item, 1);
  1811. if (!$result['code']) {
  1812. foreach ($result['data']['data'] as $data_item) {
  1813. foreach ($data_item['mch_goods'] as $mch_goods_item) {
  1814. foreach ($mch_goods_item['mch_order'] as $mch_order_item) {
  1815. $md_id = $mch_order_item['md_id'];
  1816. $driverMdBind = DriverMdBind::findOne(['md_id' => $md_id, 'is_delete' => 0]);
  1817. if (!$driverMdBind) {
  1818. throw new \Exception('当前门店未绑定线路 不可收货');
  1819. }
  1820. foreach ($mch_order_item['md_order'] as $md_order_item) {
  1821. $goods_attr = json_decode($md_order_item['goods_attr'], true);
  1822. $attr_id = array_column($goods_attr['attr_list'], 'attr_id');
  1823. sort($attr_id);
  1824. $agentFrontCentralizeGoods = AgentFrontCentralizeGoods::findOne([
  1825. 'cloud_goods_id' => $md_order_item['goods_id'],
  1826. 'attr' => json_encode($attr_id),
  1827. 'centralize_goods_type' => $md_order_item['centralize_goods_type'],
  1828. 'front_admin_id' => get_admin()->id,
  1829. 'status' => AgentFrontCentralizeGoods::STATUS_SORTING
  1830. ]);
  1831. if (!$agentFrontCentralizeGoods) {
  1832. $agentFrontCentralizeGoods = new AgentFrontCentralizeGoods();
  1833. $agentFrontCentralizeGoods->front_admin_id = get_admin()->id;
  1834. $agentFrontCentralizeGoods->cloud_goods_id = $md_order_item['goods_id'];
  1835. $agentFrontCentralizeGoods->attr = json_encode($attr_id);
  1836. $agentFrontCentralizeGoods->attr_info = $md_order_item['goods_attr'];
  1837. $agentFrontCentralizeGoods->goods_no = $md_order_item['goods_no'];
  1838. $agentFrontCentralizeGoods->goods_name = $md_order_item['goods_name'];
  1839. $agentFrontCentralizeGoods->pic_url = $md_order_item['pic_url'];
  1840. $agentFrontCentralizeGoods->centralize_goods_type = $md_order_item['centralize_goods_type'];
  1841. $agentFrontCentralizeGoods->supplier_id = $data_item['supplier_id'];
  1842. }
  1843. $agentFrontCentralizeGoods->goods_num += $md_order_item['goods_num'];
  1844. if (!$agentFrontCentralizeGoods->save()) {
  1845. throw new \Exception(implode(';', array_values($agentFrontCentralizeGoods->firstErrors)));
  1846. }
  1847. //判断是否重复插入
  1848. $agentFrontCentralizeGoodsLog = AgentFrontCentralizeGoodsLog::findOne([
  1849. 'centralize_goods_id' => $agentFrontCentralizeGoods->id,
  1850. 'cloud_order_id' => $md_order_item['order_id'],
  1851. 'md_id' => $mch_order_item['md_id']
  1852. ]);
  1853. if ($agentFrontCentralizeGoodsLog) {
  1854. throw new \Exception('重复插入数据');
  1855. }
  1856. $agentFrontCentralizeGoodsExt = AgentFrontCentralizeGoodsExt::findOne([
  1857. 'centralize_goods_id' => $agentFrontCentralizeGoods->id,
  1858. 'md_id' => $mch_order_item['md_id'],
  1859. 'status' => AgentFrontCentralizeGoodsExt::STATUS_WAIT_SORTING
  1860. ]);
  1861. if (!$agentFrontCentralizeGoodsExt) {
  1862. $agentFrontCentralizeGoodsExt = new AgentFrontCentralizeGoodsExt();
  1863. $agentFrontCentralizeGoodsExt->goods_num = 0;
  1864. }
  1865. $agentFrontCentralizeGoodsExt->centralize_goods_id = $agentFrontCentralizeGoods->id;
  1866. // $agentFrontCentralizeGoodsExt->cloud_order_id = $md_order_item['order_id'];
  1867. $agentFrontCentralizeGoodsExt->md_id = $mch_order_item['md_id'];
  1868. $agentFrontCentralizeGoodsExt->goods_num += $md_order_item['goods_num'];
  1869. if (!$agentFrontCentralizeGoodsExt->save()) {
  1870. throw new \Exception(implode(';', array_values($agentFrontCentralizeGoodsExt->firstErrors)));
  1871. }
  1872. //判断是否重复插入
  1873. $agentFrontCentralizeGoodsLog = new AgentFrontCentralizeGoodsLog();
  1874. $agentFrontCentralizeGoodsLog->centralize_goods_id = $agentFrontCentralizeGoods->id;
  1875. $agentFrontCentralizeGoodsLog->cloud_order_id = $md_order_item['order_id'];
  1876. $agentFrontCentralizeGoodsLog->md_id = $mch_order_item['md_id'];
  1877. $agentFrontCentralizeGoodsLog->save();
  1878. if (!$agentFrontCentralizeGoodsLog->save()) {
  1879. throw new \Exception(implode(';', array_values($agentFrontCentralizeGoodsLog->firstErrors)));
  1880. }
  1881. }
  1882. }
  1883. }
  1884. }
  1885. }
  1886. }
  1887. }
  1888. $getGoodsCateUrl = "/cloud/user/setDistributionStatus";
  1889. $getGoodsCateData['access_token'] = $cloud_token;
  1890. $getGoodsCateData['ids'] = $this->ids;
  1891. $getGoodsCateData['status'] = $this->status;
  1892. $getGoodsCateData['admin_id'] = get_admin()->id;
  1893. $getGoodsCateInfo = cloud_post($this->domain.$getGoodsCateUrl,$getGoodsCateData);
  1894. $getGoodsCateInfo = json_decode($getGoodsCateInfo,true);
  1895. if($getGoodsCateInfo['code'] != 0){
  1896. debug_log(['getGoodsCateInfo' => $getGoodsCateInfo], 'setDistributionStatus.log');
  1897. }
  1898. $t->commit();
  1899. return $this->outPutData(0, $getGoodsCateInfo['msg']);
  1900. } catch (\Exception $e) {
  1901. debug_log([
  1902. 'message' => $e->getMessage(),
  1903. 'line' => $e->getLine(),
  1904. 'file' => $e->getFile()
  1905. ], 'setDistributionStatus.log');
  1906. $t->rollBack();
  1907. return $this->outPutData(1, $e->getMessage());
  1908. }
  1909. }
  1910. //会员等级列表
  1911. public function userLevelSearch () {
  1912. try {
  1913. //获取平台token
  1914. $cloud_token = get_platform_token();
  1915. if (!$cloud_token) {
  1916. return [
  1917. 'code' => 1,
  1918. 'msg' => '网络问题请重试',
  1919. ];
  1920. }
  1921. $getGoodsCateUrl = "/cloud/user/userLevelSearch";
  1922. $getGoodsCateData['access_token'] = $cloud_token;
  1923. $getGoodsCateData['name'] = $this->name;
  1924. $getGoodsCateData['page'] = $this->page;
  1925. $getGoodsCateData['limit'] = $this->limit;
  1926. //$getGoodsCateData['status'] = (int)$this->status;
  1927. $getGoodsCateInfo = cloud_post($this->domain.$getGoodsCateUrl,$getGoodsCateData);
  1928. $getGoodsCateInfo = json_decode($getGoodsCateInfo,true);
  1929. if($getGoodsCateInfo['code'] != 0){
  1930. throw new \Exception($getGoodsCateInfo['msg']);
  1931. }
  1932. return $this->outPutData(0, $getGoodsCateInfo['msg'], $getGoodsCateInfo['data']);
  1933. } catch (\Exception $e) {
  1934. return $this->outPutData(1, $e->getMessage());
  1935. }
  1936. }
  1937. //会员等级列表
  1938. public function setUserLevelStatus () {
  1939. try {
  1940. //获取平台token
  1941. $cloud_token = get_platform_token();
  1942. if (!$cloud_token) {
  1943. return [
  1944. 'code' => 1,
  1945. 'msg' => '网络问题请重试',
  1946. ];
  1947. }
  1948. $getGoodsCateUrl = "/cloud/user/setUserLevelStatus";
  1949. $getGoodsCateData['access_token'] = $cloud_token;
  1950. $getGoodsCateData['id'] = $this->id;
  1951. $getGoodsCateData['status'] = $this->status;
  1952. $getGoodsCateInfo = cloud_post($this->domain.$getGoodsCateUrl,$getGoodsCateData);
  1953. $getGoodsCateInfo = json_decode($getGoodsCateInfo,true);
  1954. if($getGoodsCateInfo['code'] != 0){
  1955. throw new \Exception($getGoodsCateInfo['msg']);
  1956. }
  1957. return $this->outPutData(0, $getGoodsCateInfo['msg']);
  1958. } catch (\Exception $e) {
  1959. return $this->outPutData(1, $e->getMessage());
  1960. }
  1961. }
  1962. //会员等级列表
  1963. public function setUserLevel () {
  1964. try {
  1965. //获取平台token
  1966. $cloud_token = get_platform_token();
  1967. if (!$cloud_token) {
  1968. return [
  1969. 'code' => 1,
  1970. 'msg' => '网络问题请重试',
  1971. ];
  1972. }
  1973. $status = $this->status ?? 1;
  1974. $getGoodsCateUrl = "/cloud/user/setUserLevel";
  1975. $getGoodsCateData['access_token'] = $cloud_token;
  1976. $getGoodsCateData['level'] = (int)$this->level;
  1977. $getGoodsCateData['name'] = $this->name;
  1978. $getGoodsCateData['profit'] = $this->profit;
  1979. $getGoodsCateData['price'] = $this->price;
  1980. $getGoodsCateData['status'] = (int)$status;
  1981. $getGoodsCateData['id'] = (int)$this->id;
  1982. $getGoodsCateInfo = cloud_post($this->domain.$getGoodsCateUrl,$getGoodsCateData);
  1983. $getGoodsCateInfo = json_decode($getGoodsCateInfo,true);
  1984. if($getGoodsCateInfo['code'] != 0){
  1985. throw new \Exception($getGoodsCateInfo['msg']);
  1986. }
  1987. return $this->outPutData(0, $getGoodsCateInfo['msg']);
  1988. } catch (\Exception $e) {
  1989. return $this->outPutData(1, $e->getMessage());
  1990. }
  1991. }
  1992. public function setAgentGoodsPercent() {
  1993. try {
  1994. //获取平台token
  1995. $cloud_token = get_platform_token();
  1996. if (!$cloud_token) {
  1997. return [
  1998. 'code' => 1,
  1999. 'msg' => '网络问题请重试',
  2000. ];
  2001. }
  2002. $status = $this->status ?? 1;
  2003. $getGoodsCateUrl = "/cloud/user/setAgentGoodsPercent";
  2004. $getGoodsCateData['access_token'] = $cloud_token;
  2005. $getGoodsCateData['id'] = (int)$this->id;
  2006. $getGoodsCateData['agent_percent'] = $this->agent_percent;
  2007. $getGoodsCateData['agent_install_percent'] = $this->agent_install_percent;
  2008. $getGoodsCateData['agent_profit_default'] = (int)$this->agent_profit_default;
  2009. $getGoodsCateInfo = cloud_post($this->domain.$getGoodsCateUrl,$getGoodsCateData);
  2010. $getGoodsCateInfo = json_decode($getGoodsCateInfo,true);
  2011. if($getGoodsCateInfo['code'] != 0){
  2012. throw new \Exception($getGoodsCateInfo['msg']);
  2013. }
  2014. return $this->outPutData(0, $getGoodsCateInfo['msg']);
  2015. } catch (\Exception $e) {
  2016. return $this->outPutData(1, $e->getMessage());
  2017. }
  2018. }
  2019. public function getUserLevel() {
  2020. try {
  2021. if (!$this->validate()) {
  2022. return [
  2023. 'code' => 1,
  2024. 'msg' => $this->getErrorSummary(false)[0],
  2025. ];
  2026. }
  2027. //获取平台token
  2028. $cloud_token = get_platform_token();
  2029. $getGoodsCateUrl = "/cloud/user/getUserLevel";
  2030. $getGoodsCateData['access_token'] = $cloud_token;
  2031. $getGoodsCateData['status'] = $this->status ?? 0;
  2032. $getGoodsCateInfo = cloud_post($this->domain.$getGoodsCateUrl,$getGoodsCateData);
  2033. $getGoodsCateInfo = json_decode($getGoodsCateInfo,true);
  2034. if($getGoodsCateInfo['code'] != 0){
  2035. throw new \Exception($getGoodsCateInfo['msg']);
  2036. }
  2037. return $getGoodsCateInfo;
  2038. } catch (\Exception $e) {
  2039. return [
  2040. 'code' => 1,
  2041. 'msg' => $e->getMessage()
  2042. ];
  2043. }
  2044. }
  2045. public function setMchLevel() {
  2046. try {
  2047. if (!$this->validate()) {
  2048. return [
  2049. 'code' => 1,
  2050. 'msg' => $this->getErrorSummary(false)[0],
  2051. ];
  2052. }
  2053. //获取平台token
  2054. $cloud_token = get_platform_token();
  2055. $getGoodsCateUrl = "/cloud/user/setMchLevel";
  2056. $getGoodsCateData['access_token'] = $cloud_token;
  2057. $getGoodsCateData['id'] = $this->id;
  2058. $getGoodsCateData['mch_id'] = $this->cloud_store_id;
  2059. $getGoodsCateInfo = cloud_post($this->domain.$getGoodsCateUrl,$getGoodsCateData);
  2060. $getGoodsCateInfo = json_decode($getGoodsCateInfo,true);
  2061. if($getGoodsCateInfo['code'] != 0){
  2062. throw new \Exception($getGoodsCateInfo['msg']);
  2063. }
  2064. return $getGoodsCateInfo;
  2065. } catch (\Exception $e) {
  2066. return [
  2067. 'code' => 1,
  2068. 'msg' => $e->getMessage()
  2069. ];
  2070. }
  2071. }
  2072. public function getSortingOrder($id = 0) {
  2073. try {
  2074. //获取平台token
  2075. $cloud_token = get_platform_token();
  2076. if (!$cloud_token) {
  2077. throw new \Exception('网络问题请重试');
  2078. }
  2079. $getGoodsCateData = [];
  2080. //搜索店铺名称
  2081. $name = $this->name;
  2082. $mch_id = '';
  2083. if ($name) {
  2084. $store_id = Store::find()->where(['AND', ['is_delete' => 0], ['LIKE', 'name', $name]])->select('id')->column();
  2085. $mch_id = StoreCloud::find()->where(['store_id' => $store_id, 'is_delete' => 0])->select('cloud_store_id')->column();
  2086. array_push($mch_id, -1);
  2087. if ($mch_id) {
  2088. $mch_id = implode(',', $mch_id);
  2089. }
  2090. }
  2091. $getGoodsCateUrl = "/cloud/user/getSortingOrder";
  2092. $getGoodsCateData['access_token'] = $cloud_token;
  2093. $getGoodsCateData['admin_id'] = get_admin()->id;
  2094. $getGoodsCateData['status'] = $this->status;
  2095. $getGoodsCateData['order_no'] = $this->order_no;
  2096. $getGoodsCateData['start_time'] = $this->start_time;
  2097. $getGoodsCateData['end_time'] = $this->end_time;
  2098. $getGoodsCateData['sorting_start_time'] = $this->sorting_start_time;
  2099. $getGoodsCateData['sorting_end_time'] = $this->sorting_end_time;
  2100. $getGoodsCateData['page'] = get_params('pageNo', get_params('page', 1));
  2101. $getGoodsCateData['limit'] = get_params('pageSize', get_params('limit', 10));
  2102. $getGoodsCateData['mch_id'] = $mch_id;
  2103. $getGoodsCateData['id'] = $id;
  2104. $getGoodsCateInfo = cloud_post($this->domain.$getGoodsCateUrl,$getGoodsCateData);
  2105. $getGoodsCateInfo = json_decode($getGoodsCateInfo,true);
  2106. if($getGoodsCateInfo['code'] != 0){
  2107. throw new \Exception($getGoodsCateInfo['msg']);
  2108. }
  2109. foreach ($getGoodsCateInfo['data']['list'] as &$item) {
  2110. $item['store_name'] = '云仓店铺';
  2111. $item['store_address'] = '-';
  2112. $item['store_mobile'] = '-';
  2113. $store_cloud = StoreCloud::findOne(['cloud_store_id' => $item['mch_id'], 'is_delete' => 0]);
  2114. if ($store_cloud) {
  2115. $store = Store::findOne($store_cloud->store_id);
  2116. $item['store_name'] = $store->name ?? $item['store_name'];
  2117. $admin = Admin::findOne(['type_id' => $store->id, 'type' => 'store', 'is_delete' => 0]);
  2118. //店铺信息
  2119. if ($admin) {
  2120. $district = District::find()->where(['id' => [$admin->province_id, $admin->city_id, $admin->district_id]])->select('name')->column();
  2121. $item['store_mobile'] = $admin->mobile;
  2122. $item['store_address'] = implode('/', $district) . ($admin->address ?: '');
  2123. }
  2124. }
  2125. $item['md_info'] = null;
  2126. if ($item['md_id'] > 0) {
  2127. $md_info = Md::findOne($item['md_id']);
  2128. $item['md_info'] = [
  2129. 'logo' => $md_info->cover_url ?? '',
  2130. 'name' => $md_info->name ?? '',
  2131. 'tel' => $md_info->mobile ?? '',
  2132. ];
  2133. }
  2134. }
  2135. return $this->outPutData(0, $getGoodsCateInfo['msg'], $getGoodsCateInfo['data']);
  2136. } catch (\Exception $e) {
  2137. return [
  2138. 'code' => 1,
  2139. 'msg' => $e->getMessage()
  2140. ];
  2141. }
  2142. }
  2143. //修改分拣单状态
  2144. // public function setSortingStatus() {
  2145. // $t = \Yii::$app->db->beginTransaction();
  2146. // try {
  2147. // $cloud_token = get_platform_token();
  2148. // $id = $this->id;
  2149. // //分拣
  2150. // $orderToLine = DriverForm::orderToLine($id, get_admin()->id);
  2151. // if($orderToLine['code'] != 0){
  2152. // throw new \Exception($orderToLine['msg']);
  2153. // }
  2154. // $getGoodsCateUrl = "/cloud/user/setSortingOrder";
  2155. // $getGoodsCateData['access_token'] = $cloud_token;
  2156. // $getGoodsCateData['admin_id'] = get_admin()->id;
  2157. // $getGoodsCateData['id'] = $id;
  2158. // $getGoodsCateInfo = cloud_post($this->domain.$getGoodsCateUrl,$getGoodsCateData);
  2159. // $getGoodsCateInfo = json_decode($getGoodsCateInfo,true);
  2160. // if($getGoodsCateInfo['code'] != 0){
  2161. // throw new \Exception($getGoodsCateInfo['msg']);
  2162. // }
  2163. // $t->commit();
  2164. // return $this->outPutData(0, $getGoodsCateInfo['msg']);
  2165. // } catch (\Exception $e) {
  2166. // $t->rollBack();
  2167. // return [
  2168. // 'code' => 1,
  2169. // 'msg' => $e->getMessage()
  2170. // ];
  2171. // }
  2172. // }
  2173. //云仓库存详情
  2174. public function getCloudPreviewNumInfo(){
  2175. //获取平台token
  2176. $cloud_token = get_platform_token();
  2177. $supplier_order_list_data = [];
  2178. $supplier_order_list_url = "/cloud/user/getCloudPreviewNumInfo";
  2179. $supplier_order_list_data['access_token'] = $cloud_token;
  2180. $supplier_order_list_data['mch_id'] = $this->could_mch_id;
  2181. if (!$supplier_order_list_data['mch_id']) {
  2182. $store_id = $this->store_id;
  2183. $storeCloud = StoreCloud::findOne(['store_id' => $store_id,'is_delete'=>0]);
  2184. $supplier_order_list_data['mch_id'] = $storeCloud->cloud_store_id ?? 0;
  2185. }
  2186. $supplier_order_list_data['name'] = $this->name;
  2187. $supplier_order_list_data['page'] = input_params('pageNo') ?: $this->page; //默认为 1
  2188. $supplier_order_list_data['limit'] = $this->limit; //默认20
  2189. $supplierOrderListInfo = cloud_post($this->domain.$supplier_order_list_url,$supplier_order_list_data);
  2190. $supplierOrderListInfo = json_decode($supplierOrderListInfo,true);
  2191. if($supplierOrderListInfo['code'] != 0){
  2192. $code = 1; //失败
  2193. return $this->outPutData($code,$supplierOrderListInfo['msg']);
  2194. }else{
  2195. if ($supplierOrderListInfo['data']['mch_info']) {
  2196. $mch_id = $supplierOrderListInfo['data']['mch_info']['mch_id'];
  2197. $store_cloud = StoreCloud::findOne(['cloud_store_id' => $mch_id, 'is_delete' => 0]);
  2198. $supplierOrderListInfo['data']['mch_info']['store_name'] = '-';
  2199. if ($store_cloud) {
  2200. $supplierOrderListInfo['data']['mch_info']['store_name'] = Store::findOne(['id' => $store_cloud->store_id, 'is_delete' => 0])->name ?? '-';
  2201. }
  2202. $user_info = StoreCloud::find()->alias('c')
  2203. ->leftJoin(['su' => SaasUser::tableName()], 'c.saas_user_id = su.id')
  2204. ->where(['c.is_delete' => 0, 'c.cloud_store_id' => $mch_id])->select('su.avatar, su.name')->asArray()->one();
  2205. if ($user_info) {
  2206. $supplierOrderListInfo['data']['mch_info']['name'] = $user_info['name'] ?: $supplierOrderListInfo['data']['mch_info']['name'];
  2207. $supplierOrderListInfo['data']['mch_info']['logo'] = $user_info['avatar'] ?: $supplierOrderListInfo['data']['mch_info']['logo'];
  2208. }
  2209. }
  2210. return $supplierOrderListInfo;
  2211. }
  2212. }
  2213. //云仓库存详情
  2214. public function getCloudPreviewNumLog(){
  2215. //获取平台token
  2216. $cloud_token = get_platform_token();
  2217. $supplier_order_list_data = [];
  2218. $supplier_order_list_url = "/cloud/user/getCloudPreviewNumLog";
  2219. $supplier_order_list_data['access_token'] = $cloud_token;
  2220. $supplier_order_list_data['id'] = $this->id;
  2221. $supplier_order_list_data['order_no'] = $this->order_no;
  2222. $supplier_order_list_data['start_time'] = $this->start_time;
  2223. $supplier_order_list_data['end_time'] = $this->end_time;
  2224. $supplier_order_list_data['page'] = input_params('pageNo') ?: $this->page; //默认为 1
  2225. $supplier_order_list_data['limit'] = $this->limit; //默认20
  2226. $supplierOrderListInfo = cloud_post($this->domain.$supplier_order_list_url,$supplier_order_list_data);
  2227. $supplierOrderListInfo = json_decode($supplierOrderListInfo,true);
  2228. if($supplierOrderListInfo['code'] != 0){
  2229. $code = 1; //失败
  2230. return $this->outPutData($code,$supplierOrderListInfo['msg']);
  2231. }else{
  2232. if ($supplierOrderListInfo['data']['mch_info']) {
  2233. $mch_id = $supplierOrderListInfo['data']['mch_info']['mch_id'];
  2234. $store_cloud = StoreCloud::findOne(['cloud_store_id' => $mch_id, 'is_delete' => 0]);
  2235. $supplierOrderListInfo['data']['mch_info']['store_name'] = '-';
  2236. if ($store_cloud) {
  2237. $supplierOrderListInfo['data']['mch_info']['store_name'] = Store::findOne(['id' => $store_cloud->store_id, 'is_delete' => 0])->name ?? '-';
  2238. }
  2239. $user_info = StoreCloud::find()->alias('c')
  2240. ->leftJoin(['su' => SaasUser::tableName()], 'c.saas_user_id = su.id')
  2241. ->where(['c.is_delete' => 0, 'c.cloud_store_id' => $mch_id])->select('su.avatar, su.name')->asArray()->one();
  2242. if ($user_info) {
  2243. $supplierOrderListInfo['data']['mch_info']['name'] = $user_info['name'] ?: $supplierOrderListInfo['data']['mch_info']['name'];
  2244. $supplierOrderListInfo['data']['mch_info']['logo'] = $user_info['avatar'] ?: $supplierOrderListInfo['data']['mch_info']['logo'];
  2245. }
  2246. }
  2247. return $supplierOrderListInfo;
  2248. }
  2249. }
  2250. //添加云仓库存商品
  2251. public function addCloudPreviewGoods(){
  2252. //获取平台token
  2253. $cloud_token = get_platform_token();
  2254. $supplier_order_list_data = [];
  2255. $supplier_order_list_url = "/cloud/user/addCloudPreviewGoods";
  2256. $supplier_order_list_data['access_token'] = $cloud_token;
  2257. $supplier_order_list_data['goods_id'] = $this->goods_id;
  2258. $supplier_order_list_data['attr'] = $this->attr;
  2259. $supplier_order_list_data['mch_id'] = $this->id;
  2260. $supplier_order_list_data['num'] = $this->num;
  2261. $supplierOrderListInfo = cloud_post($this->domain.$supplier_order_list_url,$supplier_order_list_data);
  2262. $supplierOrderListInfo = json_decode($supplierOrderListInfo,true);
  2263. if($supplierOrderListInfo['code'] != 0){
  2264. $code = 1; //失败
  2265. return $this->outPutData($code,$supplierOrderListInfo['msg']);
  2266. }else{
  2267. return $supplierOrderListInfo;
  2268. }
  2269. }
  2270. //修改云仓库存数量
  2271. public function setPreviewGoodsNum(){
  2272. //获取平台token
  2273. $cloud_token = get_platform_token();
  2274. $supplier_order_list_data = [];
  2275. $supplier_order_list_url = "/cloud/user/setPreviewGoodsNum";
  2276. $supplier_order_list_data['access_token'] = $cloud_token;
  2277. $supplier_order_list_data['id'] = $this->id;
  2278. $supplier_order_list_data['type'] = $this->type;
  2279. $supplier_order_list_data['desc'] = $this->desc;
  2280. $supplier_order_list_data['num'] = $this->num;
  2281. $supplierOrderListInfo = cloud_post($this->domain.$supplier_order_list_url,$supplier_order_list_data);
  2282. $supplierOrderListInfo = json_decode($supplierOrderListInfo,true);
  2283. if($supplierOrderListInfo['code'] != 0){
  2284. $code = 1; //失败
  2285. return $this->outPutData($code,$supplierOrderListInfo['msg']);
  2286. }else{
  2287. return $supplierOrderListInfo;
  2288. }
  2289. }
  2290. //云仓库存详情
  2291. public function getCloudPreviewGoodsList(){
  2292. //获取平台token
  2293. $cloud_token = get_platform_token();
  2294. $supplier_order_list_data = [];
  2295. $supplier_order_list_url = "/cloud/user/getCloudPreviewGoodsList";
  2296. $supplier_order_list_data['access_token'] = $cloud_token;
  2297. $supplier_order_list_data['page'] = input_params('pageNo') ?: $this->page; //默认为 1
  2298. $supplier_order_list_data['limit'] = $this->limit; //默认20
  2299. $supplierOrderListInfo = cloud_post($this->domain.$supplier_order_list_url,$supplier_order_list_data);
  2300. $supplierOrderListInfo = json_decode($supplierOrderListInfo,true);
  2301. if($supplierOrderListInfo['code'] != 0){
  2302. $code = 1; //失败
  2303. return $this->outPutData($code,$supplierOrderListInfo['msg']);
  2304. }else{
  2305. return $supplierOrderListInfo;
  2306. }
  2307. }
  2308. //增加供货渠道
  2309. public function addUserGoodsChannel() {
  2310. $t = \Yii::$app->db->beginTransaction();
  2311. try {
  2312. $cloud_token = get_platform_token();
  2313. $id = $this->id;
  2314. $name = $this->name;
  2315. $status = $this->status;
  2316. $rate = $this->rate;
  2317. if (!in_array($status, [0, 1])) {
  2318. throw new \Exception('状态错误');
  2319. }
  2320. $goodsChannelData = [];
  2321. $goodsChannelUrl = "/cloud/user/goodsChannelSave";
  2322. $goodsChannelData['access_token'] = $cloud_token;
  2323. $goodsChannelData['id'] = $id;
  2324. $goodsChannelData['name'] = $name;
  2325. $goodsChannelData['status'] = $status;
  2326. $goodsChannelData['rate'] = $rate;
  2327. $goodsChannelResult = cloud_post($this->domain . $goodsChannelUrl, $goodsChannelData);
  2328. $goodsChannelResult = json_decode($goodsChannelResult, true);
  2329. if ($goodsChannelResult['code']) {
  2330. throw new \Exception($goodsChannelResult['msg']);
  2331. }
  2332. //参数示例
  2333. $t->commit();
  2334. return $goodsChannelResult;
  2335. } catch (\Exception $e) {
  2336. $t->rollBack();
  2337. return [
  2338. 'code' => 1,
  2339. 'msg' => $e->getMessage()
  2340. ];
  2341. }
  2342. }
  2343. //供货渠道列表
  2344. public function userGoodsChannel($no_page = 0) {
  2345. try {
  2346. $cloud_token = get_platform_token();
  2347. $status = $this->status;
  2348. $name = $this->name;
  2349. $start_time = $this->start_time;
  2350. $end_time = $this->end_time;
  2351. if (!in_array($status, [-1, 0, 1])) {
  2352. throw new \Exception('状态错误');
  2353. }
  2354. $goodsChannelData = [];
  2355. $goodsChannelUrl = "/cloud/user/goodsChannelList";
  2356. $goodsChannelData['access_token'] = $cloud_token;
  2357. $goodsChannelData['status'] = $status;//0禁用 1启用 -1全部
  2358. $goodsChannelData['name'] = $name;//供货渠道名称
  2359. $goodsChannelData['start_time'] = $start_time;//供货渠道创建开始时间
  2360. $goodsChannelData['end_time'] = $end_time;//供货渠道创建结束时间
  2361. $goodsChannelData['page'] = $this->page;
  2362. $goodsChannelData['limit'] = $this->limit;
  2363. $goodsChannelData['no_page'] = $no_page;//无分页情况
  2364. $goodsChannelResult = cloud_post($this->domain . $goodsChannelUrl, $goodsChannelData);
  2365. $goodsChannelResult = json_decode($goodsChannelResult, true);
  2366. if ($goodsChannelResult['code']) {
  2367. throw new \Exception($goodsChannelResult['msg']);
  2368. }
  2369. return $goodsChannelResult;
  2370. } catch (\Exception $e) {
  2371. return [
  2372. 'code' => 1,
  2373. 'msg' => $e->getMessage()
  2374. ];
  2375. }
  2376. }
  2377. //供货渠道删除
  2378. public function userGoodsChannelStatus() {
  2379. $t = \Yii::$app->db->beginTransaction();
  2380. try {
  2381. $cloud_token = get_platform_token();
  2382. $ids = $this->ids;
  2383. $status = $this->status;
  2384. $goodsChannelData = [];
  2385. $goodsChannelUrl = "/cloud/user/goodsChannelStatus";
  2386. $goodsChannelData['access_token'] = $cloud_token;
  2387. $goodsChannelData['ids'] = $ids;
  2388. $goodsChannelData['status'] = $status;//0禁用 1启用 2删除
  2389. $goodsChannelResult = cloud_post($this->domain . $goodsChannelUrl, $goodsChannelData);
  2390. $goodsChannelResult = json_decode($goodsChannelResult, true);
  2391. if ($goodsChannelResult['code']) {
  2392. throw new \Exception($goodsChannelResult['msg']);
  2393. }
  2394. $t->commit();
  2395. return $goodsChannelResult;
  2396. } catch (\Exception $e) {
  2397. $t->rollBack();
  2398. return [
  2399. 'code' => 1,
  2400. 'msg' => $e->getMessage()
  2401. ];
  2402. }
  2403. }
  2404. //设置云仓用户供货渠道
  2405. public function setUserGoodsChannel() {
  2406. $cloud_token = get_platform_token();
  2407. $goodsChannelData = [];
  2408. $goodsChannelUrl = "/cloud/user/setUserGoodsChannel";
  2409. $goodsChannelData['access_token'] = $cloud_token;
  2410. $goodsChannelData['mch_id'] = $this->id;
  2411. $goodsChannelData['channel_id'] = $this->channel_id;//0禁用 1启用 2删除
  2412. $goodsChannelResult = cloud_post($this->domain . $goodsChannelUrl, $goodsChannelData);
  2413. return json_decode($goodsChannelResult, true);
  2414. }
  2415. //云仓用户修改店铺
  2416. public function setCloudUserStore() {
  2417. try {
  2418. $cloud_store_id = $this->id;
  2419. $store_id = $this->store_id;
  2420. $store_cloud = StoreCloud::findOne(['cloud_store_id' => $cloud_store_id, 'is_delete' => 0]);
  2421. $cloud_user_id = $store_cloud->cloud_user_id;
  2422. if ($store_cloud) {
  2423. $old_store_id = $store_cloud->store_id;
  2424. $other_store = StoreCloud::find()->where(['store_id' => $store_id, 'is_delete' => 0])->andWhere(['<>', 'id', $store_cloud->id])
  2425. ->asArray()->one();
  2426. if ($other_store) {
  2427. throw new \Exception('有其他云仓账户绑定该商城');
  2428. }
  2429. StoreCloud::updateAll(['store_id' => 0], ['store_id' => $store_id, 'is_delete' => 0]);
  2430. $store_cloud->store_id = $store_id;
  2431. if (!$store_cloud->save()) {
  2432. throw new \Exception(json_encode($store_cloud->errors, JSON_UNESCAPED_UNICODE));
  2433. }
  2434. if (intval($old_store_id) !== intval($store_id)) {
  2435. $this->delUserCloudGoodsBind($cloud_user_id, $old_store_id);
  2436. }
  2437. return [
  2438. 'code' => 0,
  2439. 'msg' => '修改成功'
  2440. ];
  2441. }
  2442. throw new \Exception('查询云仓账户信息失败');
  2443. } catch (\Exception $e) {
  2444. return [
  2445. 'code' => 1,
  2446. 'msg' => $e->getMessage()
  2447. ];
  2448. }
  2449. }
  2450. //修复更换云仓店铺后 店铺没有云仓商品问题
  2451. public function delUserCloudGoodsBind($cloud_user_id, $old_store_id) {
  2452. try {
  2453. //获取平台token
  2454. $cloud_token = get_platform_token();
  2455. if (!$cloud_token) {
  2456. return [
  2457. 'code' => 1,
  2458. 'msg' => '网络问题请重试',
  2459. ];
  2460. }
  2461. $store_cloud = StoreCloud::findOne(['cloud_user_id' => $cloud_user_id, 'is_delete' => 0]);
  2462. if (empty($store_cloud)) {
  2463. return [
  2464. 'code' => 1,
  2465. 'msg' => '云仓用户查询失败',
  2466. ];
  2467. }
  2468. $delGoodsBindUrl = "/cloud/user/delUserCloudGoodsBind";
  2469. $delGoodsBindData['access_token'] = $cloud_token;
  2470. $delGoodsBindData['user_id'] = $cloud_user_id;
  2471. $delGoodsBindInfo = cloud_post($this->domain . $delGoodsBindUrl, $delGoodsBindData);
  2472. $delGoodsBindInfo = json_decode($delGoodsBindInfo, true);
  2473. if($delGoodsBindInfo['code'] != 0){
  2474. throw new \Exception($delGoodsBindInfo['msg']);
  2475. }
  2476. $bind_goods_id = $delGoodsBindInfo['data'];
  2477. if (!empty($bind_goods_id)) {
  2478. Goods::updateAll(['is_delete' => 1], ['is_delete' => 0, 'store_id' => $old_store_id, 'cloud_goods_id' => $bind_goods_id]);
  2479. }
  2480. return $this->outPutData(0, $delGoodsBindInfo['msg']);
  2481. } catch (\Exception $e) {
  2482. return [
  2483. 'code' => 1,
  2484. 'msg' => $e->getMessage()
  2485. ];
  2486. }
  2487. }
  2488. //云仓库存详情
  2489. public function setPlatformNegotiatedPrice($service_charge_rate){
  2490. //获取平台token
  2491. $cloud_token = get_platform_token();
  2492. $supplier_order_list_data = [];
  2493. $supplier_order_list_url = "/cloud/user/setPlatformNegotiatedPrice";
  2494. $supplier_order_list_data['access_token'] = $cloud_token;
  2495. $supplier_order_list_data['platform_negotiated_rate'] = $service_charge_rate;
  2496. $supplierOrderListInfo = cloud_post($this->domain.$supplier_order_list_url,$supplier_order_list_data);
  2497. $supplierOrderListInfo = json_decode($supplierOrderListInfo,true);
  2498. if($supplierOrderListInfo['code'] != 0){
  2499. $code = 1; //失败
  2500. return $this->outPutData($code,$supplierOrderListInfo['msg']);
  2501. }else{
  2502. return $supplierOrderListInfo;
  2503. }
  2504. }
  2505. //设置平台协议价
  2506. public function setGoodsPlatformNegotiatedPrice()
  2507. {
  2508. //获取平台token
  2509. $cloud_token = get_platform_token();
  2510. $set_goods_platform_negotiated_price_data = [];
  2511. $set_goods_platform_negotiated_price_url = "/cloud/user/setGoodsPlatformNegotiatedPrice";
  2512. $set_goods_platform_negotiated_price_data['access_token'] = $cloud_token;
  2513. $set_goods_platform_negotiated_price_data['goods_id'] = $this->goods_id;
  2514. $set_goods_platform_negotiated_price_data['attr'] = $this->attr;
  2515. $set_goods_platform_negotiated_price_data['platform_negotiated_price'] = $this->platform_negotiated_price;
  2516. $set_goods_platform_negotiated_price_info = cloud_post($this->domain . $set_goods_platform_negotiated_price_url, $set_goods_platform_negotiated_price_data);
  2517. $set_goods_platform_negotiated_price_info = json_decode($set_goods_platform_negotiated_price_info, true);
  2518. if ($set_goods_platform_negotiated_price_info['code'] != 0) {
  2519. $code = 1; //失败
  2520. return $this->outPutData($code, $set_goods_platform_negotiated_price_info['msg']);
  2521. } else {
  2522. return $set_goods_platform_negotiated_price_info;
  2523. }
  2524. }
  2525. public function getCloudProfitList() {
  2526. $cloud_token = get_platform_token();
  2527. $set_goods_platform_negotiated_price_data = [];
  2528. $set_goods_platform_negotiated_price_url = "/cloud/user/getCloudProfitList";
  2529. $set_goods_platform_negotiated_price_data['access_token'] = $cloud_token;
  2530. $set_goods_platform_negotiated_price_data['order_no'] = $this->order_no;
  2531. $set_goods_platform_negotiated_price_data['supplier_name'] = $this->supplier_name;
  2532. $set_goods_platform_negotiated_price_data['store_name'] = $this->name;
  2533. $set_goods_platform_negotiated_price_data['start_time'] = $this->start_time;
  2534. $set_goods_platform_negotiated_price_data['end_time'] = $this->end_time;
  2535. $set_goods_platform_negotiated_price_data['limit'] = $this->limit;
  2536. $set_goods_platform_negotiated_price_data['page'] = $this->page;
  2537. $set_goods_platform_negotiated_price_info = cloud_post($this->domain . $set_goods_platform_negotiated_price_url, $set_goods_platform_negotiated_price_data);
  2538. $set_goods_platform_negotiated_price_info = json_decode($set_goods_platform_negotiated_price_info, true);
  2539. if ($set_goods_platform_negotiated_price_info['code'] != 0) {
  2540. $code = 1; //失败
  2541. return $this->outPutData($code, $set_goods_platform_negotiated_price_info['msg']);
  2542. } else {
  2543. return $set_goods_platform_negotiated_price_info;
  2544. }
  2545. }
  2546. public function setCloudUrl() {
  2547. try {
  2548. $cloud_token = get_platform_token();
  2549. // $id = $this->id;
  2550. $data_url = "/cloud/user/setCloudUrl";
  2551. $data['access_token'] = $cloud_token;
  2552. // $data['old_url'] = $this->old_url;
  2553. $data['url'] = \Yii::$app->request->hostName;
  2554. $getGoodsCateInfo = cloud_post($this->domain.$data_url,$data);
  2555. $getGoodsCateInfo = json_decode($getGoodsCateInfo,true);
  2556. if($getGoodsCateInfo['code'] != 0){
  2557. throw new \Exception($getGoodsCateInfo['msg']);
  2558. }
  2559. return $this->outPutData(0, $getGoodsCateInfo['msg']);
  2560. } catch (\Exception $e) {
  2561. return [
  2562. 'code' => 1,
  2563. 'msg' => $e->getMessage()
  2564. ];
  2565. }
  2566. }
  2567. //返回数据
  2568. private function outPutData($code,$msg,$data=[]){
  2569. $putData = [];
  2570. $putData['code'] = $code;
  2571. $putData['msg'] = $msg;
  2572. if($data) $putData['data'] = $data;
  2573. if($msg == 'token不能为空'){
  2574. $putData['code'] = -1;
  2575. }
  2576. return $putData;
  2577. }
  2578. }