SupplierForm.php 135 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766
  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\librarys\Picqer\Barcode\BarcodeGeneratorJPG;
  11. use app\models\AgentFrontBind;
  12. use app\models\AgentFrontCentralizeGoods;
  13. use app\models\AgentFrontCentralizeGoodsExt;
  14. use app\models\AgentGoodsBindGoods;
  15. use app\models\Attr;
  16. use app\models\AttrGroup;
  17. use app\models\District;
  18. use app\models\Goods;
  19. use app\models\Md;
  20. use app\models\Order;
  21. use app\models\OrderDetail;
  22. use app\models\OrderRefund;
  23. use app\models\OrderTransit;
  24. use app\models\PurchaseOrderDetail;
  25. use app\models\SaasUser;
  26. use app\models\Store;
  27. use app\models\StoreCloud;
  28. use app\models\User;
  29. use app\utils\CurlHelper;
  30. use app\utils\Export;
  31. use app\utils\ExportList;
  32. use app\utils\OrderNo;
  33. use app\utils\PrintOrder;
  34. use app\utils\Refund;
  35. use app\utils\Wechat\WechatBusinessPay;
  36. use Spatie\SimpleExcel\SimpleExcelReader;
  37. use Spatie\SimpleExcel\SimpleExcelWriter;
  38. use Yii;
  39. use Exception;
  40. use yii\base\Model;
  41. use app\models\Admin;
  42. use app\models\Supplier;
  43. use app\models\Option;
  44. //use linslin\yii2\curl;
  45. use app\models\Share;
  46. use yii\base\BaseObject;
  47. use yii\helpers\Json;
  48. use app\jobs\BatchDownGoodsJob;
  49. use app\constants\OptionSetting;
  50. use app\models\PurchaseOrder;
  51. use app\modules\alliance\models\purchase\order\OrderForm;
  52. class SupplierForm extends Model
  53. {
  54. public $name;
  55. public $password;
  56. public $tel;
  57. public $logo;
  58. public $type;
  59. public $cash_type; //提现方式 1--微信支付 2--支付宝 3--银行卡
  60. public $account; //账号 微信 支付宝 银行卡号
  61. public $bank_name; //银行卡开户行
  62. public $certificate;
  63. public $id_card_reverse;
  64. public $id_card_front;
  65. public $page;
  66. public $limit;
  67. public $token_supplier_id; //云库供货商id
  68. public $supplier_id; //云库供货商id
  69. public $could_user_id; //云库会员id
  70. public $could_mch_id; //商户ID
  71. public $start_time; //开始时间
  72. public $end_time; //结束时间
  73. public $order_no; //订单号
  74. public $price; //变动金额
  75. public $desc; //详情
  76. public $status; //状态
  77. public $pic_url; //规格图片
  78. public $num; //库存
  79. public $attr_id; //商品属性id
  80. public $goods_id; //商品ID、大于0编辑, 等于0 添加
  81. public $goods_no; //商品货号
  82. public $g_s_pic_url; //商品缩略图
  83. public $g_price; //售价
  84. public $g_wholesale_price; // 批发价
  85. public $g_wholesale_ladder_rebate; // 批发价阶梯折扣 json
  86. public $g_wholesale_rebate_switch; // 是否开启批发价阶梯折扣
  87. public $wholesale_ladder_type; //批发阶梯价类型 0折扣 1价格
  88. public $g_original_price; //零售价
  89. public $g_unit; //单位
  90. public $g_shop_count; //起购数量
  91. public $g_pic_list; //商品轮播图 [{'pic_url':'111'},{'pic_url':'222'}]
  92. public $g_send_type; //0 全部配送方式 1 仅转单 2 仅采购
  93. public $weight; //重量 单位g
  94. public $order_id; //订单id
  95. public $express_name; //快递公司
  96. public $express_no; //快递号
  97. public $attr; //商品规格
  98. public $send_type; //0 快递配送 1集采 2 自主配送 4云仓库存 5 仓库同城
  99. public $send_type_num; //是否支持云仓库存
  100. public $centralize_goods_type; //集采商品类型 0线货 1团货
  101. public $cancel_type; //1 取消通过 2 取消失败
  102. public $use_attr = 0; //是否使用规格
  103. public $reason; //拒绝退换原因
  104. public $is_agree; //是否同意退换货
  105. public $mobile; //收件人手机号
  106. public $detail; //收件人详细地址
  107. public $zipcode; //收件人邮编
  108. public $is_change; //是否更改规格信息
  109. public $attrs = []; //规格json
  110. public $cat_id;
  111. public $words = '';
  112. public $zip_code;
  113. public $seller_comments;
  114. public $address_data;
  115. public $fields;
  116. public $order_type;
  117. public $user_name;
  118. public $goods_name;
  119. public $search;
  120. public $xlsx;
  121. public $stbz_goods_id;
  122. public $jst_goods_id;
  123. public $jst_supplier_id;
  124. public $is_purchase;
  125. public $area;
  126. public $id;
  127. public $ids;
  128. public $goods_area_rules_id;
  129. public $export;
  130. public $video_url;
  131. public $salesman_id;
  132. public $sort;
  133. public $is_need_install;
  134. public $is_default;
  135. public $freight;
  136. public $supplier_name;
  137. public $is_level;
  138. public $sorting_start_time;
  139. public $sorting_end_time;
  140. //满赠
  141. public $goods_full_give_switch;
  142. public $goods_full_give_info;
  143. private $domain;
  144. public $market_price;
  145. public $purchase_order_id;
  146. public $underlined_price;//原价(划线价)
  147. public $is_selection;
  148. public $pay_price;
  149. public $express_price;
  150. public $mch_order_no;
  151. public $old_order_no;
  152. public function __construct($config = [])
  153. {
  154. parent::__construct($config);
  155. $this->domain = (new OptionSetting)->getCloudDomainName();
  156. }
  157. /**
  158. * @return array the validation rules.
  159. */
  160. public function rules()
  161. {
  162. return [
  163. [['certificate', 'id_card_reverse','id_card_front','logo','pic_url','g_s_pic_url', 'reason', 'ids'], 'string', 'max' => 255],
  164. [['name', 'password','g_unit','account','bank_name','start_time','end_time','express_name','express_no', 'user_name', 'goods_name', 'sorting_start_time', 'sorting_end_time'], 'string', 'max'=> 255],
  165. [['tel','price','g_price','g_original_price', 'g_wholesale_price', 'g_shop_count', 'weight', 'g_wholesale_rebate_switch', 'salesman_id', 'sort', 'market_price', 'pay_price', 'express_price', 'underlined_price'], 'number'],
  166. [['cash_type','type','page','limit','supplier_id','could_mch_id','could_user_id','status','g_send_type','attr_id','num','send_type', 'send_type_num', 'centralize_goods_type','cancel_type', 'use_attr', 'is_agree', 'order_type', 'is_purchase', 'id', 'goods_area_rules_id', 'export', 'is_level', 'wholesale_ladder_type', 'goods_full_give_switch'],'integer'],
  167. [['goods_no','order_no' ,'desc', 'mobile', 'detail', 'zipcode', 'cat_id', 'g_wholesale_ladder_rebate','order_id','goods_id', 'fields', 'search', 'xlsx', 'goods_full_give_info'],'string'],
  168. [['attrs', 'g_pic_list', 'token_supplier_id', 'words', 'address_data', 'seller_comments', 'is_need_install', 'is_default', 'freight', 'purchase_order_id', 'mch_order_no', 'old_order_no', 'zip_code'], 'safe'],
  169. [['area', 'video_url', 'supplier_name'], 'string'],
  170. [['stbz_goods_id', 'is_selection'], 'integer'],
  171. [['jst_goods_id', 'jst_supplier_id'], 'safe'],
  172. // ['g_pic_list',function ($attribute, $params) {
  173. // if(!is_array($this->g_pic_list)){
  174. // $this->addError('g_pic_list','g_pic_list is not array!');
  175. // }
  176. // }],
  177. ];
  178. }
  179. //订单取消审核
  180. public function getLastOrderInfo(){
  181. if (!$this->validate()) {
  182. return [
  183. 'code' => 1,
  184. 'msg' => $this->getErrorSummary(false)[0],
  185. ];
  186. }
  187. $cacheK_id = 'id_SupplierForm_getLastOrderInfo_maxId_' . $this->token_supplier_id . $this->supplier_id;
  188. $cacheK_purchase_order_id = 'purchase_order_id_SupplierForm_getLastOrderInfo_maxId_' . $this->token_supplier_id . $this->supplier_id;
  189. $cacheV_id = (int)cache()->get($cacheK_id);
  190. $cacheV_purchase_order_id = (int)cache()->get($cacheK_purchase_order_id);
  191. $url = "/cloud/supplier/getLastOrderInfo";
  192. $data = [];
  193. $data['access_token'] = get_supplier_token($this->token_supplier_id, $this->supplier_id); //获取供货商的token信息
  194. $data['purchase_order_id'] = $cacheV_purchase_order_id; //订单id
  195. $data['id'] = $cacheV_id; //订单id
  196. $res = cloud_post($this->domain.$url,$data);
  197. // var_dump($res, $url, $data);
  198. $res = json_decode($res,true);
  199. if($res['code'] != 0){
  200. $code = 1; //失败
  201. return $this->outPutData($code,$res['msg']);
  202. }else{
  203. if($res['data']){
  204. if($res['data']['order_info']){
  205. cache()->set($cacheK_id, $res['data']['order_info']['id']);
  206. }
  207. if($res['data']['purchase_order_info']){
  208. cache()->set($cacheK_purchase_order_id, $res['data']['purchase_order_info']['id']);
  209. }
  210. }
  211. return $this->outPutData($res['code'],$res['msg'],$res['data']);
  212. }
  213. }
  214. //订单取消审核
  215. public function supplierOrderCancel(){
  216. if (!$this->validate()) {
  217. return [
  218. 'code' => 1,
  219. 'msg' => $this->getErrorSummary(false)[0],
  220. ];
  221. }
  222. $supplier_order_cancel_url = "/cloud/supplier/supplierOrderCancel";
  223. $supplier_order_cancel_data = [];
  224. $supplier_order_cancel_data['access_token'] = get_supplier_token($this->token_supplier_id); //获取供货商的token信息
  225. $supplier_order_cancel_data['order_id'] = $this->order_id; //订单id
  226. $supplier_order_cancel_data['cancel_type'] = $this->cancel_type; //1 通过 2 拒绝
  227. $supplierOrderCancelInfo = cloud_post($this->domain.$supplier_order_cancel_url,$supplier_order_cancel_data);
  228. $supplierOrderCancelInfo = json_decode($supplierOrderCancelInfo,true);
  229. if($supplierOrderCancelInfo['code'] != 0){
  230. $code = 1; //失败
  231. return $this->outPutData($code,$supplierOrderCancelInfo['msg']);
  232. }else{
  233. // if ((int)$this->cancel_type === 1) {
  234. // $purchase_order = PurchaseOrder::findOne(['cloud_order_id' => $this->order_id]);
  235. // if ($purchase_order && (int)$purchase_order->pay_type === 1) {
  236. // $res = WechatBusinessPay::orderRefund($purchase_order, OrderNo::ORDER_ALLIANCE_PURCHASE, $purchase_order->pay_price, 'POR' . $purchase_order->order_no);
  237. // if ($res['code'] === 1) {
  238. // return $res;
  239. // }
  240. // }
  241. // }
  242. if (intval($this->cancel_type) === 1) {
  243. $purchaseOrder = PurchaseOrder::findOne(['cloud_order_id' => $this->order_id]);
  244. try {
  245. $supplier = Supplier::findOne(['cloud_supplier_id' => $purchaseOrder->cloud_supplier_id]);
  246. $printer_order = new PrintOrder(0, $this->order_id, 'confirm', 0, 0, 1, 0, $supplier->id);
  247. $printer_order->print_order();
  248. } catch (\Exception $e) {
  249. debug_log([
  250. 'event' => 'supplierOrderCancel',
  251. 'message' => $e->getMessage(),
  252. 'line' => $e->getLine(),
  253. 'file' => $e->getFile()
  254. ], 'cloud_printer.log');
  255. }
  256. }
  257. return $this->outPutData($supplierOrderCancelInfo['code'],$supplierOrderCancelInfo['msg']);
  258. }
  259. }
  260. //获取运费规则
  261. public function supplierGetRules(){
  262. if (!$this->validate()) {
  263. return [
  264. 'code' => 1,
  265. 'msg' => $this->getErrorSummary(false)[0],
  266. ];
  267. }
  268. $supplier_get_rules_url = "/cloud/supplier/supplierGetRules";
  269. $supplier_get_rules_data = [];
  270. $supplier_get_rules_data['access_token'] = get_supplier_token($this->token_supplier_id); //获取供货商的token信息
  271. $supplier_get_rules_data['id'] = $this->id;
  272. $supplierGetRulesInfo = cloud_post($this->domain.$supplier_get_rules_url,$supplier_get_rules_data);
  273. $supplierGetRulesInfo = json_decode($supplierGetRulesInfo,true);
  274. if($supplierGetRulesInfo['code'] != 0){
  275. $code = 1; //失败
  276. return $this->outPutData($code,$supplierGetRulesInfo['msg']);
  277. }else{
  278. return $this->outPutData($supplierGetRulesInfo['code'],$supplierGetRulesInfo['msg'],$supplierGetRulesInfo['data']);
  279. }
  280. }
  281. //删除运费规则
  282. public function supplierDelRules(){
  283. if (!$this->validate()) {
  284. return [
  285. 'code' => 1,
  286. 'msg' => $this->getErrorSummary(false)[0],
  287. ];
  288. }
  289. $supplier_get_rules_url = "/cloud/supplier/supplierDelRules";
  290. $supplier_get_rules_data = [];
  291. $supplier_get_rules_data['access_token'] = get_supplier_token($this->token_supplier_id); //获取供货商的token信息
  292. $supplier_get_rules_data['id'] = $this->id;
  293. $supplierGetRulesInfo = cloud_post($this->domain.$supplier_get_rules_url,$supplier_get_rules_data);
  294. $supplierGetRulesInfo = json_decode($supplierGetRulesInfo,true);
  295. if($supplierGetRulesInfo['code'] != 0){
  296. $code = 1; //失败
  297. return $this->outPutData($code,$supplierGetRulesInfo['msg']);
  298. }else{
  299. return $this->outPutData($supplierGetRulesInfo['code'],$supplierGetRulesInfo['msg'],$supplierGetRulesInfo['data']);
  300. }
  301. }
  302. //修改运费规则状态
  303. public function supplierSetStatus(){
  304. if (!$this->validate()) {
  305. return [
  306. 'code' => 1,
  307. 'msg' => $this->getErrorSummary(false)[0],
  308. ];
  309. }
  310. $supplier_get_rules_url = "/cloud/supplier/supplierSetStatus";
  311. $supplier_get_rules_data = [];
  312. $supplier_get_rules_data['access_token'] = get_supplier_token($this->token_supplier_id); //获取供货商的token信息
  313. $supplier_get_rules_data['id'] = $this->id;
  314. $supplier_get_rules_data['is_default'] = $this->is_default;
  315. $supplierGetRulesInfo = cloud_post($this->domain.$supplier_get_rules_url,$supplier_get_rules_data);
  316. $supplierGetRulesInfo = json_decode($supplierGetRulesInfo,true);
  317. if($supplierGetRulesInfo['code'] != 0){
  318. $code = 1; //失败
  319. return $this->outPutData($code,$supplierGetRulesInfo['msg']);
  320. }else{
  321. return $this->outPutData($supplierGetRulesInfo['code'],$supplierGetRulesInfo['msg'],$supplierGetRulesInfo['data']);
  322. }
  323. }
  324. //获取运费规则
  325. public function supplierGetRulesList(){
  326. if (!$this->validate()) {
  327. return [
  328. 'code' => 1,
  329. 'msg' => $this->getErrorSummary(false)[0],
  330. ];
  331. }
  332. $supplier_get_rules_url = "/cloud/supplier/supplierGetRulesList";
  333. $supplier_get_rules_data = [];
  334. $supplier_get_rules_data['access_token'] = get_supplier_token($this->token_supplier_id); //获取供货商的token信息
  335. $supplierGetRulesInfo = cloud_post($this->domain.$supplier_get_rules_url,$supplier_get_rules_data);
  336. $supplierGetRulesInfo = json_decode($supplierGetRulesInfo,true);
  337. if($supplierGetRulesInfo['code'] != 0){
  338. $code = 1; //失败
  339. return $this->outPutData($code,$supplierGetRulesInfo['msg']);
  340. }else{
  341. return $this->outPutData($supplierGetRulesInfo['code'],$supplierGetRulesInfo['msg'],$supplierGetRulesInfo['data']);
  342. }
  343. }
  344. //供货单订单发货
  345. public function supplierOrderSend($cloud_supplier_id = 0){
  346. if (!$this->validate()) {
  347. return [
  348. 'code' => 1,
  349. 'msg' => $this->getErrorSummary(false)[0],
  350. ];
  351. }
  352. if (!empty($this->xlsx)) {
  353. $supplier_order_send_url = "/cloud/supplier/supplierOrderAllSend";
  354. $supplier_order_send_data = [];
  355. $supplier_order_send_data['access_token'] = get_supplier_token($cloud_supplier_id); //获取供货商的token信息
  356. $xlsx_path = $this->saveTempImage($this->xlsx);
  357. $rows = SimpleExcelReader::create($xlsx_path)->noHeaderRow()->getRows();
  358. $array = [];
  359. $rows->each(function($rowProperties) use (&$array) {
  360. array_push($array, $rowProperties);
  361. });
  362. unset($array[0]);
  363. $array = array_values($array);
  364. $supplier_order_send_data['xlsx'] = json_encode($array);
  365. } else {
  366. $supplier_order_send_url = "/cloud/supplier/supplierOrderSend";
  367. $supplier_order_send_data = [];
  368. $supplier_order_send_data['access_token'] = get_supplier_token($cloud_supplier_id); //获取供货商的token信息
  369. $supplier_order_send_data['order_ids'] = $this->order_id; //订单ID
  370. $supplier_order_send_data['express_name'] = $this->express_name; //快递公司
  371. $supplier_order_send_data['express_no'] = $this->express_no; //快递号
  372. $supplier_order_send_data['send_type'] = $this->send_type; //1 快递配送 2 自主配送
  373. }
  374. $supplierOrderSendInfo = cloud_post($this->domain.$supplier_order_send_url,$supplier_order_send_data);
  375. $supplierOrderSendInfo = json_decode($supplierOrderSendInfo,true);
  376. if($supplierOrderSendInfo['code'] != 0){
  377. $code = 1; //失败
  378. return $this->outPutData($code,$supplierOrderSendInfo['msg']);
  379. }else{
  380. if (!empty($array)) {
  381. foreach ($array as $item) {
  382. $order = PurchaseOrder::find()->where(['cloud_order_id' => $this->order_id])->one();
  383. $of = new OrderForm();
  384. $of->order_id = $order->id;
  385. $of->express = $this->express_name;
  386. $of->express_no = $this->express_no;
  387. $of->words = $this->words;
  388. $res = $of->send();
  389. if ($res['code'] !== 0) {
  390. return $res;
  391. }
  392. }
  393. }
  394. return $this->outPutData($supplierOrderSendInfo['code'],$supplierOrderSendInfo['msg']);
  395. }
  396. }
  397. //供货单订单删除
  398. public function supplierOrderDel(){
  399. if (!$this->validate()) {
  400. return [
  401. 'code' => 1,
  402. 'msg' => $this->getErrorSummary(false)[0],
  403. ];
  404. }
  405. $supplier_order_send_url = "/cloud/supplier/supplierOrderDel";
  406. $supplier_order_send_data = [];
  407. $supplier_order_send_data['access_token'] = get_supplier_token(); //获取供货商的token信息
  408. $supplier_order_send_data['order_ids'] = $this->order_id; //订单ID
  409. $supplierOrderSendInfo = cloud_post($this->domain.$supplier_order_send_url,$supplier_order_send_data);
  410. $supplierOrderSendInfo = json_decode($supplierOrderSendInfo,true);
  411. if($supplierOrderSendInfo['code'] != 0){
  412. $code = 1; //失败
  413. return $this->outPutData($code,$supplierOrderSendInfo['msg']);
  414. }else{
  415. return $this->outPutData($supplierOrderSendInfo['code'],$supplierOrderSendInfo['msg']);
  416. }
  417. }
  418. //供货单修改收货地址 / 卖家备注
  419. public function supplierOrderSetAddress(){
  420. if (!$this->validate()) {
  421. return [
  422. 'code' => 1,
  423. 'msg' => $this->getErrorSummary(false)[0],
  424. ];
  425. }
  426. $supplier_order_send_url = "/cloud/supplier/setOrderAddress";
  427. $supplier_order_send_data = [];
  428. $supplier_order_send_data['access_token'] = get_supplier_token(); //获取供货商的token信息
  429. $supplier_order_send_data['order_id'] = $this->order_id;
  430. $supplier_order_send_data['address_data'] = $this->address_data;
  431. $supplier_order_send_data['remark'] = $this->seller_comments;
  432. $supplier_order_send_data['order_type'] = $this->order_type;
  433. $supplierOrderSendInfo = cloud_post($this->domain.$supplier_order_send_url,$supplier_order_send_data);
  434. $supplierOrderSendInfo = json_decode($supplierOrderSendInfo,true);
  435. if($supplierOrderSendInfo['code'] != 0){
  436. $code = 1; //失败
  437. return $this->outPutData($code,$supplierOrderSendInfo['msg']);
  438. }else{
  439. if (intval($this->order_type)) {
  440. $order = PurchaseOrder::find()->where(['cloud_order_id' => $this->order_id])->one();
  441. $address_data = json_decode($this->address_data, true);
  442. if($address_data){
  443. $order->province_id = $address_data['province'];
  444. $order->city_id = $address_data['city'];
  445. $order->district_id = $address_data['district'];
  446. $order->address = $address_data['address'];
  447. $order->name = $address_data['name'];
  448. $order->mobile = $address_data['mobile'];
  449. }
  450. if($this->seller_comments){
  451. $order->seller_comments = $this->seller_comments;
  452. }
  453. $order->save();
  454. }
  455. return $this->outPutData($supplierOrderSendInfo['code'],$supplierOrderSendInfo['msg']);
  456. }
  457. }
  458. //供货单修改收货地址 / 卖家备注
  459. public function supplierPurchaseOrderSetAddress(){//setPurchaseOrderAddress
  460. if (!$this->validate()) {
  461. return [
  462. 'code' => 1,
  463. 'msg' => $this->getErrorSummary(false)[0],
  464. ];
  465. }
  466. $supplier_order_send_url = "/cloud/supplier/setPurchaseOrderAddress";
  467. $supplier_order_send_data = [];
  468. $supplier_order_send_data['access_token'] = get_supplier_token(); //获取供货商的token信息
  469. $supplier_order_send_data['order_id'] = $this->order_id;
  470. $supplier_order_send_data['address_data'] = $this->address_data;
  471. $supplier_order_send_data['remark'] = $this->seller_comments;
  472. $supplier_order_send_data['order_type'] = $this->order_type;
  473. $supplierOrderSendInfo = cloud_post($this->domain.$supplier_order_send_url,$supplier_order_send_data);
  474. $supplierOrderSendInfo = json_decode($supplierOrderSendInfo,true);
  475. if($supplierOrderSendInfo['code'] != 0){
  476. $code = 1; //失败
  477. return $this->outPutData($code,$supplierOrderSendInfo['msg']);
  478. }else{
  479. $OrderTransit = OrderTransit::findOne(['cloud_order_id' => $this->order_id]);
  480. $order = Order::find()->where(['id' => $OrderTransit->order_id])->one();
  481. $address_data = json_decode($this->address_data);
  482. if($address_data){
  483. $order->address = $address_data->address;
  484. $order->name = $address_data->name;
  485. $order->mobile = $address_data->mobile;
  486. }
  487. if($this->seller_comments){
  488. $order->seller_comments = $this->seller_comments;
  489. }
  490. $order->save();
  491. return $this->outPutData($supplierOrderSendInfo['code'],$supplierOrderSendInfo['msg']);
  492. }
  493. }
  494. //订单列表(新)
  495. public function supplierSendTypeList($cloud_supplier_id = 0){
  496. if (!$this->validate()) {
  497. return [
  498. 'code' => 1,
  499. 'msg' => $this->getErrorSummary(false)[0],
  500. ];
  501. }
  502. // 获取可导出数据
  503. $f = new ExportList();
  504. $exportList = $f->getList();
  505. $supplier_order_list_url = "/cloud/supplier/supplierSendTypeList";
  506. $supplier_order_list_data = [];
  507. $supplier_order_list_data['access_token'] = get_supplier_token($cloud_supplier_id); //获取供货商的token信息
  508. $admin = get_admin();
  509. if ($admin->type === 'admin' || $admin->type === Admin::ADMIN_TYPE_SAAS_STAFF) {
  510. $supplier_order_list_url = "/cloud/user/supplierPurchaseOrderList";
  511. $supplier_order_list_data['access_token'] = get_platform_token();
  512. // $admin = get_admin();
  513. // $admin_id = $admin->id;
  514. // if ($admin->username == 'admin') {
  515. // $admin_id = null;
  516. // }
  517. // if ($admin_id) {
  518. // $admin_model = Admin::findOne($admin_id);
  519. // $area_level = $admin_model->area_level;
  520. $cloud_supplier_id = Supplier::find()->where(['is_delete' => 0])->select('cloud_supplier_id')->column();
  521. if (!empty($cloud_supplier_id)) {
  522. $supplier_order_list_data['supplier_id'] = implode(',', $cloud_supplier_id);
  523. }
  524. if (!empty($this->supplier_name)) {
  525. $supplier_order_list_data['supplier_name'] = $this->supplier_name;
  526. }
  527. // $salesman_id = $this->salesman_id;
  528. // if ($salesman_id) {
  529. // $query->andWhere([
  530. // 'salesman_id' => $salesman_id
  531. // ]);
  532. // }
  533. // if($area_level == 1){
  534. // $query->andWhere(
  535. // ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id, 'district_id' => $admin_model->district_id]);
  536. // } elseif ($area_level == 2){
  537. // $query->andWhere(
  538. // ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id]);
  539. // } elseif ($area_level == 3){
  540. // $query->andWhere(['province_id' => $admin_model->province_id]);
  541. // }
  542. // $ids = $query->select('cloud_supplier_id')->column();
  543. // if ($ids) {
  544. // if(is_array($ids)){
  545. // $ids = implode(',', $ids);
  546. // }
  547. // $supplier_order_list_data['supplier_id'] = $ids;
  548. // } else {
  549. // return $this->outPutData(0,'获取成功',[
  550. // 'list' => []
  551. // ]);
  552. // }
  553. // }
  554. }
  555. $supplier_order_list_data['page'] = $this->page; //订单ID
  556. $supplier_order_list_data['mobile'] = $this->mobile; //订单ID
  557. $supplier_order_list_data['user_name'] = $this->user_name; //订单ID
  558. $supplier_order_list_data['goods_name'] = $this->goods_name; //订单ID
  559. $supplier_order_list_data['limit'] = $this->limit; //1 取消通过 2 取消失败
  560. $supplier_order_list_data['status'] = $this->status; //-1 全部 0 待供货商确认 1 供货商已发货 2 已确认收货
  561. $supplier_order_list_data['mch_id'] = $this->could_mch_id; //商户ID
  562. $supplier_order_list_data['type'] = $this->type ?: 0; //订单类型0:快递 1:自助配送 2:云仓库存 6:仓库快递
  563. if($this->start_time) $supplier_order_list_data['start_time'] = strtotime($this->start_time); //开始时间
  564. if($this->end_time) $supplier_order_list_data['end_time'] = strtotime($this->end_time); //结束时间
  565. if($this->order_no) $supplier_order_list_data['order_no'] = $this->order_no; //订单号
  566. if($this->order_id) $supplier_order_list_data['order_id'] = $this->order_id;
  567. if (!empty(trim($this->mch_order_no))) {
  568. $mch_order_id = Order::find()->where(['LIKE', 'order_no', $this->mch_order_no])->select('id')->column();
  569. if (!empty($mch_order_id)) {
  570. $mch_order_id = implode(',', $mch_order_id);
  571. } else {
  572. $mch_order_id = '-1';
  573. }
  574. $supplier_order_list_data['mch_order_ids'] = $mch_order_id;
  575. }
  576. $supplierOrderListInfo = cloud_post($this->domain.$supplier_order_list_url,$supplier_order_list_data);
  577. $supplierOrderListInfo = json_decode($supplierOrderListInfo,true);
  578. if($supplierOrderListInfo['code'] != 0){
  579. $code = 1; //失败
  580. return $this->outPutData($code,$supplierOrderListInfo['msg']);
  581. }else{
  582. $msg = '查询成功';
  583. $xlsx = \Yii::$app->request->hostInfo . '/web/statics/Template.xlsx';
  584. $supplier_id = get_supplier_id();
  585. $is_stbz = false;
  586. $supplier = Supplier::findOne($supplier_id);
  587. if ($supplier && $supplier->is_stbz == 1) {
  588. $is_stbz = true;
  589. }
  590. foreach ($supplierOrderListInfo['data']['list'] as &$item) {
  591. if (!empty($item['platform_order_no'])) {
  592. $item['mch_order_no'] = Order::findOne($item['platform_order_no'])->order_no;
  593. } else {
  594. $item['mch_order_no'] = PurchaseOrder::findOne(['cloud_order_id' => $item['id']])->order_no;
  595. }
  596. if ($item['mch_id']) {
  597. $store_cloud = StoreCloud::findOne(['cloud_store_id' => $item['mch_id'], 'is_delete' => 0]);
  598. if ($store_cloud) {
  599. $store = Store::findOne($store_cloud->store_id);
  600. $item['mch']['name'] = $store->name ?: $item['mch']['name'];
  601. // $item['user']['store_name'] = $store->name ?: $item['user']['store_name'];
  602. }
  603. }
  604. }
  605. $supplierOrderListInfo['data'] = array_merge($supplierOrderListInfo['data'], ['export_list' => $exportList, 'supplier_id' => $supplier_id, 'xlsx' => $xlsx, 'is_stbz' => $is_stbz]);
  606. return $this->outPutData($supplierOrderListInfo['code'], $msg, $supplierOrderListInfo['data']);
  607. }
  608. }
  609. //供货单列表
  610. public function supplierOrderList($cloud_supplier_id = 0){
  611. if (!$this->validate()) {
  612. return [
  613. 'code' => 1,
  614. 'msg' => $this->getErrorSummary(false)[0],
  615. ];
  616. }
  617. // 获取可导出数据
  618. $f = new ExportList();
  619. $exportList = $f->getList();
  620. $supplier_order_list_url = "/cloud/supplier/supplierOrderList";
  621. $supplier_order_list_data = [];
  622. $supplier_order_list_data['access_token'] = get_supplier_token($cloud_supplier_id); //获取供货商的token信息
  623. $admin = get_admin();
  624. if ($admin->type === 'admin' || $admin->type === Admin::ADMIN_TYPE_FRONT_AGENT) {
  625. $supplier_order_list_url = "/cloud/user/supplierOrderList";
  626. $supplier_order_list_data['access_token'] = get_platform_token();
  627. $admin = get_admin();
  628. $admin_id = $admin->id;
  629. if ($admin->username == 'admin') {
  630. $admin_id = null;
  631. }
  632. if ($admin_id) {
  633. $admin_model = Admin::findOne($admin_id);
  634. $area_level = $admin_model->area_level;
  635. $query = Supplier::find()->where(['is_delete' => 0]);
  636. $salesman_id = $this->salesman_id;
  637. if ($salesman_id) {
  638. $query->andWhere([
  639. 'salesman_id' => $salesman_id
  640. ]);
  641. }
  642. if($area_level == 1){
  643. $query->andWhere(
  644. ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id, 'district_id' => $admin_model->district_id]);
  645. } elseif ($area_level == 2){
  646. $query->andWhere(
  647. ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id]);
  648. } elseif ($area_level == 3){
  649. $query->andWhere(['province_id' => $admin_model->province_id]);
  650. }
  651. $ids = $query->select('cloud_supplier_id')->column();
  652. if ($ids) {
  653. if(is_array($ids)){
  654. $ids = implode(',', $ids);
  655. }
  656. $supplier_order_list_data['supplier_id'] = $ids;
  657. } else {
  658. return $this->outPutData(0,'获取成功',[
  659. 'list' => []
  660. ]);
  661. }
  662. }
  663. }
  664. $supplier_order_list_data['page'] = $this->page; //订单ID
  665. $supplier_order_list_data['mobile'] = $this->mobile; //订单ID
  666. $supplier_order_list_data['user_name'] = $this->user_name; //订单ID
  667. $supplier_order_list_data['goods_name'] = $this->goods_name; //订单ID
  668. $supplier_order_list_data['limit'] = $this->limit; //1 取消通过 2 取消失败
  669. $supplier_order_list_data['status'] = $this->status; //-1 全部 0 待供货商确认 1 供货商已发货 2 已确认收货
  670. $supplier_order_list_data['mch_id'] = $this->could_mch_id; //商户ID
  671. $supplier_order_list_data['type'] = $this->type ?: 0; //商户ID
  672. if($this->start_time) $supplier_order_list_data['start_time'] = strtotime($this->start_time); //开始时间
  673. if($this->end_time) $supplier_order_list_data['end_time'] = strtotime($this->end_time); //结束时间
  674. if($this->order_no) $supplier_order_list_data['order_no'] = $this->order_no; //订单号
  675. if($this->order_id) $supplier_order_list_data['order_id'] = $this->order_id;
  676. $supplierOrderListInfo = cloud_post($this->domain.$supplier_order_list_url,$supplier_order_list_data);
  677. $supplierOrderListInfo = json_decode($supplierOrderListInfo,true);
  678. if($supplierOrderListInfo['code'] != 0){
  679. $code = 1; //失败
  680. return $this->outPutData($code,$supplierOrderListInfo['msg']);
  681. }else{
  682. $msg = '查询成功';
  683. $xlsx = \Yii::$app->request->hostInfo . '/web/statics/Template.xlsx';
  684. $supplier_id = get_supplier_id();
  685. $is_stbz = false;
  686. $supplier = Supplier::findOne($supplier_id);
  687. if ($supplier && $supplier->is_stbz == 1) {
  688. $is_stbz = true;
  689. }
  690. $supplierOrderListInfo['data'] = array_merge($supplierOrderListInfo['data'], ['export_list' => $exportList, 'supplier_id' => $supplier_id, 'xlsx' => $xlsx, 'is_stbz' => $is_stbz]);
  691. return $this->outPutData($supplierOrderListInfo['code'], $msg, $supplierOrderListInfo['data']);
  692. }
  693. }
  694. //订单取消审核
  695. public function supplierPurchaseCancel(){
  696. if (!$this->validate()) {
  697. return [
  698. 'code' => 1,
  699. 'msg' => $this->getErrorSummary(false)[0],
  700. ];
  701. }
  702. $supplier_purchase_cancel_url = "/cloud/supplier/supplierPurchaseCancel";
  703. $supplier_purchase_cancel_data = [];
  704. $supplier_purchase_cancel_data['access_token'] = get_supplier_token(); //获取供货商的token信息
  705. $supplier_purchase_cancel_data['order_id'] = $this->order_id; //订单ID
  706. $supplier_purchase_cancel_data['cancel_type'] = $this->cancel_type; //1 取消通过 2 取消失败
  707. $supplierPurchaseCancelInfo = cloud_post($this->domain.$supplier_purchase_cancel_url,$supplier_purchase_cancel_data);
  708. $supplierPurchaseCancelInfo = json_decode($supplierPurchaseCancelInfo,true);
  709. if($supplierPurchaseCancelInfo['code'] != 0){
  710. $code = 1; //失败
  711. return $this->outPutData($code,$supplierPurchaseCancelInfo['msg']);
  712. }else{
  713. if (intval($this->cancel_type) === 1) {
  714. try {
  715. $orderTransit = OrderTransit::findOne(['cloud_order_id' => $this->order_id]);
  716. $supplier = Supplier::findOne(['cloud_supplier_id' => $orderTransit->cloud_supplier_id]);
  717. $printer_order = new PrintOrder(0, $this->order_id, 'confirm', 0, 0, 1, 0, $supplier->id);
  718. $printer_order->print_order();
  719. } catch (\Exception $e) {
  720. debug_log([
  721. 'event' => 'supplierPurchaseCancel',
  722. 'message' => $e->getMessage(),
  723. 'line' => $e->getLine(),
  724. 'file' => $e->getFile()
  725. ], 'cloud_printer.log');
  726. }
  727. }
  728. return $this->outPutData($supplierPurchaseCancelInfo['code'],$supplierPurchaseCancelInfo['msg']);
  729. }
  730. }
  731. //订单发货
  732. public function supplierPurchaseSend($cloud_supplier_id = 0){
  733. if (!$this->validate()) {
  734. return [
  735. 'code' => 1,
  736. 'msg' => $this->getErrorSummary(false)[0],
  737. ];
  738. }
  739. if (!empty($this->xlsx)) {
  740. $supplier_purchase_send_url = "/cloud/supplier/supplierPurchaseXlsxSend";
  741. $supplier_purchase_send_data = [];
  742. $supplier_purchase_send_data['access_token'] = get_supplier_token($cloud_supplier_id); //获取供货商的token信息
  743. $xlsx_path = $this->saveTempImage($this->xlsx);
  744. $rows = SimpleExcelReader::create($xlsx_path)->noHeaderRow()->getRows();
  745. $array = [];
  746. $rows->each(function($rowProperties) use (&$array) {
  747. array_push($array, $rowProperties);
  748. });
  749. unset($array[0]);
  750. $array = array_values($array);
  751. $supplier_purchase_send_data['xlsx'] = json_encode($array);
  752. } else {
  753. $supplier_purchase_send_url = "/cloud/supplier/supplierPurchaseSend";
  754. $supplier_purchase_send_data = [];
  755. $supplier_purchase_send_data['access_token'] = get_supplier_token($cloud_supplier_id); //获取供货商的token信息
  756. $supplier_purchase_send_data['order_ids'] = $this->order_id; //订单ID
  757. $supplier_purchase_send_data['express_name'] = $this->express_name; //快递公司
  758. $supplier_purchase_send_data['express_no'] = $this->express_no; //快递号
  759. $supplier_purchase_send_data['send_type'] = $this->send_type; //1 快递配送 2 自主配送
  760. $supplier_purchase_send_data['words'] = $this->words;
  761. $supplier_purchase_send_data['zip_code'] = $this->zip_code;
  762. }
  763. $supplierPurchaseSendInfo = cloud_post($this->domain.$supplier_purchase_send_url,$supplier_purchase_send_data);
  764. $supplierPurchaseSendInfo = json_decode($supplierPurchaseSendInfo,true);
  765. if($supplierPurchaseSendInfo['code'] != 0){
  766. $code = 1; //失败
  767. return $this->outPutData($code,$supplierPurchaseSendInfo['msg']);
  768. }else{
  769. return $this->outPutData($supplierPurchaseSendInfo['code'],$supplierPurchaseSendInfo['msg']);
  770. }
  771. }
  772. //订单修改发货信息
  773. public function updateOrderSendInfo($cloud_supplier_id = 0){
  774. if (!$this->validate()) {
  775. return [
  776. 'code' => 1,
  777. 'msg' => $this->getErrorSummary(false)[0],
  778. ];
  779. }
  780. $supplier_purchase_send_url = "/cloud/supplier/updateOrderSendInfo";
  781. $supplier_purchase_send_data = [];
  782. $supplier_purchase_send_data['access_token'] = get_supplier_token($cloud_supplier_id); //获取供货商的token信息
  783. $supplier_purchase_send_data['order_id'] = $this->order_id; //订单ID
  784. $supplier_purchase_send_data['express_name'] = $this->express_name; //快递公司
  785. $supplier_purchase_send_data['express_no'] = $this->express_no; //快递号
  786. $supplier_purchase_send_data['send_type'] = $this->send_type; //1 快递配送 2 自主配送
  787. $supplier_purchase_send_data['words'] = $this->words;
  788. $supplier_purchase_send_data['zip_code'] = $this->zip_code;
  789. $supplier_purchase_send_data['order_type'] = $this->order_type;
  790. $supplierPurchaseSendInfo = cloud_post($this->domain.$supplier_purchase_send_url,$supplier_purchase_send_data);
  791. $supplierPurchaseSendInfo = json_decode($supplierPurchaseSendInfo,true);
  792. if($supplierPurchaseSendInfo['code'] != 0){
  793. $code = 1; //失败
  794. return $this->outPutData($code,$supplierPurchaseSendInfo['msg']);
  795. }else{
  796. return $this->outPutData($supplierPurchaseSendInfo['code'],$supplierPurchaseSendInfo['msg']);
  797. }
  798. }
  799. //订单删除
  800. public function supplierPurchaseDel(){
  801. if (!$this->validate()) {
  802. return [
  803. 'code' => 1,
  804. 'msg' => $this->getErrorSummary(false)[0],
  805. ];
  806. }
  807. $supplier_purchase_send_url = "/cloud/supplier/supplierPurchaseDel";
  808. $supplier_purchase_send_data = [];
  809. $supplier_purchase_send_data['access_token'] = get_supplier_token(); //获取供货商的token信息
  810. $supplier_purchase_send_data['order_ids'] = $this->order_id; //订单ID
  811. $supplierPurchaseSendInfo = cloud_post($this->domain.$supplier_purchase_send_url,$supplier_purchase_send_data);
  812. $supplierPurchaseSendInfo = json_decode($supplierPurchaseSendInfo,true);
  813. if($supplierPurchaseSendInfo['code'] != 0){
  814. $code = 1; //失败
  815. return $this->outPutData($code,$supplierPurchaseSendInfo['msg']);
  816. }else{
  817. return $this->outPutData($supplierPurchaseSendInfo['code'],$supplierPurchaseSendInfo['msg']);
  818. }
  819. }
  820. //转单列表
  821. public function supplierPurchaseOrderList($cloud_supplier_id = 0, $auto = 0){
  822. if (!$this->validate()) {
  823. return [
  824. 'code' => 1,
  825. 'msg' => $this->getErrorSummary(false)[0],
  826. ];
  827. }
  828. // 获取可导出数据
  829. $f = new ExportList();
  830. $exportList = $f->getList();
  831. $admin = null;
  832. if ($auto === 0) {
  833. $admin = get_admin();
  834. }
  835. $supplier_purchase_order_list_url = "/cloud/supplier/supplierPurchaseOrderList";
  836. $supplier_purchase_order_list_data = [];
  837. $supplier_purchase_order_list_data['access_token'] = get_supplier_token($cloud_supplier_id); //获取供货商的token信息
  838. if (($admin->type === 'admin' && $admin->username !== 'admin') || $admin->type === Admin::ADMIN_TYPE_FRONT_AGENT) {
  839. $supplier_purchase_order_list_url = "/cloud/user/supplierPurchaseOrderList";
  840. $supplier_purchase_order_list_data['access_token'] = get_platform_token();
  841. $admin_id = $admin->id;
  842. if ($admin_id) {
  843. $admin_model = Admin::findOne($admin_id);
  844. $area_level = $admin_model->area_level;
  845. $query = Supplier::find()->where(['is_delete' => 0]);
  846. $salesman_id = $this->salesman_id;
  847. if ($salesman_id) {
  848. $query->andWhere([
  849. 'salesman_id' => $salesman_id
  850. ]);
  851. }
  852. if($area_level == 1){
  853. $query->andWhere(
  854. ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id, 'district_id' => $admin_model->district_id]);
  855. } elseif ($area_level == 2){
  856. $query->andWhere(
  857. ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id]);
  858. } elseif ($area_level == 3){
  859. $query->andWhere(['province_id' => $admin_model->province_id]);
  860. }
  861. $ids = $query->select('cloud_supplier_id')->column();
  862. if ($ids) {
  863. if(is_array($ids)){
  864. $ids = implode(',', $ids);
  865. }
  866. $supplier_purchase_order_list_data['supplier_id'] = $ids;
  867. } else {
  868. return $this->outPutData(0,'获取成功',[
  869. 'list' => []
  870. ]);
  871. }
  872. }
  873. }
  874. $supplier_purchase_order_list_data['page'] = $this->page; //默认为 1
  875. $supplier_purchase_order_list_data['limit'] = $this->limit; //默认20
  876. $supplier_purchase_order_list_data['status'] = $this->status; //-1 全部 0 待供货商确认 1 供货商已发货 2 已确认收货
  877. $supplier_purchase_order_list_data['mch_id'] = $this->could_mch_id; //商户ID
  878. if($this->start_time) $supplier_purchase_order_list_data['start_time'] = strtotime($this->start_time); //开始时间
  879. if($this->end_time) $supplier_purchase_order_list_data['end_time'] = strtotime($this->end_time); //结束时间
  880. if($this->order_no) $supplier_purchase_order_list_data['order_no'] = $this->order_no; //订单号
  881. if($this->order_id) $supplier_purchase_order_list_data['order_id'] = $this->order_id; //订单号
  882. $supplierPurchaseOrderListInfo = cloud_post($this->domain.$supplier_purchase_order_list_url,$supplier_purchase_order_list_data);
  883. $supplierPurchaseOrderListInfo = json_decode($supplierPurchaseOrderListInfo,true);
  884. if($supplierPurchaseOrderListInfo['code'] != 0){
  885. $code = 1; //失败
  886. return $this->outPutData($code,$supplierPurchaseOrderListInfo['msg']);
  887. }else{
  888. $msg = '获取成功';
  889. $data = $supplierPurchaseOrderListInfo['data'];
  890. if ($auto === 0) {
  891. $xlsx = \Yii::$app->request->hostInfo . '/web/statics/Template.xlsx';
  892. $is_stbz = false;
  893. $supplier_id = get_supplier_id();
  894. $supplier = Supplier::findOne($supplier_id);
  895. if ($supplier && $supplier->is_stbz == 1) {
  896. $is_stbz = true;
  897. }
  898. $data = array_merge([
  899. 'export_list' => $exportList,
  900. 'supplier_id' => $supplier_id,
  901. 'xlsx' => $xlsx,
  902. 'is_stbz' => $is_stbz,
  903. ], $data);
  904. }
  905. return $this->outPutData($supplierPurchaseOrderListInfo['code'],$msg,$data);
  906. }
  907. }
  908. public function supplierSendTypeRefundList() {
  909. if (!$this->validate()) {
  910. return [
  911. 'code' => 1,
  912. 'msg' => $this->getErrorSummary(false)[0],
  913. ];
  914. }
  915. $supplier_purchase_order_list_url = "/cloud/supplier/supplierSendTypeRefundList";
  916. $supplier_purchase_order_list_data = [];
  917. $supplier_purchase_order_list_data['access_token'] = get_supplier_token(); //获取供货商的token信息
  918. $admin = get_admin();
  919. if ($admin->type === 'admin' || $admin->type === Admin::ADMIN_TYPE_FRONT_AGENT) {
  920. $supplier_purchase_order_list_url = "/cloud/user/supplierPurchaseOrderRefundList";
  921. $supplier_purchase_order_list_data['access_token'] = get_platform_token();
  922. $admin = get_admin();
  923. $admin_id = $admin->id;
  924. if ($admin->username == 'admin') {
  925. $admin_id = null;
  926. }
  927. if ($admin_id) {
  928. $admin_model = Admin::findOne($admin_id);
  929. $area_level = $admin_model->area_level;
  930. $query = Supplier::find()->where(['is_delete' => 0]);
  931. $salesman_id = $this->salesman_id;
  932. if ($salesman_id) {
  933. $query->andWhere([
  934. 'salesman_id' => $salesman_id
  935. ]);
  936. }
  937. if($area_level == 1){
  938. $query->andWhere(
  939. ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id, 'district_id' => $admin_model->district_id]);
  940. } elseif ($area_level == 2){
  941. $query->andWhere(
  942. ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id]);
  943. } elseif ($area_level == 3){
  944. $query->andWhere(['province_id' => $admin_model->province_id]);
  945. }
  946. $ids = $query->select('cloud_supplier_id')->column();
  947. if ($ids) {
  948. if(is_array($ids)){
  949. $ids = implode(',', $ids);
  950. }
  951. $supplier_purchase_order_list_data['supplier_id'] = $ids;
  952. } else {
  953. return $this->outPutData(0,'获取成功',[
  954. 'list' => []
  955. ]);
  956. }
  957. }
  958. }
  959. $supplier_purchase_order_list_data['page'] = $this->page; //默认为 1
  960. $supplier_purchase_order_list_data['limit'] = $this->limit; //默认20
  961. $supplier_purchase_order_list_data['status'] = $this->status; //-1 全部 0 待供货商确认 1 供货商已发货 2 已确认收货
  962. $supplier_purchase_order_list_data['type'] = $this->type;
  963. if($this->start_time) $supplier_purchase_order_list_data['start_time'] = strtotime($this->start_time); //开始时间
  964. if($this->end_time) $supplier_purchase_order_list_data['end_time'] = strtotime($this->end_time); //结束时间
  965. if($this->order_no) $supplier_purchase_order_list_data['order_no'] = $this->order_no; //订单号
  966. if($this->old_order_no) $supplier_purchase_order_list_data['old_order_no'] = $this->old_order_no; //订单号
  967. if (!empty(trim($this->mch_order_no))) {
  968. $mch_order_id = Order::find()->where(['LIKE', 'order_no', $this->mch_order_no])->select('id')->column();
  969. if (!empty($mch_order_id)) {
  970. $mch_order_id = implode(',', $mch_order_id);
  971. } else {
  972. $mch_order_id = '-1';
  973. }
  974. $supplier_purchase_order_list_data['mch_order_ids'] = $mch_order_id;
  975. }
  976. $supplierPurchaseOrderListInfo = cloud_post($this->domain.$supplier_purchase_order_list_url,$supplier_purchase_order_list_data);
  977. $supplierPurchaseOrderListInfo = json_decode($supplierPurchaseOrderListInfo,true);
  978. if($supplierPurchaseOrderListInfo['code'] != 0){
  979. $code = 1; //失败
  980. return $this->outPutData($code,$supplierPurchaseOrderListInfo['msg']);
  981. }else{
  982. foreach ($supplierPurchaseOrderListInfo['data']['list'] as &$item) {
  983. $order = Order::findOne(['id' => $item['platform_order_no']]);
  984. $item['platform_order_no'] = $order->order_no ?: '';
  985. }
  986. $msg = '获取成功';
  987. return $this->outPutData($supplierPurchaseOrderListInfo['code'],$msg,$supplierPurchaseOrderListInfo['data']);
  988. }
  989. }
  990. //转单售后列表
  991. public function supplierPurchaseOrderRefundList(){
  992. if (!$this->validate()) {
  993. return [
  994. 'code' => 1,
  995. 'msg' => $this->getErrorSummary(false)[0],
  996. ];
  997. }
  998. $supplier_purchase_order_list_url = "/cloud/supplier/supplierPurchaseOrderRefundList";
  999. $supplier_purchase_order_list_data = [];
  1000. $supplier_purchase_order_list_data['access_token'] = get_supplier_token(); //获取供货商的token信息
  1001. $admin = get_admin();
  1002. if ($admin->type === 'admin' || $admin->type === Admin::ADMIN_TYPE_FRONT_AGENT) {
  1003. $supplier_purchase_order_list_url = "/cloud/user/supplierPurchaseOrderRefundList";
  1004. $supplier_purchase_order_list_data['access_token'] = get_platform_token();
  1005. $admin = get_admin();
  1006. $admin_id = $admin->id;
  1007. if ($admin->username == 'admin') {
  1008. $admin_id = null;
  1009. }
  1010. if ($admin_id) {
  1011. $admin_model = Admin::findOne($admin_id);
  1012. $area_level = $admin_model->area_level;
  1013. $query = Supplier::find()->where(['is_delete' => 0]);
  1014. $salesman_id = $this->salesman_id;
  1015. if ($salesman_id) {
  1016. $query->andWhere([
  1017. 'salesman_id' => $salesman_id
  1018. ]);
  1019. }
  1020. if($area_level == 1){
  1021. $query->andWhere(
  1022. ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id, 'district_id' => $admin_model->district_id]);
  1023. } elseif ($area_level == 2){
  1024. $query->andWhere(
  1025. ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id]);
  1026. } elseif ($area_level == 3){
  1027. $query->andWhere(['province_id' => $admin_model->province_id]);
  1028. }
  1029. $ids = $query->select('cloud_supplier_id')->column();
  1030. if ($ids) {
  1031. if(is_array($ids)){
  1032. $ids = implode(',', $ids);
  1033. }
  1034. $supplier_purchase_order_list_data['supplier_id'] = $ids;
  1035. } else {
  1036. return $this->outPutData(0,'获取成功',[
  1037. 'list' => []
  1038. ]);
  1039. }
  1040. }
  1041. }
  1042. $supplier_purchase_order_list_data['page'] = $this->page; //默认为 1
  1043. $supplier_purchase_order_list_data['limit'] = $this->limit; //默认20
  1044. $supplier_purchase_order_list_data['status'] = $this->status; //-1 全部 0 待供货商确认 1 供货商已发货 2 已确认收货
  1045. $supplier_purchase_order_list_data['mch_id'] = $this->could_mch_id; //商户ID
  1046. $supplier_purchase_order_list_data['order_type'] = $this->order_type;
  1047. if($this->start_time) $supplier_purchase_order_list_data['start_time'] = strtotime($this->start_time); //开始时间
  1048. if($this->end_time) $supplier_purchase_order_list_data['end_time'] = strtotime($this->end_time); //结束时间
  1049. if($this->order_no) $supplier_purchase_order_list_data['order_no'] = $this->order_no; //订单号
  1050. $supplierPurchaseOrderListInfo = cloud_post($this->domain.$supplier_purchase_order_list_url,$supplier_purchase_order_list_data);
  1051. $supplierPurchaseOrderListInfo = json_decode($supplierPurchaseOrderListInfo,true);
  1052. if($supplierPurchaseOrderListInfo['code'] != 0){
  1053. $code = 1; //失败
  1054. return $this->outPutData($code,$supplierPurchaseOrderListInfo['msg']);
  1055. }else{
  1056. $msg = '获取成功';
  1057. return $this->outPutData($supplierPurchaseOrderListInfo['code'],$msg,$supplierPurchaseOrderListInfo['data']);
  1058. }
  1059. }
  1060. //供货商创建提现申请
  1061. public function storeSetSupplierCash(){
  1062. if (!$this->validate()) {
  1063. return [
  1064. 'code' => 1,
  1065. 'msg' => $this->getErrorSummary(false)[0],
  1066. ];
  1067. }
  1068. $supplier_id = get_supplier_id();
  1069. if(!$supplier_id || $supplier_id < 0){
  1070. $code = 1; //失败
  1071. $msg = "会员信息有误!";
  1072. return $this->outPutData($code,$msg);
  1073. }
  1074. $supplierInfo = Supplier::find()->where(['id'=>$supplier_id,'is_delete'=>0])->one();
  1075. if(!$supplierInfo || !$supplierInfo['cloud_user_id'] || $supplierInfo['cloud_user_id'] < 0){
  1076. $code = 1; //失败
  1077. $msg = "会员信息有误!";
  1078. return $this->outPutData($code,$msg);
  1079. }
  1080. $supplier_cash_url = "/cloud/supplier/storeSetSupplierCash";
  1081. $supplier_cash_data = [];
  1082. $supplier_cash_data['access_token'] = get_supplier_token(); //获取供货商的token信息
  1083. $supplier_cash_data['user_id'] = $supplierInfo['cloud_user_id']; //会员Id
  1084. $supplier_cash_data['price'] = number_format($this->price, 2,".",""); //充值金额
  1085. $supplier_cash_data['type'] = $this->type; //类型 0 会员 1 商户 2 供货商 暂时仅做供货商提现
  1086. $supplier_cash_data['cash_type'] = $this->cash_type; //提现方式 1--微信支付 2--支付宝 3--银行卡
  1087. $supplier_cash_data['account'] = $this->account; //账号 微信 支付宝 银行卡号
  1088. $supplier_cash_data['name'] = $this->name; //姓名
  1089. $supplier_cash_data['bank_name'] = $this->bank_name; //银行
  1090. $supplierCashInfo = cloud_post($this->domain.$supplier_cash_url,$supplier_cash_data);
  1091. $supplierCashInfo = json_decode($supplierCashInfo,true);
  1092. if($supplierCashInfo['code'] != 0){
  1093. $code = 1; //失败
  1094. return $this->outPutData($code,$supplierCashInfo['msg']);
  1095. }else{
  1096. return $this->outPutData($supplierCashInfo['code'],$supplierCashInfo['msg']);
  1097. }
  1098. }
  1099. //处理请求
  1100. public function supplierApplyHandle($cloud_supplier_id = 0)
  1101. {
  1102. try {
  1103. /**
  1104. * is_agree 1 同意退换货
  1105. * is_agree 2 拒绝退换货 拒绝原因
  1106. * 判断type (商户申请状态 1退货退款 2换货)
  1107. *
  1108. * is_agree 1 status 1 确认收货 type = 1 打款完成
  1109. * is_agree 1 status 1 确认收货 type = 2 处理换货
  1110. * is_agree 2 || status 2 已经拒绝
  1111. */
  1112. if (!$this->validate()) {
  1113. return [
  1114. 'code' => 1,
  1115. 'msg' => $this->getErrorSummary(false)[0],
  1116. ];
  1117. }
  1118. $is_agree = (int)$this->is_agree;
  1119. $status = (int)$this->status;
  1120. $reason = $this->reason;
  1121. $order_id = (int)$this->order_id;
  1122. $mobile = $this->mobile;
  1123. $name = $this->name;
  1124. $detail = $this->detail;
  1125. $zipcode = $this->zipcode;
  1126. if ($is_agree === 2 || $status === 2) {
  1127. if (empty($reason)) {
  1128. $code = 1; //失败
  1129. $msg = "请填写拒绝原因";
  1130. return $this->outPutData($code,$msg);
  1131. }
  1132. }
  1133. $supplier_apply_url = "/cloud/supplier/supplierApplyHandle";
  1134. $supplier_apply_data = [];
  1135. $supplier_apply_data['access_token'] = get_supplier_token($cloud_supplier_id); //获取供货商的token信息
  1136. $supplier_apply_data['is_agree'] = $is_agree;
  1137. $supplier_apply_data['status'] = $status;
  1138. $supplier_apply_data['reason'] = $reason;
  1139. $supplier_apply_data['mobile'] = $mobile;
  1140. $supplier_apply_data['name'] = $name;
  1141. $supplier_apply_data['detail'] = $detail;
  1142. $supplier_apply_data['zipcode'] = $zipcode;
  1143. $supplier_apply_data['order_id'] = $order_id;
  1144. $supplierApplyInfo = cloud_post($this->domain.$supplier_apply_url,$supplier_apply_data);
  1145. $supplierApplyInfo = json_decode($supplierApplyInfo,true);
  1146. debug_log($supplierApplyInfo, 'supplierApplyHandle.log');
  1147. // if(input_params('debug')){
  1148. // var_dump($supplierApplyInfo);die;
  1149. // }
  1150. if($supplierApplyInfo['code'] != 0){
  1151. $code = 1; //失败
  1152. throw new \Exception($supplierApplyInfo['msg']);
  1153. }else{
  1154. $data = $supplierApplyInfo['data'];
  1155. if ((int)$data['order_type'] === 0) {
  1156. $order = OrderTransit::findOne(['cloud_order_id' => $data['order_id']]);
  1157. if ($order && intval($order->status) === 0 && $is_agree === 1) {//未发货状态申请售后,直接调用退款
  1158. $status = 1;
  1159. }
  1160. //只查询一条订单详情记录
  1161. $cancel_examine_item_info = [];
  1162. $cancel_examine_info = json_decode($order->cancel_examine_info, true);
  1163. debug_log(['cancel_examine_info' => $cancel_examine_info], 'supplierRefund.log');
  1164. debug_log(['order_detail' => $data['order_detail']], 'supplierRefund.log');
  1165. if ($cancel_examine_info) {
  1166. foreach ($cancel_examine_info as $cancel_examine_item) {
  1167. foreach ($data['order_detail'] as $detail_item) {
  1168. if ($cancel_examine_item['cloud_goods_id'] == $detail_item['goods_id']
  1169. && $cancel_examine_item['goods_no'] == $detail_item['goods_no']) {
  1170. //符合条件 修改状态
  1171. debug_log(['cancel_examine_item_' => $cancel_examine_item_info], 'supplierRefund.log');
  1172. $cancel_examine_item_info[] = $cancel_examine_item;
  1173. }
  1174. }
  1175. }
  1176. debug_log(['cancel_examine_item' => $cancel_examine_item_info], 'supplierRefund.log');
  1177. //查询售后订单 售后订单不止一条可能会有问题
  1178. //20241106 增加多条售后订单记录流程
  1179. $store_order_detail_id = array_column($cancel_examine_item_info, 'store_order_detail_id');
  1180. sort($store_order_detail_id);
  1181. //目前提交售后要么就是全部提交 要么就是单个单个提交
  1182. $orderRefund = null;
  1183. $orderRefundList = OrderRefund::find()->where(['order_id' => $order->order_id])->asArray()->all();
  1184. //假设全部提交情况下
  1185. // debug_log(['orderRefundList' => $orderRefundList], 'supplierRefund.log');
  1186. foreach ($orderRefundList as $orderRefundItem) {
  1187. $refund_detail_id = json_decode($orderRefundItem['order_detail_id'], true);
  1188. sort($refund_detail_id);
  1189. debug_log([
  1190. 'id' => $orderRefundItem['id'],
  1191. 'refund_detail_id' => $refund_detail_id,
  1192. 'store_order_detail_id' => $store_order_detail_id,
  1193. 'bool' => !array_diff($store_order_detail_id, $refund_detail_id)
  1194. ], 'supplierRefund.log');
  1195. if (!array_diff($store_order_detail_id, $refund_detail_id)) {
  1196. $orderRefund = OrderRefund::findOne($orderRefundItem['id']);
  1197. }
  1198. }
  1199. //全部提交情况不存在 列出单个提交的情况
  1200. if (!$orderRefund) {
  1201. foreach ($orderRefundList as $orderRefundItem) {
  1202. $refund_detail_id = json_decode($orderRefundItem['order_detail_id'], true);
  1203. if (in_array($refund_detail_id[0], $store_order_detail_id)) {
  1204. $orderRefund = OrderRefund::findOne($orderRefundItem['id']);
  1205. }
  1206. }
  1207. }
  1208. //以上情况都不存在
  1209. if (empty($orderRefund)) {
  1210. throw new \Exception('售后订单不存在');
  1211. }
  1212. } else {
  1213. $orderRefund = OrderRefund::findOne([
  1214. 'order_id' => $order->order_id
  1215. ]);
  1216. }
  1217. //如果同意售后就修改商城订单状态,且更改地址为供货商地址信息
  1218. if ($is_agree === 1) {
  1219. if ($orderRefund) {
  1220. //供货商同意之后将商城订单状态修改为同意
  1221. $orderRefund->is_agree = 1;
  1222. $orderRefund->address_id = 0;
  1223. $orderRefund->refund_address = json_encode(
  1224. [
  1225. 'name' => $name,
  1226. 'address' => $detail,
  1227. 'mobile' => $mobile
  1228. ]
  1229. , JSON_UNESCAPED_UNICODE);
  1230. }
  1231. }
  1232. } else {
  1233. $order = PurchaseOrder::findOne(['cloud_order_id' => $data['order_id']]);
  1234. if ($order && intval($order->trade_status) === 0 && $is_agree === 1) {
  1235. $status = 1;
  1236. }
  1237. }
  1238. if ((int)$status === 1) {
  1239. if ((int)$data['order_type'] === 1) {
  1240. $order->trade_status = 1;
  1241. } else {
  1242. $order->status = -1;
  1243. }
  1244. $order->cancel_examine = 2;
  1245. if ($data) {
  1246. //微信支付退款操作
  1247. if (isset($order->pay_type) && (int)$order->pay_type === 1) {
  1248. $res = WechatBusinessPay::orderRefund($order, OrderNo::ORDER_ALLIANCE_PURCHASE, $data['refund_price'], $data['order_refund_no']);
  1249. if ($res['code'] === 1) {
  1250. return $res;
  1251. }
  1252. }
  1253. }
  1254. // 赤店新增逻辑 未进件情况下转单需要从商城余额抵扣金额 ...
  1255. // 申请售后, 需要从商城金额扣款 (已经从用户到账金额里扣减了)
  1256. // if (intval($order->is_use_platform_mch) && (int)$data['order_type'] === 0) {
  1257. // $store_info = Store::findOne($order->store_id);
  1258. // Store::addMoney($store_info, $order->order_price, '商城云仓订单售后');
  1259. // }
  1260. //如果是转单订单 供货商取消之后需要原路退回金额 当前版本下用户申请售后 商家同意后 用户直接与供货商交互
  1261. ///流程为用户确认收货后-申请售后-商城同意售后-API(商城向供货商申请售后)-供货商同意后填写收货地址-用户在客户端可以看到供货商填写的手机号以及地址信息
  1262. ///用户发货-供货商后台进行收货-售后完成给商城用户退款
  1263. if ((int)$data['order_type'] === 0) {
  1264. if (!empty($orderRefund)) {
  1265. //给商城用户退款
  1266. $orderRefundForm = new OrderRefundForm();
  1267. $orderRefundForm->order_refund_id = $orderRefund->id;
  1268. $orderRefundForm->store_id = $order->store_id;
  1269. $orderRefundForm->type = 1;
  1270. $orderRefundForm->action = 1;
  1271. $orderRefundForm->refund = 1;
  1272. $refund_result = $orderRefundForm->save(1);
  1273. debug_log($refund_result, 'SupplierRefund.log');
  1274. }
  1275. }
  1276. $type = 1;
  1277. if (intval($data['order_type'])) {//批发
  1278. $type = 2;
  1279. }
  1280. try {
  1281. $supplier = Supplier::findOne(['cloud_supplier_id' => $order->cloud_supplier_id]);
  1282. $printer_order = new PrintOrder(0, $order->cloud_order_id, 'confirm', 0, 0, $type, 0, $supplier->id);
  1283. $printer_order->print_order();
  1284. } catch (\Exception $e) {
  1285. debug_log([
  1286. 'event' => 'supplierApplyHandle',
  1287. 'message' => $e->getMessage(),
  1288. 'line' => $e->getLine(),
  1289. 'file' => $e->getFile()
  1290. ], 'cloud_printer.log');
  1291. }
  1292. }
  1293. if ($is_agree === 2 || $status === 2) {
  1294. // $order->cancel_examine = 0;
  1295. if ($is_agree === 2) {
  1296. if (!empty($orderRefund)) {
  1297. $orderRefund->is_agree = 2;
  1298. $orderRefund->status = 2;
  1299. }
  1300. }
  1301. if ($order->cancel_examine_info) {
  1302. $cancel_examine_info = json_decode($order->cancel_examine_info, true);
  1303. foreach ($cancel_examine_info as $cancel_examine_index => $cancel_examine_item) {
  1304. foreach ($data['order_detail'] as $detail_item) {
  1305. if ($cancel_examine_item['cloud_goods_id'] == $detail_item['goods_id']
  1306. && $cancel_examine_item['goods_no'] == $detail_item['goods_no']) {
  1307. unset($cancel_examine_info[$cancel_examine_index]);
  1308. }
  1309. }
  1310. }
  1311. $order->cancel_examine_info = json_encode(array_values($cancel_examine_info));
  1312. } else {
  1313. $order->cancel_examine = 0;
  1314. }
  1315. }
  1316. if (!$order->save()) {
  1317. throw new \Exception(json_encode($order->errors));
  1318. }
  1319. if ($orderRefund && !$orderRefund->save()) {
  1320. throw new \Exception(json_encode($order->errors));
  1321. }
  1322. return $this->outPutData($supplierApplyInfo['code'],$supplierApplyInfo['msg']);
  1323. }
  1324. } catch (\Exception $e) {
  1325. $code = 1; //失败
  1326. return $this->outPutData($code, $e->getMessage() . $e->getLine());
  1327. }
  1328. }
  1329. //余额记录
  1330. public function supplierGetBalanceLog(){
  1331. if (!$this->validate()) {
  1332. return [
  1333. 'code' => 1,
  1334. 'msg' => $this->getErrorSummary(false)[0],
  1335. ];
  1336. }
  1337. $get_balance_log_url = "/cloud/supplier/supplierGetBalanceLog";
  1338. $get_balance_log_data = [];
  1339. $get_balance_log_data['access_token'] = get_supplier_token(); //获取供货商的token信息
  1340. if($this->page) $get_balance_log_data['page'] = $this->page; //计费方式【1=>按重计费、2=>按件计费】
  1341. if($this->limit) $get_balance_log_data['limit'] = $this->limit;
  1342. $getBalanceLogInfo = cloud_post($this->domain.$get_balance_log_url,$get_balance_log_data);
  1343. $getBalanceLogInfo = json_decode($getBalanceLogInfo,true);
  1344. if($getBalanceLogInfo['code'] != 0){
  1345. $code = 1; //失败
  1346. return $this->outPutData($code,$getBalanceLogInfo['msg']);
  1347. }else{
  1348. $msg = '获取成功';
  1349. return $this->outPutData($getBalanceLogInfo['code'],$msg,$getBalanceLogInfo['data']);
  1350. }
  1351. }
  1352. //余额冻结记录
  1353. public function supplierGetBalanceFrozenLog(){
  1354. if (!$this->validate()) {
  1355. return [
  1356. 'code' => 1,
  1357. 'msg' => $this->getErrorSummary(false)[0],
  1358. ];
  1359. }
  1360. $get_balance_log_url = "/cloud/supplier/supplierGetBalanceFrozenLog";
  1361. $get_balance_log_data = [];
  1362. $get_balance_log_data['access_token'] = get_supplier_token(); //获取供货商的token信息
  1363. if($this->page) $get_balance_log_data['page'] = $this->page; //计费方式【1=>按重计费、2=>按件计费】
  1364. if($this->limit) $get_balance_log_data['limit'] = $this->limit;
  1365. $getBalanceLogInfo = cloud_post($this->domain.$get_balance_log_url,$get_balance_log_data);
  1366. $getBalanceLogInfo = json_decode($getBalanceLogInfo,true);
  1367. if($getBalanceLogInfo['code'] != 0){
  1368. $code = 1; //失败
  1369. return $this->outPutData($code,$getBalanceLogInfo['msg']);
  1370. }else{
  1371. $msg = '获取成功';
  1372. return $this->outPutData($getBalanceLogInfo['code'],$msg,$getBalanceLogInfo['data']);
  1373. }
  1374. }
  1375. //商品提交审核
  1376. public function auditSubmit(){
  1377. if (!$this->validate()) {
  1378. return [
  1379. 'code' => 1,
  1380. 'msg' => $this->getErrorSummary(false)[0],
  1381. ];
  1382. }
  1383. $rules_url = "/cloud/supplier/supplierPutGoodsAudit";
  1384. $rules_data = [];
  1385. $rules_data['access_token'] = get_supplier_token($this->token_supplier_id); //获取供货商的token信息
  1386. $rules_data['goods_id'] = $this->goods_id; //商品ID
  1387. $rulesInfo = cloud_post($this->domain.$rules_url,$rules_data);
  1388. $rulesInfo = json_decode($rulesInfo,true);
  1389. if($rulesInfo['code'] != 0){
  1390. $code = 1; //失败
  1391. return $this->outPutData($code,$rulesInfo['msg']);
  1392. }else{
  1393. if ((int)$this->status === 0) {
  1394. Goods::updateAll(['status' => 0], ['cloud_goods_id' => $this->goods_id, 'is_wholesale' => 0]);
  1395. }
  1396. $code = $rulesInfo['code'];
  1397. return $this->outPutData($code,$rulesInfo['msg'], $rulesInfo['data']);
  1398. }
  1399. }
  1400. //商品上下架
  1401. public function setRules(){
  1402. if (!$this->validate()) {
  1403. return [
  1404. 'code' => 1,
  1405. 'msg' => $this->getErrorSummary(false)[0],
  1406. ];
  1407. }
  1408. $rules_url = "/cloud/supplier/supplierSetRules";
  1409. $rules_data = [];
  1410. $rules_data['access_token'] = get_supplier_token(); //获取供货商的token信息
  1411. $rules_data['type'] = $this->type; //计费方式【1=>按重计费、2=>按件计费】
  1412. $rules_data['desc'] = $this->desc;
  1413. $rules_data['id'] = $this->id;
  1414. $rules_data['is_default'] = $this->is_default;
  1415. $rules_data['name'] = $this->name;
  1416. $rulesInfo = cloud_post($this->domain.$rules_url,$rules_data);
  1417. $rulesInfo = json_decode($rulesInfo,true);
  1418. if($rulesInfo['code'] != 0){
  1419. $code = 1; //失败
  1420. return $this->outPutData($code,$rulesInfo['msg']);
  1421. }else{
  1422. $code = $rulesInfo['code'];
  1423. return $this->outPutData($code,$rulesInfo['msg']);
  1424. }
  1425. }
  1426. //商品状态
  1427. public function setGoodsStatus(){
  1428. if (!$this->validate()) {
  1429. return [
  1430. 'code' => 1,
  1431. 'msg' => $this->getErrorSummary(false)[0],
  1432. ];
  1433. }
  1434. $goods_status_url = "/cloud/supplier/supplierSetGoodsStatus";
  1435. $goods_status_data = [];
  1436. $goods_status_data['access_token'] = get_supplier_token(); //获取供货商的token信息
  1437. $goods_status_data['goods_ids'] = $this->goods_id; //商品ID
  1438. if(in_array($this->status,[0,1,2])){ $goods_status_data['status'] = $this->status; }//0 下架 1 上架 2删除
  1439. //检测胜天半子
  1440. if ($this->stbz_goods_id && intval($this->status) === 1) {
  1441. $id = \get_params('id', $this->stbz_goods_id);
  1442. $params = [
  1443. 'id' => $id,
  1444. ];
  1445. $key = md5(json_encode(\array_merge($params, ['type' => 'stbz_get_goods_item'])));
  1446. if (\Yii::$app->cache->exists($key)) {
  1447. $data = \Yii::$app->cache->get($key);
  1448. $returnData = \json_decode($data, true);
  1449. } else {
  1450. $data = \stbz_client()->getApiResponse('get', '/v2/Goods/Detail', $params);
  1451. $returnData = \json_decode($data, true);
  1452. if ($returnData['code'] != 1) {
  1453. return [
  1454. 'code' => 1,
  1455. 'msg' => $returnData['msg'],
  1456. ];
  1457. }
  1458. \Yii::$app->cache->set($key, $data, 600);
  1459. }
  1460. if (!$returnData['data']) {
  1461. return [
  1462. 'code' => 1,
  1463. 'msg' => '胜天半子商品不存在',
  1464. ];
  1465. }
  1466. if (intval($returnData['data']['status']) === 0) {
  1467. return [
  1468. 'code' => 1,
  1469. 'msg' => '胜天半子商品已下架',
  1470. ];
  1471. }
  1472. }
  1473. $goodsStatusInfo = cloud_post($this->domain.$goods_status_url,$goods_status_data);
  1474. $goodsStatusInfo = json_decode($goodsStatusInfo,true);
  1475. if($goodsStatusInfo['code'] != 0){
  1476. $code = 1; //失败
  1477. return $this->outPutData($code,$goodsStatusInfo['msg']);
  1478. }else{
  1479. if (in_array($this->status, [0, 2])) {
  1480. $goods_id = $this->goods_id;
  1481. if (is_string($this->goods_id)) {
  1482. $goods_id = explode(',', $this->goods_id);
  1483. }
  1484. Goods::updateAll(['status' => 0], ['cloud_goods_id' => $goods_id, 'is_wholesale' => 0]);
  1485. }
  1486. return $this->outPutData($goodsStatusInfo['code'] ,$goodsStatusInfo['msg']);
  1487. }
  1488. }
  1489. //添加编辑规格
  1490. public function setGoodsAttr(){
  1491. if (!$this->validate()) {
  1492. return [
  1493. 'code' => 1,
  1494. 'msg' => $this->getErrorSummary(false)[0],
  1495. ];
  1496. }
  1497. $goods_attr_url = "/cloud/supplier/supplierSetGoodsAttr";
  1498. $goods_attr_data = [];
  1499. $goods_attr_data['access_token'] = get_supplier_token(); //获取供货商的token信息
  1500. $goods_attr_data['attr_id'] = ($this->attr_id) ? $this->attr_id : 0 ; //规格ID 0添加 大于0 编辑
  1501. $goods_attr_data['name'] = $this->name; //规格名称
  1502. $goods_attr_data['goods_id'] = $this->goods_id; //商品ID
  1503. $goods_attr_data['price'] = number_format($this->price, 2,".",""); //价格
  1504. $goods_attr_data['pic_url'] = $this->pic_url; //规格图片
  1505. $goods_attr_data['num'] = $this->num; //库存
  1506. // $goods_attr_data['weight'] = $this->weight;
  1507. $goods_attr_data['goods_no'] = $this->goods_no; //规格货号
  1508. $goodsAttrInfo = cloud_post($this->domain.$goods_attr_url,$goods_attr_data);
  1509. $goodsAttrInfo = json_decode($goodsAttrInfo,true);
  1510. if($goodsAttrInfo['code'] != 0){
  1511. $code = 1; //失败
  1512. return $this->outPutData($code,$goodsAttrInfo['msg']);
  1513. }else{
  1514. return $this->outPutData($goodsAttrInfo['code'],$goodsAttrInfo['msg']);
  1515. }
  1516. }
  1517. //添加编辑规格
  1518. public function setGoodsAttrNum($supplier_id, $goods_id, $updateAttrList, $store_id = 0){
  1519. if (!$this->validate()) {
  1520. return [
  1521. 'code' => 1,
  1522. 'msg' => $this->getErrorSummary(false)[0],
  1523. ];
  1524. }
  1525. $goods_attr_url = "/cloud/supplier/setGoodsAttrNum";
  1526. $goods_attr_data = [];
  1527. $goods_attr_data['access_token'] = get_supplier_token(0, $supplier_id); //获取供货商的token信息
  1528. $goods_attr_data['attrs'] = json_encode($updateAttrList);
  1529. $store_id && $goods_attr_data['store_id'] = $store_id;
  1530. $goods_attr_data['goods_id'] = $goods_id; //商品ID
  1531. $setGoodsAttrNum = cloud_post($this->domain.$goods_attr_url,$goods_attr_data);
  1532. $setGoodsAttrNum = json_decode($setGoodsAttrNum,true);
  1533. if($setGoodsAttrNum['code'] != 0){
  1534. $code = 1; //失败
  1535. return $this->outPutData($code,$setGoodsAttrNum['msg']);
  1536. }else{
  1537. return $this->outPutData($setGoodsAttrNum['code'],$setGoodsAttrNum['msg']);
  1538. }
  1539. }
  1540. //创建商品
  1541. public function setGoods(){
  1542. if (!$this->validate()) {
  1543. return [
  1544. 'code' => 1,
  1545. 'msg' => $this->getErrorSummary(false)[0],
  1546. ];
  1547. }
  1548. $price = number_format($this->g_price, 2,".","");
  1549. $goods_url = "/cloud/supplier/supplierSetGoods";
  1550. $goods_data = [];
  1551. $goods_data['access_token'] = get_supplier_token($this->token_supplier_id); //获取供货商的token信息
  1552. $goods_data['goods_id'] = ($this->goods_id) ? $this->goods_id : 0;
  1553. $goods_data['name'] = $this->name; //默认为 1
  1554. $goods_data['pic_url'] = $this->g_s_pic_url;
  1555. $goods_data['video_url'] = $this->video_url;
  1556. $goods_data['desc'] = $this->desc;
  1557. $goods_data['num'] = $this->num; //库存
  1558. $goods_data['use_attr'] = $this->use_attr; //是否使用规格 默认0不使用
  1559. $goods_data['price'] = $price; //售价
  1560. $goods_data['wholesale_price'] = number_format((float)$this->g_wholesale_price, 2,".",""); // 批发价
  1561. $goods_data['wholesale_ladder_rebate'] = $this->g_wholesale_ladder_rebate; // 批发阶梯折扣
  1562. $goods_data['wholesale_rebate_switch'] = $this->g_wholesale_rebate_switch; // 是否开启批发阶梯折扣
  1563. $goods_data['wholesale_ladder_type'] = $this->wholesale_ladder_type; // 是否开启批发阶梯折扣
  1564. $goods_data['cat_id'] = $this->cat_id;
  1565. $goods_data['sort'] = $this->sort;
  1566. $goods_data['is_change'] = $this->is_change ?: 0;
  1567. $goods_data['original_price'] = number_format($this->g_original_price, 2,".",""); //零售价
  1568. $goods_data['pic_list'] = json_encode($this->g_pic_list);
  1569. $goods_data['is_purchase'] = $this->is_purchase;
  1570. $goods_data['is_need_install'] = (int)$this->is_need_install;
  1571. $goods_data['stbz_goods_id'] = $this->stbz_goods_id ?: 0;
  1572. $goods_data['jst_goods_id'] = $this->jst_goods_id ?: 0;
  1573. $goods_data['jst_supplier_id'] = $this->jst_supplier_id ?: 0;
  1574. $goods_data['freight'] = (int)$this->freight;
  1575. $goods_data['is_level'] = (int)$this->is_level;
  1576. $goods_data['goods_full_give_switch'] = (int)$this->goods_full_give_switch;
  1577. $goods_data['goods_full_give_info'] = $this->goods_full_give_info;
  1578. $goods_data['market_price'] = $this->market_price ?: 0;
  1579. $goods_data['underlined_price'] = sprintf('%.2f', $this->underlined_price);
  1580. $goods_data['send_type_num'] = $this->send_type_num ?: 0;
  1581. $goods_data['centralize_goods_type'] = $this->centralize_goods_type ?: 0;
  1582. //增加平台协议价
  1583. $platform_negotiated_price = $this->setPlatformNegotiatedPrice($price);
  1584. $goods_data['platform_negotiated_price'] = $platform_negotiated_price;
  1585. if($this->goods_area_rules_id) $goods_data['goods_area_rules_id'] = $this->goods_area_rules_id;
  1586. if($this->g_unit) $goods_data['unit'] = $this->g_unit;
  1587. if($this->g_shop_count) $goods_data['shop_count'] = $this->g_shop_count;
  1588. if($this->g_send_type) $goods_data['send_type'] = $this->g_send_type;
  1589. if($this->goods_no) $goods_data['goods_no'] = $this->goods_no; //默认20
  1590. if ($this->weight) $goods_data['weight'] = number_format($this->weight, 2, '.', ''); // 重量,克
  1591. $is_supplier_set_price = Option::get('is_supplier_set_price', 0, 'cloud', 1)['value'];
  1592. $goods_data['is_supplier_set_price'] = $is_supplier_set_price;
  1593. $attrs = $this->attrs;
  1594. foreach ($attrs as &$attr_item) {
  1595. $attr_item['platform_negotiated_price'] = $this->setPlatformNegotiatedPrice($attr_item['price']);
  1596. }
  1597. $goods_data['attrs'] = json_encode($attrs);
  1598. $goods_data['is_selection'] = $this->is_selection;
  1599. $goodsDataInfo = cloud_post($this->domain.$goods_url,$goods_data);
  1600. $goodsDataInfo = json_decode($goodsDataInfo,true);
  1601. if($goodsDataInfo['code'] != 0){
  1602. $code = 1;//失败
  1603. return $this->outPutData($code,$goodsDataInfo['msg']);
  1604. }else{
  1605. if (!empty($this->goods_id) && $goodsDataInfo['data']['open'] == true) {
  1606. Goods::updateAll(['status' => 0],['cloud_goods_id' => $this->goods_id, 'is_wholesale' => 0]);
  1607. }
  1608. return $this->outPutData($goodsDataInfo['code'] ,$goodsDataInfo['msg'], $goodsDataInfo['data']);
  1609. }
  1610. }
  1611. public function setPlatformNegotiatedPrice($price) {
  1612. $platform_profit_strategy = Option::get('platform_profit_strategy', 0, 'store')['value'];
  1613. $platform_profit_strategy = json_decode($platform_profit_strategy, true);
  1614. if (!empty($platform_profit_strategy)) {
  1615. //服务收费start
  1616. if (intval($platform_profit_strategy['service_charge_model'])) {
  1617. //平台溢价
  1618. $service_charge_rate = $platform_profit_strategy['service_charge_rate'];
  1619. } else {
  1620. //供货商抽成
  1621. $service_charge_rate = 0;
  1622. }
  1623. $price = sprintf('%.2f', ($price * (1 + ($service_charge_rate / 100))));
  1624. }
  1625. return $price;
  1626. }
  1627. //获取商品列表
  1628. public function goodsList(){
  1629. if (!$this->validate()) {
  1630. return [
  1631. 'code' => 1,
  1632. 'msg' => $this->getErrorSummary(false)[0],
  1633. ];
  1634. }
  1635. $goods_list_url = "/cloud/supplier/supplierGetGoodsList";
  1636. $goods_list_data = [];
  1637. $goods_list_data['access_token'] = get_supplier_token(); //获取供货商的token信息
  1638. $goods_list_data['page'] = input_params('pageNo') ?: $this->page; //默认为 1
  1639. $goods_list_data['limit'] = $this->limit; //默认20
  1640. if($this->goods_id) $goods_list_data['goods_id'] = $this->goods_id;
  1641. if($this->cat_id) $goods_list_data['cat_id'] = (int)$this->cat_id;
  1642. if($this->supplier_id) $goods_list_data['supplier_id'] = $this->supplier_id;
  1643. if($this->name) $goods_list_data['name'] = $this->name; //商品名称
  1644. if($this->status != -1) $goods_list_data['status'] = $this->status; //-1 全部 0 下架 1 上架
  1645. $goodsListInfo = cloud_post($this->domain.$goods_list_url,$goods_list_data);
  1646. $goodsListInfo = json_decode($goodsListInfo,true);
  1647. if($goodsListInfo['code'] != 0){
  1648. $code = 1;//失败
  1649. return $this->outPutData($code,$goodsListInfo['msg']);
  1650. }else{
  1651. foreach ($goodsListInfo['data']['list'] as &$item) {
  1652. $agent_goods = AgentGoodsBindGoods::find()->where(['cloud_goods_id' => $item['id'], 'is_delete' => 0])
  1653. ->select('goods_agent_admin_id')
  1654. ->column();
  1655. $item['admin_list'] = Admin::find()->where(
  1656. ['id' => $agent_goods, 'type' => Admin::ADMIN_TYPE_GOODS_AGENT, 'is_delete' => 0]
  1657. )->select('id, name, address, mobile, province_id, city_id, district_id')->asArray()->all();
  1658. foreach ($item['admin_list'] as &$value) {
  1659. $province_id = $value['province_id'];
  1660. $city_id = $value['city_id'];
  1661. $district_id = $value['district_id'];
  1662. $district = District::find()->where(['id' => [$province_id, $city_id, $district_id]])->select('name')->column();
  1663. $value['address'] = implode('', $district) . $value['address'];
  1664. }
  1665. }
  1666. return $this->outPutData($goodsListInfo['code'],"获取成功",$goodsListInfo['data']);
  1667. }
  1668. }
  1669. //获取商品审核列表
  1670. public function goodsAuditList(){
  1671. if (!$this->validate()) {
  1672. return [
  1673. 'code' => 1,
  1674. 'msg' => $this->getErrorSummary(false)[0],
  1675. ];
  1676. }
  1677. $goods_list_url = "/cloud/supplier/supplierGetGoodsAuditList";
  1678. $goods_list_data = [];
  1679. $goods_list_data['access_token'] = get_supplier_token(); //获取供货商的token信息
  1680. $goods_list_data['page'] = $this->page; //默认为 1
  1681. $goods_list_data['limit'] = $this->limit; //默认20
  1682. if($this->goods_id) $goods_list_data['goods_id'] = $this->goods_id;
  1683. if($this->supplier_id) $goods_list_data['supplier_id'] = $this->supplier_id;
  1684. if($this->name) $goods_list_data['name'] = $this->name; //商品名称
  1685. if($this->status) $goods_list_data['status'] = $this->status; //0全部 1审核中 2成功 3失败
  1686. $goodsListInfo = cloud_post($this->domain.$goods_list_url,$goods_list_data);
  1687. $goodsListInfo = json_decode($goodsListInfo,true);
  1688. if($goodsListInfo['code'] != 0){
  1689. $code = 1;//失败
  1690. return $this->outPutData($code,$goodsListInfo['msg']);
  1691. }else{
  1692. return $this->outPutData($goodsListInfo['code'],"获取成功",$goodsListInfo['data']);
  1693. }
  1694. }
  1695. //转单详情
  1696. public function purchaseOrderInfo($order_id, $supplier_id)
  1697. {
  1698. // $order_id = explode(',', $order_id);
  1699. // $cloud_order_id = $order_id;
  1700. // $cache = \Yii::$app->cache->get('cloud_supplier_cache_token_' . $supplier_id);
  1701. // if ($cache) {
  1702. // $params = json_decode($cache, true);
  1703. // //3天刷新token
  1704. // if (time() - $params['time'] < (3 * 24 * 3600) ) {
  1705. // //return $params['access_token'];
  1706. // $token = $params['access_token'];
  1707. // } else {
  1708. // $supplier = Supplier::findOne($supplier_id);
  1709. // $response = get_cloud_token($supplier->name, $supplier->password);
  1710. // $token = '';
  1711. // if ($response['code'] == 0 && $response['taken']) {
  1712. // $token = $response['taken'];
  1713. // }
  1714. // }
  1715. // } else {
  1716. // $supplier = Supplier::findOne($supplier_id);
  1717. // $response = get_cloud_token($supplier->name, $supplier->password);
  1718. // $token = '';
  1719. // if ($response['code'] == 0 && $response['taken']) {
  1720. // $token = $response['taken'];
  1721. // }
  1722. // }
  1723. $token = get_supplier_token(0, $supplier_id);
  1724. $data = [];
  1725. $fields = json_decode($this->fields, true);
  1726. $search = json_decode($this->search, true);
  1727. $supplier_purchase_order_list_url = "/cloud/supplier/supplierPurchaseOrderList";
  1728. $supplier_purchase_order_list_data = [];
  1729. $supplier_purchase_order_list_data['access_token'] = $token; //获取供货商的token信息
  1730. $supplier_purchase_order_list_data['order_id'] = (string)$order_id; //默认为 1
  1731. $supplier_purchase_order_list_data['order_type'] = $this->order_type;
  1732. $supplier_purchase_order_list_data['start_time'] = (int)strtotime($search['start_time']);
  1733. $supplier_purchase_order_list_data['end_time'] = (int)strtotime($search['end_time']);
  1734. $supplier_purchase_order_list_data['order_no'] = $search['order_no'];
  1735. $supplier_purchase_order_list_data['mobile'] = $search['mobile'];
  1736. $supplier_purchase_order_list_data['user_name'] = $search['user_name'];
  1737. $supplier_purchase_order_list_data['status'] = $search['status'];
  1738. $supplier_purchase_order_list_data['export'] = 1;
  1739. $supplierPurchaseOrderListInfo = cloud_post($this->domain.$supplier_purchase_order_list_url,$supplier_purchase_order_list_data);
  1740. $supplierPurchaseOrderListInfo = json_decode($supplierPurchaseOrderListInfo,true);
  1741. if($supplierPurchaseOrderListInfo['code'] != 0){
  1742. $code = 1; //失败
  1743. return $this->outPutData($code,$supplierPurchaseOrderListInfo['msg']);
  1744. }else{
  1745. $order_list = $supplierPurchaseOrderListInfo['data'];
  1746. $goods = [];
  1747. foreach ($order_list['list'] as $item) {
  1748. foreach ($item['goods_list'] as $goods_item) {
  1749. $attr = '';
  1750. if ($goods_item['attr']['attr_list']) {
  1751. foreach ($goods_item['attr']['attr_list'] as $attr_item) {
  1752. $attr .= $attr_item['attr_group_name'] . ':' . $attr_item['attr_name'] . ';';
  1753. }
  1754. } else {
  1755. foreach ($goods_item['attr'] as $attr_item) {
  1756. $attr .= $attr_item['attr_group_name'] . ':' . $attr_item['attr_name'] . ';';
  1757. }
  1758. }
  1759. $goods[] = [
  1760. 'order_no' => $item['order_no'], //订单编号
  1761. 'nickname' => $item['name'], //下单用户
  1762. 'good_name' => $goods_item['name'],//商品名称
  1763. 'attr' => $attr, //商品规格
  1764. 'good_num' => $goods_item['num'],//商品数量
  1765. 'goods_no' => $goods_item['goods_no'],//货号
  1766. 'name' => $item['name'],//下单人
  1767. 'mobile' => $item['mobile'],//手机号
  1768. 'address' => $item['address'],//地址
  1769. 'cost_price' => $item['goods_price'],//成本价
  1770. 'total_price' => $item['goods_price'],//总价
  1771. 'pay_price' => $item['goods_price'], //支付价
  1772. 'content' => $item['content'],//商家留言
  1773. 'apply_delete' => ((int)$item['is_refund'] == 1 ? '取消申请订单' : '未取消订单'),//申请状态
  1774. 'send_time' => !empty($item['send_time']) ? date('Y-m-d H:i:s', $item['send_time']) : '', //发货时间
  1775. 'merchant_remark' => $item['seller_desc'],//商家留言
  1776. 'created_at' => !empty($item['pay_time']) ? date('Y-m-d H:i:s', $item['pay_time']) : '',//下单时间
  1777. 'pay_type' => '线上支付',//支付类型 支付方式:1:微信支付,2:货到付款,3:余额支付,4:支付宝,5:抖音支付,6:线下支付
  1778. 'trade_status' => $item['status'],//订单状态 订单状态,-1:默认,0:待发货,1:已取消,2:已发货,3:已确认
  1779. 'pay_time' => !empty($item['pay_time']) ? date('Y-m-d H:i:s', $item['pay_time']) : ''//支付时间
  1780. ];
  1781. }
  1782. }
  1783. }
  1784. foreach ($goods as $index => &$item) {
  1785. foreach ($item as $i => $e) {
  1786. foreach ($fields as $f => $f_e) {
  1787. $open = true;
  1788. if ($f === $i) {
  1789. $open = false;
  1790. $item[$f_e] = $e;
  1791. }
  1792. if ($open) {
  1793. unset($item[$i]);
  1794. }
  1795. }
  1796. }
  1797. }
  1798. $writer = SimpleExcelWriter::streamDownload(time() . '.xlsx')
  1799. ->addRows($goods)->toBrowser();
  1800. // Export::order_3($goods, $fields);
  1801. }
  1802. //获取商品规则列表
  1803. public function goodsSaleRulesList(){
  1804. if (!$this->validate()) {
  1805. return [
  1806. 'code' => 1,
  1807. 'msg' => $this->getErrorSummary(false)[0],
  1808. ];
  1809. }
  1810. $goods_list_url = "/cloud/supplier/getGoodsSaleRulesList";
  1811. $goods_list_data = [];
  1812. $goods_list_data['access_token'] = get_supplier_token(); //获取供货商的token信息
  1813. $goods_list_data['page'] = $this->page; //默认为 1
  1814. $goods_list_data['limit'] = $this->limit; //默认20
  1815. if($this->name) $goods_list_data['name'] = $this->name; //商品名称
  1816. if($this->status !== null && $this->status !== '') $goods_list_data['status'] = $this->status; //0全部 1审核中 2成功 3失败
  1817. $goodsListInfo = cloud_post($this->domain.$goods_list_url,$goods_list_data);
  1818. $goodsListInfo = json_decode($goodsListInfo,true);
  1819. if($goodsListInfo['code'] != 0){
  1820. $code = 1;//失败
  1821. return $this->outPutData($code,$goodsListInfo['msg']);
  1822. }else{
  1823. return $this->outPutData($goodsListInfo['code'],"获取成功",$goodsListInfo['data']);
  1824. }
  1825. }
  1826. //保存商品规则
  1827. public function goodsSaleRulesSave(){
  1828. if (!$this->validate()) {
  1829. return [
  1830. 'code' => 1,
  1831. 'msg' => $this->getErrorSummary(false)[0],
  1832. ];
  1833. }
  1834. $goods_list_url = "/cloud/supplier/setGoodsSaleRules";
  1835. $goods_list_data = [];
  1836. $goods_list_data['access_token'] = get_supplier_token(); //获取供货商的token信息
  1837. $goods_list_data['name'] = $this->name; //默认为 1
  1838. $goods_list_data['area'] = $this->area; //默认20
  1839. $goods_list_data['status'] = $this->status; //默认20
  1840. if($this->id) $goods_list_data['id'] = $this->id;
  1841. $goodsListInfo = cloud_post($this->domain.$goods_list_url,$goods_list_data);
  1842. $goodsListInfo = json_decode($goodsListInfo,true);
  1843. if($goodsListInfo['code'] != 0){
  1844. $code = 1;//失败
  1845. return $this->outPutData($code,$goodsListInfo['msg']);
  1846. }else{
  1847. return $this->outPutData($goodsListInfo['code'],"操作成功",$goodsListInfo['data']);
  1848. }
  1849. }
  1850. //修改商品规则状态
  1851. public function setGoodsSaleRulesStatus(){
  1852. if (!$this->validate()) {
  1853. return [
  1854. 'code' => 1,
  1855. 'msg' => $this->getErrorSummary(false)[0],
  1856. ];
  1857. }
  1858. $goods_list_url = "/cloud/supplier/setGoodsSaleRulesStatus";
  1859. $goods_list_data = [];
  1860. $goods_list_data['access_token'] = get_supplier_token(); //获取供货商的token信息
  1861. $goods_list_data['status'] = $this->status;
  1862. $goods_list_data['id'] = $this->id;
  1863. $goods_list_data['ids'] = $this->ids;
  1864. $goodsListInfo = cloud_post($this->domain.$goods_list_url,$goods_list_data);
  1865. $goodsListInfo = json_decode($goodsListInfo,true);
  1866. if($goodsListInfo['code'] != 0){
  1867. $code = 1;//失败
  1868. return $this->outPutData($code,$goodsListInfo['msg']);
  1869. }else{
  1870. return $this->outPutData($goodsListInfo['code'],"操作成功",$goodsListInfo['data']);
  1871. }
  1872. }
  1873. public function agentOrderGroupList() {
  1874. try {
  1875. if (!$this->validate()) {
  1876. return [
  1877. 'code' => 1,
  1878. 'msg' => $this->getErrorSummary(false)[0],
  1879. ];
  1880. }
  1881. $admin = get_admin();
  1882. $goods_list_data = [];
  1883. $goods_list_url = "/cloud/supplier/getAgentOrderGroup";
  1884. $goods_list_data['access_token'] = get_supplier_token(); //获取供货商的token信息
  1885. if ($admin->type === Admin::ADMIN_TYPE_FRONT_AGENT || $admin->type === 'admin') {
  1886. if ($admin->type === 'admin') {
  1887. $cloud_supplier_id = Supplier::find()->where(['is_delete' => 0])->select('cloud_supplier_id')->column();
  1888. } else {
  1889. $supplier_id = AgentFrontBind::find()->where(['front_agent_admin_id' => $admin->id, 'type' => 0, 'status' => 1, 'is_delete' => 0])
  1890. ->select('type_id')->column();
  1891. $cloud_supplier_id = Supplier::find()->where(['id' => $supplier_id, 'is_delete' => 0])->select('cloud_supplier_id')->column();
  1892. }
  1893. $goods_list_url = "/cloud/user/getAgentOrderGroup";
  1894. $goods_list_data['access_token'] = get_platform_token();
  1895. if ($this->supplier_name) {
  1896. $goods_list_data['supplier_name'] = $this->supplier_name;
  1897. }
  1898. $goods_list_data['supplier_id'] = implode(',', $cloud_supplier_id);
  1899. }
  1900. $goods_list_data['status'] = $this->status;
  1901. $goods_list_data['goods_name'] = $this->goods_name;
  1902. $goods_list_data['type'] = $this->type;
  1903. $goods_list_data['page'] = $this->page; //默认为 1
  1904. $goods_list_data['limit'] = $this->limit; //默认20
  1905. $goodsListInfo = cloud_post($this->domain.$goods_list_url,$goods_list_data);
  1906. $goodsListInfo = json_decode($goodsListInfo,true);
  1907. if($goodsListInfo['code'] != 0){
  1908. throw new \Exception($goodsListInfo['msg']);
  1909. }else{
  1910. if (!empty($goodsListInfo['data'])) {
  1911. foreach ($goodsListInfo['data']['data'] as &$data) {
  1912. $admin_id = $data['admin_id'];
  1913. $admin = Admin::findOne(['id' => $admin_id]);
  1914. $district = District::find()->where(['id' => [$admin->province_id, $admin->city_id, $admin->district_id]])->select('name')->column();
  1915. $data['admin_name'] = $admin->name;
  1916. $data['admin_tel'] = $admin->mobile;
  1917. $data['admin_address'] = implode('/', $district) . ($admin->address ?: '');
  1918. if (!empty($data['platform_order_no'])) {
  1919. $data['mch_order_no'] = Order::findOne($data['platform_order_no'])->order_no;
  1920. } else {
  1921. $data['mch_order_no'] = PurchaseOrder::findOne(['cloud_order_id' => $data['order_id']])->order_no;
  1922. }
  1923. $data['md_info'] = null;
  1924. if ($data['md_id'] > 0) {
  1925. $md_info = Md::findOne($data['md_id']);
  1926. $data['md_info'] = [
  1927. 'logo' => $md_info->cover_url ?? '',
  1928. 'name' => $md_info->name ?? '',
  1929. 'tel' => $md_info->mobile ?? '',
  1930. ];
  1931. }
  1932. if (isset($data['store']['user_id'])) {
  1933. $store_cloud = StoreCloud::findOne(['cloud_user_id' => $data['store']['user_id'], 'is_delete' => 0]);
  1934. if ($store_cloud) {
  1935. $store = Store::findOne($store_cloud->store_id);
  1936. if ($store) {
  1937. $data['store'] = [
  1938. 'name' => $store->name,
  1939. 'tel' => $store->contact_tel ?: $store_cloud->tel ,
  1940. 'logo' => $store->logo,
  1941. ];
  1942. }
  1943. }
  1944. }
  1945. }
  1946. }
  1947. return $this->outPutData($goodsListInfo['code'],"获取成功",$goodsListInfo['data']);
  1948. }
  1949. } catch (\Exception $e) {
  1950. return $this->outPutData(1, $e->getMessage());
  1951. }
  1952. }
  1953. public function agentOrderDistribution() {
  1954. try {
  1955. if (!$this->validate()) {
  1956. return [
  1957. 'code' => 1,
  1958. 'msg' => $this->getErrorSummary(false)[0],
  1959. ];
  1960. }
  1961. $goods_list_url = "/cloud/supplier/agentOrderDistribution";
  1962. $goods_list_data = [];
  1963. $goods_list_data['access_token'] = get_supplier_token(); //获取供货商的token信息
  1964. $goods_list_data['start_time'] = $this->start_time;
  1965. $goods_list_data['end_time'] = $this->end_time;
  1966. $goodsListInfo = cloud_post($this->domain.$goods_list_url,$goods_list_data);
  1967. $goodsListInfo = json_decode($goodsListInfo,true);
  1968. if($goodsListInfo['code'] != 0){
  1969. throw new \Exception($goodsListInfo['msg']);
  1970. }else{
  1971. return $this->outPutData($goodsListInfo['code'],"获取成功");
  1972. }
  1973. } catch (\Exception $e) {
  1974. return $this->outPutData(1, $e->getMessage());
  1975. }
  1976. }
  1977. public function agentOrderDistributionList($id = 0, $status = 0) {
  1978. try {
  1979. if (!$this->validate()) {
  1980. return [
  1981. 'code' => 1,
  1982. 'msg' => $this->getErrorSummary(false)[0],
  1983. ];
  1984. }
  1985. $goods_list_url = "/cloud/supplier/agentOrderDistributionList";
  1986. $goods_list_data = [];
  1987. $goods_list_data['access_token'] = get_supplier_token(); //获取供货商的token信息
  1988. $admin = get_admin();
  1989. if ($admin->type === 'admin' || $admin->type === Admin::ADMIN_TYPE_FRONT_AGENT) {
  1990. $goods_list_url = "/cloud/user/agentOrderDistributionList";
  1991. $goods_list_data['access_token'] = get_platform_token();
  1992. $goods_list_data['admin_id'] = $admin->id;
  1993. }
  1994. $goods_list_data['status'] = $status ?: $this->status;
  1995. $goods_list_data['id'] = $id ?: $this->id;
  1996. if ($this->order_no) {
  1997. $goods_list_data['order_no'] = $this->order_no;
  1998. }
  1999. if ($this->sorting_start_time) {
  2000. $goods_list_data['sorting_start_time'] = $this->sorting_start_time;
  2001. }
  2002. if ($this->sorting_end_time) {
  2003. $goods_list_data['sorting_end_time'] = $this->sorting_end_time;
  2004. }
  2005. if ($this->start_time) {
  2006. $goods_list_data['start_time'] = $this->start_time;
  2007. }
  2008. if ($this->end_time) {
  2009. $goods_list_data['end_time'] = $this->end_time;
  2010. }
  2011. $goods_list_data['goods_name'] = $this->goods_name;
  2012. $goods_list_data['page'] = $this->page; //默认为 1
  2013. $goods_list_data['limit'] = $this->limit; //默认20
  2014. $goodsListInfo = cloud_post($this->domain.$goods_list_url,$goods_list_data);
  2015. $goodsListInfo = json_decode($goodsListInfo,true);
  2016. if($goodsListInfo['code'] != 0){
  2017. throw new \Exception($goodsListInfo['msg']);
  2018. }else{
  2019. $generator = new BarcodeGeneratorJPG();
  2020. if (!empty($goodsListInfo['data'])) {
  2021. foreach ($goodsListInfo['data']['data'] as &$data) {
  2022. $admin_id = $data['admin_id'];
  2023. $admin = Admin::findOne(['id' => $admin_id]);
  2024. $district = District::find()->where(['id' => [$admin->province_id, $admin->city_id, $admin->district_id]])->select('name')->column();
  2025. $data['admin_name'] = $admin->name;
  2026. $data['admin_tel'] = $admin->mobile;
  2027. $data['admin_address'] = implode('/', $district) . ($admin->address ?: '');
  2028. $data['goods_num'] = 0;
  2029. foreach ($data['mch_goods'] as &$mch_goods) {
  2030. $cloud_store_id = $mch_goods['store_id'];
  2031. $store_cloud = StoreCloud::findOne(['cloud_store_id' => $cloud_store_id, 'is_delete' => 0]);
  2032. if ($store_cloud) {
  2033. $store = Store::findOne($store_cloud->store_id);
  2034. $mch_goods['store_name'] = $store->name;
  2035. }
  2036. foreach ($mch_goods['mch_order'] as &$mch_order_item) {
  2037. $md_id = $mch_order_item['md_id'];
  2038. $md_info = Md::findOne($md_id);
  2039. $mch_order_item['md_name'] = $md_info->name ?? ($store->name ?? '');
  2040. $mch_order_item['md_mobile'] = $md_info->mobile ?? '';
  2041. $mch_order_item['goods_num'] += array_sum(array_column($mch_order_item['md_order'], 'goods_num'));
  2042. }
  2043. $data['goods_num'] += array_sum(array_column($mch_goods['mch_order'], 'goods_num'));
  2044. }
  2045. foreach ($data['goods'] as &$goods_item) {
  2046. $barcode = $generator->getBarcode($goods_item['goods_no'], $generator::TYPE_CODE_128, 2, 30);
  2047. $file_name = md5($goods_item['goods_no'] . '_cloud_goods_no_barcode'). '.jpg';
  2048. $code_path = \Yii::$app->runtimePath . '/image/' . $file_name;
  2049. $pic_url = str_replace('http://', 'https://', \Yii::$app->request->hostInfo . '/runtime/image/' . $file_name . '?v=' . time());
  2050. // 创建一个图像资源
  2051. $image = imagecreatefromstring($barcode);
  2052. // 定义颜色
  2053. $black = imagecolorallocate($image, 0, 0, 0);
  2054. $white = imagecolorallocate($image, 255, 255, 255);
  2055. // 获取图像的宽度和高度
  2056. $imageWidth = imagesx($image);
  2057. $imageHeight = imagesy($image);
  2058. // 计算文本的位置
  2059. $fontSize = 4; // 字体大小
  2060. $textWidth = imagefontwidth($fontSize) * strlen($goods_item['goods_no']);
  2061. $textX = ($imageWidth - $textWidth) / 2;
  2062. $textY = $imageHeight + 5; // 文本在条形码下方的位置
  2063. // 创建一个新的图像,高度增加以容纳文本
  2064. $newImageHeight = $imageHeight + 20; // 增加高度以容纳文本
  2065. $newImage = imagecreatetruecolor($imageWidth, $newImageHeight);
  2066. // 填充背景色
  2067. imagefilledrectangle($newImage, 0, 0, $imageWidth, $newImageHeight, $white);
  2068. // 将条形码图像复制到新图像上
  2069. imagecopy($newImage, $image, 0, 0, 0, 0, $imageWidth, $imageHeight);
  2070. // 在条形码下方添加代码文本
  2071. imagestring($newImage, $fontSize, $textX, $textY, $goods_item['goods_no'], $black);
  2072. // 保存图片到指定路径
  2073. imagepng($newImage, $code_path);
  2074. // 释放内存
  2075. imagedestroy($image);
  2076. imagedestroy($newImage);
  2077. $goods_item['barcode'] = $pic_url;
  2078. }
  2079. }
  2080. }
  2081. return $this->outPutData($goodsListInfo['code'],"获取成功",$goodsListInfo['data']);
  2082. }
  2083. } catch (\Exception $e) {
  2084. return $this->outPutData(1,$e->getMessage());
  2085. }
  2086. }
  2087. //更改配送单状态
  2088. public function setDistributionStatus()
  2089. {
  2090. $t = \Yii::$app->db->beginTransaction();
  2091. try {
  2092. if (!$this->validate()) {
  2093. return [
  2094. 'code' => 1,
  2095. 'msg' => $this->getErrorSummary(false)[0],
  2096. ];
  2097. }
  2098. //获取平台token
  2099. $cloud_token = get_supplier_token();
  2100. $getGoodsCateUrl = "/cloud/supplier/setDistributionStatus";
  2101. $getGoodsCateData['access_token'] = $cloud_token;
  2102. $getGoodsCateData['ids'] = $this->ids;
  2103. $getGoodsCateData['status'] = $this->status;
  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. $t->commit();
  2110. return $this->outPutData(0, $getGoodsCateInfo['msg']);
  2111. } catch (\Exception $e) {
  2112. $t->rollBack();
  2113. return $this->outPutData(1, $e->getMessage());
  2114. }
  2115. }
  2116. //打印配货单
  2117. public function exportDistributionInfo()
  2118. {
  2119. try {
  2120. if (!$this->validate()) {
  2121. return [
  2122. 'code' => 1,
  2123. 'msg' => $this->getErrorSummary(false)[0],
  2124. ];
  2125. }
  2126. $goods_list_url = "/cloud/user/agentOrderDistributionList";
  2127. if ((int)$this->export === 2) {
  2128. $goods_list_url = "/cloud/user/getAgentOrderDistributionList";
  2129. }
  2130. $goods_list_data['access_token'] = get_platform_token();
  2131. $goods_list_data['id'] = $this->id;
  2132. $goods_list_data['export'] = $this->export;
  2133. $goodsListInfo = cloud_post($this->domain.$goods_list_url,$goods_list_data);
  2134. $goodsListInfo = json_decode($goodsListInfo,true);
  2135. if($goodsListInfo['code'] != 0){
  2136. throw new \Exception($goodsListInfo['msg']);
  2137. }else{
  2138. if (!empty($goodsListInfo['data'])) {
  2139. if ((int)$this->export === 1) {
  2140. $title = [];
  2141. $data = [];
  2142. foreach ($goodsListInfo['data']['data'] as $_data) {
  2143. $admin_id = $_data['admin_id'];
  2144. $admin = Admin::findOne(['id' => $admin_id]);
  2145. $_data['admin_name'] = $admin->name;
  2146. $District = District::find()->where(['id' => [$admin->province_id, $admin->city_id, $admin->district_id]])->select('name')->column();
  2147. $address = implode(',', $District);
  2148. $title = [
  2149. [
  2150. 'goods_name' => "服务商:" . $_data['admin_name'] . '/' . $admin->mobile,
  2151. 'goods_attr' => "服务商地址:" . $address . $admin->address,
  2152. 'goods_num' => "供货商:" . $_data['supplier_name']
  2153. ]
  2154. ];
  2155. foreach ($_data['goods'] as $index => $good) {
  2156. $data[$index]['goods_name'] = $good['goods_name'];
  2157. // if ((int)$this->export === 2) {
  2158. // $data[$index]['goods_name'] = $good['goods_name'];
  2159. // }
  2160. $attrs = json_decode($good['goods_attr'], true);
  2161. $attr_str = '';
  2162. foreach ($attrs as $attr) {
  2163. $attr_str .= $attr['attr_group_name'] . ':' . $attr['attr_name'] . ';';
  2164. }
  2165. $data[$index]['goods_attr'] = $attr_str;
  2166. $data[$index]['goods_num'] = $good['goods_num'];
  2167. }
  2168. }
  2169. $field = [
  2170. [
  2171. 'goods_name' => '商品',
  2172. 'goods_attr' => '规格',
  2173. 'goods_num' => '数量'
  2174. ]
  2175. ];
  2176. $file_name = '配货单';
  2177. } else {
  2178. $data = [];
  2179. $_data = $goodsListInfo['data']['data'];
  2180. // foreach ($goodsListInfo['data']['data'] as $_data) {
  2181. $admin_id = $_data['admin_id'];
  2182. $admin = Admin::findOne(['id' => $admin_id]);
  2183. $_data['admin_name'] = $admin->name;
  2184. $District = District::find()->where(['id' => [$admin->province_id, $admin->city_id, $admin->district_id]])->select('name')->column();
  2185. $address = implode(',', $District);
  2186. $title = [
  2187. [
  2188. 'goods_name' => "服务商:" . $_data['admin_name'] . '/' . $admin->mobile,
  2189. 'goods_attr' => "服务商地址:" . $address . $admin->address,
  2190. ]
  2191. ];
  2192. $num = 0;
  2193. foreach ($_data['mch'] as $index => $mch) {
  2194. if ((int)$mch['type'] === 1) {
  2195. $mch['mch']['name'] = '采购:' . $mch['address'];
  2196. }
  2197. foreach ($mch['goods'] as $goods_index => $goods) {
  2198. $store_cloud = StoreCloud::findOne(['cloud_user_id' => $mch['mch']['user_id'], 'is_delete' => 0]);
  2199. $data[$num]['mch_name'] = Store::findOne($store_cloud->store_id)->name;//$goods_index === 0 ? $mch['mch']['name'] : '';
  2200. $data[$num]['goods_name'] = $goods['name'];
  2201. $data[$num]['goods_num'] = $goods['goods_num'];
  2202. $_attrs = json_decode($goods['goods_attr'], true);
  2203. $attr = '';
  2204. foreach ($_attrs as $_attr) {
  2205. $attr .= $_attr['attr_group_name'] . ':' . $_attr['attr_name'] . ';';
  2206. }
  2207. $data[$num]['goods_attr'] = $attr;
  2208. $num++;
  2209. }
  2210. // if ((int)$this->export === 2) {
  2211. // $data[$index]['goods_name'] = $good['goods_name'];
  2212. // }
  2213. }
  2214. $field = [
  2215. [
  2216. 'mch_name' => '商户信息',
  2217. 'goods_name' => '商品',
  2218. 'goods_num' => '数量',
  2219. 'goods_attr' => '规格'
  2220. ]
  2221. ];
  2222. // }
  2223. $file_name = '配送单';
  2224. }
  2225. $data = array_merge($title, $field, $data);
  2226. SimpleExcelWriter::streamDownload($file_name . time() . '.xlsx')
  2227. ->noHeaderRow()
  2228. ->addRows($data)
  2229. ->toBrowser();
  2230. }
  2231. // return $this->outPutData($goodsListInfo['code'],"获取成功",$goodsListInfo['data']);
  2232. }
  2233. } catch (\Exception $e) {
  2234. return $this->outPutData(1, $e->getMessage() . $e->getLine());
  2235. }
  2236. }
  2237. public function getAgentOrderDistributionList() {
  2238. try {
  2239. if (!$this->validate()) {
  2240. return [
  2241. 'code' => 1,
  2242. 'msg' => $this->getErrorSummary(false)[0],
  2243. ];
  2244. }
  2245. $goods_list_url = "/cloud/user/getAgentOrderDistributionList";
  2246. $goods_list_data['access_token'] = get_platform_token();
  2247. $goods_list_data['id'] = $this->id;
  2248. $goods_list_data['export'] = $this->export;
  2249. $goodsListInfo = cloud_post($this->domain.$goods_list_url,$goods_list_data);
  2250. $goodsListInfo = json_decode($goodsListInfo,true);
  2251. if($goodsListInfo['code'] != 0){
  2252. throw new \Exception($goodsListInfo['msg']);
  2253. }else{
  2254. if (!empty($goodsListInfo['data'])) {
  2255. $data = [];
  2256. $_data = $goodsListInfo['data']['data'];
  2257. // $order_no = $_data['order_no'];
  2258. $sorting_time = $_data['order_no'];
  2259. // foreach ($goodsListInfo['data']['data'] as $_data) {
  2260. $admin_id = $_data['admin_id'];
  2261. $admin = Admin::findOne(['id' => $admin_id]);
  2262. // $_data['admin_name'] = $admin->name;
  2263. $admin_title = [
  2264. 'admin_name' => $admin->name,
  2265. 'admin_mobile' => $admin->mobile,
  2266. 'order_no' => $_data['order_no'],
  2267. 'send_time' => $_data['send_time'] ? date('Y-m-d H:i:s', $_data['send_time']) : '-',
  2268. 'sorting_time' => $_data['sorting_time'] ? date('Y-m-d H:i:s', $_data['sorting_time']) : '-',
  2269. ];
  2270. $data = $_data['mch'];
  2271. foreach ($data as $index => &$mch) {
  2272. $cloud_user_id = $mch['mch']['user_id'];
  2273. $store_cloud = StoreCloud::findOne(['cloud_user_id' => $cloud_user_id]);
  2274. if ($store_cloud) {
  2275. $store_id = $store_cloud->store_id;
  2276. $store = Store::findOne($store_id);
  2277. $address = '';
  2278. $mobile = '';
  2279. if ($store) {
  2280. $address = Option::get('address', $store_id, 'store', '')['value'];
  2281. $district = District::find()->where(['id' => [$store->province_id, $store->city_id, $store->district_id]])->select('name')->column();
  2282. if ($district) {
  2283. $district = implode('', $district);
  2284. $address = $district . $address;
  2285. }
  2286. $admin = Admin::findOne(['type' => 'store', 'type_id' => $store->id]);
  2287. $mobile = $admin->mobile;
  2288. }
  2289. $mch['mch'] = [
  2290. 'name' => $store->name ?? '-',
  2291. 'address' => $address,
  2292. 'mobile' => $mobile
  2293. ];
  2294. foreach ($mch['goods'] as &$goods) {
  2295. $goods['goods_attr'] = json_decode($goods['goods_attr'], true);
  2296. }
  2297. }
  2298. // if ((int)$mch['type'] === 1) {
  2299. // $mch['mch']['name'] = '采购:' . $mch['address'];
  2300. // }
  2301. // foreach ($mch['goods'] as $goods_index => $goods) {
  2302. // $store_cloud = StoreCloud::findOne(['cloud_user_id' => $mch['mch']['user_id'], 'is_delete' => 0]);
  2303. //// $data[$num]['store_name'] = Store::findOne($store_cloud->store_id)->name;
  2304. // $data[$num]['mch_name'] = Store::findOne($store_cloud->store_id)->name;//$goods_index === 0 ? $mch['mch']['name'] : '';
  2305. // $data[$num]['goods_name'] = $goods['name'];
  2306. // $data[$num]['goods_num'] = $goods['goods_num'];
  2307. // $_attrs = json_decode($goods['goods_attr'], true);
  2308. // $attr = '';
  2309. // foreach ($_attrs as $_attr) {
  2310. // $attr .= $_attr['attr_group_name'] . ':' . $_attr['attr_name'] . ';';
  2311. // }
  2312. // $data[$num]['goods_attr'] = $attr;
  2313. // $num++;
  2314. // }
  2315. }
  2316. return [
  2317. 'code' => 0,
  2318. 'msg' => 'success',
  2319. 'data' => [
  2320. 'goods' => $data,
  2321. 'admin_title' => $admin_title
  2322. ]
  2323. ];
  2324. }
  2325. }
  2326. } catch (\Exception $e) {
  2327. return [
  2328. 'code' => 1,
  2329. 'msg' => $e->getMessage()
  2330. ];
  2331. }
  2332. }
  2333. //供货单列表(推送到聚水潭)
  2334. public function supplierOrderList2Jst($supplier_id = 0, $time = 0){
  2335. $cloud_supplier_id = Supplier::find()->where(['id' => $supplier_id, 'is_delete' => 0])->select('cloud_supplier_id')->scalar();
  2336. $supplier_order_list_url = "/user/getSupplierOrderList";
  2337. $supplier_order_list_data = [];
  2338. $supplier_order_list_data['time'] = $time;
  2339. $supplier_order_list_data['supplier_id'] = (int)$cloud_supplier_id;
  2340. $supplierOrderListInfo = cloud_post($this->domain.$supplier_order_list_url,$supplier_order_list_data);
  2341. $supplierOrderListInfo = json_decode($supplierOrderListInfo,true);
  2342. if($supplierOrderListInfo['code'] != 0){
  2343. $code = 1; //失败
  2344. return $this->outPutData($code,$supplierOrderListInfo['msg']);
  2345. }else{
  2346. return $supplierOrderListInfo;
  2347. }
  2348. }
  2349. //云仓库存列表
  2350. public function getCloudPreviewNum(){
  2351. //获取平台token
  2352. $cloud_token = get_supplier_token();
  2353. $supplier_order_list_data = [];
  2354. $supplier_order_list_url = "/cloud/supplier/getCloudPreviewNum";
  2355. $supplier_order_list_data['access_token'] = $cloud_token;
  2356. $supplier_order_list_data['name'] = $this->name;
  2357. $supplier_order_list_data['mobile'] = $this->mobile;
  2358. $supplier_order_list_data['page'] = input_params('pageNo') ?: $this->page; //默认为 1
  2359. $supplier_order_list_data['limit'] = $this->limit; //默认20
  2360. $supplierOrderListInfo = cloud_post($this->domain.$supplier_order_list_url,$supplier_order_list_data);
  2361. $supplierOrderListInfo = json_decode($supplierOrderListInfo,true);
  2362. if($supplierOrderListInfo['code'] != 0){
  2363. $code = 1; //失败
  2364. return $this->outPutData($code,$supplierOrderListInfo['msg']);
  2365. }else{
  2366. if ($supplierOrderListInfo['data']['list']) {
  2367. foreach ($supplierOrderListInfo['data']['list'] as &$item) {
  2368. $store_cloud = StoreCloud::findOne(['cloud_store_id' => $item['mch_id'], 'is_delete' => 0]);
  2369. $item['store_name'] = '-';
  2370. if ($store_cloud) {
  2371. $item['store_name'] = Store::findOne(['id' => $store_cloud->store_id, 'is_delete' => 0])->name ?? '-';
  2372. }
  2373. $user_info = StoreCloud::find()->alias('c')
  2374. ->leftJoin(['su' => SaasUser::tableName()], 'c.saas_user_id = su.id')
  2375. ->where(['c.is_delete' => 0, 'c.cloud_store_id' => $item['mch_id']])->select('su.avatar, su.name')->asArray()->one();
  2376. if ($user_info) {
  2377. $item['name'] = $user_info['name'] ?: $item['name'];
  2378. $item['logo'] = $user_info['avatar'] ?: $item['logo'];
  2379. }
  2380. }
  2381. }
  2382. return $supplierOrderListInfo;
  2383. }
  2384. }
  2385. //云仓库存列表
  2386. public function getCloudPreviewNumInfo(){
  2387. //获取平台token
  2388. $cloud_token = get_supplier_token();
  2389. $supplier_order_list_data = [];
  2390. $supplier_order_list_url = "/cloud/supplier/getCloudPreviewNumInfo";
  2391. $supplier_order_list_data['access_token'] = $cloud_token;
  2392. $supplier_order_list_data['mch_id'] = $this->could_mch_id;
  2393. $supplier_order_list_data['page'] = input_params('pageNo') ?: $this->page; //默认为 1
  2394. $supplier_order_list_data['limit'] = $this->limit; //默认20
  2395. $supplierOrderListInfo = cloud_post($this->domain.$supplier_order_list_url,$supplier_order_list_data);
  2396. $supplierOrderListInfo = json_decode($supplierOrderListInfo,true);
  2397. if($supplierOrderListInfo['code'] != 0){
  2398. $code = 1; //失败
  2399. return $this->outPutData($code,$supplierOrderListInfo['msg']);
  2400. }else{
  2401. if ($supplierOrderListInfo['data']['mch_info']) {
  2402. $mch_id = $supplierOrderListInfo['data']['mch_info']['mch_id'];
  2403. $store_cloud = StoreCloud::findOne(['cloud_store_id' => $mch_id, 'is_delete' => 0]);
  2404. $supplierOrderListInfo['data']['mch_info']['store_name'] = '-';
  2405. if ($store_cloud) {
  2406. $supplierOrderListInfo['data']['mch_info']['store_name'] = Store::findOne(['id' => $store_cloud->store_id, 'is_delete' => 0])->name ?? '-';
  2407. }
  2408. $user_info = StoreCloud::find()->alias('c')
  2409. ->leftJoin(['su' => SaasUser::tableName()], 'c.saas_user_id = su.id')
  2410. ->where(['c.is_delete' => 0, 'c.cloud_store_id' => $mch_id])->select('su.avatar, su.name')->asArray()->one();
  2411. if ($user_info) {
  2412. $supplierOrderListInfo['data']['mch_info']['name'] = $user_info['name'] ?: $supplierOrderListInfo['data']['mch_info']['name'];
  2413. $supplierOrderListInfo['data']['mch_info']['logo'] = $user_info['avatar'] ?: $supplierOrderListInfo['data']['mch_info']['logo'];
  2414. }
  2415. }
  2416. return $supplierOrderListInfo;
  2417. }
  2418. }
  2419. //订单改价
  2420. public function modifyPrice() {
  2421. $t = \Yii::$app->db->beginTransaction();
  2422. try {
  2423. //获取平台token
  2424. $order = PurchaseOrder::findOne(['cloud_order_id' => $this->order_id, 'is_delete' => 0]);
  2425. if (!$order) {
  2426. return [
  2427. 'code' => 1,
  2428. 'msg' => '订单不存在'
  2429. ];
  2430. }
  2431. //判断价格是否小于0
  2432. if ((isset($this->pay_price) && $this->pay_price < 0) || (isset($this->express_price) && $this->express_price < 0)) {
  2433. return [
  2434. 'code' => 1,
  2435. 'msg' => '价格不能小于0'
  2436. ];
  2437. }
  2438. $money = doubleval($order->pay_price);
  2439. $express = doubleval($order->express_price);
  2440. if ($this->goods_id) {
  2441. $purchase_goods = PurchaseOrderDetail::findOne(['goods_id' => $this->goods_id, 'is_delete' => 0, 'order_id' => $order->id]);
  2442. //->asArray()->all();
  2443. if (!$purchase_goods) {
  2444. throw new \Exception('商品查询失败');
  2445. }
  2446. $purchaseOrderDetail = PurchaseOrderDetail::findOne($purchase_goods->id);
  2447. $purchaseOrderDetail->before_update_price = $purchase_goods->total_price;
  2448. $purchaseOrderDetail->total_price = $this->pay_price;
  2449. if (!$purchaseOrderDetail->save()) {
  2450. throw new \Exception(json_encode($purchaseOrderDetail->errors, JSON_UNESCAPED_UNICODE));
  2451. }
  2452. }
  2453. $goods_total_price = PurchaseOrderDetail::find()->where(['order_id' => $order->id, 'is_delete' => 0])->select('total_price')->sum('total_price');
  2454. //计算支付总金额
  2455. $express_ = $express;
  2456. if (isset($this->express_price)) {
  2457. $express_ = $this->express_price;
  2458. }
  2459. $order->pay_price = ($goods_total_price + $express_);
  2460. if (isset($this->express_price)) {
  2461. $order->express_price = $this->express_price;
  2462. }
  2463. $order->before_update_price = $money;
  2464. $order->before_update_express = $express;
  2465. if (!$order->save()) {
  2466. throw new \Exception(json_encode($order->errors, JSON_UNESCAPED_UNICODE));
  2467. }
  2468. $cloud_token = get_supplier_token();
  2469. $supplier_order_modify_price = [];
  2470. $supplier_order_modify_price_url = "/cloud/supplier/modifyPrice";
  2471. $supplier_order_modify_price['access_token'] = $cloud_token;
  2472. $supplier_order_modify_price['pay_price'] = $this->pay_price;
  2473. $supplier_order_modify_price['express_price'] = $this->express_price;
  2474. $supplier_order_modify_price['order_id'] = $this->order_id;
  2475. $supplier_order_modify_price['goods_id'] = $this->goods_id;
  2476. $supplier_order_modify_price['send_type'] = $this->send_type;
  2477. $supplierOrderModifyPriceInfo = cloud_post($this->domain . $supplier_order_modify_price_url, $supplier_order_modify_price);
  2478. $supplierOrderModifyPriceInfo = json_decode($supplierOrderModifyPriceInfo,true);
  2479. if($supplierOrderModifyPriceInfo['code'] != 0){
  2480. throw new \Exception($supplierOrderModifyPriceInfo['msg'], $supplierOrderModifyPriceInfo['code']);
  2481. }else{
  2482. $t->commit();
  2483. return $supplierOrderModifyPriceInfo;
  2484. }
  2485. } catch (\Exception $e) {
  2486. $t->rollBack();
  2487. return [
  2488. 'code' => 1,
  2489. 'msg' => $e->getMessage()
  2490. ];
  2491. }
  2492. }
  2493. //获取平台token
  2494. public function actionGetSaasToken(){
  2495. // $content = Option::get('cloud', 0, 'saas');
  2496. // if (!$content['value']){
  2497. // return false;
  2498. // }
  2499. // $params = json_decode($content['value'],true);
  2500. // $tokenInfo = get_cloud_token($params['name'],$params['password']);
  2501. // $params['access_token'] = $tokenInfo['taken'];
  2502. // Option::set('cloud', json_encode($params), 0, 'saas');
  2503. get_platform_token();
  2504. }
  2505. //返回数据
  2506. private function outPutData($code,$msg,$data=[]){
  2507. $putData = [];
  2508. $putData['code'] = $code;
  2509. $putData['msg'] = $msg;
  2510. if($data) $putData['data'] = $data;
  2511. return $putData;
  2512. }
  2513. //获取网络图片到临时目录
  2514. public function saveTempImage($url)
  2515. {
  2516. if (strpos($url, 'http') === false) {
  2517. $url = 'http:' . trim($url);
  2518. }
  2519. if (!is_dir(\Yii::$app->runtimePath . '/xlsx')) {
  2520. mkdir(\Yii::$app->runtimePath . '/xlsx');
  2521. }
  2522. $save_path = \Yii::$app->runtimePath . '/xlsx/' . md5($url) . '.xlsx';
  2523. CurlHelper::download($url, $save_path);
  2524. return $save_path;
  2525. }
  2526. }