After.php 111 KB

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