After.php 113 KB

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