After.php 108 KB

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