After.php 133 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\ActionLog;
  4. use app\admin\model\DataGroup as DataGroupModel;
  5. use app\admin\model\GoodLog;
  6. use app\admin\model\GoodStockInfo;
  7. use app\admin\model\ProcessOrder;
  8. use app\admin\model\SaleCgdPrice;use app\admin\model\ThData;use think\App;
  9. use think\Exception;
  10. use think\facade\Db;
  11. use think\facade\Validate;
  12. //售后
  13. class After extends Base
  14. {
  15. public function __construct(App $app)
  16. {
  17. parent::__construct($app);
  18. }
  19. //新建售后申请单
  20. public function create()
  21. {
  22. $param = $this->request->only(['outCode', 'errorCode', 'remark' => '', 'is_receive', 'num', 'except_code' => '', 'img'], 'post', 'trim');
  23. $val = Validate::rule([
  24. 'outCode' => 'require',
  25. 'errorCode' => 'require',
  26. 'is_receive' => 'require|in:0,1',
  27. 'num' => 'requireIf:is_receive,1',
  28. 'except_code' => 'require',
  29. 'img' => 'require',
  30. ]);
  31. if ($val->check($param) == false) return json_show(1004, $val->getError());
  32. // $outCode = isset($this->post['outCode']) &&$this->post['outCode']!=''?trim($this->post['outCode']) :"";
  33. // if($outCode==''){
  34. // return error_show(1004,"参数outCode 不能为空");
  35. // }
  36. $orderout = Db::name("order_out")
  37. ->field('id,orderCode,wsm_code,send_num,order_type')
  38. ->where(["outCode" => $param['outCode'], 'is_del' => 0])
  39. ->findOrEmpty();
  40. if (empty($orderout)) return error_show(1005, "未找到发货单数据");
  41. $after_num = Db::name("order_return")
  42. ->where(["orderCode" => $orderout['orderCode'], "outCode" => $param['outCode'], 'is_del' => 0])
  43. ->where("status", "not in", [5, 6, 8])
  44. ->sum("error_num");
  45. $th_num = Db::name("order_back")
  46. ->where(["orderCode" => $orderout['orderCode'], "outCode" => $param['outCode'], "is_del" => 0])
  47. ->where("status", "<", 4)
  48. ->sum("return_num");
  49. if ($th_num != 0 || $after_num != 0) return error_show(1005, "存在售后或售后退货未结束流程");
  50. $oder = Db::name("sale")
  51. ->where(["orderCode" => $orderout['orderCode'], "is_del" => 0])
  52. ->findOrEmpty();
  53. if (empty($oder)) return error_show(1005, "未找到订单数据");
  54. if ($oder['order_type'] != 1) {
  55. $wsm = Db::name("warehouse_info")
  56. ->where(["wsm_code" => $orderout['wsm_code']])
  57. ->findOrEmpty();
  58. if (empty($wsm)) return error_show(1005, "未找到仓库数据");
  59. // $cgder =$wsm['contactor_name'] ??'';
  60. // $cgderid =$wsm['contactor'] ??0;
  61. }
  62. // else{
  63. // $roleArr=\think\facade\Config::get("app");
  64. // $kuguan = Db::name("user_role")->where(["roleid"=>$roleArr['wsm_cgder_role'],"is_del"=>0])->column("uid");
  65. // if(empty($kuguan)){
  66. // return error_show(1005,"未找到仓库管理员数据");
  67. // }
  68. // $userinfo = Db::name("dapart_user")
  69. // $cgder =$wsm['contactor_name'] ??'';
  70. // $cgderid =$wsm['contactor'] ??0;
  71. // }
  72. if ($oder['order_type'] == 3||$oder['order_type'] == 4) {
  73. $goon = Db::name("good_zixun")
  74. ->where(["spuCode" => $oder['good_code'], "is_del" => 0])
  75. ->findOrEmpty();
  76. } else {
  77. $goon = Db::name('good_platform')
  78. ->alias('a')
  79. ->field("b.creater,b.createrid,b.supplierNo,b.supplierName")
  80. ->join('good b', 'b.spuCode=a.spuCode', 'left')
  81. ->where(['a.skuCode' => $oder['skuCode']])
  82. ->findOrEmpty();
  83. }
  84. // $errorCode = isset($this->post['errorCode']) &&$this->post['errorCode']!=''?trim($this->post['errorCode']) :"";
  85. // if($param['outCode']==''){
  86. // return error_show(1004,"参数errorCode 不能为空");
  87. // }
  88. $error = Db::name('result_info')
  89. ->where(["result_code" => $param['errorCode'], "is_del" => 0])
  90. ->findOrEmpty();
  91. if (empty($error)) return error_show(1005, "未找到退货原因数据");
  92. $userCommon = \app\admin\common\User::getIns();
  93. $supplier = $userCommon->handle('sInfo', ['code' => $goon['supplierNo']]);
  94. // if (!isset($supplier['code']) || $supplier['code'] != 0) return json_show($supplier['code'], $supplier['message'], $supplier['data']);
  95. $supplier = $supplier['data'];
  96. // $names = $userCommon->handle('getCodeAndName', ['code' => [$oder['customer_code'], $oder['supplierNo']]]);
  97. // $supplier =Db::name("supplier")->where(["code"=>$goon['supplierNo']])->find();
  98. // if($supplier==false){
  99. // return error_show(1005,"未找到商品供应商数据");
  100. // }
  101. // $remark =isset($this->post['remark']) &&$this->post['remark']!=''?trim($this->post['remark']) :"";
  102. // $is_receive =isset($this->post['is_receive']) &&$this->post['is_receive']!==''?intval($this->post['is_receive']):"";
  103. // if($is_receive===""){
  104. // return error_show(1004,"参数 is_receive 不能为空");
  105. // }
  106. $num = $param['is_receive'] == 1 ? $param['num'] : $orderout['send_num'];
  107. // if($param['is_receive']==0){
  108. // $num=$orderout['send_num'];
  109. // }else{
  110. // $num =isset($this->post['num']) &&$this->post['num']!=''?intval($this->post['num']) :"";
  111. // if($num==""){
  112. // return error_show(1004,"参数 num 不能为空或零");
  113. // }
  114. // }
  115. $thnum = Db::name("order_back")
  116. ->where(["orderCode" => $orderout['orderCode'], "outCode" => $param['outCode'], "is_del" => 0])
  117. ->where("status", "=", 4)
  118. ->sum("return_num");
  119. if ($num > ($orderout['send_num'] - $thnum)) return error_show(1004, "可用售后数量不足");
  120. $fininfo =GetFin("admin/orderischeck",["token"=>$this->post['token'],"orderCode"=>$orderout['orderCode']]);
  121. if(!isset($fininfo['code'])||$fininfo['code']!=0 ){
  122. return json_show(10005, $fininfo['message']??"结算校验失败",$fininfo['data']??[]);
  123. }
  124. // $except_code =isset($this->post['except_code']) &&$this->post['except_code']!=''?trim($this->post['except_code']) :"";
  125. // $img = isset($this->post['img']) &&$this->post['img']!=''?trim($this->post['img']) :"";
  126. // $token = isset($this->post['token'])&&$this->post['token']!='' ? trim($this->post['token']):"";
  127. // if($token==''){
  128. // return error_show(105,"参数token不能为空");
  129. // }
  130. // $user =GetUserInfo($token);
  131. // if(empty($user)||$user['code']!=0){
  132. // return error_show(102,"申请人数据不存在");
  133. // }
  134. $rm = $this->uid;//isset($user["data"]['id']) ? $user["data"]['id'] : "";
  135. $ri = $this->uname;//isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  136. $returnCode = makeNo("RS");
  137. Db::startTrans();
  138. try {
  139. $in = [
  140. "returnCode" => $returnCode,
  141. "outCode" => $param['outCode'],
  142. "orderCode" => $oder['orderCode'],
  143. "good_code" => $oder['good_code'],
  144. "good_name" => $oder['good_name'],
  145. "customer_code" => $oder['customer_code'],
  146. "customer_name" =>$oder['customerName'],
  147. "apply_id" => $rm,
  148. "apply_name" => $ri,
  149. 'supplierNo' => $goon['supplierNo'],
  150. 'supplierName' => $goon['supplierName'],
  151. "cgder" => $wsm['contactor_name'] ?? '',
  152. "cgderid" => $wsm['contactor'] ?? 0,
  153. "person" => $supplier['person'] ?? '',
  154. "person_id" => $supplier['personid'] ?? 0,
  155. 'total_num' => $orderout['send_num'],
  156. "error_code" => $param['errorCode'],
  157. "error_num" => $num,
  158. "error_img" => is_array($param['img']) ? implode(',', $param['img']) : $param['img'],
  159. "error_msg" => $error['result'],
  160. "error_remark" => $param['remark'],
  161. "is_receive" => $param['is_receive'],
  162. "remark" => '',
  163. "except_code" => $param['except_code'],
  164. "order_type" => $orderout['order_type'],
  165. 'companyNo' => $oder['supplierNo'],
  166. 'companyName' => $oder['supplierName'],
  167. "status" => 1,
  168. "is_del" => 0,
  169. "addtime" => date("Y-m-d H:i:s"),
  170. "updatetime" => date("Y-m-d H:i:s"),
  171. ];
  172. $create = Db::name("order_return")->insert($in, true);
  173. $orde = ["order_code" => $returnCode, "status" => $in['status'], "action_remark" => '', "action_type" => "create"];
  174. ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], $orde, 'SHD', 1, $orde);
  175. if ($create > 0) {
  176. //维护台账
  177. // Db::name('standing_book')
  178. // ->whereFindInSet('outCode', $param['outCode'])
  179. // ->update([
  180. // 'returnCode' => $returnCode,
  181. // 'updatetime' => date("Y-m-d H:i:s")
  182. // ]);
  183. Db::execute("UPDATE `wsm_standing_book` SET `returnCode`=CONCAT(IFNULL(`returnCode`,''),',{$returnCode}'),`updatetime`='" . date('Y-m-d H:i:s') . "' WHERE FIND_IN_SET('{$param['outCode']}',`outCode`)");
  184. //当状态为1(即待业务审核)时,要将待办数据推给以下角色的用户
  185. // $user = Db::name('user_role')
  186. // ->where([
  187. // ['is_del', '=', 0],
  188. // ['roleid', 'in', [12, 13, 17, 28]],//12客服负责人,13项目负责人,17平台负责人,28网络负责人
  189. // ['status', '=', 1],
  190. // ])->column('uid');
  191. //筛选符合数据权限的用户
  192. // $temp = getUserIdsByShare('', $in['apply_id']);
  193. // $user = array_intersect($user, $temp);
  194. $process = ["order_code" => $returnCode, "order_id" => $create, "order_status" => $in['status'], "order_type" => 'SHD', "before_status" => 0, 'holder_id' => $in['apply_id']];
  195. ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], $process);
  196. Db::commit();
  197. return json_show(0, "售后申请单新建成功", ["returnCode" => $returnCode]);
  198. }
  199. Db::rollback();
  200. return error_show(1005, "售后申请单新建失败");
  201. } catch (Exception $exception) {
  202. Db::rollback();
  203. return json_show(1005, $exception->getMessage());
  204. }
  205. }
  206. //售后申请单列表
  207. public function list()
  208. {
  209. $param = $this->request->only([
  210. 'page' => 1,
  211. 'size' => 10,
  212. 'relaComNo' => '',
  213. 'returnCode' => '',
  214. 'outCode' => '',
  215. 'status' => '',
  216. 'order_type' => '',
  217. 'orderCode' => '',
  218. 'good_code' => '',
  219. 'good_name' => '',
  220. 'except_code' => '',
  221. 'apply_name' => '',
  222. 'start' => '',
  223. 'end' => '',
  224. 'company_name' => '',//部门名称
  225. 'supplierNo' => '',
  226. 'customer_code' => '',
  227. 'companyNo' => '',
  228. 'order_source' => '',
  229. 'use_type' => '',
  230. ], 'post', 'trim');
  231. $where = [['a.is_del', "=", 0]];
  232. if ($param['relaComNo'] !== '') $where[] = ['c.supplierNo', "=", $param['relaComNo']];
  233. if ($param['returnCode'] !== '') $where[] = ['a.returnCode', "like", "%{$param['returnCode']}%"];
  234. if ($param['outCode'] !== '') $where[] = ['a.outCode', "like", "%{$param['outCode']}%"];
  235. if ($param['status'] !== '') $where[] = ['a.status', "=", $param['status']];
  236. if ($param['order_type'] !== "") $where[] = ['a.order_type', "=", $param['order_type']];
  237. if ($param['orderCode'] != "") $where[] = ['a.orderCode', "like", "%{$param['orderCode']}%"];
  238. if ($param['good_code'] != "") $where[] = ['a.good_code', "like", "%{$param['good_code']}%"];
  239. if ($param['good_name'] != "") $where[] = ['a.good_name', "like", "%{$param['good_name']}%"];
  240. if ($param['customer_code'] != "") $where[] = ['a.customer_code', "like", "%{$param['customer_code']}%"];
  241. if ($param['except_code'] != "") $where[] = ['a.except_code', "=", $param['except_code']];
  242. if ($param['apply_name'] != "") $where[] = ['a.apply_name', "like", "%{$param['apply_name']}%"];
  243. if ($param['start'] !== "") $where[] = ['a.addtime', ">=", $param['start']];
  244. if ($param['end'] !== "") $where[] = ['a.addtime', "<=", $param['end']];
  245. if ($param['order_source'] !== "") $where[] = ['c.order_source', "=", $param['order_source']];
  246. if ($param['supplierNo'] !== "") $where[] = ['a.supplierNo', "like", '%' . $param['supplierNo'] . '%'];
  247. if ($param['companyNo'] !== "") $where[] = ['a.companyNo', "like", '%' . $param['companyNo'] . '%'];
  248. if ($param['use_type'] !== '') $where[] = ['p.use_type', '=', $param['use_type']];
  249. $condition = [];
  250. //只有level2的账号过滤数据权限
  251. if ($this->level == 2) {
  252. $hand = resign_hand_user($this->uid, 0);
  253. $role = $this->checkDataShare();
  254. if (!empty($role[DataGroupModel::$type_全部])) {
  255. $arr = array_unique(array_merge($hand, $role[DataGroupModel::$type_全部]));
  256. $condition[] = ["a.person_id", "in", $hand];
  257. $condition[] = ["a.apply_id", "in", $arr];
  258. $condition[] = ["a.cgderid", "in", $hand];
  259. // //查询所负责的供应商
  260. // $supplierNos = Db::connect('mysql_sys')
  261. // ->name('supplier')
  262. // ->where(['is_del' => 0, 'personid' => $arr])
  263. // ->column('code');
  264. // $condition[] = ["a.supplierNo", "in", $supplierNos];//这个地方不应该使用condition,应该使用where与其他条件并列
  265. }
  266. }
  267. //level3账号不允许看到库存品订单
  268. if ($this->level == 3) $where[] = ['c.is_stock', '<>', 1];
  269. // $condition .="a.cgderid in {$hand} or a.person_id in {$hand} or a.apply_id in ("
  270. // .implode(',',$role[DataGroupModel::$type_全部]).")";
  271. if ($param['company_name'] !== "") $where[] = ["a.apply_id", 'in', get_company_item_user_by_name($param['company_name'])];
  272. $count = Db::name("order_return")
  273. ->alias("a")
  274. ->leftJoin("order_returninfo b", "a.returnCode=b.returnCode")
  275. ->leftJoin("sale c", "c.orderCode=a.orderCode AND c.is_del=0")
  276. ->leftJoin('platform p', 'p.id=c.platform_id AND p.is_del=0')
  277. ->where($where)
  278. ->where(function ($query) use ($condition) {
  279. $query->whereOr($condition);
  280. })
  281. ->count('a.id');
  282. // $total = ceil($count/$size);
  283. // $page = $total>=$page ? $page :$total;
  284. $list = Db::name("order_return")
  285. ->alias("a")
  286. ->leftJoin("order_returninfo b", "a.returnCode=b.returnCode")
  287. ->leftJoin("sale c", "c.orderCode=a.orderCode AND c.is_del=0")
  288. ->leftJoin('platform p', 'p.id=c.platform_id AND p.is_del=0')
  289. ->where($where)
  290. ->where(function ($query) use ($condition) {
  291. $query->whereOr($condition);
  292. })
  293. ->field("a.*,b.return_wsm,b.contactor,b.mobile,b.addr,b.addr_code,b.post_code,b.post_company,b.post_fee,b.gys_remark,c.order_source,p.use_type")
  294. ->page($param['page'], $param['size'])
  295. ->order("a.addtime desc")
  296. ->select()
  297. ->toArray();
  298. //申请人及部门
  299. $all_createrid = array_column($list, 'apply_id');
  300. $item = get_company_name_by_uid($all_createrid);
  301. //获取最新的供应商负责人信息
  302. $codes = array_unique(array_column($list,'supplierNo'));
  303. if($codes){
  304. $tmp=\app\admin\common\User::getIns()->handle('sGetList',['more_code'=>$codes,'size'=>count($codes)]);
  305. $person = array_column($tmp['data']['list'],'person','code');
  306. $personid = array_column($tmp['data']['list'],'personid','code');
  307. }
  308. //获取客户信息
  309. // $all_customer_code = array_column($list, 'customer_code');
  310. // $userCommon = \app\admin\common\User::getIns();
  311. // $customer_ = $userCommon->handle('getCodeAndName', ['code' => array_unique(array_merge(array_column($list, 'customer_code'), array_column($list, 'supplierNo')))]);
  312. //校验是否开通了供应商账号
  313. $supp_account = checkHasAccountBySupplierNos(array_unique(array_column($list,'supplierNo')));
  314. $data = [];
  315. foreach ($list as $value) {
  316. // $value['customer_name'] = $customer_['data'][$value['customer_code']] ?? '';
  317. // $value['supplierName'] = $customer_['data'][$value['supplierNo']] ?? '';
  318. $value['company_name'] = $item[$value['apply_id']] ?? '';
  319. $value['has_account'] = (int)isset($supp_account[$value['supplierNo']]);
  320. $value['person'] = $person[$value['supplierNo']]??0;
  321. $value['person_id'] = $personid[$value['supplierNo']]??0;
  322. //是否具有编辑权限
  323. // $value['is_allow_update'] = 0;
  324. // if (in_array($this->roleid, [1, 33]) || in_array($value['apply_id'], $role[DataGroupModel::$type_可编辑])) $value['is_allow_update'] = 1;
  325. $data[] = $value;
  326. }
  327. return app_show(0, "获取成功", ['list' => $data, "count" => $count]);
  328. }
  329. /**
  330. * @return \think\response\Json|void
  331. * @throws \think\db\exception\DataNotFoundException
  332. * @throws \think\db\exception\DbException
  333. * @throws \think\db\exception\ModelNotFoundException
  334. */
  335. public function info()
  336. {
  337. $bkcode = $this->request->post('returnCode', '', 'trim');//isset($this->post['returnCode']) && $this->post['returnCode'] != "" ? trim($this->post['returnCode']) : "";
  338. if ($bkcode == "") return error_show(1005, "参数returnCode 不能为空");
  339. $info = Db::name("order_return")
  340. ->alias("a")
  341. ->leftJoin("order_returninfo b", "a.returnCode=b.returnCode")
  342. ->field("a.*,b.return_wsm,b.contactor,b.mobile,b.addr,b.addr_code,b.post_code,b.post_company,b.post_fee,b.gys_remark")
  343. ->where(['a.returnCode' => $bkcode])
  344. ->findOrEmpty();
  345. if (empty($info)) return error_show(1005, "未找到售后数据");
  346. $orderinfo = Db::name("sale")->where(["orderCode" => $info["orderCode"]])->findOrEmpty();
  347. $info['origin_price'] = $orderinfo['origin_price'];
  348. $info['order_type'] = $orderinfo['order_type'];
  349. $info['order_source'] = $orderinfo['order_source'];
  350. $info['is_stock'] = $orderinfo['is_stock'];
  351. // $info['customer_code'] = $orderinfo['customer_code'];
  352. // $info['companyNo'] = $orderinfo['supplierNo'];
  353. $info['sale_price'] = $orderinfo['sale_price'];
  354. $info['total_price'] = sprintf("%1\$.2f", $orderinfo['sale_price'] * $info['error_num']);
  355. if ($orderinfo['order_type'] == 3 || $orderinfo['order_type'] == 4) {
  356. $goon = Db::name("good_zixun")
  357. ->field('cat_id,supplierNo')
  358. ->where(["spuCode" => $orderinfo['good_code'], "is_del" => 0])
  359. ->findOrEmpty();
  360. } else {
  361. $goon = Db::name('good_platform')
  362. ->alias('a')
  363. ->field('b.cat_id,b.supplierNo')
  364. ->join('good b', 'b.spuCode=a.spuCode', 'left')
  365. ->where(['a.skuCode' => $orderinfo['skuCode']])
  366. ->findOrEmpty();
  367. }
  368. if (empty($goon)) return error_show(1003, "未找到商品数据");
  369. // $info['supplierNo'] = $goon['supplierNo'];
  370. $int = isset($goon['cat_id']) && $goon['cat_id'] != 0 ? made($goon['cat_id']) : [];
  371. $info['can'] = $int;
  372. $addcode = '';
  373. if ($info['addr_code'] != "") {
  374. $temp=json_decode($info['addr_code'],true);
  375. if($temp) $addcode = $info['addr_code'];
  376. else {
  377. $temp = explode(',',$info['addr_code']);
  378. $addcode = json_encode(["provice_code" => $temp[0], "city_code" => $temp[1], "area_code" => $temp[2]]);
  379. }
  380. // list($a, $b, $c) = explode(",", $info['addr_code']);
  381. // $addcode = json_encode(["provice_code" => $a, "city_code" => $b, "area_code" => $c]);
  382. }
  383. $info["addr_cn"] = GetAddr($addcode);
  384. // $info["addr_code"]=json_decode($addcode,true);
  385. $out = Db::name("order_out")->where(["outCode" => $info['outCode'], "is_del" => 0])->find();
  386. $info['out_num'] = isset($out['send_num']) ? $out['send_num'] : '';
  387. // $customer = Db::name("customer_info")->where(["companyNo"=>$info['customer_code']])->find();
  388. $wsmcode = [];
  389. $info['wsm_supplier'] = '';
  390. if ($info['return_wsm'] != '') {
  391. $wsmcode = Db::name("warehouse_info")
  392. ->alias("a")
  393. // ->leftJoin("supplier b", "a.supplierNo=b.code")
  394. ->where(["a.wsm_code" => $info['return_wsm']])
  395. // ->field("a.name as wsm_name,a.wsm_code,a.contactor_name,a.position,a.mobile,a.addrs_code,a.addr,a.companyNo,a.supplierNo")
  396. ->find();
  397. }
  398. // $userCommon = \app\admin\common\User::getIns();
  399. // $names = $userCommon->handle('getCodeAndName', ['code' => [
  400. // $wsmcode['supplierNo'] ?? '',
  401. // $wsmcode['companyNo'] ?? '',
  402. //// $info['customer_code'],
  403. //// $info['companyNo'],
  404. //// $info['supplierNo'],
  405. // ]]);
  406. if ($info['return_wsm'] != '') {
  407. $info['wsm_supplierNo'] = $wsmcode['supplierNo'] ?? "";
  408. $info['wsm_supplier'] = $wsmcode['supplierName'];//isset($wsmcode['name']) ? $wsmcode['name'] : "";
  409. $info['wsm_customer_name'] = $wsmcode['companyName'];//isset($customer['company']) ? trim($customer['company']) : '';
  410. $info['wsm_customer_code'] = $wsmcode['companyNo'] ?? "";//isset($customer['companyNo']) ? trim($customer['companyNo']) : '';
  411. $info['wsm_code'] = isset($wsmcode['wsm_code']) ? $wsmcode['wsm_code'] : "";
  412. $info['wsm_name'] = isset($wsmcode['name']) ? $wsmcode['name'] : "";
  413. }
  414. // $customer = [];
  415. // if (isset($orderinfo['supplierNo']) && $orderinfo['supplierNo'] != '') {
  416. // $customer = Db::name("business")->field('id,company,companyNo')->where(["companyNo" => $orderinfo['supplierNo']])->find();
  417. // }
  418. // $info['customer_name'] = $names['data'][$info['customer_code']] ?? '';
  419. // $info['companyName'] = $names['data'][$info['companyNo']] ?? '';
  420. // $info['supplierName'] = $names['data'][$info['supplierNo']] ?? '';
  421. //仓库的联系人、职位、电话、省市区和地址
  422. isset($wsmcode['contactor_name']) ? $info['contactor'] = $wsmcode['contactor_name'] : '';//联系人
  423. isset($wsmcode['mobile']) ? $info['mobile'] = $wsmcode['mobile'] : '';//电话
  424. isset($wsmcode['addrs_code']) ? $info['addr_code'] = $wsmcode['addrs_code'] : '';//省市区
  425. isset($wsmcode['addr']) ? $info['addr'] = $wsmcode['addr'] : '';//和地址
  426. // $info['position'] = $wsmcode['position'];//职位
  427. // $info['mobile'] = $wsmcode['mobile'];//电话
  428. // $info['addrs_code'] = json_decode($wsmcode['addrs_code'], true);//省市区编码
  429. // $info['addr'] = $wsmcode['addr'];//地址
  430. $info['spuCode'] = $orderinfo['good_code'];
  431. $info['skuCode'] = $orderinfo['skuCode'];
  432. $info['return_tag'] = $info['return_tag'] == 0 ? "" : $info['return_tag'];
  433. $info['is_th'] = $info['is_th'] == 0 ? "" : $info['is_th'];
  434. //校验是否开通了供应商账号
  435. $supp_account = checkHasAccountBySupplierNos([$info['supplierNo']]);
  436. $info['has_account']=(int)isset($supp_account[$info['supplierNo']]);
  437. return app_show(0, "获取成功", $info);
  438. }
  439. //售后申请单 审核
  440. //申请单状态:
  441. //1待业务审核,
  442. //2待采购审核,
  443. //3待设置仓库(该节点废除),
  444. //4待客户退货(已收到货才有),
  445. //5售后已完成,
  446. //6业务已驳回,
  447. //7采购已驳回(该节点废除),
  448. //8申请已取消,
  449. //9供应商审核,
  450. //10业务公司修改待供应商确认
  451. //11待设置退货工单(已收到货才有),
  452. //12待库管收货(已收到货才有),
  453. public function status()
  454. {
  455. try {
  456. $param = $this->request->only([
  457. 'returnCode',
  458. 'status',
  459. 'remark' => '',
  460. 'wsm_code' => '',
  461. 'contactor' => '',
  462. 'mobile' => '',
  463. 'addr_code' => '',
  464. 'addr' => '',
  465. ], 'post', 'trim');
  466. $val = Validate::rule([
  467. 'returnCode' => 'require',
  468. 'status' => 'require|number|in:1,2,4,5,6,9,10,11',
  469. 'remark' => 'requireIf:status,6|requireIf:status,10',
  470. ]);
  471. if ($val->check($param) == false) throw new Exception($val->getError());
  472. $info = Db::name("order_return")
  473. ->where(['is_del' => 0, 'returnCode' => $param['returnCode']])
  474. ->findOrEmpty();
  475. if (empty($info)) throw new Exception('未找到售后数据');
  476. if ($info['status'] == 6) throw new Exception('业务已驳回,无法操作');
  477. if ($info['status'] == 5) throw new Exception('售后已完成,无法操作');
  478. if ($info['status'] == 8) throw new Exception('申请已取消,无法操作');
  479. switch ($info['status']) {
  480. case 1:
  481. if (in_array($param['status'], [6, 2, 9]) == false) throw new Exception('选项错误');
  482. if ($info['order_type'] == 1 && $param['status'] == 9) throw new Exception('选项错误');
  483. //库存品不允许供应商审核,只允许走2-11-4-12-5流程
  484. break;
  485. case 9:
  486. if (in_array($param['status'], [2, 4]) == false) throw new Exception('选项错误');
  487. if ($param['status'] == 2 && $param['remark'] == '') throw new Exception('remark不能为空');
  488. if ($param['status'] == 4) {
  489. $info['return_tag'] = 1;
  490. if ($param['contactor'] == '') throw new Exception('收货人不能为空');
  491. if ($param['mobile'] == '') throw new Exception('联系电话不能为空');
  492. if ($param['addr_code'] == '') throw new Exception('省市区编码不能为空');
  493. if ($param['addr'] == '') throw new Exception('退货地址不能为空');
  494. }else{
  495. $info['return_tag'] = 2;
  496. }
  497. break;
  498. case 2:
  499. if ((($info['order_type'] == 1) && (in_array($param['status'], [10, 11]) == false)
  500. || (($info['order_type'] != 1) && (in_array($param['status'], [10,4]) == false)))) throw new Exception('选项错误');
  501. break;
  502. case 10:
  503. if (in_array($param['status'], [2, 4]) == false) throw new Exception('选项错误');
  504. if ($param['status'] == 2 && $param['remark'] == '') throw new Exception('remark不能为空');
  505. if ($param['status'] == 4) {
  506. $info['return_tag'] = 1;
  507. if ($param['contactor'] == '') throw new Exception('收货人不能为空');
  508. if ($param['mobile'] == '') throw new Exception('联系电话不能为空');
  509. if ($param['addr_code'] == '') throw new Exception('省市区编码不能为空');
  510. if ($param['addr'] == '') throw new Exception('退货地址不能为空');
  511. }else{
  512. $info['return_tag'] = 2;
  513. }
  514. break;
  515. }
  516. if(in_array($info['status'],[9,10])&& $param['status'] == 4){
  517. $fininfo =GetFin("admin/orderischeck",["token"=>$this->post['token'],"orderCode"=>$info['orderCode'],"isCgd"=>1]);
  518. if(!isset($fininfo['code'])||$fininfo['code']!=0 )return json_show(10005, $fininfo['message']??'结算校验失败',$fininfo['data']??[]);
  519. }else{
  520. $fininfo =GetFin("admin/orderischeck",["token"=>$this->post['token'],"orderCode"=>$info['orderCode']]);
  521. if(!isset($fininfo['code'])||$fininfo['code']!=0 )return json_show(10005, $fininfo['message']??'结算校验失败',$fininfo['data']??[]);
  522. }
  523. //获取最新的供应商负责人
  524. $s_info = \app\admin\common\User::getIns()->handle('sInfo', ['code' => $info['supplierNo']]);
  525. $info['person_id'] = $s_info['data']['personid']??"0";
  526. $info['person'] = $s_info['data']['person']??"";
  527. //当处于以下节点时,level2账号必须是供应商负责人操作,level3账号不做限制
  528. // if (in_array($info['status'], [9, 10]) && ($this->level == 2) && ($this->uid != $info['person_id'])) return json_show(1004, '您不是供应商负责人,此时无权操作');
  529. if ($param['remark'] != '') $info['remark'] = $param['remark'];
  530. Db::startTrans();
  531. try {
  532. $date = date('Y-m-d H:i:s');
  533. $action_log_user = ['id' => $this->uid, 'nickname' => $this->uname];
  534. //如果是小循环,增加次数
  535. if ($param['status'] == 10) $info['loop_total'] += 1;//只要走到节点10(业务公司修改,待供应商确认),就增加次数
  536. //判断 退回供应商 or 退回业务公司
  537. if ($info['status'] == 2 && $param['status'] == 11) {
  538. //退入次品仓,维护
  539. $wsm = Db::name('warehouse_info')->where(['is_del' => 0, 'wsm_code' => $param['wsm_code']])->findOrEmpty();
  540. if (empty($wsm)) throw new Exception('返回仓库不存在');
  541. if ($wsm['wsm_type'] != 4) throw new Exception('不是次品仓');
  542. Db::name('order_returninfo')->insert([
  543. 'returnCode' => $param['returnCode'],
  544. 'return_wsm' => $param['wsm_code'],
  545. 'contactor' => $wsm['contactor_name'],
  546. 'mobile' => $wsm['mobile'],
  547. 'addr' => $wsm['addr'],
  548. 'addr_code' => $wsm['addrs_code'],
  549. 'post_code' => '',
  550. 'post_company' => '',
  551. 'post_fee' => 0,
  552. 'gys_remark' => '',
  553. 'addtime' => $date,
  554. ]);
  555. }
  556. $var = $info['status'];
  557. $info['status'] = $param['status'];
  558. $info['updatetime'] = $date;
  559. $up = Db::name("order_return")->save($info);
  560. if ($up) {
  561. //售后完成
  562. if ($param['status'] == 5 && $info['is_receive'] == 0) {
  563. $orde = Db::name("order_out")
  564. ->field('id,outCode,status,send_num,error_num')
  565. ->where(["outCode" => $info['outCode'], "is_del" => 0])
  566. ->findOrEmpty();
  567. if (empty($orde)) throw new Exception('未找到出库单数据');
  568. $sale = Db::name("sale")
  569. ->field('id,th_num,th_fee,sale_price,good_code,good_name,cat_id,order_type')
  570. ->where(['is_del' => 0, "orderCode" => $info['orderCode']])
  571. ->findOrEmpty();
  572. if (empty($sale)) throw new Exception('未找到销售单数据');
  573. $od_status = $orde['status'];
  574. // $orde['status'] = 4;
  575. if ($info['error_num'] >= $orde['send_num']) $orde['status'] = 4;
  576. $orde['send_num'] -= $info['error_num'];
  577. $orde['error_num'] += $info['error_num'];
  578. $orde['updatetime'] = $date;
  579. $out = Db::name("order_out")->save($orde);
  580. if ($out == false) throw new Exception("发货单更新失败");
  581. $order = ["order_code" => $orde['outCode'], "status" => $od_status, "action_remark" => '', "action_type" => "edit"];
  582. ActionLog::logAdd($action_log_user, $order, "CKD", $orde['status'], $this->post);
  583. $process = ["order_code" => $orde['outCode'], "order_id" => $orde['id'], "order_status" => $orde['status'], "order_type" => "CKD", "before_status" => $od_status];
  584. ProcessOrder::AddProcess($action_log_user, $process);
  585. $sale['th_num'] += $info['error_num'];
  586. $sale['th_fee'] += round($info['error_num'] * $sale['sale_price'], 2);
  587. $sale['updatetime'] = $date;
  588. $sup = Db::name("sale")->save($sale);
  589. if ($sup == false) throw new Exception("销售单更新失败");
  590. $data = [
  591. "orderCode" => $info['orderCode'],
  592. "th_type" => 2,
  593. "th_num" => $info['error_num'],
  594. "th_fee" => round($info['error_num'] * $sale['sale_price'], 2),
  595. "thCode" => $info['returnCode'],
  596. "spuCode" => $sale['good_code'],
  597. "good_name" => $sale['good_name'],
  598. "cat_id" => $sale['cat_id'],
  599. "apply_id" => $info['apply_id'],
  600. "apply_name" => $info['apply_name'],
  601. "addtime" => $date,
  602. "status" => 1,
  603. "is_del" => 0
  604. ];
  605. $inse = Db::name("th_data")->insert($data);
  606. if ($inse == false) throw new Exception('退回单更新失败');
  607. if($sale['order_type']==1)SaleCgdPrice::RePrice($sale['id'],$info['error_num']);
  608. }
  609. //维护退货地址的收货信息
  610. if ($info['is_receive'] == 1 && $param['status'] == 4) {
  611. $tmp = Db::name('order_returninfo')
  612. ->field('id')
  613. ->where('returnCode', $param['returnCode'])
  614. ->findOrEmpty();
  615. if (empty($tmp)) {
  616. //新增
  617. Db::name('order_returninfo')
  618. ->insert([
  619. 'returnCode' => $param['returnCode'],
  620. 'return_wsm' => $param['wsm_code'],
  621. 'contactor' => $param['contactor'],
  622. 'mobile' => $param['mobile'],
  623. 'addr' => $param['addr'],
  624. 'addr_code' => $param['addr_code'],
  625. 'addtime' => $date
  626. ]);
  627. } else {
  628. Db::name('order_returninfo')
  629. ->where('id', $tmp['id'])
  630. ->update([
  631. 'return_wsm' => $param['wsm_code'],
  632. 'contactor' => $param['contactor'],
  633. 'mobile' => $param['mobile'],
  634. 'addr' => $param['addr'],
  635. 'addr_code' => $param['addr_code'],
  636. ]);
  637. }
  638. }
  639. $order = ["order_code" => $info['returnCode'], "status" => $var, "action_remark" => '', "action_type" => "edit"];
  640. ActionLog::logAdd($action_log_user, $order, "SHD", $info['status'], $this->post);
  641. $process = ["order_code" => $info['returnCode'], "order_id" => $info['id'], "order_status" => $param['status'], "order_type" => "SHD", "before_status" => $var, 'wait_id' => $info['person_id'], 'wait_name' => $info['person'], 'holder_id' => $info['person_id']];
  642. ProcessOrder::AddProcess($action_log_user, $process);
  643. Db::commit();
  644. return app_show(0, "更新成功");
  645. }
  646. throw new Exception('更新失败');
  647. } catch (Exception $e) {
  648. Db::rollback();
  649. throw new Exception($e->getMessage());
  650. }
  651. } catch (Exception $exception) {
  652. return json_show(1005, $exception->getMessage() );
  653. }
  654. }
  655. //设置仓库
  656. public function setWsm(){
  657. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  658. if($bkcode==""){
  659. return error_show(1005,"参数returnCode 不能为空");
  660. }
  661. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  662. if(empty($info)){
  663. return error_show(1005,"未找到售后数据");
  664. }
  665. if($info['status']!=3){
  666. return error_show(1005,"采购主管未审核无法设置退回仓库");
  667. }
  668. $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code']!="" ? trim($this->post['wsm_code']) :"";
  669. $warehouse=[];
  670. if($info['return_tag']==2) {
  671. if($wsm_code==""){
  672. return error_show(1005,"参数 wsm_code 不能为空");
  673. }
  674. $warehouse =Db::name("warehouse_info")->where(["wsm_code"=>$wsm_code])->find();
  675. if($warehouse==false){
  676. return error_show(1005,"仓库数据未找到");
  677. }
  678. $wareaddr =Db::name("warehouse_addr")->where(["wsm_code"=>$wsm_code,"is_del"=>0,"status"=>1])->find();
  679. }
  680. $addrcode=isset($this->post['addr_code'])&&$this->post['addr_code']!=""?$this->post['addr_code']:"";
  681. if($addrcode==""){
  682. return error_show(1005,"参数 addr_code 不能为空");
  683. }
  684. $addr=isset($this->post['addr'])&&$this->post['addr']!=""?trim($this->post['addr']):"";
  685. if($addr==""){
  686. return error_show(1005,"参数 addr 不能为空");
  687. }
  688. $mobile=isset($this->post['mobile'])&&$this->post['mobile']!=""?trim($this->post['mobile']):"";
  689. if($mobile==""){
  690. return error_show(1005,"参数 mobile 不能为空");
  691. }
  692. $contactor=isset($this->post['contactor'])&&$this->post['contactor']!=""?trim($this->post['contactor']):"";
  693. if($contactor==""){
  694. return error_show(1005,"参数 contactor 不能为空");
  695. }
  696. $returninfo=[
  697. "returnCode"=>$bkcode,
  698. "return_wsm"=>$wsm_code,
  699. "contactor"=>$contactor,
  700. "mobile"=>$mobile ,
  701. "addr"=>$addr,
  702. "addr_code"=>$addrcode,
  703. "addtime"=>date("Y-m-d H:i:s")
  704. ];
  705. Db::startTrans();
  706. try {
  707. $in=Db::name("order_returninfo")->insert($returninfo);
  708. if($in){
  709. if($info['return_tag']==2 &&$wareaddr==false) {
  710. $addrs =[
  711. "wsm_code"=>$wsm_code,
  712. "wsm_type"=>1,
  713. "wsm_name"=>$contactor,
  714. "wsm_addr"=>$addr,
  715. "addr_code"=>$addrcode,
  716. "wsm_mobile"=>$mobile,
  717. "status"=>'1',
  718. "is_del"=>'0',
  719. "addtime"=>date("Y-m-d H:i:s"),
  720. "updatetime"=>date("Y-m-d H:i:s")
  721. ];
  722. $wareaddr =Db::name("warehouse_addr")->insert($addrs);
  723. if($wareaddr==false){
  724. Db::rollback();
  725. return app_show(1004,"退货仓库地址录入失败");
  726. }
  727. }
  728. $old_info_status = $info['status'];
  729. $info['status']=4;
  730. if($info['order_type']==1){
  731. $info['cgder']=$warehouse['contactor_name']??"";
  732. $info['cgderid']=$warehouse['contactor']??0;
  733. }
  734. $info["updatetime"]=date("Y-m-d H:i:s");
  735. $up =Db::name("order_return")->save($info);
  736. if($up){
  737. //修改状态,添加待办
  738. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
  739. "order_code" => $info['returnCode'],//销售单code
  740. "status" => $old_info_status,//这里的status是之前的值
  741. "action_remark" => '',//备注
  742. "action_type" => "status"//新建create,编辑edit,更改状态status
  743. ], "SHD", $info['status'], $info);
  744. ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], [
  745. "order_type" => 'SHD',
  746. "order_code" => $info['returnCode'],//销售单code
  747. "order_id" => $info['id'],
  748. "order_status" => $info['status'],
  749. "before_status"=>$old_info_status,
  750. 'holder_id'=>$info['apply_id']
  751. ]);
  752. Db::commit();
  753. return app_show(0,"退货仓库设置成功");
  754. }
  755. }
  756. Db::rollback();
  757. return error_show(1004,"设置失败");
  758. }catch (\Exception $e){
  759. Db::rollback();
  760. return error_show(1004,$e->getMessage());
  761. }
  762. }
  763. /**
  764. * @return \think\response\Json|void
  765. * @throws \think\db\exception\DataNotFoundException
  766. * @throws \think\db\exception\DbException
  767. * @throws \think\db\exception\ModelNotFoundException
  768. */
  769. public function postfeed(){
  770. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  771. if($bkcode==""){
  772. return error_show(1005,"参数returnCode 不能为空");
  773. }
  774. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  775. if(empty($info)){
  776. return error_show(1005,"未找到售后数据");
  777. }
  778. $contactor = isset($this->post['contactor']) && $this->post['contactor']!="" ? trim($this->post['contactor']) :"";
  779. $mobile = isset($this->post['mobile']) && $this->post['mobile']!="" ? trim($this->post['mobile']):"";
  780. $addr = isset($this->post['addr']) && $this->post['addr']!="" ? trim($this->post['addr']):"";
  781. $addr_code = isset($this->post['addr_code']) && $this->post['addr_code']!=""&&!empty($this->post['addr_code']) ?
  782. $this->post['addr_code']:"";
  783. $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code']!="" ? trim($this->post['wsm_code']):"";
  784. if($wsm_code==""){
  785. return error_show(1005,"参数 wsm_code不能为空");
  786. }
  787. if($info['is_th']==0&&$info['order_type']==1) {
  788. $wsm = Db::name("warehouse_info")->where(["wsm_code" => $wsm_code])->find();
  789. if (empty($wsm)) {
  790. return error_show(1005, "未找到仓库数据");
  791. }
  792. $sm = Db::name("warehouse_addr")->where(["wsm_code" => $wsm_code,"is_del"=>0])->find();
  793. $contactor==""?(isset($sm['wsm_name']) ? $contactor=$sm['wsm_name']:""):"";
  794. $sm['wsm_name'] =isset($sm['wsm_name']) ? $sm['wsm_name']:"";
  795. $mobile==""?(isset($sm['wsm_mobile']) ? $mobile=$sm['wsm_mobile']:""):"";
  796. $sm['wsm_mobile'] =isset($sm['wsm_mobile']) ? $sm['wsm_mobile']:"";
  797. $addr==""?(isset($sm['wsm_addr']) ? $addr=$sm['wsm_addr']:""):"";
  798. $sm['wsm_addr'] =isset($sm['wsm_addr']) ? $sm['wsm_addr']:"";
  799. $addr_code==""?(isset($sm['addr_code']) ? $addr=$sm['addr_code']:""):"";
  800. $sm['addr_code'] =isset($sm['addr_code']) ? $sm['addr_code']:"";
  801. }
  802. $remark = isset($this->post['remark']) && $this->post['remark']!="" ? trim($this->post['remark']):"";
  803. if($info['is_th']==1 && $info['order_type']==1){
  804. if($contactor==''){
  805. return error_show(1005,"参数 contactor 不能为空");
  806. }
  807. if($mobile==''){
  808. return error_show(1005,"参数 mobile 不能为空");
  809. }
  810. if($addr==''){
  811. return error_show(1005,"参数 addr 不能为空");
  812. }
  813. if($addr_code==''){
  814. return error_show(1005,"参数 addr_code 不能为空");
  815. }
  816. if($addr_code!==''&&is_array($addr_code)){
  817. $addrs=[];
  818. $addrs['provice_code'] = $addr_code[0];
  819. $addrs['city_code'] = $addr_code[1];
  820. $addrs['area_code'] = $addr_code[2];
  821. $addr_code = json_encode($addrs);
  822. }
  823. }
  824. Db::startTrans();
  825. try{
  826. $var=$info['status'];
  827. $info['status']=$info['order_type']==1?3:4;
  828. $info['remark']=$remark;
  829. $info['updatetime']=date("Y-m-d H:i:s");
  830. $up =Db::name("order_return")->save($info);
  831. if($up){
  832. // var_dump($contactor);
  833. $returninfo = Db::name("order_returninfo")->where(["returnCode"=>$bkcode])->find();
  834. if(empty($returninfo)){
  835. $returninfo=[
  836. "returnCode"=>$bkcode,
  837. "return_wsm"=>$wsm_code,
  838. "contactor"=>$contactor,
  839. "mobile"=>$mobile ,
  840. "addr"=>$addr,
  841. "addr_code"=>$addr_code,
  842. "addtime"=>date("Y-m-d H:i:s")
  843. ];
  844. }else{
  845. $returninfo['return_wsm'] = $wsm_code;
  846. //if($info['is_th']==1 && $info['order_type']==1) {
  847. $contactor !==""? $returninfo['contactor'] = $contactor:"";
  848. $mobile!==""?$returninfo['mobile'] = $mobile:"";
  849. $addr!==""? $returninfo['addr'] = $addr:"";
  850. $addr_code!==""?$returninfo['addr_code'] = $addr_code:"";
  851. // }
  852. }
  853. // var_dump($contactor);
  854. // var_dump($returninfo);
  855. $in=Db::name("order_returninfo")->save($returninfo);
  856. if($in){
  857. $order = ["order_code"=>$info['returnCode'],"status"=>$var,"action_remark"=>'',"action_type"=>"edit"];
  858. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname],$order,"SHD",$info['status'],$this->post);
  859. $process=["order_code"=>$info['returnCode'],"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>"SHD","before_status"=>$var,'holder_id'=>$info['apply_id']];
  860. ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname],$process);
  861. Db::commit();
  862. return app_show(0,"更新成功");
  863. }
  864. }
  865. Db::rollback();
  866. return error_show(1004,"更新失败");
  867. }catch (\Exception $e){
  868. Db::rollback();
  869. return error_show(1004,$e->getMessage());
  870. }
  871. }
  872. /**
  873. * @return \think\response\Json|void
  874. * @throws \think\db\exception\DataNotFoundException
  875. * @throws \think\db\exception\DbException
  876. * @throws \think\db\exception\ModelNotFoundException
  877. */
  878. public function addpost(){
  879. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  880. if($bkcode==""){
  881. return error_show(1005,"参数returnCode 不能为空");
  882. }
  883. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  884. if(empty($info)){
  885. return error_show(1005,"未找到售后数据");
  886. }
  887. $return_info = Db::name("order_returninfo")->where(['returnCode'=>$bkcode])->find();
  888. if(empty($return_info)){
  889. $return_info=[
  890. "returnCode"=>$bkcode,
  891. "return_wsm"=>'',
  892. "contactor"=>'',
  893. "mobile"=>'',
  894. "addr"=>'',
  895. "addr_code"=>'',
  896. "addtime"=>date("Y-m-d H:i:s"),
  897. "post_company"=>'',
  898. "post_code"=>'',
  899. "post_fee"=>'',
  900. ];
  901. }
  902. $post_own = isset($this->post['own']) &&$this->post['own']!='' ? trim($this->post['own']):"";
  903. if($post_own==''){
  904. return error_show(1005,"参数own不能为空");
  905. }
  906. $info['post_own'] = $post_own;
  907. $post_company = isset($this->post['company'])&&$this->post['company']!='' ? trim($this->post['company']):"";
  908. if($post_company==''){
  909. return error_show(1005,"参数company不能为空");
  910. }
  911. $return_info['post_company'] = $post_company;
  912. $post_code = isset($this->post['post_code'])&&$this->post['post_code']!='' ? trim($this->post['post_code']):"";
  913. if($post_code==''){
  914. return error_show(1005,"参数post_code不能为空");
  915. }
  916. $return_info['post_code'] = $post_code;
  917. $fee= isset($this->post['post_fee'])&&$this->post['post_fee']!=='' ? round($this->post['post_fee'],2):"";
  918. if($fee===''){
  919. return error_show(1005,"参数post_fee不能为空");
  920. }
  921. $return_info['post_fee'] = $fee;
  922. Db::startTrans();
  923. try{
  924. $str=$info['status'];
  925. $info['status']=$info['order_type']==1?4:5;
  926. $info['updatetime']=date("Y-m-d H:i:s");
  927. $up =Db::name("order_return")->save($info);
  928. if($up){
  929. $order = ["order_code"=>$info['orderCode'],"status"=>$str,"action_remark"=>'',"action_type"=>"edit"];
  930. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname],$order,"SHD",$info['status'],$this->post);
  931. $process=["order_code"=>$info['returnCode'],"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>"SHD","before_status"=>$str,'holder_id'=>$info['apply_id']];
  932. ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname],$process);
  933. $in=Db::name("order_returninfo")->save($return_info);
  934. if($in){
  935. $data=[
  936. 'thNo'=>makeNo("ST"),
  937. "orderCode"=>$info['orderCode'],
  938. "order_type"=>$info['order_type'],
  939. "outCode"=>$info['outCode'],
  940. "returnCode"=>$info['returnCode'],
  941. "good_code"=>$info['good_code'],
  942. "good_name"=>$info['good_name'],
  943. "return_wsm"=>$return_info['return_wsm'],
  944. "return_num"=>$info['error_num'],
  945. "contactor"=>$return_info['contactor'],
  946. "mobile"=>$return_info['mobile'],
  947. "addr"=>$return_info['addr'],
  948. "addr_code"=>$return_info['addr_code'],
  949. "return_code"=>$info['error_code'],
  950. "return_msg"=>$info['error_msg'],
  951. "post_fee"=>$return_info['post_fee'],
  952. "post_code"=>$return_info['post_code'],
  953. "post_company"=>$return_info['post_company'],
  954. "customer_code"=>$info['customer_code'],
  955. "customer_name"=>$info['customer_name'],
  956. "addtime"=>date("Y-m-d H:i:s"),
  957. "updatetime"=>date("Y-m-d H:i:s"),
  958. 'supplierNo' => $info['supplierNo'],
  959. 'supplierName' => $info['supplierName'],
  960. 'companyNo' => $info['companyNo'],
  961. 'companyName' => $info['companyName'],
  962. ];
  963. $back =Db::name("order_back")->insert($data,true);
  964. if($back>0){
  965. //维护台账
  966. // Db::name('standing_book')
  967. // ->where('returnCode', $bkcode)
  968. // ->update([
  969. // 'thNo' => $data['thNo'],
  970. // 'updatetime' => date("Y-m-d H:i:s")
  971. // ]);
  972. Db::execute("UPDATE `wsm_standing_book` SET `thNo`=CONCAT(IFNULL(`thNo`,''),',{$data['thNo']}'),`updatetime`='" . date('Y-m-d H:i:s') . "' WHERE FIND_IN_SET('{$bkcode}',`returnCode`)");//这里的returnCode可能有多个
  973. $order = ["order_code"=>$data['thNo'],"status"=>0,"action_remark"=>'',"action_type"=>"create"];
  974. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname],$order,"CKTHD", 0,$data);
  975. $process=["order_code"=>$data['thNo'],"order_id"=>$back,"order_status"=>0,"order_type"=>"CKTHD","before_status"=>0];
  976. ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname],$process);
  977. Db::commit();
  978. return app_show(0,"更新成功");
  979. }
  980. }
  981. }
  982. Db::rollback();
  983. return error_show(1004,"更新失败");
  984. }catch (\Exception $e){
  985. Db::rollback();
  986. return error_show(1004,$e->getMessage());
  987. }
  988. }
  989. /**
  990. * @return \think\response\Json|void
  991. * @throws \think\db\exception\DataNotFoundException
  992. * @throws \think\db\exception\DbException
  993. * @throws \think\db\exception\ModelNotFoundException
  994. */
  995. public function GysFeed(){
  996. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  997. if($bkcode==""){
  998. return error_show(1005,"参数returnCode 不能为空");
  999. }
  1000. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  1001. if(empty($info)){
  1002. return error_show(1005,"未找到售后数据");
  1003. }
  1004. $isth = isset($this->post['is_th']) && $this->post['is_th']!="" ? intval($this->post['is_th']):"0";
  1005. $contactor = isset($this->post['contactor']) && $this->post['contactor']!="" ? trim($this->post['contactor'])
  1006. :"";
  1007. $mobile = isset($this->post['mobile']) && $this->post['mobile']!="" ? trim($this->post['mobile']):"";
  1008. $addr = isset($this->post['addr']) && $this->post['addr']!="" ? trim($this->post['addr']):"";
  1009. $addr_code = isset($this->post['addr_code']) && $this->post['addr_code']!=""&&!empty($this->post['addr_code']) ? $this->post['addr_code']:"";
  1010. $remark = isset($this->post['remark']) && $this->post['remark']!="" ? trim($this->post['remark']):"";
  1011. if($isth==1){
  1012. if($contactor==''){
  1013. return error_show(1005,"参数 contactor 不能为空");
  1014. }
  1015. if($mobile==''){
  1016. return error_show(1005,"参数 mobile 不能为空");
  1017. }
  1018. if($addr==''){
  1019. return error_show(1005,"参数 addr 不能为空");
  1020. }
  1021. // var_dump(isset($this->post['addr_code']) , $this->post['addr_code']!="",!empty($addr_code));
  1022. if($addr_code==''){
  1023. return error_show(1005,"参数 addr_code 不能为空");
  1024. }
  1025. if(is_array($addr_code)){
  1026. $addrs=[];
  1027. $addrs['provice_code'] = $addr_code[0];
  1028. $addrs['city_code'] = $addr_code[1];
  1029. $addrs['area_code'] = $addr_code[2];
  1030. $addr_code = json_encode($addrs);
  1031. }
  1032. }
  1033. $orde= Db::name("order_out")->where(["outCode"=>$info['outCode'],"is_del"=>0])->find();
  1034. if(empty($orde)){
  1035. return error_show(1005,"未找到出库单数据");
  1036. }
  1037. Db::startTrans();
  1038. try{
  1039. $stat=$info['status'];
  1040. $info['status']=$info['order_status']==1?5:3;
  1041. $info['is_th']=$isth;
  1042. $info['updatetime']=date("Y-m-d H:i:s");
  1043. $up =Db::name("order_return")->save($info);
  1044. if($up){
  1045. $returninfo = Db::name("order_returninfo")->where(["returnCode"=>$bkcode])->find();
  1046. if(empty($returninfo)){
  1047. $returninfo=[
  1048. "returnCode"=>$bkcode,
  1049. "return_wsm"=>'',
  1050. "contactor"=>$contactor,
  1051. "mobile"=>$mobile ,
  1052. "addr"=>$addr,
  1053. "addr_code"=>$addr_code,
  1054. "gys_remark"=>$remark,
  1055. "addtime"=>date("Y-m-d H:i:s")
  1056. ];
  1057. }else{
  1058. $returninfo['return_wsm'] = '';
  1059. $returninfo['contactor'] = $contactor;
  1060. $returninfo['mobile'] = $mobile;
  1061. $returninfo['addr'] = $addr;
  1062. $returninfo['gys_remark'] = $remark;
  1063. $returninfo['addr_code'] = $addr_code;
  1064. }
  1065. $in=Db::name("order_returninfo")->save($returninfo);
  1066. if($in){
  1067. $order = ["order_code"=>$info['returnCode'],"status"=>$stat,"action_remark"=>'',"action_type"=>"edit"];
  1068. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname],$order,"SHD", $info['status'],$this->post);
  1069. $process=["order_code"=>$info['returnCode'],"order_id"=>$info['id'],"order_status"=>$info['status'],"SHD","before_status"=>$stat,'holder_id'=>$info['apply_id']];
  1070. ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname],$process);
  1071. Db::commit();
  1072. return app_show(0,"更新成功");
  1073. }
  1074. }
  1075. Db::rollback();
  1076. return error_show(1004,"更新失败");
  1077. }catch (\Exception $e){
  1078. Db::rollback();
  1079. return error_show(1004,$e->getMessage());
  1080. }
  1081. }
  1082. public function GetWsm(){
  1083. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  1084. if($bkcode==""){
  1085. return error_show(1005,"参数returnCode 不能为空");
  1086. }
  1087. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  1088. if($info==false){
  1089. return error_show(1005,"未找到售后数据");
  1090. }
  1091. $list=[];
  1092. if($info['is_th']==1){
  1093. if($info["order_type"]==1){
  1094. $out =Db::name("order_out")->where(["outCode"=>$info['outCode'],"is_del"=>0])->find();
  1095. if(empty($out)){
  1096. return error_show(1005,"未找到出库单数据");
  1097. }
  1098. $ware = Db::name("warehouse_info")->alias("a")->leftJoin("warehouse_addr b","a.wsm_code=b.wsm_code and b.status=1 and b.is_del=0")
  1099. ->where(["a.status"=>1,"wsm_type"=>1,"a.is_del"=>0,"a.supplierNo"=>$out['wsm_code']])->field("a.wsm_code,a.name,b.wsm_name,b.wsm_mobile,b.wsm_addr,b.addr_code")->find();
  1100. if(empty($ware)){
  1101. return error_show(1005,"未找到仓库数据");
  1102. }
  1103. $temp['wsm_code']=isset($ware['wsm_code'])?$ware['wsm_code']:"";
  1104. $temp['wsm_name']=isset($ware['name'])?$ware['name']:"";
  1105. $temp['contactor'] = isset($ware['wsm_name'])?$ware['wsm_name']:"";
  1106. $temp['mobile'] =isset($ware['wsm_mobile'])?$ware['wsm_mobile']:"";
  1107. $temp['addr'] =isset($ware['wsm_addr'])?$ware['wsm_addr']:"";
  1108. $temp['addr_code'] = isset($ware['addr_code'])?$ware['addr_code']:"";
  1109. $temp['addr_cn'] =GetAddr( $ware['addr_code']);
  1110. $list[]=$temp;
  1111. }else {
  1112. $returninfo = Db::name("order_returninfo")->where(["returnCode" => $bkcode])->find();
  1113. if (empty($returninfo)) {
  1114. return error_show(1005, "未找到供应商仓库数据");
  1115. }
  1116. $data = [];
  1117. $data['wsm_code'] = isset($returninfo['return_wsm']) && $returninfo['return_wsm'] != "" ? $returninfo['return_wsm'] : "-";
  1118. $data['wsm_name'] = '供应商仓';
  1119. $data['supplier_name'] = '供应商';
  1120. $data['contactor'] = $returninfo['contactor'];
  1121. $data['mobile'] = $returninfo['mobile'];
  1122. $data['addr'] = $returninfo['addr'];
  1123. $data['addr_cn'] =GetAddr( $returninfo['addr_code']);
  1124. $data['addr_code'] = $returninfo['addr_code'];
  1125. $list[] = $data;
  1126. }
  1127. }
  1128. $supplier = Db::name("supplier")->where(["is_platform"=>1,"status"=>1,"is_del"=>0])->column("code,name");
  1129. if(empty($supplier)){
  1130. return error_show(1005,"未找到供应商仓库数据");
  1131. }
  1132. foreach ($supplier as $value){
  1133. $temp=[];
  1134. $ware = Db::name("warehouse_info")->alias("a")->leftJoin("warehouse_addr b","a.wsm_code=b.wsm_code and b.status=1 and b.is_del=0")
  1135. ->where(["a.wsm_type"=>1,"a.status"=>1,"a.is_del"=>0,"a.supplierNo"=>$value['code']])->field("a.wsm_code,a.name,b.wsm_name,b.wsm_mobile,b.wsm_addr,b.addr_code")->find();
  1136. if(empty($ware)){
  1137. continue;
  1138. }
  1139. $temp['wsm_code']=isset($ware['wsm_code'])?$ware['wsm_code']:"";
  1140. $temp['wsm_name']=isset($ware['name'])?$ware['name']:"";
  1141. $temp['supplier_name']=$value['name'];
  1142. $temp['contactor'] = isset($ware['wsm_name'])?$ware['wsm_name']:"";
  1143. $temp['mobile'] =isset($ware['wsm_mobile'])?$ware['wsm_mobile']:"";
  1144. $temp['addr'] =isset($ware['wsm_addr'])?$ware['wsm_addr']:"";
  1145. $temp['addr_cn'] =GetAddr($ware['addr_code']);
  1146. $temp['addr_code'] = isset($ware['addr_code'])?$ware['addr_code']:"";
  1147. $list[]=$temp;
  1148. }
  1149. return app_show(0,"获取成功",$list);
  1150. }
  1151. //客户发货
  1152. public function setdelivery()
  1153. {
  1154. $param = $this->request->only(['returnCode', 'company', 'post_code', 'post_fee'], 'post', 'trim');
  1155. $val = Validate::rule([
  1156. 'returnCode|售后申请单编号' => 'require',
  1157. 'company|快递公司名' => 'require|max:255',
  1158. 'post_code|快递单号' => 'require|max:255',
  1159. 'post_fee|快递费用' => 'require|float',
  1160. ]);
  1161. if ($val->check($param) == false) return json_show(1004, $val->getError());
  1162. $bkcode = $param['returnCode'];
  1163. $company = $param['company'];
  1164. $post_code = $param['post_code'];
  1165. $post_fee = $param['post_fee'];
  1166. $info = Db::name("order_return")
  1167. ->where(['is_del' => 0, 'returnCode' => $bkcode])
  1168. ->findOrEmpty();
  1169. if (empty($info)) return error_show(1005, "未找到售后数据");
  1170. if (($info['is_receive'] != 1 || $info['status'] != 4)) return error_show(1005, "售后单流程状态有误");
  1171. $out = Db::name("order_out")
  1172. ->where(["outCode" => $info["outCode"], "is_del" => 0])
  1173. ->findOrEmpty();
  1174. if (empty($out)) return error_show(1005, "未找到发货单数据");
  1175. $sale = Db::name('sale')
  1176. ->where(['orderCode' => $info['orderCode'], "is_del" => 0])
  1177. ->findOrEmpty();
  1178. if (empty($sale)) return error_show(1004, "未找到销售单数据");
  1179. Db::startTrans();
  1180. try {
  1181. $returninfo = Db::name("order_returninfo")->where(["returnCode" => $bkcode])->findOrEmpty();
  1182. if (empty($returninfo)) {
  1183. //查询次品仓的信息
  1184. $wsm = Db::name('warehouse_info')
  1185. ->where(['is_del' => 0, 'companyNo' => $sale['supplierNo'], 'status' => 1, 'wsm_type' => 4])
  1186. ->findOrEmpty();
  1187. $returninfo = [
  1188. "returnCode" => $bkcode,
  1189. "return_wsm" => $wsm['wsm_code'] ?? '',
  1190. "contactor" => $wsm['contactor_name'] ?? '',
  1191. "mobile" => $wsm['mobile'] ?? '',
  1192. "addr" => $wsm['addr'] ?? '',
  1193. "addr_code" => $wsm['addrs_code'] ?? '',
  1194. "post_code" => $post_code,
  1195. "post_company" => $company,
  1196. "post_fee" => $post_fee,
  1197. "gys_remark" => "",
  1198. "addtime" => date("Y-m-d H:i:s")
  1199. ];
  1200. $up = Db::name("order_returninfo")->insert($returninfo);
  1201. } else {
  1202. $up = Db::name("order_returninfo")
  1203. ->where(["returnCode" => $bkcode])
  1204. ->update([
  1205. 'post_fee' => $post_fee,
  1206. 'post_company' => $company,
  1207. 'post_code' => $post_code,
  1208. ]);
  1209. }
  1210. if ($up) {
  1211. //查看是否有退货工单设置信息
  1212. $temp = Db::name('order_return_prepare')
  1213. ->field('id')
  1214. ->where(['is_del' => 0, 'returnCode' => $bkcode,'status'=>1])
  1215. ->findOrEmpty();
  1216. if (empty($temp)) $info['status'] = 5;//没有,更新到status5,售后申请已结束
  1217. else $info['status'] = 12;//存在,要更新到status12(待库管收货)
  1218. $old_info_status = $info['status'];
  1219. // $info['status'] = 5;
  1220. $info['updatetime'] = date("y-m-d H:i:s");
  1221. $ro = Db::name("order_return")->save($info);
  1222. if ($ro) {
  1223. //修改状态,添加待办
  1224. ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
  1225. "order_code" => $info['returnCode'],//销售单code
  1226. "status" => $old_info_status,//这里的status是之前的值
  1227. "action_remark" => '',//备注
  1228. "action_type" => "status"//新建create,编辑edit,更改状态status
  1229. ], "SHD", $info['status'], $this->post);
  1230. ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], [
  1231. "order_type" => 'SHD',
  1232. "order_code" => $info['returnCode'],//销售单code
  1233. "order_id" => $info['id'],
  1234. "order_status" => $info['status'],
  1235. "before_status" => $old_info_status,
  1236. 'holder_id' => $info['apply_id']
  1237. ]);
  1238. //如果售后已完成,维护销售单、发货单和采购单
  1239. if ($info['status'] == 5) {
  1240. $sale['th_num'] += $info['error_num'];
  1241. if ($sale['th_num'] == $sale['good_num']) $sale['status'] = 3;
  1242. $sale['th_fee'] += round($info['error_num'] * $sale['sale_price'], 2);
  1243. $sale['updatetime'] = date("Y-m-d H:i:s");
  1244. Db::name("sale")->save($sale);
  1245. SaleCgdPrice::RePrice($sale['id'],$info['error_num']);
  1246. if ($info['error_num'] >= $out['send_num']) $out['status'] = 4;
  1247. $out['send_num'] -= $info['error_num'];
  1248. $out['error_num'] += $info['error_num'];
  1249. $out['updatetime'] = date("Y-m-d H:i:s");
  1250. $upout = Db::name("order_out")->save($out);
  1251. if ($upout == false) throw new Exception('出库单数据更新失败');
  1252. $error_num = $info['error_num'];
  1253. $tmp_ooc = Db::name('order_out_child')
  1254. ->where(['is_del' => 0, 'outCode' => $info["outCode"]])
  1255. ->field('id,num')
  1256. ->select()
  1257. ->toArray();
  1258. foreach ($tmp_ooc as $tmp) {
  1259. if ($tmp['num'] >= $error_num) {
  1260. Db::name('order_out_child')
  1261. ->data(['updatetime' => date("Y-m-d H:i:s")])
  1262. ->where(['is_del' => 0, 'id' => $tmp["id"]])
  1263. ->dec('num', $error_num)
  1264. ->update();
  1265. $error_num = 0;
  1266. } else {
  1267. Db::name('order_out_child')
  1268. ->where(['is_del' => 0, 'id' => $tmp["id"]])
  1269. ->update(['num' => 0, 'updatetime' => date("Y-m-d H:i:s")]);
  1270. $error_num -= $tmp['num'];
  1271. }
  1272. if ($error_num == 0) break;
  1273. }
  1274. //如果供应商承担,维护采购单 todo:: 新逻辑 无论供应商是否同意退货采购单都要减退回
  1275. // if ($info['return_tag'] == 1) {
  1276. $cgd_info = Db::name('order_num')
  1277. ->alias('a')
  1278. ->field('a.id,b.id cgd_id,b.good_price,b.cgdNo')
  1279. ->leftJoin('purchease_order b','b.cgdNo=a.cgdNo')
  1280. ->where(['a.orderCode' => $info['orderCode']])
  1281. ->findOrEmpty();
  1282. if (!empty($cgd_info)) {
  1283. $up= Db::name('purchease_order')
  1284. ->where(['is_del' => 0, 'id' => $cgd_info['cgd_id']])
  1285. ->data(['updatetime' => date("Y-m-d H:i:s")])
  1286. ->inc('th_num', $info['error_num'])
  1287. ->inc('th_fee', round($cgd_info['good_price'] * $info['error_num'], 2))
  1288. ->update();
  1289. if($up==false) throw new Exception('采购单更新失败');
  1290. }
  1291. // }
  1292. //todo::供应商不同意退货 生成转库存数据
  1293. }
  1294. Db::commit();
  1295. if($info["status"]==5){
  1296. $data = [
  1297. 'orderCode' => $info['orderCode'],
  1298. 'th_type' => 2,
  1299. 'th_num' => $info['error_num'],
  1300. 'th_fee' => round($info['error_num'] * $sale['sale_price'], 2),
  1301. 'thCode' => $info['returnCode'],
  1302. 'spuCode' => $sale['good_code'],
  1303. 'good_name' => $sale['good_name'],
  1304. 'sale_price' => $sale['sale_price'],
  1305. 'cgd_price' => $cgd_info['good_price'],
  1306. 'cgdNo' => $cgd_info['cgdNo'],
  1307. 'cat_id' => $sale['cat_id'],
  1308. 'apply_id' => $info['apply_id'],
  1309. 'apply_name' => $info['apply_name'],
  1310. 'addtime' => $info['updatetime'],
  1311. 'status' => 1,
  1312. 'is_del' => 0
  1313. ];
  1314. event('thdata',$data);
  1315. }
  1316. return json_show(0, '退货成功');
  1317. } else throw new Exception('修改售后申请单状态失败');
  1318. } else throw new Exception('退货失败');
  1319. } catch (Exception $e) {
  1320. Db::rollback();
  1321. return json_show(1004, $e->getMessage());
  1322. }
  1323. }
  1324. //取消售后
  1325. public function Cancel()
  1326. {
  1327. //接收参数
  1328. $data = $this->request->only(['token', 'returnCode'], 'post', 'trim');
  1329. $val = Validate::rule(['returnCode|售后单编号' => 'require']);
  1330. if (!$val->check($data)) return error_show(1005, $val->getError());
  1331. Db::startTrans();
  1332. try {
  1333. $rs = Db::name('order_return')
  1334. ->field('id,status,apply_id')
  1335. ->where([
  1336. ['returnCode', '=', $data['returnCode']],
  1337. ['is_del', '=', 0]
  1338. ])->findOrEmpty();
  1339. if (empty($rs)) throw new Exception('该售后单记录不存在');
  1340. if (in_array($rs['status'], [5,6,8,11,12])) throw new Exception('不允许取消');
  1341. //修改记录
  1342. $res = Db::name('order_return')
  1343. ->where(['id' => $rs['id']])
  1344. ->update(['status' => 8, 'updatetime' => date('Y-m-d H:i:s')]);
  1345. if (!$res) throw new Exception('该售后单记录修改失败');
  1346. //记录日志
  1347. ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], ["order_code" => $data['returnCode'], "status" => $rs['status'], "action_remark" => '', "action_type" => "delete"], 'SHD', 8, $this->post);
  1348. ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], ["order_code" => $data['returnCode'], "order_id" => $rs['id'], "order_status" => 8, "order_type" => 'SHD', "before_status" => $rs['status'], 'holder_id' => $rs['apply_id']]);
  1349. Db::name('order_return_prepare')
  1350. ->where(['is_del' => 0, 'returnCode' => $data['returnCode'], 'status' => 1])
  1351. ->update(['status' => 2, 'updatetime' => date('Y-m-d H:i:s')]);
  1352. //提交
  1353. Db::commit();
  1354. return app_show(0, "取消成功");
  1355. } catch (\Exception $e) {
  1356. Db::rollback();
  1357. return error_show(1004, $e->getMessage());
  1358. }
  1359. }
  1360. //根据审核完成的售后申请单,创建新的销售单和采购单
  1361. public function createSaleAndCgdByAfter()
  1362. {
  1363. $param = $this->request->only(['token', 'returnCode'], 'post', 'trim');
  1364. $val = Validate::rule(['token' => 'require', 'returnCode|售后申请单编号' => 'require']);
  1365. if (!$val->check($param)) return error_show(1005, $val->getError());
  1366. //查询售后申请单详情
  1367. $info = Db::name('order_return')
  1368. ->where('returnCode', $param['returnCode'])
  1369. ->where('is_del', 0)
  1370. ->find();
  1371. if (empty($info)) return error_show(1005, '该售后申请单不存在');
  1372. if ($info['status'] != 5) return error_show(1005, '该售后申请单尚未审核完成');
  1373. if ($info['is_reissue'] == 1) return error_show(1005, '该售后申请单已完成补发,无法重复进行');
  1374. $apply_id = GetUserInfo($param['token']);
  1375. if (empty($apply_id) || $apply_id['code'] != 0) return error_show(1002, "申请人数据不存在");
  1376. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1377. $ri = isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  1378. //原本销售单信息
  1379. $old_sale = Db::name('sale')->where(['is_del' => 0, 'orderCode' => $info['orderCode']])->find();
  1380. if (empty($old_sale)) return error_show(1005, '没有对应的销售单信息');
  1381. //发货单信息
  1382. $old_out = Db::name('order_out')->where(['is_del' => 0, 'orderCode' => $info['orderCode'], 'outCode' => $info['outCode']])->find();
  1383. if (empty($old_out)) return error_show(1005, '没有对应的发货单信息');
  1384. //根据是否咨询类商品,分别处理
  1385. if ($info['order_type'] == 3) return $this->createSaleZixun($info['id'], $info['good_code'], $info, $old_sale, $rm, $ri, $old_out['addrid'], $param['token']);
  1386. else return $this->createSaleNotZixun($info['id'], $info['good_code'], $info, $old_sale, $rm, $ri, $old_out, $param['token']);
  1387. }
  1388. /**
  1389. * 咨询类商品处理
  1390. * @param int $orid 对应售后记录的id
  1391. * @param string $spuCode 商品的spuCode
  1392. * @param array $info 售后申请单的详情
  1393. * @param array $old_sale 原始销售订单
  1394. * @param int $rm 操作人id
  1395. * @param string $ri 操作人名称
  1396. * @param int $addrid 原始发货单的地址id
  1397. * @param string $token 当前用户的token
  1398. * @throws \think\db\exception\DataNotFoundException
  1399. * @throws \think\db\exception\DbException
  1400. * @throws \think\db\exception\ModelNotFoundException
  1401. */
  1402. private function createSaleZixun(int $orid = 0, string $spuCode = '', array $info = [], array $old_sale = [], int $rm = 0, string $ri = '', int $addrid = 0, string $token = '')
  1403. {
  1404. $zxinfo = Db::name("consult_bids")->where(["bidNo" => $old_sale['zxNo'], "is_del" => 0])->find();
  1405. if ($zxinfo == false) return error_show(1005, '未找到咨询单商品信息');
  1406. $good_num = $info['error_num'];
  1407. $sale_price = 0;
  1408. $orderCode = makeNo("QR");
  1409. $skuCode = "";
  1410. //原有采购单信息
  1411. $old_cgd = Db::name('order_num')
  1412. ->alias('on')
  1413. ->field('on.id onid,po.*')
  1414. ->leftJoin('purchease_order po', 'po.cgdNo=on.cgdNo')
  1415. ->where('on.orderCode', $old_sale['orderCode'])
  1416. ->find();
  1417. $cgd = array_merge($old_cgd, [
  1418. 'id' => null,
  1419. // "supplierNo"=>$zxinfo['supplierNo'],
  1420. // "companyNo"=>$zxorder['companyNo'],
  1421. "spuCode" => $spuCode,
  1422. "skuCode" => $skuCode,
  1423. "orderCode" => $orderCode,
  1424. // "good_name"=>$zxinfo['good_name'],
  1425. "sale_price" => $old_cgd['good_price'],//采购单价格不为0,取原采购单的价格
  1426. "total_fee" => round($old_cgd['good_price'] * $good_num, 2),
  1427. // "pakge_fee"=>$zxinfo['pakge_fee'],
  1428. // "cert_fee"=>$zxinfo['cert_fee'],
  1429. // "open_fee"=>$zxinfo['open_fee'],
  1430. 'cost_fee' => $old_cgd['teach_fee'],
  1431. // $old_sale['cost_fee']=$old_sale['teach_fee'];
  1432. // "mark_fee"=>$zxinfo['mark_fee'],
  1433. // "demo_fee"=>$zxinfo['demo_fee'],
  1434. // "nake_fee"=>$zxinfo['nake_fee'],
  1435. // "delivery_fee"=>$zxinfo['delivery_fee'],
  1436. "good_num" => $good_num,
  1437. "createrid" => $rm,
  1438. "creater" => $ri,
  1439. "good_type" => 1,
  1440. // "weight"=>$zxinfo['good_weight'],
  1441. // "gold_price"=>$zxinfo['gold_price'],
  1442. // "is_diff"=>$zxinfo['is_diff'],
  1443. "order_type" => 3,//咨询商品
  1444. "order_source" => 6,//6售后补换货
  1445. // 'send_way'=>$zxinfo['send_way']
  1446. 'token' => $token,
  1447. 'good_createrid' => $zxinfo['createrid'],
  1448. 'good_creater' => $zxinfo['creater'],//商品创建人
  1449. ]);
  1450. // $token=isset($this->post['token'])&&$this->post['token']!=""? trim($this->post['token']):"";
  1451. // if($token==""){
  1452. // return error_show(102, "参数token不能为空");
  1453. // }
  1454. // $apply_id = GetUserInfo($token);
  1455. // if (empty($apply_id) || $apply_id['code'] != 0) {
  1456. // return error_show(102, "申请人数据不存在");
  1457. // }
  1458. // $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1459. // $ri = isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  1460. // $va = isset($this->post['order_addr']) && $this->post['order_addr'] !== "" ? $this->post['order_addr'] : "";
  1461. // $send_num=0;
  1462. // if($sendtype==1){
  1463. // if ($va == "") {
  1464. // return error_show(1002, "参数order_addr不能为空");
  1465. // }
  1466. // $send_num = array_sum(array_column($va,"receipt_quantity"));
  1467. // }
  1468. // if($good_num<$send_num){
  1469. // return error_show(1002, "发货数量不能超过购买数量");
  1470. // }
  1471. // $arrtime=isset($this->post['arrtime'])&&$this->post['arrtime']!="" ?$this->post['arrtime']:"";
  1472. // if($arrtime==""){
  1473. // return error_show(1002, "参数arrtime不能为空");
  1474. // }
  1475. //新加字段
  1476. // $platform_order=isset($this->post['platform_order'])&&$this->post['platform_order']!="" ?$this->post['platform_order']:"";
  1477. // $workNo=isset($this->post['workNo'])&&$this->post['workNo']!="" ?$this->post['workNo']:"";
  1478. // $proof_type = isset($this->post['proof_type']) && $this->post['proof_type'] != "" ? intval($this->post['proof_type']) : 0;
  1479. // $proof_url = isset($this->post['proof_url']) && $this->post['proof_url'] != "" ? trim($this->post['proof_url']) : '';
  1480. Db::startTrans();
  1481. try {
  1482. // $zx =Db::name("consult_info")->where(["infoNo"=>$zxinfo['infoNo'],"is_del"=>0])->lock(true)->find();
  1483. // if($zx==false){
  1484. // Db::rollback();
  1485. // return error_show(1003,"未找到咨询单信息");
  1486. // }
  1487. // $supplier_temp_info = Db::name('supplier')
  1488. // ->field('id,person,personid')
  1489. // ->where('code',$old_cgd['supplierNo'])
  1490. // ->findOrEmpty();
  1491. $user= \app\admin\common\User::getIns();
  1492. $supplier_temp_info =$user->handle("sInfo",["code"=>$old_cgd['supplierNo']]);
  1493. $data = array_merge($old_sale, [
  1494. 'id' => null,
  1495. "orderCode" => $orderCode,
  1496. "good_code" => $spuCode,
  1497. // "skuCode"=>$skuCode,
  1498. // "customer_code"=>$zxorder['khNo'],
  1499. // "good_name"=>isset($zxinfo['good_name'])&&$zxinfo['good_name']!==''?$zxinfo['good_name']:'',
  1500. "good_num" => $good_num,
  1501. // "cat_id"=>$zxinfo['cat_id'],
  1502. "apply_id" => $rm,
  1503. "apply_name" => $ri,
  1504. // "origin_price"=>$zxinfo['total_fee'],
  1505. // "sale_price" => $old_sale['sale_price'],//取原价格
  1506. // "post_fee"=>0,
  1507. "status" => 0,
  1508. "send_status" => 0,
  1509. "th_num" => 0,
  1510. "th_fee" => 0,//退货金额为0
  1511. "send_num" => 0,
  1512. "wsend_num" => $good_num,
  1513. // "send_status"=>1,
  1514. "good_type" => 1,
  1515. // "send_type"=>$sendtype,
  1516. // "supplierNo"=>$zxorder['companyNo'],
  1517. "is_del" => 0,
  1518. // "zxNo"=>$bidNo,
  1519. // "platform_order"=>$platform_order,
  1520. // "platform_id"=> $zxorder['platform_code'],
  1521. "remark" => $old_sale['orderCode'],
  1522. // "arrive_time"=>$arrtime,
  1523. // "is_stock"=>0,
  1524. // "is_activity"=>0,
  1525. // "proof_id"=>0,
  1526. "order_type" => 3,
  1527. "order_source" => 6,//6售后补换货
  1528. // 'good_weight'=>$zxinfo['good_weight'],
  1529. // 'gold_price'=>$zxinfo['gold_price'],
  1530. // 'cost_price'=>$zxinfo['sale_cost_fee'],
  1531. // 'diff_weight'=>0,
  1532. // 'diff_fee'=>0,
  1533. "addtime" => date("Y-m-d H:i:s"),
  1534. "updatetime" => date("Y-m-d H:i:s"),
  1535. 'returnCode' => $info['returnCode'],
  1536. // 'total_price' => round($sale_price * $good_num, 2),
  1537. // 'workNo'=>$workNo,
  1538. 'cgderid' => $supplier_temp_info['data']['personid']??0,
  1539. 'cgder' => $supplier_temp_info['data']['person']??"",//采购员(供应商负责人)
  1540. 'good_createrid' => $zxinfo['createrid'],
  1541. 'good_creater' => $zxinfo['creater'],//商品创建人
  1542. ]);
  1543. $datainfo = Db::name('sale')->insertGetId($data);
  1544. if ($datainfo > 0) {
  1545. $standing_book_data = [
  1546. 'sale_id' => $datainfo,
  1547. 'infoNo' => $zxinfo['infoNo'],
  1548. 'updatetime' => date('Y-m-d H:i:s')
  1549. ];
  1550. //修改状态,添加待办
  1551. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
  1552. "order_code" => $orderCode,//销售单code
  1553. "status" => 0,//这里的status是之前的值
  1554. "action_remark" => '',//备注
  1555. "action_type" => "create"//新建create,编辑edit,更改状态status
  1556. ], "XSQRD", $data['status'], $data);
  1557. ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], [
  1558. "order_type" => 'XSQRD',
  1559. "order_code" => $orderCode,//销售单code
  1560. "order_id" => $datainfo,
  1561. "order_status" => $data['status'],
  1562. "before_status" => 0,
  1563. 'holder_id' => $data['apply_id']
  1564. ]);
  1565. // $old_zx_status = $zx['status'];
  1566. // $zx['status']=5;
  1567. // $zx['updatetime']=date("Y-m-d H:i:s");
  1568. // $sa=Db::name("consult_info")->save($zx);
  1569. // if($sa==false){
  1570. // Db::rollback();
  1571. // return error_show(1002,"咨询单修改失败");
  1572. // }else{
  1573. // //修改状态,添加待办
  1574. // ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
  1575. // "order_code" => $zx['infoNo'],//咨询单详情编号
  1576. // "status" => $old_zx_status,//这里的status是之前的值
  1577. // "action_remark" => '',//备注
  1578. // "action_type" => "status"//新建create,编辑edit,更改状态status
  1579. // ], "ZXD", 5, $zx);
  1580. //
  1581. // }
  1582. $this->createCgd($cgd, $standing_book_data);
  1583. // if($bol==false){
  1584. // Db::rollback();
  1585. // return error_show(1002,"咨询订单创建失败");
  1586. // }
  1587. // $limt=[
  1588. // "spuCode"=>$zxinfo['spuCode'],
  1589. // "good_name"=>$zxinfo['good_name'],
  1590. // "brand_id"=>$zxinfo['brand_id'],
  1591. // "good_unit"=>$zxinfo['unit_id'],
  1592. // "cat_id"=>$zxinfo['cat_id'],
  1593. // "good_type"=>0,
  1594. // "moq"=>1,
  1595. // "customized"=>$zxinfo['work_day'],
  1596. // "tax"=>$zxinfo['tax'],
  1597. // "supplierNo"=>$zxinfo["supplierNo"],
  1598. // "is_auth"=>0,
  1599. // "craft_desc"=>$zxinfo['good_name'],
  1600. // "good_remark"=>"",
  1601. // "platform_id"=>$zxorder['platform_id'],
  1602. // "good_img"=>$zxinfo['good_img'],
  1603. // "good_thumb_img"=>"",
  1604. // "good_info_img"=>"",
  1605. // "specinfo"=>$zxinfo['specinfo'],
  1606. // "work_day"=>$zxinfo['work_day'],
  1607. // "noble_metal"=>$zxinfo['metal_id'],
  1608. // "is_gold_price"=>$zxinfo['is_gold_price'],
  1609. // "config"=>$zxinfo['config'],
  1610. // "other_config"=>$zxinfo['other_config'],
  1611. // "weight"=>$zxinfo['weight'],
  1612. // "good_weight"=>$zxinfo['good_weight'],
  1613. // "is_diff"=>$zxinfo['is_diff'],
  1614. // "supply_area"=>$zxinfo['supply_area'],
  1615. // "pay_way"=>$zxinfo['pay_way'],
  1616. // "send_way"=>$zxinfo['send_way'],
  1617. // "companyNo"=>$zxorder['companyNo'],
  1618. // "status"=>1,
  1619. // "is_del"=>0,
  1620. // "createrid"=>$zxinfo['createrid'],
  1621. // "creater"=>$zxinfo['creater'],
  1622. // "addtime"=>date("Y-m-d H:i:s"),
  1623. // "updatetime"=>date("Y-m-d H:i:s"),
  1624. // 'proof_type' => $proof_type,//凭证类型
  1625. // 'proof_url' => $proof_url,//凭证文件
  1626. // ];
  1627. // $good = Db::name("good_zixun")->insert($limt);
  1628. // if(!$good){
  1629. // Db::rollback();
  1630. // return error_show(1006,"咨询商品录入失败");
  1631. // }
  1632. // if(!empty($va)){
  1633. $order = Db::name("order_num")->where(["orderCode" => $orderCode, "status" => 1])->where([["wsend_num", ">=", 0]])->find();
  1634. if (empty($order)) throw new Exception('采购单关联数据未找到');
  1635. // foreach ($va as $value){
  1636. // $temp=[];
  1637. // $addrs=[];
  1638. // if($value['addr_code']!==''&&is_array($value['addr_code'])&&!empty($value['addr_code'])){
  1639. // $addrs['provice_code'] = $value['addr_code'][0];
  1640. // $addrs['city_code'] = $value['addr_code'][1];
  1641. // $addrs['area_code'] = $value['addr_code'][2];
  1642. // $addr = json_encode($addrs);
  1643. // }else{
  1644. // $addr = isset($value['addr_code'])?$value['addr_code']:'';
  1645. // }
  1646. // $temp['orderCode']=$orderCode;
  1647. // $temp['contactor']=$value['contactor'];
  1648. // $temp['mobile'] = $value['mobile'];
  1649. // $temp['addr'] = $value['addr'];
  1650. // $temp['addr_code']=$addr;
  1651. // $temp['customer_code'] =$zxorder['khNo'];
  1652. // $temp['receipt_quantity']=$value['receipt_quantity'];
  1653. // $temp['post_fee'] =0;
  1654. // $temp['is_del'] =0;
  1655. // $temp['addtime'] =date("Y-m-d H:i:s");
  1656. // $temp['updatetime'] =date("Y-m-d H:i:s");
  1657. // $temp['arrive_time']=$arrtime;
  1658. $old_out_addr_info = Db::name('order_out')
  1659. ->alias('oo')
  1660. ->field('oo.id,oa.addr,oa.addr_code,oa.contactor,oa.mobile,oa.customer_code,oa.post_fee,oa.arrive_time')
  1661. ->leftJoin('order_addr oa', 'oa.id=oo.addrid')
  1662. ->where(['oo.outCode' => $info['outCode'], 'oo.orderCode' => $info['orderCode']])
  1663. ->find();
  1664. if (empty($old_out_addr_info)) throw new Exception('发货单对应的地址信息查不到');
  1665. $temp = [
  1666. 'orderCode' => $orderCode,
  1667. 'addr' => $old_out_addr_info['addr'],
  1668. 'addr_code' => $old_out_addr_info['addr_code'],
  1669. 'contactor' => $old_out_addr_info['contactor'],
  1670. 'mobile' => $old_out_addr_info['mobile'],
  1671. 'customer_code' => $old_out_addr_info['customer_code'],
  1672. 'receipt_quantity' => $good_num,
  1673. 'arrive_time' => $old_out_addr_info['arrive_time'],
  1674. 'addtime' => date("Y-m-d H:i:s"),
  1675. 'updatetime' => date("Y-m-d H:i:s"),
  1676. // ''=>'',
  1677. ];
  1678. $addrid = Db::name('order_addr')->insertGetId($temp);
  1679. // if($vmp>0){
  1680. $outCode = makeNo("DF");
  1681. $out = [
  1682. "orderCode" => $orderCode,
  1683. "outCode" => $outCode,
  1684. "apply_id" => $rm,
  1685. "apply_name" => $ri,
  1686. 'addrid' => $addrid,
  1687. "post_name" => "",
  1688. "post_code" => "",
  1689. "post_fee" => 0,
  1690. "sendtime" => date("Y-m-d H:i:s"),
  1691. "send_num" => $good_num,
  1692. "check_num" => 0,
  1693. "error_num" => 0,
  1694. "wsm_code" => "",
  1695. "order_type" => 3,
  1696. "status" => 0,
  1697. "addtime" => date("Y-m-d H:i:s"),
  1698. "updatetime" => date("Y-m-d H:i:s")
  1699. ];
  1700. $ou = Db::name("order_out")->insert($out);
  1701. if ($ou == false) throw new Exception('发货地址添加创建失败');
  1702. else {
  1703. //修改状态,添加待办
  1704. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
  1705. "order_code" => $outCode,//出库单号
  1706. "status" => 0,//这里的status是之前的值
  1707. "action_remark" => '',//备注
  1708. "action_type" => "create"//新建create,编辑edit,更改状态status
  1709. ], "CKD", 0, $out);
  1710. ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], [
  1711. "order_type" => 'CKD',
  1712. "order_code" => $outCode,//出库单号
  1713. "order_id" => Db::name("order_out")->getLastInsID(),
  1714. "order_status" => 0,
  1715. "before_status" => 0,
  1716. 'holder_id' => $out['apply_id']
  1717. ]);
  1718. //将发货编号添加到台账中
  1719. $standing_book_data['outCode'][] = $outCode;
  1720. }
  1721. $order['send_num'] += $good_num;
  1722. $order['wsend_num'] -= $good_num;
  1723. if ($order['wsend_num'] < 0) throw new Exception('发货数量已超出总数');
  1724. $ups = Db::name("order_num")->save($order);
  1725. if ($ups) {
  1726. $sen = Db::name("order_send")->save([
  1727. "cgdNo" => $order['cgdNo'],
  1728. "outCode" => $outCode,
  1729. "send_num" => $good_num,
  1730. "status" => 1,
  1731. "addtime" => date("Y-m-d H:i:s"),
  1732. "updatetime" => date("Y-m-d H:i:s")
  1733. ]);
  1734. if ($sen == false) throw new Exception('发货地址添加创建失败');
  1735. }
  1736. // }else{
  1737. // Db::rollback();
  1738. // return error_show(1002,"发货地址添加创建失败");
  1739. // }
  1740. // }
  1741. //处理台账
  1742. if (isset($standing_book_data['outCode'])) {
  1743. Db::execute("UPDATE `wsm_standing_book` SET `outCode`=CONCAT(IFNULL(`outCode`,''),'," . implode(',', $standing_book_data['outCode']) . "'),`updatetime`='" . date('Y-m-d H:i:s') . "' WHERE `infoNo`='{$standing_book_data['infoNo']}'");
  1744. unset($standing_book_data['outCode']);
  1745. }
  1746. Db::name('standing_book')->where('infoNo', $standing_book_data['infoNo'])->update($standing_book_data);
  1747. Db::name('order_return')
  1748. ->where(['id' => $orid, 'is_reissue' => 0])
  1749. ->update([
  1750. 'is_reissue' => 1,
  1751. 'newOrderCode' => $orderCode,
  1752. 'updatetime' => date('Y-m-d H:i:s')
  1753. ]);
  1754. Db::commit();
  1755. return app_show(0, "咨询订单创建成功", ["order_code" => $orderCode]);
  1756. }
  1757. Db::rollback();
  1758. return error_show(1002, "咨询订单创建失败");
  1759. } catch (Exception $e) {
  1760. Db::rollback();
  1761. return error_show(1003, $e->getMessage() . '|' . $e->getFile() . ':' . $e->getLine());
  1762. }
  1763. }
  1764. private function createCgd($data,array &$standing_book_da=[]){
  1765. $cgdCode = makeNo("CG");
  1766. // $supplier=Db::name("supplier")->where(["code"=>$data['supplierNo'],"is_del"=>0])->find();
  1767. $user= \app\admin\common\User::getIns();
  1768. $supplier_temp =$user->handle("sInfo",["code"=>$data['supplierNo']]);
  1769. if($supplier_temp['code']!=0 || empty($supplier_temp['data']) ) throw new Exception('该供应商不存在');
  1770. $supplier=$supplier_temp['data'];
  1771. $wsm= Db::name("warehouse_info")
  1772. ->where(["supplierNo"=>$data["supplierNo"],"companyNo"=>$data['companyNo'],"wsm_type"=>2,"is_del"=>0])
  1773. ->find();
  1774. if($wsm==false){
  1775. $wsm_code = makeNo("WSM");
  1776. $inwsm=[
  1777. "wsm_code"=>$wsm_code,
  1778. "name"=>$supplier['name'],
  1779. "wsm_type"=>2,
  1780. "supplierNo"=>$supplier['code'],
  1781. "addr"=>"",
  1782. "addrs_code"=>"",
  1783. "contactor"=>$data['order_type']==1? $supplier['personid']:$data['createrid'],
  1784. "contactor_name"=>$data['order_type']==1? $supplier['person']:$data['creater'],
  1785. "mobile"=>"",
  1786. "position"=>"",
  1787. "companyNo"=>$data['companyNo'],
  1788. "status"=>1,
  1789. "is_del"=>0,
  1790. "addtime"=>date("Y-m-d H:i:s"),
  1791. "updatetime"=>date("Y-m-d H:i:s")
  1792. ];
  1793. $in = Db::name("warehouse_info")->insert($inwsm);
  1794. if($in==false) throw new Exception('仓库新增失败');
  1795. }else $wsm_code =$wsm['wsm_code'];
  1796. //判断该供应商是否开通了供应商账号
  1797. $from_tag=checkHasAccountBySupplierNos([$data['supplierNo']]);
  1798. $cg =[
  1799. "cgdNo"=>$cgdCode,
  1800. "bkcode"=>"",
  1801. "wsm_code"=>$wsm_code,
  1802. "cgder"=>$data['good_creater'],
  1803. "cgder_id"=>$data['good_createrid'],
  1804. "spuCode"=>$data['spuCode'],
  1805. "skuCode"=>$data['skuCode'],
  1806. "good_name"=>$data['good_name'],
  1807. "good_num"=>$data['good_num'],
  1808. "good_price"=>$data['sale_price'],
  1809. "total_fee"=>round($data['sale_price']*$data['good_num'],2),
  1810. "pakge_fee"=>$data['pakge_fee'],
  1811. "cert_fee"=>$data['cert_fee'],
  1812. "open_fee"=>$data['open_fee'],
  1813. "teach_fee"=>$data['cost_fee'],
  1814. "mark_fee"=>$data['mark_fee'],
  1815. "demo_fee"=>$data['demo_fee'],
  1816. "nake_fee"=>$data['nake_fee'],
  1817. "weight"=>$data['weight'],
  1818. "delivery_fee"=>$data['delivery_fee'],
  1819. "gold_price"=>$data['gold_price'],
  1820. "diff_weight"=>"0",
  1821. "diff_fee"=>"0",
  1822. "supplierNo"=>$data['supplierNo'],
  1823. "supplier_name"=>$supplier['name'],
  1824. "companyNo"=>$data['companyNo'],
  1825. "send_status"=>1,
  1826. "send_num"=>0,
  1827. "wsend_num"=>$data['good_num'],
  1828. "remark"=>"",
  1829. "status"=>0,//0初始化
  1830. "lasttime"=>date("Y-m-d H:i:s"),
  1831. "is_del"=>0,
  1832. "order_type"=>$data['order_type'],
  1833. "order_source"=>$data['order_source'],
  1834. "good_type"=>$data['good_type'],
  1835. "addtime"=>date("Y-m-d H:i:s"),
  1836. "updatetime"=>date("Y-m-d H:i:s"),
  1837. 'good_createrid' => $data['good_createrid'],
  1838. 'good_creater' => $data['good_createrid'],//商品创建人
  1839. 'from_tag' => isset($from_tag[$data['supplierNo']]) ? 2 : 1,//来源标签:1采销(默认),2供应商端
  1840. ];
  1841. $up =Db::name("purchease_order")->insertGetId($cg);
  1842. if($up){
  1843. //修改状态,添加待办
  1844. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
  1845. "order_code" => $cg['cgdNo'],//销售单code
  1846. "status" => 0,//这里的status是之前的值
  1847. "action_remark" => '',//备注
  1848. "action_type" => "create"//新建create,编辑edit,更改状态status
  1849. ], "CGD", $cg['status'], $cg);
  1850. ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], [
  1851. "order_type" => 'CGD',
  1852. "order_code" => $cg['cgdNo'],//销售单code
  1853. "order_id" => $up,
  1854. "order_status" => $cg['status'],
  1855. "before_status"=> 0,
  1856. 'holder_id' => $supplier['personid'],
  1857. 'wait_id' => $supplier['personid'],
  1858. 'wait_name' => $supplier['person'],
  1859. ]);
  1860. $standing_book_da = array_merge($standing_book_da, [
  1861. 'orderCode' => $data['orderCode'],
  1862. 'cgdNo' => $cgdCode,
  1863. 'spuCode' => $data['spuCode'],
  1864. 'skuCode' => $data['skuCode'],
  1865. 'order_type' => $data['order_type'],
  1866. 'order_source' => $data['order_source'],
  1867. 'supplierNo' => $data['supplierNo'],
  1868. "companyNo" => $data['companyNo'],
  1869. ]);
  1870. $rela=[
  1871. "orderCode"=>$data['orderCode'],
  1872. "cgdNo"=>$cgdCode,
  1873. "spuCode"=>$data['spuCode'],
  1874. "good_num"=>$data['good_num'],
  1875. "wsend_num"=>$data['good_num'],
  1876. "send_num"=>0,
  1877. "wait_num"=>0,
  1878. "status"=>1,
  1879. "source"=>2
  1880. ];
  1881. Db::name("order_num")->save($rela);
  1882. $stokc =Db::name("good_stock")
  1883. ->where(['spuCode'=>$data['spuCode'],"wsm_code"=>$wsm_code, "is_del"=>0])
  1884. ->find();
  1885. if($stokc==false){
  1886. $stokc=[
  1887. "spuCode"=>$data['spuCode'],
  1888. "wsm_code"=>$wsm_code,
  1889. "wait_in_stock"=>$data['good_num'],
  1890. "wait_out_stock"=>0,
  1891. "usable_stock"=>0,
  1892. "intra_stock"=>0,
  1893. "total_stock"=>0,
  1894. "status"=>1,
  1895. "addtime"=>date("Y-m-d H:i:s"),
  1896. "updatetime"=>date("Y-m-d H:i:s")
  1897. ];
  1898. }else{
  1899. $stokc['wait_in_stock']+=$data['good_num'];
  1900. $stokc['updatetime']=date("Y-m-d H:i:s");
  1901. }
  1902. $stoc= Db::name("good_stock")->save($stokc);
  1903. if($stoc==false) throw new Exception('商品仓库库存修改失败');
  1904. $good_data[] = ['good_log_code' =>$cgdCode, "stock_id" => isset($stoc['id'])?$stoc['id']:Db::name("good_stock")->getLastInsID(), "type" => 1,'stock'=>$data['good_num'], "stock_name" => "wait_in_stock"];
  1905. GoodLog::LogAdd($data['token'],$good_data,"CGD");
  1906. return true;
  1907. }else throw new Exception('商品仓库库存修改失败');
  1908. }
  1909. //创建采购单
  1910. /**
  1911. * 非咨询类商品处理
  1912. * @param int $orid 售后记录的id
  1913. * @param string $spuCode 商品的spuCode
  1914. * @param array $info 售后申请单的详情
  1915. * @param array $old_sale 原始销售订单信息
  1916. * @param int $rm 操作人id
  1917. * @param string $ri 操作人名称
  1918. * @param array $old_out 原始发货单信息
  1919. * @param string $token 当前用户的token
  1920. * @throws \think\db\exception\DataNotFoundException
  1921. * @throws \think\db\exception\DbException
  1922. * @throws \think\db\exception\ModelNotFoundException
  1923. */
  1924. private function createSaleNotZixun(int $orid = 0, string $spuCode = '', array $info = [], array $old_sale = [], int $rm = 0, string $ri = '', array $old_out = [], string $token = '')
  1925. {
  1926. $goodinfo = Db::name('good')
  1927. ->alias('g')
  1928. ->field('g.*,gp.skuCode')
  1929. ->join('good_platform gp', 'gp.spuCode=g.spuCode AND gp.exam_status=3')
  1930. ->where('g.spuCode', $spuCode)
  1931. ->where('gp.skuCode', $old_sale['skuCode'])
  1932. ->find();
  1933. if (empty($goodinfo)) return error_show(1005, '查不到这个商品,或该商品已下线无法售后');
  1934. $is_activity = $old_sale['is_activity'];
  1935. $actcode = $old_sale['activity_code'];
  1936. $good_num = $info['error_num'];//数量,取售后申请单中的异常数量
  1937. $supplierNo = $old_sale['supplierNo'];
  1938. $sale_price = 0;
  1939. $origin_price = $old_sale['origin_price'];
  1940. $goodtype = $old_sale['good_type'];
  1941. $is_stock = $goodinfo['is_stock'];
  1942. $skuCode = $goodinfo['skuCode'];
  1943. $orderCode = makeNo("QR");
  1944. if ($is_stock == 1) {
  1945. $stock_num = Db::name("good_stock")->alias("a")
  1946. ->leftJoin("warehouse_info b", "a.wsm_code=b.wsm_code")
  1947. ->leftJoin("good_stock_info c", "a.id=c.stockid and c.balance_num>0")
  1948. ->where(["spuCode" => $spuCode, "a.is_del" => 0, "a.status" => 1, "b.wsm_type" => 5, "b.companyNo" =>$supplierNo])
  1949. ->sum('balance_num');
  1950. if($stock_num < $good_num){
  1951. return error_show(1003, "批次库存数量不足"); //库存不足
  1952. }
  1953. }
  1954. $goodinfo['cgd_gold_price'] = 0;
  1955. if ($goodtype == 1) {
  1956. if ($is_activity == 1) {
  1957. $act = Db::name("activity_info")
  1958. ->alias("a")
  1959. ->leftJoin("good_activity b", "a.activity_code=b.activity_code")
  1960. ->where(["a.skuCode" => $skuCode, "a.activity_code" => $actcode, "a.is_del" => 0, "a.status" => 1, "b.status" => 6, "b.is_del" => 0])
  1961. ->find();
  1962. if ($act == false) return error_show(1003, "未找到相关活动价");
  1963. if ($act['moq_num'] > $good_num) return error_show(1003, "商品不满足活动价起订量{$act['moq_num']}");
  1964. if ($act['activity_stock'] < $good_num) return error_show(1003, "商品活动库存剩余{$act['activity_stock']}");
  1965. }
  1966. // else {
  1967. // $good = Db::name("good_ladder")
  1968. // ->where(["skuCode" => $skuCode, "is_del" => 0, "status" => 1])
  1969. // ->where([["min_num", "<=", $good_num]])
  1970. // ->order("min_num desc")
  1971. // ->find();
  1972. //
  1973. // if ($good == false) return error_show(1003, "未找到相关阶梯价格");
  1974. //
  1975. // if ($goodinfo['is_gold_price'] == 1 && $is_stock != 1) {
  1976. // $gold = Db::name("gold_price1")
  1977. // ->field('id,price')
  1978. // ->where(["type" => $goodinfo['noble_metal'], "is_del" => 0, "status" => 1])
  1979. // ->order("addtime desc")
  1980. // ->find();
  1981. //
  1982. // $goodinfo['cgd_gold_price'] = $gold["price"];
  1983. // }
  1984. // }
  1985. }
  1986. //原有采购单信息
  1987. if ($is_stock != 1){
  1988. $old_cgd = Db::name('order_num')
  1989. ->alias('on')
  1990. ->field('on.id onid,po.*')
  1991. ->leftJoin('purchease_order po', 'po.cgdNo=on.cgdNo')
  1992. ->where('on.orderCode', $old_sale['orderCode'])
  1993. ->find();
  1994. $cgd = array_merge($old_cgd, [
  1995. 'id' => null,
  1996. // "supplierNo" => $ct['supplierNo'],
  1997. // "companyNo" => $supplierNo,
  1998. "orderCode" => $orderCode,
  1999. "spuCode" => $spuCode,
  2000. "skuCode" => $skuCode,
  2001. // "good_name" => $ct['good_name'],
  2002. "sale_price" => $old_cgd['good_price'],//采购单价格不为0,取原采购单的价格
  2003. "total_fee" => $old_cgd['good_price'] * $good_num,
  2004. // "pakge_fee" => isset($origin['package_fee']) ? $origin['package_fee'] : 0,
  2005. // "cert_fee" => isset($origin['cert_fee']) ? $origin['cert_fee'] : 0,
  2006. // "open_fee" => $ct['open_fee'],
  2007. // "cost_fee" => isset($origin['cost_fee']) ? $origin['cost_fee'] : 0,
  2008. 'cost_fee' => $old_cgd['teach_fee'],
  2009. // "mark_fee" => isset($origin['mark_fee']) ? $origin['mark_fee'] : 0,
  2010. // "nake_fee" => isset($origin['nake_fee']) ? $origin['nake_fee'] : 0,
  2011. // "delivery_fee" => isset($origin['delivery_fee']) ? $origin['delivery_fee'] : 0,
  2012. // "demo_fee" => $ct['demo_fee'],
  2013. "good_num" => $good_num,
  2014. // "good_type" => $goodtype,
  2015. // "weight" => $ct['noble_weight'],
  2016. // "gold_price" => isset($ct['cgd_gold_price']) ? $ct['cgd_gold_price'] : 0,
  2017. // "order_type" => $is_stock == 1 ? 1 : 2,
  2018. "order_source" => 6,//6售后补换货
  2019. "createrid" => $rm,
  2020. "creater" => $ri,
  2021. // 'send_way' => 2,
  2022. 'token' => $token,
  2023. 'addtime' => date('Y-m-d H:i:s'),
  2024. 'updatetime' => date('Y-m-d H:i:s'),
  2025. 'good_createrid' => $goodinfo['createrid'],
  2026. 'good_creater' => $goodinfo['creater'],//商品创建人
  2027. ]);
  2028. // $supplier_temp_info = Db::name('supplier')
  2029. // ->field('id,person,personid')
  2030. // ->where('code',$cgd['supplierNo'])
  2031. // ->findOrEmpty();
  2032. $user= \app\admin\common\User::getIns();
  2033. $supplier_temp =$user->handle("sInfo",["code"=>$cgd['supplierNo']]);
  2034. }else{
  2035. $user= \app\admin\common\User::getIns();
  2036. $supplier_temp =$user->handle("sInfo",["code"=>$goodinfo['supplierNo']]);
  2037. // $supplier_temp_info = Db::name('supplier')
  2038. // ->field('id,person,personid')
  2039. // ->where('code',$goodinfo['supplierNo'])
  2040. // ->findOrEmpty();
  2041. }
  2042. $supplier_temp_info = [
  2043. "id"=>$supplier_temp['data']['id']??0,
  2044. "person"=>$supplier_temp['data']['person']??'',
  2045. "personid"=>$supplier_temp['data']['personid']??0,
  2046. ];
  2047. // $addrlist = isset($this->post['addrlist']) && $this->post['addrlist'] !=="" ?$this->post['addrlist']:"";
  2048. $send_num = 0;
  2049. // if($sendtype==1){
  2050. // if($addrlist=="" || empty($addrlist) ||!is_array($addrlist)){
  2051. // return error_show(1004,"参数addrlist不能为空");
  2052. // }
  2053. // $send_num = array_sum(array_column($addrlist,"receipt_quantity"));
  2054. // }
  2055. // if($send_num>$good_num){
  2056. // return error_show(1004,"发货数量超出订单总数量");
  2057. // }
  2058. // $remark =isset($this->post['remark']) && $this->post['remark'] !=="" ?trim($this->post['remark']):"";
  2059. // $proof_id =isset($this->post['proof_id']) && $this->post['proof_id'] !=="" ?intval($this->post['proof_id']):0;
  2060. // $apply_id = GetUserInfo($param['token']);
  2061. // if (empty($apply_id) || $apply_id['code'] != 0) return error_show(1002, "申请人数据不存在");
  2062. // $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  2063. // $ri = isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  2064. Db::startTrans();
  2065. try {
  2066. $data = array_merge($old_sale, [
  2067. 'id' => null,
  2068. "orderCode" => $orderCode,
  2069. "good_code" => $spuCode,
  2070. "skuCode" => $skuCode,
  2071. // "customer_code" => $info['customer_code'],
  2072. // "good_name" => (isset($goodinfo['good_name']) && $goodinfo['good_name'] !== '') ? $goodinfo['good_name'] : '',
  2073. "good_num" => $good_num,
  2074. // "cat_id" => $goodinfo['cat_id'],
  2075. "apply_id" => $rm,
  2076. "apply_name" => $ri,
  2077. "origin_price" => $origin_price,
  2078. // "sale_price" => $old_sale['sale_price'],//取原价格
  2079. // "total_price" => $sale_price,//取原总价
  2080. // "post_fee" => 0,
  2081. // "status" => 0,
  2082. "th_num" => 0,
  2083. "th_fee" => 0,//退货金额为0
  2084. "send_num" => 0,
  2085. "wsend_num" => $good_num,
  2086. // "send_status" => 0,
  2087. // "good_type" => $goodtype,
  2088. // "send_type" => $old_sale['send_type'],
  2089. // "supplierNo" => $supplierNo,
  2090. // "is_del" => 0,
  2091. // "zxNo" => "",
  2092. // "platform_order" => $old_sale['platform_order'],
  2093. // "platform_id" => $old_sale['platform_id'],
  2094. "remark" => $old_sale['orderCode'],
  2095. // "is_stock" => $is_stock,
  2096. "is_activity" => $is_activity,
  2097. "activity_code" => $actcode,
  2098. // "order_type" => $is_stock == 1 ? 1 : 2,
  2099. "order_source" => 6,//6售后补换货
  2100. // "poNo"=>$poNo,
  2101. // 'good_weight' => $ct['noble_weight'],
  2102. // 'gold_price' => isset($ct['cgd_gold_price']) ? $ct['cgd_gold_price'] : 0,
  2103. // 'cost_price' => isset($good['cost_fee']) ? $good['cost_fee'] : 0,
  2104. // 'diff_weight' => 0,
  2105. // 'diff_fee' => 0,
  2106. // "workNo" => '',
  2107. 'status' => 0,
  2108. "addtime" => date("Y-m-d H:i:s"),
  2109. "updatetime" => date("Y-m-d H:i:s"),
  2110. // 'total_price' => round($sale_price * $good_num, 2),
  2111. // 'proof_id' => $old_sale['proof_id'],
  2112. // 'paytime' => $old_sale['paytime'],
  2113. 'returnCode' => $info['returnCode'],
  2114. 'cgderid' => $supplier_temp_info['personid'],
  2115. 'cgder' => $supplier_temp_info['person'],//采购员(供应商负责人)
  2116. 'good_createrid' => $goodinfo['createrid'],
  2117. 'good_creater' => $goodinfo['creater'],//商品创建人
  2118. ]);
  2119. $datainfo = Db::name('sale')->insertGetId($data);
  2120. if ($datainfo > 0) {
  2121. //修改状态,添加待办
  2122. ActionLog::logAdd($token, [
  2123. "order_code" => $orderCode,//销售单code
  2124. "status" => 0,//这里的status是之前的值
  2125. "action_remark" => '',//备注
  2126. "action_type" => "create"//新建create,编辑edit,更改状态status
  2127. ], "XSQRD", 0, $this->post);
  2128. ProcessOrder::AddProcess($token, [
  2129. "order_type" => 'XSQRD',
  2130. "order_code" => $orderCode,//销售单code
  2131. "order_id" => $datainfo,
  2132. "order_status" => 0,
  2133. "before_status" => 0,
  2134. 'holder_id' => $data['apply_id']
  2135. ]);
  2136. if ($is_activity == 1) {
  2137. $actup = [
  2138. "activity_stock" => $act['activity_stock'] - $good_num,
  2139. "updatetime" => date("Y-m-d H:i:s")
  2140. ];
  2141. $actupp = Db::name("activity_info")
  2142. ->where(["skuCode" => $skuCode, "activity_code" => $actcode, "is_del" => 0, "status" => 1])
  2143. ->save($actup);
  2144. if ($actupp == false) throw new Exception('活动库存修改失败');
  2145. }
  2146. $outstatus = 0;
  2147. $standing_book_da = ['sale_id' => $datainfo, 'customer_code' => $old_sale['customer_code'], 'skuCode' => $skuCode, 'updatetime' => date('Y-m-d H:i:s')];
  2148. if ($is_stock == 0) $this->createCgd($cgd, $standing_book_da);
  2149. else {
  2150. $outstatus = 1;
  2151. $stockid= Db::name("good_stock")->alias("a")
  2152. ->leftJoin("warehouse_info b", "a.wsm_code=b.wsm_code")
  2153. ->where(["spuCode" => $spuCode, "a.is_del" => 0, "a.status" => 1, "b.wsm_type" => 5, "b.companyNo" =>$supplierNo])
  2154. ->column('a.id');
  2155. $stockinfo =GoodStockInfo::OrderBn($orderCode,$stockid,$good_num);
  2156. if($stockinfo==false){
  2157. throw new Exception('库存商品更新库存失败');
  2158. }
  2159. // $bol = $this->RelaCgd([
  2160. // 'orderCode' => $orderCode,
  2161. // "good_num" => $good_num,
  2162. // "spuCode" => $spuCode,
  2163. // "companyNo" => $supplierNo,
  2164. // "cost_fee" => isset($goodinfo['cost_fee']) ? $goodinfo['cost_fee'] : 0,
  2165. // 'order_type' => $data['order_type'],
  2166. // 'order_source' => $data['order_source'],
  2167. // ], $standing_book_da);
  2168. // if (isset($stock)) {
  2169. //
  2170. // $stck = [
  2171. // "usable_stock" => $stock['usable_stock'] - $good_num,
  2172. // "wait_out_stock" => $stock['wait_out_stock'] + $good_num,
  2173. // "updatetime" => date("Y-m-d H:i:s")
  2174. // ];
  2175. //
  2176. // $upad = Db::name("good_stock")->where($stock)->update($stck);
  2177. // if ($upad == false) throw new Exception('库存商品更新库存失败');
  2178. // $stockinfo =GoodStockInfo::OrderBn($orderCode,$stock['id'],$good_num);
  2179. // if($stockinfo==false){
  2180. // throw new Exception('库存商品更新库存失败'); //库存不足
  2181. // }
  2182. // //商品变动日志表,good_log_code字段存储采购单号
  2183. // $good_data[] = ['good_log_code' => $orderCode, "stock_id" => $stock['id'], "type" => 2, 'stock' => $good_num, "stock_name" => "usable_stock"];
  2184. // $good_data[] = ['good_log_code' => $orderCode, "stock_id" => $stock['id'], "type" => 1, 'stock' => $good_num, "stock_name" => "wait_out_stock"];
  2185. // GoodLog::LogAdd($token, $good_data, "XSQRD");
  2186. // }
  2187. }
  2188. // $old_out = Db::name('order_out')
  2189. // ->field('id,addrid,wsm_code')
  2190. // ->where(['orderCode' => $info['orderCode'], 'outCode' => $info['outCode']])
  2191. // ->find();
  2192. $old_out_addr_info = Db::name('order_out')
  2193. ->alias('oo')
  2194. ->field('oo.id,oa.addr,oa.addr_code,oa.contactor,oa.mobile,oa.customer_code,oa.post_fee,oa.arrive_time')
  2195. ->leftJoin('order_addr oa', 'oa.id=oo.addrid')
  2196. ->where(['oo.outCode' => $info['outCode'], 'oo.orderCode' => $info['orderCode']])
  2197. ->find();
  2198. if (empty($old_out_addr_info)) throw new Exception('发货单对应的地址信息查不到');
  2199. $temp = [
  2200. 'orderCode' => $orderCode,
  2201. 'addr' => $old_out_addr_info['addr'],
  2202. 'addr_code' => $old_out_addr_info['addr_code'],
  2203. 'contactor' => $old_out_addr_info['contactor'],
  2204. 'mobile' => $old_out_addr_info['mobile'],
  2205. 'customer_code' => $old_out_addr_info['customer_code'],
  2206. 'receipt_quantity' => $good_num,
  2207. 'arrive_time' => $old_out_addr_info['arrive_time'],
  2208. 'addtime' => date("Y-m-d H:i:s"),
  2209. 'updatetime' => date("Y-m-d H:i:s"),
  2210. // ''=>'',
  2211. ];
  2212. $addrid = Db::name('order_addr')->insertGetId($temp);
  2213. $outCode = makeNo("DF");
  2214. $out = array_merge($old_out, [
  2215. 'id' => null,
  2216. "orderCode" => $orderCode,
  2217. "outCode" => $outCode,
  2218. "apply_id" => $rm,
  2219. "apply_name" => $ri,
  2220. "addrid" => $addrid,
  2221. "post_name" => "",
  2222. "post_code" => "",
  2223. "post_fee" => 0,
  2224. "sendtime" => date("Y-m-d H:i:s"),
  2225. "send_num" => $good_num,
  2226. "check_num" => 0,
  2227. "error_num" => 0,
  2228. "wsm_code" => isset($old_out['wsm_code']) ? $old_out['wsm_code'] : '',
  2229. "order_type" => $is_stock == 1 ? 1 : 2,
  2230. "status" => $outstatus,
  2231. "addtime" => date("Y-m-d H:i:s"),
  2232. "updatetime" => date("Y-m-d H:i:s")
  2233. ]);
  2234. Db::name("order_out")->insert($out);
  2235. $standing_book_da['outCode'] = $outCode;
  2236. if($is_stock==0){
  2237. $order = Db::name("order_num")->where(["orderCode" => $orderCode, "status" => 1])->where([["wsend_num", ">=", 0]])->find();
  2238. if (empty($order)) throw new Exception('采购单关联数据未找到');
  2239. $order['send_num'] += $good_num;
  2240. $order['wsend_num'] -= $good_num;
  2241. if ($order['wsend_num'] < 0) throw new Exception('发货数量已超出总数');
  2242. $ups = Db::name("order_num")->save($order);
  2243. if ($ups) {
  2244. $sen = Db::name("order_send")->save([
  2245. "cgdNo" => $order['cgdNo'],
  2246. "outCode" => $outCode,
  2247. "send_num" => $good_num,
  2248. "status" => 1,
  2249. "addtime" => date("Y-m-d H:i:s"),
  2250. "updatetime" => date("Y-m-d H:i:s")
  2251. ]);
  2252. if ($sen == false) throw new Exception('发货地址添加创建失败');
  2253. }
  2254. }
  2255. if (!isset($standing_book_da['returnCode'])) $standing_book_da['returnCode'] = '';
  2256. if (!isset($standing_book_da['thNo'])) $standing_book_da['thNo'] = '';
  2257. if (!isset($standing_book_da['returnGoodCode'])) $standing_book_da['returnGoodCode'] = '';
  2258. if (!isset($standing_book_da['wsm_in_code'])) $standing_book_da['wsm_in_code'] = '';
  2259. if (!isset($standing_book_da['cgdReturnCode'])) $standing_book_da['cgdReturnCode'] = '';
  2260. //处理台账
  2261. Db::name('standing_book')->insert(array_merge($standing_book_da, ['addtime' => date('Y-m-d H:i:s'), 'updatetime' => date('Y-m-d H:i:s'), 'standBookNo' => makeNo('IO')]));
  2262. //维护售后申请单
  2263. Db::name('order_return')
  2264. ->where(['id' => $orid, 'is_reissue' => 0])
  2265. ->update([
  2266. 'is_reissue' => 1,
  2267. 'newOrderCode' => $orderCode,
  2268. 'updatetime' => date('Y-m-d H:i:s')
  2269. ]);
  2270. Db::commit();
  2271. return error_show(0, "操作成功");
  2272. } else throw new Exception('咨询订单创建失败');
  2273. } catch (\Exception $e) {
  2274. Db::rollback();
  2275. return error_show(1005, $e->getMessage() . '|' . $e->getFile() . '|' . $e->getLine());
  2276. }
  2277. }
  2278. //创建采购单
  2279. public function RelaCgd($outinfo,array &$standing_book_da=[]){
  2280. $cgd = Db::name("order_bk")->where([["spuCode","=",$outinfo['spuCode']],["is_del","=",0],["balance_num",">=",$outinfo['good_num']],['companyNo',"=",$outinfo['companyNo']]])->lock(true)->find();
  2281. if($cgd==false) throw new Exception('未查询到备库单信息');
  2282. $good=Db::name("good")
  2283. ->where(["spuCode"=>$outinfo['spuCode'],"is_del"=>0])
  2284. ->find();
  2285. if($good==false) throw new Exception('未查询到商品信息');
  2286. $cgdinfo =Db::name("purchease_order")
  2287. ->where(['cgdNo'=>$cgd['cgdNo'],"is_del"=>0])
  2288. ->find();
  2289. if($cgdinfo==false) throw new Exception('未查询到采购单信息');
  2290. //判断该供应商是否开通了供应商账号
  2291. $from_tag=checkHasAccountBySupplierNos([$cgdinfo['supplierNo']]);
  2292. $QrdCgd=[
  2293. "cgdNo"=>makeNo("CG"),
  2294. "bkcode" => $cgdinfo['bkcode'],
  2295. 'wsm_code'=>$cgdinfo['wsm_code'],
  2296. "cgder_id"=>$cgdinfo['cgder_id'],
  2297. "cgder"=>$cgdinfo['cgder'],
  2298. "spuCode"=>$cgdinfo['spuCode'],
  2299. "good_name"=>$cgdinfo['good_name'],
  2300. "good_num"=>$outinfo['good_num'],
  2301. "good_price"=>$cgdinfo['good_price'],
  2302. "total_fee"=>round($cgdinfo['good_price']*$outinfo['good_num'],2),
  2303. "pakge_fee"=>$cgdinfo['pakge_fee'],
  2304. "cert_fee"=>$cgdinfo['cert_fee'],
  2305. "open_fee"=>$cgdinfo['open_fee'],
  2306. "delivery_fee"=>$cgdinfo['delivery_fee'],
  2307. "mark_fee"=>$cgdinfo['mark_fee'],
  2308. "teach_fee"=>$cgdinfo['teach_fee'],
  2309. "nake_fee"=>$cgdinfo['nake_fee'],
  2310. "demo_fee"=>$cgdinfo['demo_fee'],
  2311. "weight"=>$cgdinfo['weight'],
  2312. "diff_weight"=>$cgdinfo['diff_weight'],
  2313. "diff_fee"=>$cgdinfo['diff_fee'],
  2314. "gold_price"=>$cgdinfo['gold_price'],
  2315. "supplierNo"=>$cgdinfo['supplierNo'],
  2316. "supplier_name"=>$cgdinfo['supplier_name'],
  2317. "companyNo"=>$cgdinfo['companyNo'],
  2318. "send_status"=>3,
  2319. "send_num"=>$outinfo['good_num'],
  2320. "wsend_num"=>0,
  2321. "remark"=>$cgdinfo['remark'],
  2322. "status"=>3,
  2323. "lasttime"=>$cgdinfo['lasttime'],
  2324. "is_del"=>0,
  2325. "order_type"=>$outinfo['order_type'],
  2326. "order_source"=>$outinfo['order_source'],
  2327. "good_type"=>$cgdinfo['good_type'],
  2328. "addtime"=>date("Y-m-d H:i:s"),
  2329. "updatetime"=>date("Y-m-d H:i:s"),
  2330. 'good_createrid' => $good['createrid'],
  2331. 'good_creater' => $good['creater'],//商品创建人
  2332. 'from_tag' => isset($from_tag[$cgdinfo['supplierNo']]) ? 2 : 1,//来源标签:1采销(默认),2供应商端
  2333. ];
  2334. $insetrCgd=Db::name("purchease_order")->insert($QrdCgd);
  2335. if($insetrCgd==false) throw new Exception('新增采购单失败');
  2336. else{
  2337. $standing_book_da = array_merge($standing_book_da, [
  2338. 'orderCode' => $outinfo['orderCode'],
  2339. 'cgdNo' => $cgdinfo['cgdNo'],
  2340. 'spuCode' => $outinfo['spuCode'],
  2341. 'order_type' => $QrdCgd['order_type'],
  2342. 'order_source' => $QrdCgd['order_source'],
  2343. 'supplierNo' => $cgdinfo['supplierNo'],
  2344. 'companyNo' => $cgdinfo['companyNo'],
  2345. 'bk_code' => $cgdinfo['bkcode'],
  2346. 'purchease_id' => Db::name('purchease')->where('bk_code', $cgdinfo['bkcode'])->value('id',0),
  2347. ]);
  2348. }
  2349. if($good['is_gold_price']==1 && $good['is_stock']==1){
  2350. $gold = Db::name("gold_price1")
  2351. ->field('id,price')
  2352. ->where(["type" => $good['noble_metal'], "is_del" => 0, "status" => 1])
  2353. ->order("addtime desc")
  2354. ->find();
  2355. $ct['cgd_gold_price']=$gold["price"];
  2356. $updat=[
  2357. "sale_price"=>0,
  2358. "total_price"=>0,
  2359. "origin_price"=>$cgdinfo['good_price'],
  2360. "gold_price"=>$gold["price"],
  2361. ];
  2362. Db::name("sale")->where(["orderCode"=>$outinfo['orderCode']])->update($updat);
  2363. // if($upsale==false){
  2364. // return false;
  2365. // }
  2366. }
  2367. $merge_num = Db::name("purchease_order")
  2368. ->where(["bkcode"=>$cgdinfo['bkcode'],"order_type"=>1,"is_del"=>0])
  2369. ->where("order_source","<>",0)
  2370. ->field("sum(send_num)-sum(th_num) as num")
  2371. ->find();
  2372. $cgd['balance_num']=$cgd['total_num']-$merge_num['num'];
  2373. $cgd['merge_num']=$merge_num['num'];
  2374. $cgd['updatetime']=date("Y-m-d H:i:s");
  2375. $up=Db::name("order_bk")->save($cgd);
  2376. if($up==false) throw new Exception('修改备库单失败');
  2377. $data=[
  2378. "orderCode"=>$outinfo['orderCode'],
  2379. "cgdNo"=>$QrdCgd['cgdNo'],
  2380. "spuCode"=>$outinfo['spuCode'],
  2381. "companyNo"=>$outinfo['companyNo'],
  2382. "good_num"=>$outinfo['good_num'],
  2383. "wsend_num"=>$outinfo['good_num'],
  2384. "send_num"=>0,
  2385. "wait_num"=>$outinfo['good_num'],
  2386. "status"=>1,
  2387. "source"=>1,
  2388. ];
  2389. $order =Db::name("order_num")->save($data);
  2390. if($order==false) throw new Exception('修改采购单销售单关联失败');
  2391. }
  2392. //导出
  2393. public function export()
  2394. {
  2395. $param = $this->request->only([
  2396. 'returnCode',
  2397. 'outCode' => '',
  2398. 'status' => '',
  2399. 'order_type' => '',
  2400. 'orderCode' => '',
  2401. 'good_code' => '',
  2402. 'good_name' => '',
  2403. 'except_code' => '',
  2404. 'apply_name' => '',
  2405. 'start' => '',
  2406. 'end' => '',
  2407. 'company_name' => '',//部门名称
  2408. 'supplierNo' => '',
  2409. 'customer_code' => '',
  2410. 'companyNo' => '',
  2411. 'order_source' => '',
  2412. ], 'post', 'trim');
  2413. $val = Validate::rule(['returnCode' => 'require|array|max:10']);
  2414. if ($val->check($param) == false) return json_show(1004, $val->getError());
  2415. $where = [['a.is_del', "=", 0], ['a.returnCode', 'in', $param['returnCode']]];
  2416. if ($param['outCode'] !== '') $where[] = ['a.outCode', "like", "%{$param['outCode']}%"];
  2417. if ($param['status'] !== '') $where[] = ['a.status', "=", $param['status']];
  2418. if ($param['order_type'] !== "") $where[] = ['a.order_type', "=", $param['order_type']];
  2419. if ($param['orderCode'] != "") $where[] = ['a.orderCode', "like", "%{$param['orderCode']}%"];
  2420. if ($param['good_code'] != "") $where[] = ['a.good_code', "like", "%{$param['good_code']}%"];
  2421. if ($param['good_name'] != "") $where[] = ['a.good_name', "like", "%{$param['good_name']}%"];
  2422. if ($param['customer_code'] != "") $where[] = ['a.customer_code', "like", "%{$param['customer_code']}%"];
  2423. if ($param['except_code'] != "") $where[] = ['a.except_code', "=", $param['except_code']];
  2424. if ($param['apply_name'] != "") $where[] = ['a.apply_name', "like", "%{$param['apply_name']}%"];
  2425. if ($param['start'] !== "") $where[] = ['a.addtime', ">=", $param['start']];
  2426. if ($param['end'] !== "") $where[] = ['a.addtime', "<=", $param['end']];
  2427. if ($param['order_source'] !== "") $where[] = ['c.order_source', "=", $param['order_source']];
  2428. if ($param['supplierNo'] !== "") $where[] = ['a.supplierNo', "like", '%' . $param['supplierNo'] . '%'];
  2429. if ($param['companyNo'] !== "") $where[] = ['a.companyNo', "like", '%' . $param['companyNo'] . '%'];
  2430. if ($param['company_name'] !== "") $where[] = ["a.apply_id", 'in', get_company_item_user_by_name($param['company_name'])];
  2431. //只有level2的账号过滤数据权限
  2432. if ($this->level == 2) {
  2433. $hand = resign_hand_user($this->uid, 0);
  2434. $role = $this->checkDataShare();
  2435. if (!empty($role[DataGroupModel::$type_全部])) {
  2436. $arr = array_unique(array_merge($hand, $role[DataGroupModel::$type_全部]));
  2437. $condition[] = ["a.person_id", "in", $hand];
  2438. $condition[] = ["a.apply_id", "in", $arr];
  2439. $condition[] = ["a.cgderid", "in", $hand];
  2440. $code = Db::connect('mysql_sys')
  2441. ->name('supplier')
  2442. ->where(['is_del' => 0, 'personid' => $this->uid])
  2443. ->column('code');
  2444. if($code) $condition[] = ["a.supplierNo", "in", $code];
  2445. }
  2446. }
  2447. //level3账号不允许看到库存品订单
  2448. if ($this->level == 3) $where[] = ['c.is_stock', '<>', 1];
  2449. // $condition .="a.cgderid in {$hand} or a.person_id in {$hand} or a.apply_id in ("
  2450. // .implode(',',$role[DataGroupModel::$type_全部]).")";
  2451. $list = Db::name('order_return')
  2452. ->field('
  2453. a.returnCode 售后申请单编码,
  2454. a.order_type 订单类型,
  2455. a.apply_name 申请人,
  2456. a.cgder 采购员,
  2457. a.person 采购负责人,
  2458. a.outCode 发货单号,
  2459. a.is_receive 是否收到货,
  2460. a.total_num 总数量,
  2461. a.error_num 异常数量,
  2462. a.error_msg 异常原因,
  2463. a.error_remark 异常备注,
  2464. a.except_code 客户意愿,
  2465. a.orderCode 订单编号,
  2466. a.good_code 商品编号,
  2467. a.good_name 商品名称,
  2468. a.customer_code 客户编码,
  2469. a.customer_name 客户名称,
  2470. a.is_post 是否承担物流费用,
  2471. a.is_th 供应商是否退货,
  2472. a.return_tag 退回何处,
  2473. a.status 状态,
  2474. a.remark 审核备注,
  2475. a.addtime 创建时间,
  2476. a.updatetime 更新时间,
  2477. a.is_reissue 是否完成补发货,
  2478. a.newOrderCode 售后完成后新的销售订单号,
  2479. a.loop_total 状态从业务公司修改待供应商确认到待采购审核的循环次数,
  2480. b.return_wsm 退回仓库,
  2481. b.contactor 仓库联系人,
  2482. b.mobile 联系方式,
  2483. b.addr 地址,
  2484. b.addr_code,
  2485. b.post_code 快递单号,
  2486. b.post_company 快递公司,
  2487. b.post_fee 快递费用,
  2488. b.gys_remark 供应商备注,
  2489. a.supplierNo 供应商编码,
  2490. a.supplierName 供应商名称,
  2491. a.companyNo 业务公司编码,
  2492. a.companyName 业务公司名称')
  2493. ->alias('a')
  2494. ->where($where)
  2495. ->where(function ($query) use ($condition) {
  2496. $query->whereOr($condition);
  2497. })
  2498. ->leftJoin('order_returninfo b', 'b.returnCode=a.returnCode')
  2499. ->leftJoin("sale c", "c.orderCode=a.orderCode AND c.is_del=0")
  2500. ->select()
  2501. ->toArray();
  2502. $order_type = [1 => '直接下单', 2 => '咨询', 3 => '项目', 4 => '平台', 5 => '有赞', 6 => '售后补换货', 7 => '报备转单', 8 => '支付渠道'];
  2503. $is_receive = [0 => '否', 1 => '是'];
  2504. $except_code = [0 => [1 => '退货', 2 => '补发'], 1 => [1 => '退货', 2 => '换货'],];//期望意愿
  2505. $return_tag = [1 => '供应商', 2 => '业务企业'];
  2506. $status = [1 => '待业务审核', 2 => '待采购审核', 4 => '待客户退货', 5 => '售后已完成', 6 => '业务已驳回', 8 => '申请已取消', 9 => '供应商审核', 10 => '业务公司修改待供应商确认'];
  2507. foreach ($list as &$value) {
  2508. $value['订单类型'] = $order_type[$value['订单类型']] ?? '';
  2509. $value['客户意愿'] = $except_code[$value['是否收到货']][$value['客户意愿']] ?? '';
  2510. $value['是否收到货'] = $is_receive[$value['是否收到货']] ?? '';
  2511. $value['是否承担物流费用'] = $is_receive[$value['是否承担物流费用']] ?? '';
  2512. $value['供应商是否退货'] = $is_receive[$value['供应商是否退货']] ?? '';
  2513. $value['退回何处'] = $return_tag[$value['退回何处']] ?? '';
  2514. $value['状态'] = $status[$value['状态']] ?? '';
  2515. $value['是否完成补发货'] = $is_receive[$value['是否完成补发货']] ?? '';
  2516. $addr_code = explode(',', $value['addr_code']);
  2517. $value['地址'] = GetAddr(json_encode(['provice_code' => $addr_code[0], 'city_code' => $addr_code[1], 'area_code' => $addr_code[2]])) . $value['地址'];
  2518. unset($value['addr_code']);
  2519. }
  2520. if (empty($list)) $list[] = ['没有相关可导出的数据'];
  2521. excelSave('售后申请单' . date('YmdHis'), array_keys($list[0]), $list);
  2522. }
  2523. }