After.php 112 KB

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