After.php 108 KB

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