| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\admin\models;
- // use app\models\Form;
- // use app\models\Option;
- use app\librarys\Picqer\Barcode\BarcodeGeneratorJPG;
- use app\models\AgentFrontBind;
- use app\models\AgentFrontCentralizeGoods;
- use app\models\AgentFrontCentralizeGoodsExt;
- use app\models\AgentGoodsBindGoods;
- use app\models\Attr;
- use app\models\AttrGroup;
- use app\models\District;
- use app\models\Goods;
- use app\models\Md;
- use app\models\Order;
- use app\models\OrderDetail;
- use app\models\OrderRefund;
- use app\models\OrderTransit;
- use app\models\PurchaseOrderDetail;
- use app\models\SaasUser;
- use app\models\Store;
- use app\models\StoreCloud;
- use app\models\User;
- use app\utils\CurlHelper;
- use app\utils\Export;
- use app\utils\ExportList;
- use app\utils\OrderNo;
- use app\utils\PrintOrder;
- use app\utils\Refund;
- use app\utils\Wechat\WechatBusinessPay;
- use Spatie\SimpleExcel\SimpleExcelReader;
- use Spatie\SimpleExcel\SimpleExcelWriter;
- use Yii;
- use Exception;
- use yii\base\Model;
- use app\models\Admin;
- use app\models\Supplier;
- use app\models\Option;
- //use linslin\yii2\curl;
- use app\models\Share;
- use yii\base\BaseObject;
- use yii\helpers\Json;
- use app\jobs\BatchDownGoodsJob;
- use app\constants\OptionSetting;
- use app\models\PurchaseOrder;
- use app\modules\alliance\models\purchase\order\OrderForm;
- class SupplierForm extends Model
- {
- public $name;
- public $password;
- public $tel;
- public $logo;
- public $type;
- public $cash_type; //提现方式 1--微信支付 2--支付宝 3--银行卡
- public $account; //账号 微信 支付宝 银行卡号
- public $bank_name; //银行卡开户行
- public $certificate;
- public $id_card_reverse;
- public $id_card_front;
- public $page;
- public $limit;
- public $token_supplier_id; //云库供货商id
- public $supplier_id; //云库供货商id
- public $could_user_id; //云库会员id
- public $could_mch_id; //商户ID
- public $start_time; //开始时间
- public $end_time; //结束时间
- public $order_no; //订单号
- public $price; //变动金额
- public $desc; //详情
- public $status; //状态
- public $pic_url; //规格图片
- public $num; //库存
- public $attr_id; //商品属性id
- public $goods_id; //商品ID、大于0编辑, 等于0 添加
- public $goods_no; //商品货号
- public $g_s_pic_url; //商品缩略图
- public $g_price; //售价
- public $g_wholesale_price; // 批发价
- public $g_wholesale_ladder_rebate; // 批发价阶梯折扣 json
- public $g_wholesale_rebate_switch; // 是否开启批发价阶梯折扣
- public $wholesale_ladder_type; //批发阶梯价类型 0折扣 1价格
- public $g_original_price; //零售价
- public $g_unit; //单位
- public $g_shop_count; //起购数量
- public $g_pic_list; //商品轮播图 [{'pic_url':'111'},{'pic_url':'222'}]
- public $g_send_type; //0 全部配送方式 1 仅转单 2 仅采购
- public $weight; //重量 单位g
- public $order_id; //订单id
- public $express_name; //快递公司
- public $express_no; //快递号
- public $attr; //商品规格
- public $send_type; //0 快递配送 1集采 2 自主配送 4云仓库存 5 仓库同城
- public $send_type_num; //是否支持云仓库存
- public $centralize_goods_type; //集采商品类型 0线货 1团货
- public $cancel_type; //1 取消通过 2 取消失败
- public $use_attr = 0; //是否使用规格
- public $reason; //拒绝退换原因
- public $is_agree; //是否同意退换货
- public $mobile; //收件人手机号
- public $detail; //收件人详细地址
- public $zipcode; //收件人邮编
- public $is_change; //是否更改规格信息
- public $attrs = []; //规格json
- public $cat_id;
- public $words = '';
- public $zip_code;
- public $seller_comments;
- public $address_data;
- public $fields;
- public $order_type;
- public $user_name;
- public $goods_name;
- public $search;
- public $xlsx;
- public $stbz_goods_id;
- public $jst_goods_id;
- public $jst_supplier_id;
- public $is_purchase;
- public $area;
- public $id;
- public $ids;
- public $goods_area_rules_id;
- public $export;
- public $video_url;
- public $salesman_id;
- public $sort;
- public $is_need_install;
- public $is_default;
- public $freight;
- public $supplier_name;
- public $is_level;
- public $sorting_start_time;
- public $sorting_end_time;
- //满赠
- public $goods_full_give_switch;
- public $goods_full_give_info;
- private $domain;
- public $market_price;
- public $purchase_order_id;
- public $underlined_price;//原价(划线价)
- public $is_selection;
- public $pay_price;
- public $express_price;
- public $mch_order_no;
- public $old_order_no;
- public function __construct($config = [])
- {
- parent::__construct($config);
- $this->domain = (new OptionSetting)->getCloudDomainName();
- }
- /**
- * @return array the validation rules.
- */
- public function rules()
- {
- return [
- [['certificate', 'id_card_reverse','id_card_front','logo','pic_url','g_s_pic_url', 'reason', 'ids'], 'string', 'max' => 255],
- [['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],
- [['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'],
- [['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'],
- [['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'],
- [['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'],
- [['area', 'video_url', 'supplier_name'], 'string'],
- [['stbz_goods_id', 'is_selection'], 'integer'],
- [['jst_goods_id', 'jst_supplier_id'], 'safe'],
- // ['g_pic_list',function ($attribute, $params) {
- // if(!is_array($this->g_pic_list)){
- // $this->addError('g_pic_list','g_pic_list is not array!');
- // }
- // }],
- ];
- }
- //订单取消审核
- public function getLastOrderInfo(){
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- $cacheK_id = 'id_SupplierForm_getLastOrderInfo_maxId_' . $this->token_supplier_id . $this->supplier_id;
- $cacheK_purchase_order_id = 'purchase_order_id_SupplierForm_getLastOrderInfo_maxId_' . $this->token_supplier_id . $this->supplier_id;
- $cacheV_id = (int)cache()->get($cacheK_id);
- $cacheV_purchase_order_id = (int)cache()->get($cacheK_purchase_order_id);
-
- $url = "/cloud/supplier/getLastOrderInfo";
- $data = [];
- $data['access_token'] = get_supplier_token($this->token_supplier_id, $this->supplier_id); //获取供货商的token信息
- $data['purchase_order_id'] = $cacheV_purchase_order_id; //订单id
- $data['id'] = $cacheV_id; //订单id
- $res = cloud_post($this->domain.$url,$data);
- // var_dump($res, $url, $data);
- $res = json_decode($res,true);
- if($res['code'] != 0){
- $code = 1; //失败
- return $this->outPutData($code,$res['msg']);
- }else{
- if($res['data']){
- if($res['data']['order_info']){
- cache()->set($cacheK_id, $res['data']['order_info']['id']);
- }
- if($res['data']['purchase_order_info']){
- cache()->set($cacheK_purchase_order_id, $res['data']['purchase_order_info']['id']);
- }
- }
- return $this->outPutData($res['code'],$res['msg'],$res['data']);
- }
- }
- //订单取消审核
- public function supplierOrderCancel(){
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- $supplier_order_cancel_url = "/cloud/supplier/supplierOrderCancel";
- $supplier_order_cancel_data = [];
- $supplier_order_cancel_data['access_token'] = get_supplier_token($this->token_supplier_id); //获取供货商的token信息
- $supplier_order_cancel_data['order_id'] = $this->order_id; //订单id
- $supplier_order_cancel_data['cancel_type'] = $this->cancel_type; //1 通过 2 拒绝
- $supplierOrderCancelInfo = cloud_post($this->domain.$supplier_order_cancel_url,$supplier_order_cancel_data);
- $supplierOrderCancelInfo = json_decode($supplierOrderCancelInfo,true);
- if($supplierOrderCancelInfo['code'] != 0){
- $code = 1; //失败
- return $this->outPutData($code,$supplierOrderCancelInfo['msg']);
- }else{
- // if ((int)$this->cancel_type === 1) {
- // $purchase_order = PurchaseOrder::findOne(['cloud_order_id' => $this->order_id]);
- // if ($purchase_order && (int)$purchase_order->pay_type === 1) {
- // $res = WechatBusinessPay::orderRefund($purchase_order, OrderNo::ORDER_ALLIANCE_PURCHASE, $purchase_order->pay_price, 'POR' . $purchase_order->order_no);
- // if ($res['code'] === 1) {
- // return $res;
- // }
- // }
- // }
- if (intval($this->cancel_type) === 1) {
- $purchaseOrder = PurchaseOrder::findOne(['cloud_order_id' => $this->order_id]);
- try {
- $supplier = Supplier::findOne(['cloud_supplier_id' => $purchaseOrder->cloud_supplier_id]);
- $printer_order = new PrintOrder(0, $this->order_id, 'confirm', 0, 0, 1, 0, $supplier->id);
- $printer_order->print_order();
- } catch (\Exception $e) {
- debug_log([
- 'event' => 'supplierOrderCancel',
- 'message' => $e->getMessage(),
- 'line' => $e->getLine(),
- 'file' => $e->getFile()
- ], 'cloud_printer.log');
- }
- }
- return $this->outPutData($supplierOrderCancelInfo['code'],$supplierOrderCancelInfo['msg']);
- }
- }
- //获取运费规则
- public function supplierGetRules(){
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- $supplier_get_rules_url = "/cloud/supplier/supplierGetRules";
- $supplier_get_rules_data = [];
- $supplier_get_rules_data['access_token'] = get_supplier_token($this->token_supplier_id); //获取供货商的token信息
- $supplier_get_rules_data['id'] = $this->id;
- $supplierGetRulesInfo = cloud_post($this->domain.$supplier_get_rules_url,$supplier_get_rules_data);
- $supplierGetRulesInfo = json_decode($supplierGetRulesInfo,true);
- if($supplierGetRulesInfo['code'] != 0){
- $code = 1; //失败
- return $this->outPutData($code,$supplierGetRulesInfo['msg']);
- }else{
- return $this->outPutData($supplierGetRulesInfo['code'],$supplierGetRulesInfo['msg'],$supplierGetRulesInfo['data']);
- }
- }
- //删除运费规则
- public function supplierDelRules(){
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- $supplier_get_rules_url = "/cloud/supplier/supplierDelRules";
- $supplier_get_rules_data = [];
- $supplier_get_rules_data['access_token'] = get_supplier_token($this->token_supplier_id); //获取供货商的token信息
- $supplier_get_rules_data['id'] = $this->id;
- $supplierGetRulesInfo = cloud_post($this->domain.$supplier_get_rules_url,$supplier_get_rules_data);
- $supplierGetRulesInfo = json_decode($supplierGetRulesInfo,true);
- if($supplierGetRulesInfo['code'] != 0){
- $code = 1; //失败
- return $this->outPutData($code,$supplierGetRulesInfo['msg']);
- }else{
- return $this->outPutData($supplierGetRulesInfo['code'],$supplierGetRulesInfo['msg'],$supplierGetRulesInfo['data']);
- }
- }
- //修改运费规则状态
- public function supplierSetStatus(){
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- $supplier_get_rules_url = "/cloud/supplier/supplierSetStatus";
- $supplier_get_rules_data = [];
- $supplier_get_rules_data['access_token'] = get_supplier_token($this->token_supplier_id); //获取供货商的token信息
- $supplier_get_rules_data['id'] = $this->id;
- $supplier_get_rules_data['is_default'] = $this->is_default;
- $supplierGetRulesInfo = cloud_post($this->domain.$supplier_get_rules_url,$supplier_get_rules_data);
- $supplierGetRulesInfo = json_decode($supplierGetRulesInfo,true);
- if($supplierGetRulesInfo['code'] != 0){
- $code = 1; //失败
- return $this->outPutData($code,$supplierGetRulesInfo['msg']);
- }else{
- return $this->outPutData($supplierGetRulesInfo['code'],$supplierGetRulesInfo['msg'],$supplierGetRulesInfo['data']);
- }
- }
- //获取运费规则
- public function supplierGetRulesList(){
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- $supplier_get_rules_url = "/cloud/supplier/supplierGetRulesList";
- $supplier_get_rules_data = [];
- $supplier_get_rules_data['access_token'] = get_supplier_token($this->token_supplier_id); //获取供货商的token信息
- $supplierGetRulesInfo = cloud_post($this->domain.$supplier_get_rules_url,$supplier_get_rules_data);
- $supplierGetRulesInfo = json_decode($supplierGetRulesInfo,true);
- if($supplierGetRulesInfo['code'] != 0){
- $code = 1; //失败
- return $this->outPutData($code,$supplierGetRulesInfo['msg']);
- }else{
- return $this->outPutData($supplierGetRulesInfo['code'],$supplierGetRulesInfo['msg'],$supplierGetRulesInfo['data']);
- }
- }
- //供货单订单发货
- public function supplierOrderSend($cloud_supplier_id = 0){
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- if (!empty($this->xlsx)) {
- $supplier_order_send_url = "/cloud/supplier/supplierOrderAllSend";
- $supplier_order_send_data = [];
- $supplier_order_send_data['access_token'] = get_supplier_token($cloud_supplier_id); //获取供货商的token信息
- $xlsx_path = $this->saveTempImage($this->xlsx);
- $rows = SimpleExcelReader::create($xlsx_path)->noHeaderRow()->getRows();
- $array = [];
- $rows->each(function($rowProperties) use (&$array) {
- array_push($array, $rowProperties);
- });
- unset($array[0]);
- $array = array_values($array);
- $supplier_order_send_data['xlsx'] = json_encode($array);
- } else {
- $supplier_order_send_url = "/cloud/supplier/supplierOrderSend";
- $supplier_order_send_data = [];
- $supplier_order_send_data['access_token'] = get_supplier_token($cloud_supplier_id); //获取供货商的token信息
- $supplier_order_send_data['order_ids'] = $this->order_id; //订单ID
- $supplier_order_send_data['express_name'] = $this->express_name; //快递公司
- $supplier_order_send_data['express_no'] = $this->express_no; //快递号
- $supplier_order_send_data['send_type'] = $this->send_type; //1 快递配送 2 自主配送
- }
- $supplierOrderSendInfo = cloud_post($this->domain.$supplier_order_send_url,$supplier_order_send_data);
- $supplierOrderSendInfo = json_decode($supplierOrderSendInfo,true);
- if($supplierOrderSendInfo['code'] != 0){
- $code = 1; //失败
- return $this->outPutData($code,$supplierOrderSendInfo['msg']);
- }else{
- if (!empty($array)) {
- foreach ($array as $item) {
- $order = PurchaseOrder::find()->where(['cloud_order_id' => $this->order_id])->one();
- $of = new OrderForm();
- $of->order_id = $order->id;
- $of->express = $this->express_name;
- $of->express_no = $this->express_no;
- $of->words = $this->words;
- $res = $of->send();
- if ($res['code'] !== 0) {
- return $res;
- }
- }
- }
- return $this->outPutData($supplierOrderSendInfo['code'],$supplierOrderSendInfo['msg']);
- }
- }
- //供货单订单删除
- public function supplierOrderDel(){
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- $supplier_order_send_url = "/cloud/supplier/supplierOrderDel";
- $supplier_order_send_data = [];
- $supplier_order_send_data['access_token'] = get_supplier_token(); //获取供货商的token信息
- $supplier_order_send_data['order_ids'] = $this->order_id; //订单ID
- $supplierOrderSendInfo = cloud_post($this->domain.$supplier_order_send_url,$supplier_order_send_data);
- $supplierOrderSendInfo = json_decode($supplierOrderSendInfo,true);
- if($supplierOrderSendInfo['code'] != 0){
- $code = 1; //失败
- return $this->outPutData($code,$supplierOrderSendInfo['msg']);
- }else{
- return $this->outPutData($supplierOrderSendInfo['code'],$supplierOrderSendInfo['msg']);
- }
- }
- //供货单修改收货地址 / 卖家备注
- public function supplierOrderSetAddress(){
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- $supplier_order_send_url = "/cloud/supplier/setOrderAddress";
- $supplier_order_send_data = [];
- $supplier_order_send_data['access_token'] = get_supplier_token(); //获取供货商的token信息
- $supplier_order_send_data['order_id'] = $this->order_id;
- $supplier_order_send_data['address_data'] = $this->address_data;
- $supplier_order_send_data['remark'] = $this->seller_comments;
- $supplier_order_send_data['order_type'] = $this->order_type;
- $supplierOrderSendInfo = cloud_post($this->domain.$supplier_order_send_url,$supplier_order_send_data);
- $supplierOrderSendInfo = json_decode($supplierOrderSendInfo,true);
- if($supplierOrderSendInfo['code'] != 0){
- $code = 1; //失败
- return $this->outPutData($code,$supplierOrderSendInfo['msg']);
- }else{
- if (intval($this->order_type)) {
- $order = PurchaseOrder::find()->where(['cloud_order_id' => $this->order_id])->one();
- $address_data = json_decode($this->address_data, true);
- if($address_data){
- $order->province_id = $address_data['province'];
- $order->city_id = $address_data['city'];
- $order->district_id = $address_data['district'];
- $order->address = $address_data['address'];
- $order->name = $address_data['name'];
- $order->mobile = $address_data['mobile'];
- }
- if($this->seller_comments){
- $order->seller_comments = $this->seller_comments;
- }
- $order->save();
- }
- return $this->outPutData($supplierOrderSendInfo['code'],$supplierOrderSendInfo['msg']);
- }
- }
- //供货单修改收货地址 / 卖家备注
- public function supplierPurchaseOrderSetAddress(){//setPurchaseOrderAddress
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- $supplier_order_send_url = "/cloud/supplier/setPurchaseOrderAddress";
- $supplier_order_send_data = [];
- $supplier_order_send_data['access_token'] = get_supplier_token(); //获取供货商的token信息
- $supplier_order_send_data['order_id'] = $this->order_id;
- $supplier_order_send_data['address_data'] = $this->address_data;
- $supplier_order_send_data['remark'] = $this->seller_comments;
- $supplier_order_send_data['order_type'] = $this->order_type;
- $supplierOrderSendInfo = cloud_post($this->domain.$supplier_order_send_url,$supplier_order_send_data);
- $supplierOrderSendInfo = json_decode($supplierOrderSendInfo,true);
- if($supplierOrderSendInfo['code'] != 0){
- $code = 1; //失败
- return $this->outPutData($code,$supplierOrderSendInfo['msg']);
- }else{
- $OrderTransit = OrderTransit::findOne(['cloud_order_id' => $this->order_id]);
- $order = Order::find()->where(['id' => $OrderTransit->order_id])->one();
- $address_data = json_decode($this->address_data);
- if($address_data){
- $order->address = $address_data->address;
- $order->name = $address_data->name;
- $order->mobile = $address_data->mobile;
- }
- if($this->seller_comments){
- $order->seller_comments = $this->seller_comments;
- }
- $order->save();
- return $this->outPutData($supplierOrderSendInfo['code'],$supplierOrderSendInfo['msg']);
- }
- }
- //订单列表(新)
- public function supplierSendTypeList($cloud_supplier_id = 0){
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- // 获取可导出数据
- $f = new ExportList();
- $exportList = $f->getList();
- $supplier_order_list_url = "/cloud/supplier/supplierSendTypeList";
- $supplier_order_list_data = [];
- $supplier_order_list_data['access_token'] = get_supplier_token($cloud_supplier_id); //获取供货商的token信息
- $admin = get_admin();
- if ($admin->type === 'admin' || $admin->type === Admin::ADMIN_TYPE_SAAS_STAFF) {
- $supplier_order_list_url = "/cloud/user/supplierPurchaseOrderList";
- $supplier_order_list_data['access_token'] = get_platform_token();
- // $admin = get_admin();
- // $admin_id = $admin->id;
- // if ($admin->username == 'admin') {
- // $admin_id = null;
- // }
- // if ($admin_id) {
- // $admin_model = Admin::findOne($admin_id);
- // $area_level = $admin_model->area_level;
- $cloud_supplier_id = Supplier::find()->where(['is_delete' => 0])->select('cloud_supplier_id')->column();
- if (!empty($cloud_supplier_id)) {
- $supplier_order_list_data['supplier_id'] = implode(',', $cloud_supplier_id);
- }
- if (!empty($this->supplier_name)) {
- $supplier_order_list_data['supplier_name'] = $this->supplier_name;
- }
- // $salesman_id = $this->salesman_id;
- // if ($salesman_id) {
- // $query->andWhere([
- // 'salesman_id' => $salesman_id
- // ]);
- // }
- // if($area_level == 1){
- // $query->andWhere(
- // ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id, 'district_id' => $admin_model->district_id]);
- // } elseif ($area_level == 2){
- // $query->andWhere(
- // ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id]);
- // } elseif ($area_level == 3){
- // $query->andWhere(['province_id' => $admin_model->province_id]);
- // }
- // $ids = $query->select('cloud_supplier_id')->column();
- // if ($ids) {
- // if(is_array($ids)){
- // $ids = implode(',', $ids);
- // }
- // $supplier_order_list_data['supplier_id'] = $ids;
- // } else {
- // return $this->outPutData(0,'获取成功',[
- // 'list' => []
- // ]);
- // }
- // }
- }
- $supplier_order_list_data['page'] = $this->page; //订单ID
- $supplier_order_list_data['mobile'] = $this->mobile; //订单ID
- $supplier_order_list_data['user_name'] = $this->user_name; //订单ID
- $supplier_order_list_data['goods_name'] = $this->goods_name; //订单ID
- $supplier_order_list_data['limit'] = $this->limit; //1 取消通过 2 取消失败
- $supplier_order_list_data['status'] = $this->status; //-1 全部 0 待供货商确认 1 供货商已发货 2 已确认收货
- $supplier_order_list_data['mch_id'] = $this->could_mch_id; //商户ID
- $supplier_order_list_data['type'] = $this->type ?: 0; //订单类型0:快递 1:自助配送 2:云仓库存 6:仓库快递
- if($this->start_time) $supplier_order_list_data['start_time'] = strtotime($this->start_time); //开始时间
- if($this->end_time) $supplier_order_list_data['end_time'] = strtotime($this->end_time); //结束时间
- if($this->order_no) $supplier_order_list_data['order_no'] = $this->order_no; //订单号
- if($this->order_id) $supplier_order_list_data['order_id'] = $this->order_id;
- if (!empty(trim($this->mch_order_no))) {
- $mch_order_id = Order::find()->where(['LIKE', 'order_no', $this->mch_order_no])->select('id')->column();
- if (!empty($mch_order_id)) {
- $mch_order_id = implode(',', $mch_order_id);
- } else {
- $mch_order_id = '-1';
- }
- $supplier_order_list_data['mch_order_ids'] = $mch_order_id;
- }
- $supplierOrderListInfo = cloud_post($this->domain.$supplier_order_list_url,$supplier_order_list_data);
- $supplierOrderListInfo = json_decode($supplierOrderListInfo,true);
- if($supplierOrderListInfo['code'] != 0){
- $code = 1; //失败
- return $this->outPutData($code,$supplierOrderListInfo['msg']);
- }else{
- $msg = '查询成功';
- $xlsx = \Yii::$app->request->hostInfo . '/web/statics/Template.xlsx';
- $supplier_id = get_supplier_id();
- $is_stbz = false;
- $supplier = Supplier::findOne($supplier_id);
- if ($supplier && $supplier->is_stbz == 1) {
- $is_stbz = true;
- }
- foreach ($supplierOrderListInfo['data']['list'] as &$item) {
- if (!empty($item['platform_order_no'])) {
- $item['mch_order_no'] = Order::findOne($item['platform_order_no'])->order_no;
- } else {
- $item['mch_order_no'] = PurchaseOrder::findOne(['cloud_order_id' => $item['id']])->order_no;
- }
- if ($item['mch_id']) {
- $store_cloud = StoreCloud::findOne(['cloud_store_id' => $item['mch_id'], 'is_delete' => 0]);
- if ($store_cloud) {
- $store = Store::findOne($store_cloud->store_id);
- $item['mch']['name'] = $store->name ?: $item['mch']['name'];
- // $item['user']['store_name'] = $store->name ?: $item['user']['store_name'];
- }
- }
- }
- $supplierOrderListInfo['data'] = array_merge($supplierOrderListInfo['data'], ['export_list' => $exportList, 'supplier_id' => $supplier_id, 'xlsx' => $xlsx, 'is_stbz' => $is_stbz]);
- return $this->outPutData($supplierOrderListInfo['code'], $msg, $supplierOrderListInfo['data']);
- }
- }
- //供货单列表
- public function supplierOrderList($cloud_supplier_id = 0){
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- // 获取可导出数据
- $f = new ExportList();
- $exportList = $f->getList();
- $supplier_order_list_url = "/cloud/supplier/supplierOrderList";
- $supplier_order_list_data = [];
- $supplier_order_list_data['access_token'] = get_supplier_token($cloud_supplier_id); //获取供货商的token信息
- $admin = get_admin();
- if ($admin->type === 'admin' || $admin->type === Admin::ADMIN_TYPE_FRONT_AGENT) {
- $supplier_order_list_url = "/cloud/user/supplierOrderList";
- $supplier_order_list_data['access_token'] = get_platform_token();
- $admin = get_admin();
- $admin_id = $admin->id;
- if ($admin->username == 'admin') {
- $admin_id = null;
- }
- if ($admin_id) {
- $admin_model = Admin::findOne($admin_id);
- $area_level = $admin_model->area_level;
- $query = Supplier::find()->where(['is_delete' => 0]);
- $salesman_id = $this->salesman_id;
- if ($salesman_id) {
- $query->andWhere([
- 'salesman_id' => $salesman_id
- ]);
- }
- if($area_level == 1){
- $query->andWhere(
- ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id, 'district_id' => $admin_model->district_id]);
- } elseif ($area_level == 2){
- $query->andWhere(
- ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id]);
- } elseif ($area_level == 3){
- $query->andWhere(['province_id' => $admin_model->province_id]);
- }
- $ids = $query->select('cloud_supplier_id')->column();
- if ($ids) {
- if(is_array($ids)){
- $ids = implode(',', $ids);
- }
- $supplier_order_list_data['supplier_id'] = $ids;
- } else {
- return $this->outPutData(0,'获取成功',[
- 'list' => []
- ]);
- }
- }
- }
- $supplier_order_list_data['page'] = $this->page; //订单ID
- $supplier_order_list_data['mobile'] = $this->mobile; //订单ID
- $supplier_order_list_data['user_name'] = $this->user_name; //订单ID
- $supplier_order_list_data['goods_name'] = $this->goods_name; //订单ID
- $supplier_order_list_data['limit'] = $this->limit; //1 取消通过 2 取消失败
- $supplier_order_list_data['status'] = $this->status; //-1 全部 0 待供货商确认 1 供货商已发货 2 已确认收货
- $supplier_order_list_data['mch_id'] = $this->could_mch_id; //商户ID
- $supplier_order_list_data['type'] = $this->type ?: 0; //商户ID
- if($this->start_time) $supplier_order_list_data['start_time'] = strtotime($this->start_time); //开始时间
- if($this->end_time) $supplier_order_list_data['end_time'] = strtotime($this->end_time); //结束时间
- if($this->order_no) $supplier_order_list_data['order_no'] = $this->order_no; //订单号
- if($this->order_id) $supplier_order_list_data['order_id'] = $this->order_id;
- $supplierOrderListInfo = cloud_post($this->domain.$supplier_order_list_url,$supplier_order_list_data);
- $supplierOrderListInfo = json_decode($supplierOrderListInfo,true);
- if($supplierOrderListInfo['code'] != 0){
- $code = 1; //失败
- return $this->outPutData($code,$supplierOrderListInfo['msg']);
- }else{
- $msg = '查询成功';
- $xlsx = \Yii::$app->request->hostInfo . '/web/statics/Template.xlsx';
- $supplier_id = get_supplier_id();
- $is_stbz = false;
- $supplier = Supplier::findOne($supplier_id);
- if ($supplier && $supplier->is_stbz == 1) {
- $is_stbz = true;
- }
- $supplierOrderListInfo['data'] = array_merge($supplierOrderListInfo['data'], ['export_list' => $exportList, 'supplier_id' => $supplier_id, 'xlsx' => $xlsx, 'is_stbz' => $is_stbz]);
- return $this->outPutData($supplierOrderListInfo['code'], $msg, $supplierOrderListInfo['data']);
- }
- }
- //订单取消审核
- public function supplierPurchaseCancel(){
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- $supplier_purchase_cancel_url = "/cloud/supplier/supplierPurchaseCancel";
- $supplier_purchase_cancel_data = [];
- $supplier_purchase_cancel_data['access_token'] = get_supplier_token(); //获取供货商的token信息
- $supplier_purchase_cancel_data['order_id'] = $this->order_id; //订单ID
- $supplier_purchase_cancel_data['cancel_type'] = $this->cancel_type; //1 取消通过 2 取消失败
- $supplierPurchaseCancelInfo = cloud_post($this->domain.$supplier_purchase_cancel_url,$supplier_purchase_cancel_data);
- $supplierPurchaseCancelInfo = json_decode($supplierPurchaseCancelInfo,true);
- if($supplierPurchaseCancelInfo['code'] != 0){
- $code = 1; //失败
- return $this->outPutData($code,$supplierPurchaseCancelInfo['msg']);
- }else{
- if (intval($this->cancel_type) === 1) {
- try {
- $orderTransit = OrderTransit::findOne(['cloud_order_id' => $this->order_id]);
- $supplier = Supplier::findOne(['cloud_supplier_id' => $orderTransit->cloud_supplier_id]);
- $printer_order = new PrintOrder(0, $this->order_id, 'confirm', 0, 0, 1, 0, $supplier->id);
- $printer_order->print_order();
- } catch (\Exception $e) {
- debug_log([
- 'event' => 'supplierPurchaseCancel',
- 'message' => $e->getMessage(),
- 'line' => $e->getLine(),
- 'file' => $e->getFile()
- ], 'cloud_printer.log');
- }
- }
- return $this->outPutData($supplierPurchaseCancelInfo['code'],$supplierPurchaseCancelInfo['msg']);
- }
- }
- //订单发货
- public function supplierPurchaseSend($cloud_supplier_id = 0){
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- if (!empty($this->xlsx)) {
- $supplier_purchase_send_url = "/cloud/supplier/supplierPurchaseXlsxSend";
- $supplier_purchase_send_data = [];
- $supplier_purchase_send_data['access_token'] = get_supplier_token($cloud_supplier_id); //获取供货商的token信息
- $xlsx_path = $this->saveTempImage($this->xlsx);
- $rows = SimpleExcelReader::create($xlsx_path)->noHeaderRow()->getRows();
- $array = [];
- $rows->each(function($rowProperties) use (&$array) {
- array_push($array, $rowProperties);
- });
- unset($array[0]);
- $array = array_values($array);
- $supplier_purchase_send_data['xlsx'] = json_encode($array);
- } else {
- $supplier_purchase_send_url = "/cloud/supplier/supplierPurchaseSend";
- $supplier_purchase_send_data = [];
- $supplier_purchase_send_data['access_token'] = get_supplier_token($cloud_supplier_id); //获取供货商的token信息
- $supplier_purchase_send_data['order_ids'] = $this->order_id; //订单ID
- $supplier_purchase_send_data['express_name'] = $this->express_name; //快递公司
- $supplier_purchase_send_data['express_no'] = $this->express_no; //快递号
- $supplier_purchase_send_data['send_type'] = $this->send_type; //1 快递配送 2 自主配送
- $supplier_purchase_send_data['words'] = $this->words;
- $supplier_purchase_send_data['zip_code'] = $this->zip_code;
- }
- $supplierPurchaseSendInfo = cloud_post($this->domain.$supplier_purchase_send_url,$supplier_purchase_send_data);
- $supplierPurchaseSendInfo = json_decode($supplierPurchaseSendInfo,true);
- if($supplierPurchaseSendInfo['code'] != 0){
- $code = 1; //失败
- return $this->outPutData($code,$supplierPurchaseSendInfo['msg']);
- }else{
- return $this->outPutData($supplierPurchaseSendInfo['code'],$supplierPurchaseSendInfo['msg']);
- }
- }
- //订单修改发货信息
- public function updateOrderSendInfo($cloud_supplier_id = 0){
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- $supplier_purchase_send_url = "/cloud/supplier/updateOrderSendInfo";
- $supplier_purchase_send_data = [];
- $supplier_purchase_send_data['access_token'] = get_supplier_token($cloud_supplier_id); //获取供货商的token信息
- $supplier_purchase_send_data['order_id'] = $this->order_id; //订单ID
- $supplier_purchase_send_data['express_name'] = $this->express_name; //快递公司
- $supplier_purchase_send_data['express_no'] = $this->express_no; //快递号
- $supplier_purchase_send_data['send_type'] = $this->send_type; //1 快递配送 2 自主配送
- $supplier_purchase_send_data['words'] = $this->words;
- $supplier_purchase_send_data['zip_code'] = $this->zip_code;
- $supplier_purchase_send_data['order_type'] = $this->order_type;
- $supplierPurchaseSendInfo = cloud_post($this->domain.$supplier_purchase_send_url,$supplier_purchase_send_data);
- $supplierPurchaseSendInfo = json_decode($supplierPurchaseSendInfo,true);
- if($supplierPurchaseSendInfo['code'] != 0){
- $code = 1; //失败
- return $this->outPutData($code,$supplierPurchaseSendInfo['msg']);
- }else{
- return $this->outPutData($supplierPurchaseSendInfo['code'],$supplierPurchaseSendInfo['msg']);
- }
- }
- //订单删除
- public function supplierPurchaseDel(){
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- $supplier_purchase_send_url = "/cloud/supplier/supplierPurchaseDel";
- $supplier_purchase_send_data = [];
- $supplier_purchase_send_data['access_token'] = get_supplier_token(); //获取供货商的token信息
- $supplier_purchase_send_data['order_ids'] = $this->order_id; //订单ID
- $supplierPurchaseSendInfo = cloud_post($this->domain.$supplier_purchase_send_url,$supplier_purchase_send_data);
- $supplierPurchaseSendInfo = json_decode($supplierPurchaseSendInfo,true);
- if($supplierPurchaseSendInfo['code'] != 0){
- $code = 1; //失败
- return $this->outPutData($code,$supplierPurchaseSendInfo['msg']);
- }else{
- return $this->outPutData($supplierPurchaseSendInfo['code'],$supplierPurchaseSendInfo['msg']);
- }
- }
- //转单列表
- public function supplierPurchaseOrderList($cloud_supplier_id = 0, $auto = 0){
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- // 获取可导出数据
- $f = new ExportList();
- $exportList = $f->getList();
- $admin = null;
- if ($auto === 0) {
- $admin = get_admin();
- }
- $supplier_purchase_order_list_url = "/cloud/supplier/supplierPurchaseOrderList";
- $supplier_purchase_order_list_data = [];
- $supplier_purchase_order_list_data['access_token'] = get_supplier_token($cloud_supplier_id); //获取供货商的token信息
- if (($admin->type === 'admin' && $admin->username !== 'admin') || $admin->type === Admin::ADMIN_TYPE_FRONT_AGENT) {
- $supplier_purchase_order_list_url = "/cloud/user/supplierPurchaseOrderList";
- $supplier_purchase_order_list_data['access_token'] = get_platform_token();
- $admin_id = $admin->id;
- if ($admin_id) {
- $admin_model = Admin::findOne($admin_id);
- $area_level = $admin_model->area_level;
- $query = Supplier::find()->where(['is_delete' => 0]);
- $salesman_id = $this->salesman_id;
- if ($salesman_id) {
- $query->andWhere([
- 'salesman_id' => $salesman_id
- ]);
- }
- if($area_level == 1){
- $query->andWhere(
- ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id, 'district_id' => $admin_model->district_id]);
- } elseif ($area_level == 2){
- $query->andWhere(
- ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id]);
- } elseif ($area_level == 3){
- $query->andWhere(['province_id' => $admin_model->province_id]);
- }
- $ids = $query->select('cloud_supplier_id')->column();
- if ($ids) {
- if(is_array($ids)){
- $ids = implode(',', $ids);
- }
- $supplier_purchase_order_list_data['supplier_id'] = $ids;
- } else {
- return $this->outPutData(0,'获取成功',[
- 'list' => []
- ]);
- }
- }
- }
- $supplier_purchase_order_list_data['page'] = $this->page; //默认为 1
- $supplier_purchase_order_list_data['limit'] = $this->limit; //默认20
- $supplier_purchase_order_list_data['status'] = $this->status; //-1 全部 0 待供货商确认 1 供货商已发货 2 已确认收货
- $supplier_purchase_order_list_data['mch_id'] = $this->could_mch_id; //商户ID
- if($this->start_time) $supplier_purchase_order_list_data['start_time'] = strtotime($this->start_time); //开始时间
- if($this->end_time) $supplier_purchase_order_list_data['end_time'] = strtotime($this->end_time); //结束时间
- if($this->order_no) $supplier_purchase_order_list_data['order_no'] = $this->order_no; //订单号
- if($this->order_id) $supplier_purchase_order_list_data['order_id'] = $this->order_id; //订单号
- $supplierPurchaseOrderListInfo = cloud_post($this->domain.$supplier_purchase_order_list_url,$supplier_purchase_order_list_data);
- $supplierPurchaseOrderListInfo = json_decode($supplierPurchaseOrderListInfo,true);
- if($supplierPurchaseOrderListInfo['code'] != 0){
- $code = 1; //失败
- return $this->outPutData($code,$supplierPurchaseOrderListInfo['msg']);
- }else{
- $msg = '获取成功';
- $data = $supplierPurchaseOrderListInfo['data'];
- if ($auto === 0) {
- $xlsx = \Yii::$app->request->hostInfo . '/web/statics/Template.xlsx';
- $is_stbz = false;
- $supplier_id = get_supplier_id();
- $supplier = Supplier::findOne($supplier_id);
- if ($supplier && $supplier->is_stbz == 1) {
- $is_stbz = true;
- }
- $data = array_merge([
- 'export_list' => $exportList,
- 'supplier_id' => $supplier_id,
- 'xlsx' => $xlsx,
- 'is_stbz' => $is_stbz,
- ], $data);
- }
- return $this->outPutData($supplierPurchaseOrderListInfo['code'],$msg,$data);
- }
- }
- public function supplierSendTypeRefundList() {
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- $supplier_purchase_order_list_url = "/cloud/supplier/supplierSendTypeRefundList";
- $supplier_purchase_order_list_data = [];
- $supplier_purchase_order_list_data['access_token'] = get_supplier_token(); //获取供货商的token信息
- $admin = get_admin();
- if ($admin->type === 'admin' || $admin->type === Admin::ADMIN_TYPE_FRONT_AGENT) {
- $supplier_purchase_order_list_url = "/cloud/user/supplierPurchaseOrderRefundList";
- $supplier_purchase_order_list_data['access_token'] = get_platform_token();
- $admin = get_admin();
- $admin_id = $admin->id;
- if ($admin->username == 'admin') {
- $admin_id = null;
- }
- if ($admin_id) {
- $admin_model = Admin::findOne($admin_id);
- $area_level = $admin_model->area_level;
- $query = Supplier::find()->where(['is_delete' => 0]);
- $salesman_id = $this->salesman_id;
- if ($salesman_id) {
- $query->andWhere([
- 'salesman_id' => $salesman_id
- ]);
- }
- if($area_level == 1){
- $query->andWhere(
- ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id, 'district_id' => $admin_model->district_id]);
- } elseif ($area_level == 2){
- $query->andWhere(
- ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id]);
- } elseif ($area_level == 3){
- $query->andWhere(['province_id' => $admin_model->province_id]);
- }
- $ids = $query->select('cloud_supplier_id')->column();
- if ($ids) {
- if(is_array($ids)){
- $ids = implode(',', $ids);
- }
- $supplier_purchase_order_list_data['supplier_id'] = $ids;
- } else {
- return $this->outPutData(0,'获取成功',[
- 'list' => []
- ]);
- }
- }
- }
- $supplier_purchase_order_list_data['page'] = $this->page; //默认为 1
- $supplier_purchase_order_list_data['limit'] = $this->limit; //默认20
- $supplier_purchase_order_list_data['status'] = $this->status; //-1 全部 0 待供货商确认 1 供货商已发货 2 已确认收货
- $supplier_purchase_order_list_data['type'] = $this->type;
- if($this->start_time) $supplier_purchase_order_list_data['start_time'] = strtotime($this->start_time); //开始时间
- if($this->end_time) $supplier_purchase_order_list_data['end_time'] = strtotime($this->end_time); //结束时间
- if($this->order_no) $supplier_purchase_order_list_data['order_no'] = $this->order_no; //订单号
- if($this->old_order_no) $supplier_purchase_order_list_data['old_order_no'] = $this->old_order_no; //订单号
- if (!empty(trim($this->mch_order_no))) {
- $mch_order_id = Order::find()->where(['LIKE', 'order_no', $this->mch_order_no])->select('id')->column();
- if (!empty($mch_order_id)) {
- $mch_order_id = implode(',', $mch_order_id);
- } else {
- $mch_order_id = '-1';
- }
- $supplier_purchase_order_list_data['mch_order_ids'] = $mch_order_id;
- }
- $supplierPurchaseOrderListInfo = cloud_post($this->domain.$supplier_purchase_order_list_url,$supplier_purchase_order_list_data);
- $supplierPurchaseOrderListInfo = json_decode($supplierPurchaseOrderListInfo,true);
- if($supplierPurchaseOrderListInfo['code'] != 0){
- $code = 1; //失败
- return $this->outPutData($code,$supplierPurchaseOrderListInfo['msg']);
- }else{
- foreach ($supplierPurchaseOrderListInfo['data']['list'] as &$item) {
- $order = Order::findOne(['id' => $item['platform_order_no']]);
- $item['platform_order_no'] = $order->order_no ?: '';
- }
- $msg = '获取成功';
- return $this->outPutData($supplierPurchaseOrderListInfo['code'],$msg,$supplierPurchaseOrderListInfo['data']);
- }
- }
- //转单售后列表
- public function supplierPurchaseOrderRefundList(){
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- $supplier_purchase_order_list_url = "/cloud/supplier/supplierPurchaseOrderRefundList";
- $supplier_purchase_order_list_data = [];
- $supplier_purchase_order_list_data['access_token'] = get_supplier_token(); //获取供货商的token信息
- $admin = get_admin();
- if ($admin->type === 'admin' || $admin->type === Admin::ADMIN_TYPE_FRONT_AGENT) {
- $supplier_purchase_order_list_url = "/cloud/user/supplierPurchaseOrderRefundList";
- $supplier_purchase_order_list_data['access_token'] = get_platform_token();
- $admin = get_admin();
- $admin_id = $admin->id;
- if ($admin->username == 'admin') {
- $admin_id = null;
- }
- if ($admin_id) {
- $admin_model = Admin::findOne($admin_id);
- $area_level = $admin_model->area_level;
- $query = Supplier::find()->where(['is_delete' => 0]);
- $salesman_id = $this->salesman_id;
- if ($salesman_id) {
- $query->andWhere([
- 'salesman_id' => $salesman_id
- ]);
- }
- if($area_level == 1){
- $query->andWhere(
- ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id, 'district_id' => $admin_model->district_id]);
- } elseif ($area_level == 2){
- $query->andWhere(
- ['province_id' => $admin_model->province_id, 'city_id' => $admin_model->city_id]);
- } elseif ($area_level == 3){
- $query->andWhere(['province_id' => $admin_model->province_id]);
- }
- $ids = $query->select('cloud_supplier_id')->column();
- if ($ids) {
- if(is_array($ids)){
- $ids = implode(',', $ids);
- }
- $supplier_purchase_order_list_data['supplier_id'] = $ids;
- } else {
- return $this->outPutData(0,'获取成功',[
- 'list' => []
- ]);
- }
- }
- }
- $supplier_purchase_order_list_data['page'] = $this->page; //默认为 1
- $supplier_purchase_order_list_data['limit'] = $this->limit; //默认20
- $supplier_purchase_order_list_data['status'] = $this->status; //-1 全部 0 待供货商确认 1 供货商已发货 2 已确认收货
- $supplier_purchase_order_list_data['mch_id'] = $this->could_mch_id; //商户ID
- $supplier_purchase_order_list_data['order_type'] = $this->order_type;
- if($this->start_time) $supplier_purchase_order_list_data['start_time'] = strtotime($this->start_time); //开始时间
- if($this->end_time) $supplier_purchase_order_list_data['end_time'] = strtotime($this->end_time); //结束时间
- if($this->order_no) $supplier_purchase_order_list_data['order_no'] = $this->order_no; //订单号
- $supplierPurchaseOrderListInfo = cloud_post($this->domain.$supplier_purchase_order_list_url,$supplier_purchase_order_list_data);
- $supplierPurchaseOrderListInfo = json_decode($supplierPurchaseOrderListInfo,true);
- if($supplierPurchaseOrderListInfo['code'] != 0){
- $code = 1; //失败
- return $this->outPutData($code,$supplierPurchaseOrderListInfo['msg']);
- }else{
- $msg = '获取成功';
- return $this->outPutData($supplierPurchaseOrderListInfo['code'],$msg,$supplierPurchaseOrderListInfo['data']);
- }
- }
- //供货商创建提现申请
- public function storeSetSupplierCash(){
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- $supplier_id = get_supplier_id();
- if(!$supplier_id || $supplier_id < 0){
- $code = 1; //失败
- $msg = "会员信息有误!";
- return $this->outPutData($code,$msg);
- }
- $supplierInfo = Supplier::find()->where(['id'=>$supplier_id,'is_delete'=>0])->one();
- if(!$supplierInfo || !$supplierInfo['cloud_user_id'] || $supplierInfo['cloud_user_id'] < 0){
- $code = 1; //失败
- $msg = "会员信息有误!";
- return $this->outPutData($code,$msg);
- }
- $supplier_cash_url = "/cloud/supplier/storeSetSupplierCash";
- $supplier_cash_data = [];
- $supplier_cash_data['access_token'] = get_supplier_token(); //获取供货商的token信息
- $supplier_cash_data['user_id'] = $supplierInfo['cloud_user_id']; //会员Id
- $supplier_cash_data['price'] = number_format($this->price, 2,".",""); //充值金额
- $supplier_cash_data['type'] = $this->type; //类型 0 会员 1 商户 2 供货商 暂时仅做供货商提现
- $supplier_cash_data['cash_type'] = $this->cash_type; //提现方式 1--微信支付 2--支付宝 3--银行卡
- $supplier_cash_data['account'] = $this->account; //账号 微信 支付宝 银行卡号
- $supplier_cash_data['name'] = $this->name; //姓名
- $supplier_cash_data['bank_name'] = $this->bank_name; //银行
- $supplierCashInfo = cloud_post($this->domain.$supplier_cash_url,$supplier_cash_data);
- $supplierCashInfo = json_decode($supplierCashInfo,true);
- if($supplierCashInfo['code'] != 0){
- $code = 1; //失败
- return $this->outPutData($code,$supplierCashInfo['msg']);
- }else{
- return $this->outPutData($supplierCashInfo['code'],$supplierCashInfo['msg']);
- }
- }
- //处理请求
- public function supplierApplyHandle($cloud_supplier_id = 0)
- {
- try {
- /**
- * is_agree 1 同意退换货
- * is_agree 2 拒绝退换货 拒绝原因
- * 判断type (商户申请状态 1退货退款 2换货)
- *
- * is_agree 1 status 1 确认收货 type = 1 打款完成
- * is_agree 1 status 1 确认收货 type = 2 处理换货
- * is_agree 2 || status 2 已经拒绝
- */
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- $is_agree = (int)$this->is_agree;
- $status = (int)$this->status;
- $reason = $this->reason;
- $order_id = (int)$this->order_id;
- $mobile = $this->mobile;
- $name = $this->name;
- $detail = $this->detail;
- $zipcode = $this->zipcode;
- if ($is_agree === 2 || $status === 2) {
- if (empty($reason)) {
- $code = 1; //失败
- $msg = "请填写拒绝原因";
- return $this->outPutData($code,$msg);
- }
- }
- $supplier_apply_url = "/cloud/supplier/supplierApplyHandle";
- $supplier_apply_data = [];
- $supplier_apply_data['access_token'] = get_supplier_token($cloud_supplier_id); //获取供货商的token信息
- $supplier_apply_data['is_agree'] = $is_agree;
- $supplier_apply_data['status'] = $status;
- $supplier_apply_data['reason'] = $reason;
- $supplier_apply_data['mobile'] = $mobile;
- $supplier_apply_data['name'] = $name;
- $supplier_apply_data['detail'] = $detail;
- $supplier_apply_data['zipcode'] = $zipcode;
- $supplier_apply_data['order_id'] = $order_id;
- $supplierApplyInfo = cloud_post($this->domain.$supplier_apply_url,$supplier_apply_data);
- $supplierApplyInfo = json_decode($supplierApplyInfo,true);
- debug_log($supplierApplyInfo, 'supplierApplyHandle.log');
- // if(input_params('debug')){
- // var_dump($supplierApplyInfo);die;
- // }
- if($supplierApplyInfo['code'] != 0){
- $code = 1; //失败
- throw new \Exception($supplierApplyInfo['msg']);
- }else{
- $data = $supplierApplyInfo['data'];
- if ((int)$data['order_type'] === 0) {
- $order = OrderTransit::findOne(['cloud_order_id' => $data['order_id']]);
- if ($order && intval($order->status) === 0 && $is_agree === 1) {//未发货状态申请售后,直接调用退款
- $status = 1;
- }
- //只查询一条订单详情记录
- $cancel_examine_item_info = [];
- $cancel_examine_info = json_decode($order->cancel_examine_info, true);
- debug_log(['cancel_examine_info' => $cancel_examine_info], 'supplierRefund.log');
- debug_log(['order_detail' => $data['order_detail']], 'supplierRefund.log');
- if ($cancel_examine_info) {
- foreach ($cancel_examine_info as $cancel_examine_item) {
- foreach ($data['order_detail'] as $detail_item) {
- if ($cancel_examine_item['cloud_goods_id'] == $detail_item['goods_id']
- && $cancel_examine_item['goods_no'] == $detail_item['goods_no']) {
- //符合条件 修改状态
- debug_log(['cancel_examine_item_' => $cancel_examine_item_info], 'supplierRefund.log');
- $cancel_examine_item_info[] = $cancel_examine_item;
- }
- }
- }
- debug_log(['cancel_examine_item' => $cancel_examine_item_info], 'supplierRefund.log');
- //查询售后订单 售后订单不止一条可能会有问题
- //20241106 增加多条售后订单记录流程
- $store_order_detail_id = array_column($cancel_examine_item_info, 'store_order_detail_id');
- sort($store_order_detail_id);
- //目前提交售后要么就是全部提交 要么就是单个单个提交
- $orderRefund = null;
- $orderRefundList = OrderRefund::find()->where(['order_id' => $order->order_id])->asArray()->all();
- //假设全部提交情况下
- // debug_log(['orderRefundList' => $orderRefundList], 'supplierRefund.log');
- foreach ($orderRefundList as $orderRefundItem) {
- $refund_detail_id = json_decode($orderRefundItem['order_detail_id'], true);
- sort($refund_detail_id);
- debug_log([
- 'id' => $orderRefundItem['id'],
- 'refund_detail_id' => $refund_detail_id,
- 'store_order_detail_id' => $store_order_detail_id,
- 'bool' => !array_diff($store_order_detail_id, $refund_detail_id)
- ], 'supplierRefund.log');
- if (!array_diff($store_order_detail_id, $refund_detail_id)) {
- $orderRefund = OrderRefund::findOne($orderRefundItem['id']);
- }
- }
- //全部提交情况不存在 列出单个提交的情况
- if (!$orderRefund) {
- foreach ($orderRefundList as $orderRefundItem) {
- $refund_detail_id = json_decode($orderRefundItem['order_detail_id'], true);
- if (in_array($refund_detail_id[0], $store_order_detail_id)) {
- $orderRefund = OrderRefund::findOne($orderRefundItem['id']);
- }
- }
- }
- //以上情况都不存在
- if (empty($orderRefund)) {
- throw new \Exception('售后订单不存在');
- }
- } else {
- $orderRefund = OrderRefund::findOne([
- 'order_id' => $order->order_id
- ]);
- }
- //如果同意售后就修改商城订单状态,且更改地址为供货商地址信息
- if ($is_agree === 1) {
- if ($orderRefund) {
- //供货商同意之后将商城订单状态修改为同意
- $orderRefund->is_agree = 1;
- $orderRefund->address_id = 0;
- $orderRefund->refund_address = json_encode(
- [
- 'name' => $name,
- 'address' => $detail,
- 'mobile' => $mobile
- ]
- , JSON_UNESCAPED_UNICODE);
- }
- }
- } else {
- $order = PurchaseOrder::findOne(['cloud_order_id' => $data['order_id']]);
- if ($order && intval($order->trade_status) === 0 && $is_agree === 1) {
- $status = 1;
- }
- }
- if ((int)$status === 1) {
- if ((int)$data['order_type'] === 1) {
- $order->trade_status = 1;
- } else {
- $order->status = -1;
- }
- $order->cancel_examine = 2;
- if ($data) {
- //微信支付退款操作
- if (isset($order->pay_type) && (int)$order->pay_type === 1) {
- $res = WechatBusinessPay::orderRefund($order, OrderNo::ORDER_ALLIANCE_PURCHASE, $data['refund_price'], $data['order_refund_no']);
- if ($res['code'] === 1) {
- return $res;
- }
- }
- }
- // 赤店新增逻辑 未进件情况下转单需要从商城余额抵扣金额 ...
- // 申请售后, 需要从商城金额扣款 (已经从用户到账金额里扣减了)
- // if (intval($order->is_use_platform_mch) && (int)$data['order_type'] === 0) {
- // $store_info = Store::findOne($order->store_id);
- // Store::addMoney($store_info, $order->order_price, '商城云仓订单售后');
- // }
- //如果是转单订单 供货商取消之后需要原路退回金额 当前版本下用户申请售后 商家同意后 用户直接与供货商交互
- ///流程为用户确认收货后-申请售后-商城同意售后-API(商城向供货商申请售后)-供货商同意后填写收货地址-用户在客户端可以看到供货商填写的手机号以及地址信息
- ///用户发货-供货商后台进行收货-售后完成给商城用户退款
- if ((int)$data['order_type'] === 0) {
- if (!empty($orderRefund)) {
- //给商城用户退款
- $orderRefundForm = new OrderRefundForm();
- $orderRefundForm->order_refund_id = $orderRefund->id;
- $orderRefundForm->store_id = $order->store_id;
- $orderRefundForm->type = 1;
- $orderRefundForm->action = 1;
- $orderRefundForm->refund = 1;
- $refund_result = $orderRefundForm->save(1);
- debug_log($refund_result, 'SupplierRefund.log');
- }
- }
- $type = 1;
- if (intval($data['order_type'])) {//批发
- $type = 2;
- }
- try {
- $supplier = Supplier::findOne(['cloud_supplier_id' => $order->cloud_supplier_id]);
- $printer_order = new PrintOrder(0, $order->cloud_order_id, 'confirm', 0, 0, $type, 0, $supplier->id);
- $printer_order->print_order();
- } catch (\Exception $e) {
- debug_log([
- 'event' => 'supplierApplyHandle',
- 'message' => $e->getMessage(),
- 'line' => $e->getLine(),
- 'file' => $e->getFile()
- ], 'cloud_printer.log');
- }
- }
- if ($is_agree === 2 || $status === 2) {
- // $order->cancel_examine = 0;
- if ($is_agree === 2) {
- if (!empty($orderRefund)) {
- $orderRefund->is_agree = 2;
- $orderRefund->status = 2;
- }
- }
- if ($order->cancel_examine_info) {
- $cancel_examine_info = json_decode($order->cancel_examine_info, true);
- foreach ($cancel_examine_info as $cancel_examine_index => $cancel_examine_item) {
- foreach ($data['order_detail'] as $detail_item) {
- if ($cancel_examine_item['cloud_goods_id'] == $detail_item['goods_id']
- && $cancel_examine_item['goods_no'] == $detail_item['goods_no']) {
- unset($cancel_examine_info[$cancel_examine_index]);
- }
- }
- }
- $order->cancel_examine_info = json_encode(array_values($cancel_examine_info));
- } else {
- $order->cancel_examine = 0;
- }
- }
- if (!$order->save()) {
- throw new \Exception(json_encode($order->errors));
- }
- if ($orderRefund && !$orderRefund->save()) {
- throw new \Exception(json_encode($order->errors));
- }
- return $this->outPutData($supplierApplyInfo['code'],$supplierApplyInfo['msg']);
- }
- } catch (\Exception $e) {
- $code = 1; //失败
- return $this->outPutData($code, $e->getMessage() . $e->getLine());
- }
- }
- //余额记录
- public function supplierGetBalanceLog(){
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- $get_balance_log_url = "/cloud/supplier/supplierGetBalanceLog";
- $get_balance_log_data = [];
- $get_balance_log_data['access_token'] = get_supplier_token(); //获取供货商的token信息
- if($this->page) $get_balance_log_data['page'] = $this->page; //计费方式【1=>按重计费、2=>按件计费】
- if($this->limit) $get_balance_log_data['limit'] = $this->limit;
- $getBalanceLogInfo = cloud_post($this->domain.$get_balance_log_url,$get_balance_log_data);
- $getBalanceLogInfo = json_decode($getBalanceLogInfo,true);
- if($getBalanceLogInfo['code'] != 0){
- $code = 1; //失败
- return $this->outPutData($code,$getBalanceLogInfo['msg']);
- }else{
- $msg = '获取成功';
- return $this->outPutData($getBalanceLogInfo['code'],$msg,$getBalanceLogInfo['data']);
- }
- }
- //余额冻结记录
- public function supplierGetBalanceFrozenLog(){
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- $get_balance_log_url = "/cloud/supplier/supplierGetBalanceFrozenLog";
- $get_balance_log_data = [];
- $get_balance_log_data['access_token'] = get_supplier_token(); //获取供货商的token信息
- if($this->page) $get_balance_log_data['page'] = $this->page; //计费方式【1=>按重计费、2=>按件计费】
- if($this->limit) $get_balance_log_data['limit'] = $this->limit;
- $getBalanceLogInfo = cloud_post($this->domain.$get_balance_log_url,$get_balance_log_data);
- $getBalanceLogInfo = json_decode($getBalanceLogInfo,true);
- if($getBalanceLogInfo['code'] != 0){
- $code = 1; //失败
- return $this->outPutData($code,$getBalanceLogInfo['msg']);
- }else{
- $msg = '获取成功';
- return $this->outPutData($getBalanceLogInfo['code'],$msg,$getBalanceLogInfo['data']);
- }
- }
- //商品提交审核
- public function auditSubmit(){
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- $rules_url = "/cloud/supplier/supplierPutGoodsAudit";
- $rules_data = [];
- $rules_data['access_token'] = get_supplier_token($this->token_supplier_id); //获取供货商的token信息
- $rules_data['goods_id'] = $this->goods_id; //商品ID
- $rulesInfo = cloud_post($this->domain.$rules_url,$rules_data);
- $rulesInfo = json_decode($rulesInfo,true);
- if($rulesInfo['code'] != 0){
- $code = 1; //失败
- return $this->outPutData($code,$rulesInfo['msg']);
- }else{
- if ((int)$this->status === 0) {
- Goods::updateAll(['status' => 0], ['cloud_goods_id' => $this->goods_id, 'is_wholesale' => 0]);
- }
- $code = $rulesInfo['code'];
- return $this->outPutData($code,$rulesInfo['msg'], $rulesInfo['data']);
- }
- }
- //商品上下架
- public function setRules(){
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- $rules_url = "/cloud/supplier/supplierSetRules";
- $rules_data = [];
- $rules_data['access_token'] = get_supplier_token(); //获取供货商的token信息
- $rules_data['type'] = $this->type; //计费方式【1=>按重计费、2=>按件计费】
- $rules_data['desc'] = $this->desc;
- $rules_data['id'] = $this->id;
- $rules_data['is_default'] = $this->is_default;
- $rules_data['name'] = $this->name;
- $rulesInfo = cloud_post($this->domain.$rules_url,$rules_data);
- $rulesInfo = json_decode($rulesInfo,true);
- if($rulesInfo['code'] != 0){
- $code = 1; //失败
- return $this->outPutData($code,$rulesInfo['msg']);
- }else{
- $code = $rulesInfo['code'];
- return $this->outPutData($code,$rulesInfo['msg']);
- }
- }
- //商品状态
- public function setGoodsStatus(){
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- $goods_status_url = "/cloud/supplier/supplierSetGoodsStatus";
- $goods_status_data = [];
- $goods_status_data['access_token'] = get_supplier_token(); //获取供货商的token信息
- $goods_status_data['goods_ids'] = $this->goods_id; //商品ID
- if(in_array($this->status,[0,1,2])){ $goods_status_data['status'] = $this->status; }//0 下架 1 上架 2删除
- //检测胜天半子
- if ($this->stbz_goods_id && intval($this->status) === 1) {
- $id = \get_params('id', $this->stbz_goods_id);
- $params = [
- 'id' => $id,
- ];
- $key = md5(json_encode(\array_merge($params, ['type' => 'stbz_get_goods_item'])));
- if (\Yii::$app->cache->exists($key)) {
- $data = \Yii::$app->cache->get($key);
- $returnData = \json_decode($data, true);
- } else {
- $data = \stbz_client()->getApiResponse('get', '/v2/Goods/Detail', $params);
- $returnData = \json_decode($data, true);
- if ($returnData['code'] != 1) {
- return [
- 'code' => 1,
- 'msg' => $returnData['msg'],
- ];
- }
- \Yii::$app->cache->set($key, $data, 600);
- }
- if (!$returnData['data']) {
- return [
- 'code' => 1,
- 'msg' => '胜天半子商品不存在',
- ];
- }
- if (intval($returnData['data']['status']) === 0) {
- return [
- 'code' => 1,
- 'msg' => '胜天半子商品已下架',
- ];
- }
- }
- $goodsStatusInfo = cloud_post($this->domain.$goods_status_url,$goods_status_data);
- $goodsStatusInfo = json_decode($goodsStatusInfo,true);
- if($goodsStatusInfo['code'] != 0){
- $code = 1; //失败
- return $this->outPutData($code,$goodsStatusInfo['msg']);
- }else{
- if (in_array($this->status, [0, 2])) {
- $goods_id = $this->goods_id;
- if (is_string($this->goods_id)) {
- $goods_id = explode(',', $this->goods_id);
- }
- Goods::updateAll(['status' => 0], ['cloud_goods_id' => $goods_id, 'is_wholesale' => 0]);
- }
- return $this->outPutData($goodsStatusInfo['code'] ,$goodsStatusInfo['msg']);
- }
- }
- //添加编辑规格
- public function setGoodsAttr(){
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- $goods_attr_url = "/cloud/supplier/supplierSetGoodsAttr";
- $goods_attr_data = [];
- $goods_attr_data['access_token'] = get_supplier_token(); //获取供货商的token信息
- $goods_attr_data['attr_id'] = ($this->attr_id) ? $this->attr_id : 0 ; //规格ID 0添加 大于0 编辑
- $goods_attr_data['name'] = $this->name; //规格名称
- $goods_attr_data['goods_id'] = $this->goods_id; //商品ID
- $goods_attr_data['price'] = number_format($this->price, 2,".",""); //价格
- $goods_attr_data['pic_url'] = $this->pic_url; //规格图片
- $goods_attr_data['num'] = $this->num; //库存
- // $goods_attr_data['weight'] = $this->weight;
- $goods_attr_data['goods_no'] = $this->goods_no; //规格货号
- $goodsAttrInfo = cloud_post($this->domain.$goods_attr_url,$goods_attr_data);
- $goodsAttrInfo = json_decode($goodsAttrInfo,true);
- if($goodsAttrInfo['code'] != 0){
- $code = 1; //失败
- return $this->outPutData($code,$goodsAttrInfo['msg']);
- }else{
- return $this->outPutData($goodsAttrInfo['code'],$goodsAttrInfo['msg']);
- }
- }
- //添加编辑规格
- public function setGoodsAttrNum($supplier_id, $goods_id, $updateAttrList, $store_id = 0){
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- $goods_attr_url = "/cloud/supplier/setGoodsAttrNum";
- $goods_attr_data = [];
- $goods_attr_data['access_token'] = get_supplier_token(0, $supplier_id); //获取供货商的token信息
- $goods_attr_data['attrs'] = json_encode($updateAttrList);
- $store_id && $goods_attr_data['store_id'] = $store_id;
- $goods_attr_data['goods_id'] = $goods_id; //商品ID
- $setGoodsAttrNum = cloud_post($this->domain.$goods_attr_url,$goods_attr_data);
- $setGoodsAttrNum = json_decode($setGoodsAttrNum,true);
- if($setGoodsAttrNum['code'] != 0){
- $code = 1; //失败
- return $this->outPutData($code,$setGoodsAttrNum['msg']);
- }else{
- return $this->outPutData($setGoodsAttrNum['code'],$setGoodsAttrNum['msg']);
- }
- }
- //创建商品
- public function setGoods(){
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- $price = number_format($this->g_price, 2,".","");
- $goods_url = "/cloud/supplier/supplierSetGoods";
- $goods_data = [];
- $goods_data['access_token'] = get_supplier_token($this->token_supplier_id); //获取供货商的token信息
- $goods_data['goods_id'] = ($this->goods_id) ? $this->goods_id : 0;
- $goods_data['name'] = $this->name; //默认为 1
- $goods_data['pic_url'] = $this->g_s_pic_url;
- $goods_data['video_url'] = $this->video_url;
- $goods_data['desc'] = $this->desc;
- $goods_data['num'] = $this->num; //库存
- $goods_data['use_attr'] = $this->use_attr; //是否使用规格 默认0不使用
- $goods_data['price'] = $price; //售价
- $goods_data['wholesale_price'] = number_format((float)$this->g_wholesale_price, 2,".",""); // 批发价
- $goods_data['wholesale_ladder_rebate'] = $this->g_wholesale_ladder_rebate; // 批发阶梯折扣
- $goods_data['wholesale_rebate_switch'] = $this->g_wholesale_rebate_switch; // 是否开启批发阶梯折扣
- $goods_data['wholesale_ladder_type'] = $this->wholesale_ladder_type; // 是否开启批发阶梯折扣
- $goods_data['cat_id'] = $this->cat_id;
- $goods_data['sort'] = $this->sort;
- $goods_data['is_change'] = $this->is_change ?: 0;
- $goods_data['original_price'] = number_format($this->g_original_price, 2,".",""); //零售价
- $goods_data['pic_list'] = json_encode($this->g_pic_list);
- $goods_data['is_purchase'] = $this->is_purchase;
- $goods_data['is_need_install'] = (int)$this->is_need_install;
- $goods_data['stbz_goods_id'] = $this->stbz_goods_id ?: 0;
- $goods_data['jst_goods_id'] = $this->jst_goods_id ?: 0;
- $goods_data['jst_supplier_id'] = $this->jst_supplier_id ?: 0;
- $goods_data['freight'] = (int)$this->freight;
- $goods_data['is_level'] = (int)$this->is_level;
- $goods_data['goods_full_give_switch'] = (int)$this->goods_full_give_switch;
- $goods_data['goods_full_give_info'] = $this->goods_full_give_info;
- $goods_data['market_price'] = $this->market_price ?: 0;
- $goods_data['underlined_price'] = sprintf('%.2f', $this->underlined_price);
- $goods_data['send_type_num'] = $this->send_type_num ?: 0;
- $goods_data['centralize_goods_type'] = $this->centralize_goods_type ?: 0;
- //增加平台协议价
- $platform_negotiated_price = $this->setPlatformNegotiatedPrice($price);
- $goods_data['platform_negotiated_price'] = $platform_negotiated_price;
- if($this->goods_area_rules_id) $goods_data['goods_area_rules_id'] = $this->goods_area_rules_id;
- if($this->g_unit) $goods_data['unit'] = $this->g_unit;
- if($this->g_shop_count) $goods_data['shop_count'] = $this->g_shop_count;
- if($this->g_send_type) $goods_data['send_type'] = $this->g_send_type;
- if($this->goods_no) $goods_data['goods_no'] = $this->goods_no; //默认20
- if ($this->weight) $goods_data['weight'] = number_format($this->weight, 2, '.', ''); // 重量,克
- $is_supplier_set_price = Option::get('is_supplier_set_price', 0, 'cloud', 1)['value'];
- $goods_data['is_supplier_set_price'] = $is_supplier_set_price;
- $attrs = $this->attrs;
- foreach ($attrs as &$attr_item) {
- $attr_item['platform_negotiated_price'] = $this->setPlatformNegotiatedPrice($attr_item['price']);
- }
- $goods_data['attrs'] = json_encode($attrs);
- $goods_data['is_selection'] = $this->is_selection;
- $goodsDataInfo = cloud_post($this->domain.$goods_url,$goods_data);
- $goodsDataInfo = json_decode($goodsDataInfo,true);
- if($goodsDataInfo['code'] != 0){
- $code = 1;//失败
- return $this->outPutData($code,$goodsDataInfo['msg']);
- }else{
- if (!empty($this->goods_id) && $goodsDataInfo['data']['open'] == true) {
- Goods::updateAll(['status' => 0],['cloud_goods_id' => $this->goods_id, 'is_wholesale' => 0]);
- }
- return $this->outPutData($goodsDataInfo['code'] ,$goodsDataInfo['msg'], $goodsDataInfo['data']);
- }
- }
- public function setPlatformNegotiatedPrice($price) {
- $platform_profit_strategy = Option::get('platform_profit_strategy', 0, 'store')['value'];
- $platform_profit_strategy = json_decode($platform_profit_strategy, true);
- if (!empty($platform_profit_strategy)) {
- //服务收费start
- if (intval($platform_profit_strategy['service_charge_model'])) {
- //平台溢价
- $service_charge_rate = $platform_profit_strategy['service_charge_rate'];
- } else {
- //供货商抽成
- $service_charge_rate = 0;
- }
- $price = sprintf('%.2f', ($price * (1 + ($service_charge_rate / 100))));
- }
- return $price;
- }
- //获取商品列表
- public function goodsList(){
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- $goods_list_url = "/cloud/supplier/supplierGetGoodsList";
- $goods_list_data = [];
- $goods_list_data['access_token'] = get_supplier_token(); //获取供货商的token信息
- $goods_list_data['page'] = input_params('pageNo') ?: $this->page; //默认为 1
- $goods_list_data['limit'] = $this->limit; //默认20
- if($this->goods_id) $goods_list_data['goods_id'] = $this->goods_id;
- if($this->cat_id) $goods_list_data['cat_id'] = (int)$this->cat_id;
- if($this->supplier_id) $goods_list_data['supplier_id'] = $this->supplier_id;
- if($this->name) $goods_list_data['name'] = $this->name; //商品名称
- if($this->status != -1) $goods_list_data['status'] = $this->status; //-1 全部 0 下架 1 上架
- $goodsListInfo = cloud_post($this->domain.$goods_list_url,$goods_list_data);
- $goodsListInfo = json_decode($goodsListInfo,true);
- if($goodsListInfo['code'] != 0){
- $code = 1;//失败
- return $this->outPutData($code,$goodsListInfo['msg']);
- }else{
- foreach ($goodsListInfo['data']['list'] as &$item) {
- $agent_goods = AgentGoodsBindGoods::find()->where(['cloud_goods_id' => $item['id'], 'is_delete' => 0])
- ->select('goods_agent_admin_id')
- ->column();
- $item['admin_list'] = Admin::find()->where(
- ['id' => $agent_goods, 'type' => Admin::ADMIN_TYPE_GOODS_AGENT, 'is_delete' => 0]
- )->select('id, name, address, mobile, province_id, city_id, district_id')->asArray()->all();
- foreach ($item['admin_list'] as &$value) {
- $province_id = $value['province_id'];
- $city_id = $value['city_id'];
- $district_id = $value['district_id'];
- $district = District::find()->where(['id' => [$province_id, $city_id, $district_id]])->select('name')->column();
- $value['address'] = implode('', $district) . $value['address'];
- }
- }
- return $this->outPutData($goodsListInfo['code'],"获取成功",$goodsListInfo['data']);
- }
- }
- //获取商品审核列表
- public function goodsAuditList(){
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- $goods_list_url = "/cloud/supplier/supplierGetGoodsAuditList";
- $goods_list_data = [];
- $goods_list_data['access_token'] = get_supplier_token(); //获取供货商的token信息
- $goods_list_data['page'] = $this->page; //默认为 1
- $goods_list_data['limit'] = $this->limit; //默认20
- if($this->goods_id) $goods_list_data['goods_id'] = $this->goods_id;
- if($this->supplier_id) $goods_list_data['supplier_id'] = $this->supplier_id;
- if($this->name) $goods_list_data['name'] = $this->name; //商品名称
- if($this->status) $goods_list_data['status'] = $this->status; //0全部 1审核中 2成功 3失败
- $goodsListInfo = cloud_post($this->domain.$goods_list_url,$goods_list_data);
- $goodsListInfo = json_decode($goodsListInfo,true);
- if($goodsListInfo['code'] != 0){
- $code = 1;//失败
- return $this->outPutData($code,$goodsListInfo['msg']);
- }else{
- return $this->outPutData($goodsListInfo['code'],"获取成功",$goodsListInfo['data']);
- }
- }
- //转单详情
- public function purchaseOrderInfo($order_id, $supplier_id)
- {
- // $order_id = explode(',', $order_id);
- // $cloud_order_id = $order_id;
- // $cache = \Yii::$app->cache->get('cloud_supplier_cache_token_' . $supplier_id);
- // if ($cache) {
- // $params = json_decode($cache, true);
- // //3天刷新token
- // if (time() - $params['time'] < (3 * 24 * 3600) ) {
- // //return $params['access_token'];
- // $token = $params['access_token'];
- // } else {
- // $supplier = Supplier::findOne($supplier_id);
- // $response = get_cloud_token($supplier->name, $supplier->password);
- // $token = '';
- // if ($response['code'] == 0 && $response['taken']) {
- // $token = $response['taken'];
- // }
- // }
- // } else {
- // $supplier = Supplier::findOne($supplier_id);
- // $response = get_cloud_token($supplier->name, $supplier->password);
- // $token = '';
- // if ($response['code'] == 0 && $response['taken']) {
- // $token = $response['taken'];
- // }
- // }
- $token = get_supplier_token(0, $supplier_id);
-
- $data = [];
- $fields = json_decode($this->fields, true);
- $search = json_decode($this->search, true);
- $supplier_purchase_order_list_url = "/cloud/supplier/supplierPurchaseOrderList";
- $supplier_purchase_order_list_data = [];
- $supplier_purchase_order_list_data['access_token'] = $token; //获取供货商的token信息
- $supplier_purchase_order_list_data['order_id'] = (string)$order_id; //默认为 1
- $supplier_purchase_order_list_data['order_type'] = $this->order_type;
- $supplier_purchase_order_list_data['start_time'] = (int)strtotime($search['start_time']);
- $supplier_purchase_order_list_data['end_time'] = (int)strtotime($search['end_time']);
- $supplier_purchase_order_list_data['order_no'] = $search['order_no'];
- $supplier_purchase_order_list_data['mobile'] = $search['mobile'];
- $supplier_purchase_order_list_data['user_name'] = $search['user_name'];
- $supplier_purchase_order_list_data['status'] = $search['status'];
- $supplier_purchase_order_list_data['export'] = 1;
- $supplierPurchaseOrderListInfo = cloud_post($this->domain.$supplier_purchase_order_list_url,$supplier_purchase_order_list_data);
-
- $supplierPurchaseOrderListInfo = json_decode($supplierPurchaseOrderListInfo,true);
- if($supplierPurchaseOrderListInfo['code'] != 0){
- $code = 1; //失败
- return $this->outPutData($code,$supplierPurchaseOrderListInfo['msg']);
- }else{
- $order_list = $supplierPurchaseOrderListInfo['data'];
- $goods = [];
- foreach ($order_list['list'] as $item) {
- foreach ($item['goods_list'] as $goods_item) {
- $attr = '';
- if ($goods_item['attr']['attr_list']) {
- foreach ($goods_item['attr']['attr_list'] as $attr_item) {
- $attr .= $attr_item['attr_group_name'] . ':' . $attr_item['attr_name'] . ';';
- }
- } else {
- foreach ($goods_item['attr'] as $attr_item) {
- $attr .= $attr_item['attr_group_name'] . ':' . $attr_item['attr_name'] . ';';
- }
- }
-
- $goods[] = [
- 'order_no' => $item['order_no'], //订单编号
- 'nickname' => $item['name'], //下单用户
- 'good_name' => $goods_item['name'],//商品名称
- 'attr' => $attr, //商品规格
- 'good_num' => $goods_item['num'],//商品数量
- 'goods_no' => $goods_item['goods_no'],//货号
- 'name' => $item['name'],//下单人
- 'mobile' => $item['mobile'],//手机号
- 'address' => $item['address'],//地址
- 'cost_price' => $item['goods_price'],//成本价
- 'total_price' => $item['goods_price'],//总价
- 'pay_price' => $item['goods_price'], //支付价
- 'content' => $item['content'],//商家留言
- 'apply_delete' => ((int)$item['is_refund'] == 1 ? '取消申请订单' : '未取消订单'),//申请状态
- 'send_time' => !empty($item['send_time']) ? date('Y-m-d H:i:s', $item['send_time']) : '', //发货时间
- 'merchant_remark' => $item['seller_desc'],//商家留言
- 'created_at' => !empty($item['pay_time']) ? date('Y-m-d H:i:s', $item['pay_time']) : '',//下单时间
- 'pay_type' => '线上支付',//支付类型 支付方式:1:微信支付,2:货到付款,3:余额支付,4:支付宝,5:抖音支付,6:线下支付
- 'trade_status' => $item['status'],//订单状态 订单状态,-1:默认,0:待发货,1:已取消,2:已发货,3:已确认
- 'pay_time' => !empty($item['pay_time']) ? date('Y-m-d H:i:s', $item['pay_time']) : ''//支付时间
- ];
- }
- }
- }
- foreach ($goods as $index => &$item) {
- foreach ($item as $i => $e) {
-
- foreach ($fields as $f => $f_e) {
- $open = true;
- if ($f === $i) {
- $open = false;
- $item[$f_e] = $e;
-
- }
- if ($open) {
- unset($item[$i]);
- }
- }
- }
- }
- $writer = SimpleExcelWriter::streamDownload(time() . '.xlsx')
- ->addRows($goods)->toBrowser();
- // Export::order_3($goods, $fields);
- }
- //获取商品规则列表
- public function goodsSaleRulesList(){
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- $goods_list_url = "/cloud/supplier/getGoodsSaleRulesList";
- $goods_list_data = [];
- $goods_list_data['access_token'] = get_supplier_token(); //获取供货商的token信息
- $goods_list_data['page'] = $this->page; //默认为 1
- $goods_list_data['limit'] = $this->limit; //默认20
- if($this->name) $goods_list_data['name'] = $this->name; //商品名称
- if($this->status !== null && $this->status !== '') $goods_list_data['status'] = $this->status; //0全部 1审核中 2成功 3失败
- $goodsListInfo = cloud_post($this->domain.$goods_list_url,$goods_list_data);
- $goodsListInfo = json_decode($goodsListInfo,true);
- if($goodsListInfo['code'] != 0){
- $code = 1;//失败
- return $this->outPutData($code,$goodsListInfo['msg']);
- }else{
- return $this->outPutData($goodsListInfo['code'],"获取成功",$goodsListInfo['data']);
- }
- }
- //保存商品规则
- public function goodsSaleRulesSave(){
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- $goods_list_url = "/cloud/supplier/setGoodsSaleRules";
- $goods_list_data = [];
- $goods_list_data['access_token'] = get_supplier_token(); //获取供货商的token信息
- $goods_list_data['name'] = $this->name; //默认为 1
- $goods_list_data['area'] = $this->area; //默认20
- $goods_list_data['status'] = $this->status; //默认20
- if($this->id) $goods_list_data['id'] = $this->id;
- $goodsListInfo = cloud_post($this->domain.$goods_list_url,$goods_list_data);
- $goodsListInfo = json_decode($goodsListInfo,true);
- if($goodsListInfo['code'] != 0){
- $code = 1;//失败
- return $this->outPutData($code,$goodsListInfo['msg']);
- }else{
- return $this->outPutData($goodsListInfo['code'],"操作成功",$goodsListInfo['data']);
- }
- }
- //修改商品规则状态
- public function setGoodsSaleRulesStatus(){
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- $goods_list_url = "/cloud/supplier/setGoodsSaleRulesStatus";
- $goods_list_data = [];
- $goods_list_data['access_token'] = get_supplier_token(); //获取供货商的token信息
- $goods_list_data['status'] = $this->status;
- $goods_list_data['id'] = $this->id;
- $goods_list_data['ids'] = $this->ids;
- $goodsListInfo = cloud_post($this->domain.$goods_list_url,$goods_list_data);
- $goodsListInfo = json_decode($goodsListInfo,true);
- if($goodsListInfo['code'] != 0){
- $code = 1;//失败
- return $this->outPutData($code,$goodsListInfo['msg']);
- }else{
- return $this->outPutData($goodsListInfo['code'],"操作成功",$goodsListInfo['data']);
- }
- }
- public function agentOrderGroupList() {
- try {
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- $admin = get_admin();
- $goods_list_data = [];
- $goods_list_url = "/cloud/supplier/getAgentOrderGroup";
- $goods_list_data['access_token'] = get_supplier_token(); //获取供货商的token信息
- if ($admin->type === Admin::ADMIN_TYPE_FRONT_AGENT || $admin->type === 'admin') {
- if ($admin->type === 'admin') {
- $cloud_supplier_id = Supplier::find()->where(['is_delete' => 0])->select('cloud_supplier_id')->column();
- } else {
- $supplier_id = AgentFrontBind::find()->where(['front_agent_admin_id' => $admin->id, 'type' => 0, 'status' => 1, 'is_delete' => 0])
- ->select('type_id')->column();
- $cloud_supplier_id = Supplier::find()->where(['id' => $supplier_id, 'is_delete' => 0])->select('cloud_supplier_id')->column();
- }
- $goods_list_url = "/cloud/user/getAgentOrderGroup";
- $goods_list_data['access_token'] = get_platform_token();
- if ($this->supplier_name) {
- $goods_list_data['supplier_name'] = $this->supplier_name;
- }
- $goods_list_data['supplier_id'] = implode(',', $cloud_supplier_id);
- }
- $goods_list_data['status'] = $this->status;
- $goods_list_data['goods_name'] = $this->goods_name;
- $goods_list_data['type'] = $this->type;
- $goods_list_data['page'] = $this->page; //默认为 1
- $goods_list_data['limit'] = $this->limit; //默认20
- $goodsListInfo = cloud_post($this->domain.$goods_list_url,$goods_list_data);
- $goodsListInfo = json_decode($goodsListInfo,true);
- if($goodsListInfo['code'] != 0){
- throw new \Exception($goodsListInfo['msg']);
- }else{
- if (!empty($goodsListInfo['data'])) {
- foreach ($goodsListInfo['data']['data'] as &$data) {
- $admin_id = $data['admin_id'];
- $admin = Admin::findOne(['id' => $admin_id]);
- $district = District::find()->where(['id' => [$admin->province_id, $admin->city_id, $admin->district_id]])->select('name')->column();
- $data['admin_name'] = $admin->name;
- $data['admin_tel'] = $admin->mobile;
- $data['admin_address'] = implode('/', $district) . ($admin->address ?: '');
- if (!empty($data['platform_order_no'])) {
- $data['mch_order_no'] = Order::findOne($data['platform_order_no'])->order_no;
- } else {
- $data['mch_order_no'] = PurchaseOrder::findOne(['cloud_order_id' => $data['order_id']])->order_no;
- }
- $data['md_info'] = null;
- if ($data['md_id'] > 0) {
- $md_info = Md::findOne($data['md_id']);
- $data['md_info'] = [
- 'logo' => $md_info->cover_url ?? '',
- 'name' => $md_info->name ?? '',
- 'tel' => $md_info->mobile ?? '',
- ];
- }
- if (isset($data['store']['user_id'])) {
- $store_cloud = StoreCloud::findOne(['cloud_user_id' => $data['store']['user_id'], 'is_delete' => 0]);
- if ($store_cloud) {
- $store = Store::findOne($store_cloud->store_id);
- if ($store) {
- $data['store'] = [
- 'name' => $store->name,
- 'tel' => $store->contact_tel ?: $store_cloud->tel ,
- 'logo' => $store->logo,
- ];
- }
- }
- }
- }
- }
- return $this->outPutData($goodsListInfo['code'],"获取成功",$goodsListInfo['data']);
- }
- } catch (\Exception $e) {
- return $this->outPutData(1, $e->getMessage());
- }
- }
- public function agentOrderDistribution() {
- try {
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- $goods_list_url = "/cloud/supplier/agentOrderDistribution";
- $goods_list_data = [];
- $goods_list_data['access_token'] = get_supplier_token(); //获取供货商的token信息
- $goods_list_data['start_time'] = $this->start_time;
- $goods_list_data['end_time'] = $this->end_time;
- $goodsListInfo = cloud_post($this->domain.$goods_list_url,$goods_list_data);
- $goodsListInfo = json_decode($goodsListInfo,true);
- if($goodsListInfo['code'] != 0){
- throw new \Exception($goodsListInfo['msg']);
- }else{
- return $this->outPutData($goodsListInfo['code'],"获取成功");
- }
- } catch (\Exception $e) {
- return $this->outPutData(1, $e->getMessage());
- }
- }
- public function agentOrderDistributionList($id = 0, $status = 0) {
- try {
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- $goods_list_url = "/cloud/supplier/agentOrderDistributionList";
- $goods_list_data = [];
- $goods_list_data['access_token'] = get_supplier_token(); //获取供货商的token信息
- $admin = get_admin();
- if ($admin->type === 'admin' || $admin->type === Admin::ADMIN_TYPE_FRONT_AGENT) {
- $goods_list_url = "/cloud/user/agentOrderDistributionList";
- $goods_list_data['access_token'] = get_platform_token();
- $goods_list_data['admin_id'] = $admin->id;
- }
- $goods_list_data['status'] = $status ?: $this->status;
- $goods_list_data['id'] = $id ?: $this->id;
- if ($this->order_no) {
- $goods_list_data['order_no'] = $this->order_no;
- }
- if ($this->sorting_start_time) {
- $goods_list_data['sorting_start_time'] = $this->sorting_start_time;
- }
- if ($this->sorting_end_time) {
- $goods_list_data['sorting_end_time'] = $this->sorting_end_time;
- }
- if ($this->start_time) {
- $goods_list_data['start_time'] = $this->start_time;
- }
- if ($this->end_time) {
- $goods_list_data['end_time'] = $this->end_time;
- }
- $goods_list_data['goods_name'] = $this->goods_name;
- $goods_list_data['page'] = $this->page; //默认为 1
- $goods_list_data['limit'] = $this->limit; //默认20
- $goodsListInfo = cloud_post($this->domain.$goods_list_url,$goods_list_data);
- $goodsListInfo = json_decode($goodsListInfo,true);
- if($goodsListInfo['code'] != 0){
- throw new \Exception($goodsListInfo['msg']);
- }else{
- $generator = new BarcodeGeneratorJPG();
- if (!empty($goodsListInfo['data'])) {
- foreach ($goodsListInfo['data']['data'] as &$data) {
- $admin_id = $data['admin_id'];
- $admin = Admin::findOne(['id' => $admin_id]);
- $district = District::find()->where(['id' => [$admin->province_id, $admin->city_id, $admin->district_id]])->select('name')->column();
- $data['admin_name'] = $admin->name;
- $data['admin_tel'] = $admin->mobile;
- $data['admin_address'] = implode('/', $district) . ($admin->address ?: '');
- $data['goods_num'] = 0;
- foreach ($data['mch_goods'] as &$mch_goods) {
- $cloud_store_id = $mch_goods['store_id'];
- $store_cloud = StoreCloud::findOne(['cloud_store_id' => $cloud_store_id, 'is_delete' => 0]);
- if ($store_cloud) {
- $store = Store::findOne($store_cloud->store_id);
- $mch_goods['store_name'] = $store->name;
- }
- foreach ($mch_goods['mch_order'] as &$mch_order_item) {
- $md_id = $mch_order_item['md_id'];
- $md_info = Md::findOne($md_id);
- $mch_order_item['md_name'] = $md_info->name ?? ($store->name ?? '');
- $mch_order_item['md_mobile'] = $md_info->mobile ?? '';
- $mch_order_item['goods_num'] += array_sum(array_column($mch_order_item['md_order'], 'goods_num'));
- }
- $data['goods_num'] += array_sum(array_column($mch_goods['mch_order'], 'goods_num'));
- }
- foreach ($data['goods'] as &$goods_item) {
- $barcode = $generator->getBarcode($goods_item['goods_no'], $generator::TYPE_CODE_128, 2, 30);
- $file_name = md5($goods_item['goods_no'] . '_cloud_goods_no_barcode'). '.jpg';
- $code_path = \Yii::$app->runtimePath . '/image/' . $file_name;
- $pic_url = str_replace('http://', 'https://', \Yii::$app->request->hostInfo . '/runtime/image/' . $file_name . '?v=' . time());
- // 创建一个图像资源
- $image = imagecreatefromstring($barcode);
- // 定义颜色
- $black = imagecolorallocate($image, 0, 0, 0);
- $white = imagecolorallocate($image, 255, 255, 255);
- // 获取图像的宽度和高度
- $imageWidth = imagesx($image);
- $imageHeight = imagesy($image);
- // 计算文本的位置
- $fontSize = 4; // 字体大小
- $textWidth = imagefontwidth($fontSize) * strlen($goods_item['goods_no']);
- $textX = ($imageWidth - $textWidth) / 2;
- $textY = $imageHeight + 5; // 文本在条形码下方的位置
- // 创建一个新的图像,高度增加以容纳文本
- $newImageHeight = $imageHeight + 20; // 增加高度以容纳文本
- $newImage = imagecreatetruecolor($imageWidth, $newImageHeight);
- // 填充背景色
- imagefilledrectangle($newImage, 0, 0, $imageWidth, $newImageHeight, $white);
- // 将条形码图像复制到新图像上
- imagecopy($newImage, $image, 0, 0, 0, 0, $imageWidth, $imageHeight);
- // 在条形码下方添加代码文本
- imagestring($newImage, $fontSize, $textX, $textY, $goods_item['goods_no'], $black);
- // 保存图片到指定路径
- imagepng($newImage, $code_path);
- // 释放内存
- imagedestroy($image);
- imagedestroy($newImage);
- $goods_item['barcode'] = $pic_url;
- }
- }
- }
- return $this->outPutData($goodsListInfo['code'],"获取成功",$goodsListInfo['data']);
- }
- } catch (\Exception $e) {
- return $this->outPutData(1,$e->getMessage());
- }
- }
- //更改配送单状态
- public function setDistributionStatus()
- {
- $t = \Yii::$app->db->beginTransaction();
- try {
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- //获取平台token
- $cloud_token = get_supplier_token();
- $getGoodsCateUrl = "/cloud/supplier/setDistributionStatus";
- $getGoodsCateData['access_token'] = $cloud_token;
- $getGoodsCateData['ids'] = $this->ids;
- $getGoodsCateData['status'] = $this->status;
- $getGoodsCateInfo = cloud_post($this->domain.$getGoodsCateUrl,$getGoodsCateData);
- $getGoodsCateInfo = json_decode($getGoodsCateInfo,true);
- if($getGoodsCateInfo['code'] != 0){
- throw new \Exception($getGoodsCateInfo['msg']);
- }
- $t->commit();
- return $this->outPutData(0, $getGoodsCateInfo['msg']);
- } catch (\Exception $e) {
- $t->rollBack();
- return $this->outPutData(1, $e->getMessage());
- }
- }
- //打印配货单
- public function exportDistributionInfo()
- {
- try {
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- $goods_list_url = "/cloud/user/agentOrderDistributionList";
- if ((int)$this->export === 2) {
- $goods_list_url = "/cloud/user/getAgentOrderDistributionList";
- }
- $goods_list_data['access_token'] = get_platform_token();
- $goods_list_data['id'] = $this->id;
- $goods_list_data['export'] = $this->export;
- $goodsListInfo = cloud_post($this->domain.$goods_list_url,$goods_list_data);
- $goodsListInfo = json_decode($goodsListInfo,true);
- if($goodsListInfo['code'] != 0){
- throw new \Exception($goodsListInfo['msg']);
- }else{
- if (!empty($goodsListInfo['data'])) {
- if ((int)$this->export === 1) {
- $title = [];
- $data = [];
- foreach ($goodsListInfo['data']['data'] as $_data) {
- $admin_id = $_data['admin_id'];
- $admin = Admin::findOne(['id' => $admin_id]);
- $_data['admin_name'] = $admin->name;
- $District = District::find()->where(['id' => [$admin->province_id, $admin->city_id, $admin->district_id]])->select('name')->column();
- $address = implode(',', $District);
- $title = [
- [
- 'goods_name' => "服务商:" . $_data['admin_name'] . '/' . $admin->mobile,
- 'goods_attr' => "服务商地址:" . $address . $admin->address,
- 'goods_num' => "供货商:" . $_data['supplier_name']
- ]
- ];
- foreach ($_data['goods'] as $index => $good) {
- $data[$index]['goods_name'] = $good['goods_name'];
- // if ((int)$this->export === 2) {
- // $data[$index]['goods_name'] = $good['goods_name'];
- // }
- $attrs = json_decode($good['goods_attr'], true);
- $attr_str = '';
- foreach ($attrs as $attr) {
- $attr_str .= $attr['attr_group_name'] . ':' . $attr['attr_name'] . ';';
- }
- $data[$index]['goods_attr'] = $attr_str;
- $data[$index]['goods_num'] = $good['goods_num'];
- }
- }
- $field = [
- [
- 'goods_name' => '商品',
- 'goods_attr' => '规格',
- 'goods_num' => '数量'
- ]
- ];
- $file_name = '配货单';
- } else {
- $data = [];
- $_data = $goodsListInfo['data']['data'];
- // foreach ($goodsListInfo['data']['data'] as $_data) {
- $admin_id = $_data['admin_id'];
- $admin = Admin::findOne(['id' => $admin_id]);
- $_data['admin_name'] = $admin->name;
- $District = District::find()->where(['id' => [$admin->province_id, $admin->city_id, $admin->district_id]])->select('name')->column();
- $address = implode(',', $District);
- $title = [
- [
- 'goods_name' => "服务商:" . $_data['admin_name'] . '/' . $admin->mobile,
- 'goods_attr' => "服务商地址:" . $address . $admin->address,
- ]
- ];
- $num = 0;
- foreach ($_data['mch'] as $index => $mch) {
- if ((int)$mch['type'] === 1) {
- $mch['mch']['name'] = '采购:' . $mch['address'];
- }
- foreach ($mch['goods'] as $goods_index => $goods) {
- $store_cloud = StoreCloud::findOne(['cloud_user_id' => $mch['mch']['user_id'], 'is_delete' => 0]);
- $data[$num]['mch_name'] = Store::findOne($store_cloud->store_id)->name;//$goods_index === 0 ? $mch['mch']['name'] : '';
- $data[$num]['goods_name'] = $goods['name'];
- $data[$num]['goods_num'] = $goods['goods_num'];
- $_attrs = json_decode($goods['goods_attr'], true);
- $attr = '';
- foreach ($_attrs as $_attr) {
- $attr .= $_attr['attr_group_name'] . ':' . $_attr['attr_name'] . ';';
- }
- $data[$num]['goods_attr'] = $attr;
- $num++;
- }
- // if ((int)$this->export === 2) {
- // $data[$index]['goods_name'] = $good['goods_name'];
- // }
- }
- $field = [
- [
- 'mch_name' => '商户信息',
- 'goods_name' => '商品',
- 'goods_num' => '数量',
- 'goods_attr' => '规格'
- ]
- ];
- // }
- $file_name = '配送单';
- }
- $data = array_merge($title, $field, $data);
- SimpleExcelWriter::streamDownload($file_name . time() . '.xlsx')
- ->noHeaderRow()
- ->addRows($data)
- ->toBrowser();
- }
- // return $this->outPutData($goodsListInfo['code'],"获取成功",$goodsListInfo['data']);
- }
- } catch (\Exception $e) {
- return $this->outPutData(1, $e->getMessage() . $e->getLine());
- }
- }
- public function getAgentOrderDistributionList() {
- try {
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- $goods_list_url = "/cloud/user/getAgentOrderDistributionList";
- $goods_list_data['access_token'] = get_platform_token();
- $goods_list_data['id'] = $this->id;
- $goods_list_data['export'] = $this->export;
- $goodsListInfo = cloud_post($this->domain.$goods_list_url,$goods_list_data);
- $goodsListInfo = json_decode($goodsListInfo,true);
- if($goodsListInfo['code'] != 0){
- throw new \Exception($goodsListInfo['msg']);
- }else{
- if (!empty($goodsListInfo['data'])) {
- $data = [];
- $_data = $goodsListInfo['data']['data'];
- // $order_no = $_data['order_no'];
- $sorting_time = $_data['order_no'];
- // foreach ($goodsListInfo['data']['data'] as $_data) {
- $admin_id = $_data['admin_id'];
- $admin = Admin::findOne(['id' => $admin_id]);
- // $_data['admin_name'] = $admin->name;
- $admin_title = [
- 'admin_name' => $admin->name,
- 'admin_mobile' => $admin->mobile,
- 'order_no' => $_data['order_no'],
- 'send_time' => $_data['send_time'] ? date('Y-m-d H:i:s', $_data['send_time']) : '-',
- 'sorting_time' => $_data['sorting_time'] ? date('Y-m-d H:i:s', $_data['sorting_time']) : '-',
- ];
- $data = $_data['mch'];
- foreach ($data as $index => &$mch) {
- $cloud_user_id = $mch['mch']['user_id'];
- $store_cloud = StoreCloud::findOne(['cloud_user_id' => $cloud_user_id]);
- if ($store_cloud) {
- $store_id = $store_cloud->store_id;
- $store = Store::findOne($store_id);
- $address = '';
- $mobile = '';
- if ($store) {
- $address = Option::get('address', $store_id, 'store', '')['value'];
- $district = District::find()->where(['id' => [$store->province_id, $store->city_id, $store->district_id]])->select('name')->column();
- if ($district) {
- $district = implode('', $district);
- $address = $district . $address;
- }
- $admin = Admin::findOne(['type' => 'store', 'type_id' => $store->id]);
- $mobile = $admin->mobile;
- }
- $mch['mch'] = [
- 'name' => $store->name ?? '-',
- 'address' => $address,
- 'mobile' => $mobile
- ];
- foreach ($mch['goods'] as &$goods) {
- $goods['goods_attr'] = json_decode($goods['goods_attr'], true);
- }
- }
- // if ((int)$mch['type'] === 1) {
- // $mch['mch']['name'] = '采购:' . $mch['address'];
- // }
- // foreach ($mch['goods'] as $goods_index => $goods) {
- // $store_cloud = StoreCloud::findOne(['cloud_user_id' => $mch['mch']['user_id'], 'is_delete' => 0]);
- //// $data[$num]['store_name'] = Store::findOne($store_cloud->store_id)->name;
- // $data[$num]['mch_name'] = Store::findOne($store_cloud->store_id)->name;//$goods_index === 0 ? $mch['mch']['name'] : '';
- // $data[$num]['goods_name'] = $goods['name'];
- // $data[$num]['goods_num'] = $goods['goods_num'];
- // $_attrs = json_decode($goods['goods_attr'], true);
- // $attr = '';
- // foreach ($_attrs as $_attr) {
- // $attr .= $_attr['attr_group_name'] . ':' . $_attr['attr_name'] . ';';
- // }
- // $data[$num]['goods_attr'] = $attr;
- // $num++;
- // }
- }
- return [
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'goods' => $data,
- 'admin_title' => $admin_title
- ]
- ];
- }
- }
- } catch (\Exception $e) {
- return [
- 'code' => 1,
- 'msg' => $e->getMessage()
- ];
- }
- }
- //供货单列表(推送到聚水潭)
- public function supplierOrderList2Jst($supplier_id = 0, $time = 0){
- $cloud_supplier_id = Supplier::find()->where(['id' => $supplier_id, 'is_delete' => 0])->select('cloud_supplier_id')->scalar();
- $supplier_order_list_url = "/user/getSupplierOrderList";
- $supplier_order_list_data = [];
- $supplier_order_list_data['time'] = $time;
- $supplier_order_list_data['supplier_id'] = (int)$cloud_supplier_id;
- $supplierOrderListInfo = cloud_post($this->domain.$supplier_order_list_url,$supplier_order_list_data);
- $supplierOrderListInfo = json_decode($supplierOrderListInfo,true);
- if($supplierOrderListInfo['code'] != 0){
- $code = 1; //失败
- return $this->outPutData($code,$supplierOrderListInfo['msg']);
- }else{
- return $supplierOrderListInfo;
- }
- }
- //云仓库存列表
- public function getCloudPreviewNum(){
- //获取平台token
- $cloud_token = get_supplier_token();
- $supplier_order_list_data = [];
- $supplier_order_list_url = "/cloud/supplier/getCloudPreviewNum";
- $supplier_order_list_data['access_token'] = $cloud_token;
- $supplier_order_list_data['name'] = $this->name;
- $supplier_order_list_data['mobile'] = $this->mobile;
- $supplier_order_list_data['page'] = input_params('pageNo') ?: $this->page; //默认为 1
- $supplier_order_list_data['limit'] = $this->limit; //默认20
- $supplierOrderListInfo = cloud_post($this->domain.$supplier_order_list_url,$supplier_order_list_data);
- $supplierOrderListInfo = json_decode($supplierOrderListInfo,true);
- if($supplierOrderListInfo['code'] != 0){
- $code = 1; //失败
- return $this->outPutData($code,$supplierOrderListInfo['msg']);
- }else{
- if ($supplierOrderListInfo['data']['list']) {
- foreach ($supplierOrderListInfo['data']['list'] as &$item) {
- $store_cloud = StoreCloud::findOne(['cloud_store_id' => $item['mch_id'], 'is_delete' => 0]);
- $item['store_name'] = '-';
- if ($store_cloud) {
- $item['store_name'] = Store::findOne(['id' => $store_cloud->store_id, 'is_delete' => 0])->name ?? '-';
- }
- $user_info = StoreCloud::find()->alias('c')
- ->leftJoin(['su' => SaasUser::tableName()], 'c.saas_user_id = su.id')
- ->where(['c.is_delete' => 0, 'c.cloud_store_id' => $item['mch_id']])->select('su.avatar, su.name')->asArray()->one();
- if ($user_info) {
- $item['name'] = $user_info['name'] ?: $item['name'];
- $item['logo'] = $user_info['avatar'] ?: $item['logo'];
- }
- }
- }
- return $supplierOrderListInfo;
- }
- }
- //云仓库存列表
- public function getCloudPreviewNumInfo(){
- //获取平台token
- $cloud_token = get_supplier_token();
- $supplier_order_list_data = [];
- $supplier_order_list_url = "/cloud/supplier/getCloudPreviewNumInfo";
- $supplier_order_list_data['access_token'] = $cloud_token;
- $supplier_order_list_data['mch_id'] = $this->could_mch_id;
- $supplier_order_list_data['page'] = input_params('pageNo') ?: $this->page; //默认为 1
- $supplier_order_list_data['limit'] = $this->limit; //默认20
- $supplierOrderListInfo = cloud_post($this->domain.$supplier_order_list_url,$supplier_order_list_data);
- $supplierOrderListInfo = json_decode($supplierOrderListInfo,true);
- if($supplierOrderListInfo['code'] != 0){
- $code = 1; //失败
- return $this->outPutData($code,$supplierOrderListInfo['msg']);
- }else{
- if ($supplierOrderListInfo['data']['mch_info']) {
- $mch_id = $supplierOrderListInfo['data']['mch_info']['mch_id'];
- $store_cloud = StoreCloud::findOne(['cloud_store_id' => $mch_id, 'is_delete' => 0]);
- $supplierOrderListInfo['data']['mch_info']['store_name'] = '-';
- if ($store_cloud) {
- $supplierOrderListInfo['data']['mch_info']['store_name'] = Store::findOne(['id' => $store_cloud->store_id, 'is_delete' => 0])->name ?? '-';
- }
- $user_info = StoreCloud::find()->alias('c')
- ->leftJoin(['su' => SaasUser::tableName()], 'c.saas_user_id = su.id')
- ->where(['c.is_delete' => 0, 'c.cloud_store_id' => $mch_id])->select('su.avatar, su.name')->asArray()->one();
- if ($user_info) {
- $supplierOrderListInfo['data']['mch_info']['name'] = $user_info['name'] ?: $supplierOrderListInfo['data']['mch_info']['name'];
- $supplierOrderListInfo['data']['mch_info']['logo'] = $user_info['avatar'] ?: $supplierOrderListInfo['data']['mch_info']['logo'];
- }
- }
- return $supplierOrderListInfo;
- }
- }
- //订单改价
- public function modifyPrice() {
- $t = \Yii::$app->db->beginTransaction();
- try {
- //获取平台token
- $order = PurchaseOrder::findOne(['cloud_order_id' => $this->order_id, 'is_delete' => 0]);
- if (!$order) {
- return [
- 'code' => 1,
- 'msg' => '订单不存在'
- ];
- }
- //判断价格是否小于0
- if ((isset($this->pay_price) && $this->pay_price < 0) || (isset($this->express_price) && $this->express_price < 0)) {
- return [
- 'code' => 1,
- 'msg' => '价格不能小于0'
- ];
- }
- $money = doubleval($order->pay_price);
- $express = doubleval($order->express_price);
- if ($this->goods_id) {
- $purchase_goods = PurchaseOrderDetail::findOne(['goods_id' => $this->goods_id, 'is_delete' => 0, 'order_id' => $order->id]);
- //->asArray()->all();
- if (!$purchase_goods) {
- throw new \Exception('商品查询失败');
- }
- $purchaseOrderDetail = PurchaseOrderDetail::findOne($purchase_goods->id);
- $purchaseOrderDetail->before_update_price = $purchase_goods->total_price;
- $purchaseOrderDetail->total_price = $this->pay_price;
- if (!$purchaseOrderDetail->save()) {
- throw new \Exception(json_encode($purchaseOrderDetail->errors, JSON_UNESCAPED_UNICODE));
- }
- }
- $goods_total_price = PurchaseOrderDetail::find()->where(['order_id' => $order->id, 'is_delete' => 0])->select('total_price')->sum('total_price');
- //计算支付总金额
- $express_ = $express;
- if (isset($this->express_price)) {
- $express_ = $this->express_price;
- }
- $order->pay_price = ($goods_total_price + $express_);
- if (isset($this->express_price)) {
- $order->express_price = $this->express_price;
- }
- $order->before_update_price = $money;
- $order->before_update_express = $express;
- if (!$order->save()) {
- throw new \Exception(json_encode($order->errors, JSON_UNESCAPED_UNICODE));
- }
- $cloud_token = get_supplier_token();
- $supplier_order_modify_price = [];
- $supplier_order_modify_price_url = "/cloud/supplier/modifyPrice";
- $supplier_order_modify_price['access_token'] = $cloud_token;
- $supplier_order_modify_price['pay_price'] = $this->pay_price;
- $supplier_order_modify_price['express_price'] = $this->express_price;
- $supplier_order_modify_price['order_id'] = $this->order_id;
- $supplier_order_modify_price['goods_id'] = $this->goods_id;
- $supplier_order_modify_price['send_type'] = $this->send_type;
- $supplierOrderModifyPriceInfo = cloud_post($this->domain . $supplier_order_modify_price_url, $supplier_order_modify_price);
- $supplierOrderModifyPriceInfo = json_decode($supplierOrderModifyPriceInfo,true);
- if($supplierOrderModifyPriceInfo['code'] != 0){
- throw new \Exception($supplierOrderModifyPriceInfo['msg'], $supplierOrderModifyPriceInfo['code']);
- }else{
- $t->commit();
- return $supplierOrderModifyPriceInfo;
- }
- } catch (\Exception $e) {
- $t->rollBack();
- return [
- 'code' => 1,
- 'msg' => $e->getMessage()
- ];
- }
- }
- //获取平台token
- public function actionGetSaasToken(){
- // $content = Option::get('cloud', 0, 'saas');
- // if (!$content['value']){
- // return false;
- // }
- // $params = json_decode($content['value'],true);
- // $tokenInfo = get_cloud_token($params['name'],$params['password']);
- // $params['access_token'] = $tokenInfo['taken'];
- // Option::set('cloud', json_encode($params), 0, 'saas');
- get_platform_token();
- }
- //返回数据
- private function outPutData($code,$msg,$data=[]){
- $putData = [];
- $putData['code'] = $code;
- $putData['msg'] = $msg;
- if($data) $putData['data'] = $data;
- return $putData;
- }
- //获取网络图片到临时目录
- public function saveTempImage($url)
- {
- if (strpos($url, 'http') === false) {
- $url = 'http:' . trim($url);
- }
- if (!is_dir(\Yii::$app->runtimePath . '/xlsx')) {
- mkdir(\Yii::$app->runtimePath . '/xlsx');
- }
- $save_path = \Yii::$app->runtimePath . '/xlsx/' . md5($url) . '.xlsx';
- CurlHelper::download($url, $save_path);
- return $save_path;
- }
- }
|