Sale.php 128 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\GoodLog;
  4. use app\admin\model\ProcessOrder;
  5. use app\BaseController;
  6. use Exception;
  7. use think\App;
  8. use think\facade\Db;
  9. use app\admin\model\ActionLog;
  10. class Sale extends BaseController
  11. {
  12. public $post = "";
  13. public function __construct(App $app)
  14. {
  15. parent::__construct($app);
  16. $this->post = $this->request->post();
  17. }
  18. public function create()
  19. {
  20. $token = isset($this->post['token']) && $this->post['token'] !=="" ?trim($this->post['token']):"";
  21. $orderCode=makeNo("CX");
  22. $customer_code= isset($this->post['customer_code'])&& $this->post['customer_code'] !=="" ? trim($this->post['customer_code']) :"";
  23. if($customer_code==""){
  24. return error_show(1002,"客户customer_code不能为空");
  25. }
  26. $customer=Db::name("customer_info")->where(["companyNo"=>$customer_code])->find();
  27. if($customer==false){
  28. return error_show(1004,"未找到客户数据");
  29. }
  30. $supplierNo= isset($this->post['supplierNo']) && $this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']) :"";
  31. if($supplierNo==""){
  32. return error_show(1002,"参数supplierNo不能为空");
  33. }
  34. $supplier=Db::name("business")->where(["companyNo"=>$supplierNo])->find();
  35. if($supplier==false){
  36. return error_show(1004,"未找到平台供应商数据");
  37. }
  38. $goodtype =isset($this->post['goodtype']) && $this->post['goodtype'] !=="" ?intval($this->post['goodtype']):"1";
  39. $order_type =isset($this->post['order_type']) && $this->post['order_type'] !=="" ?intval($this->post['order_type'])
  40. :"1";
  41. $sendtype =isset($this->post['sendtype']) && $this->post['sendtype'] !=="" ?intval($this->post['sendtype']):"";
  42. if($sendtype==''){
  43. return error_show(1004,"参数sendtype不能为空");
  44. }
  45. $platform_id =isset($this->post['platform_id']) && $this->post['platform_id'] !=="" ?intval($this->post['platform_id']):"";
  46. if($platform_id==''){
  47. return error_show(1004,"参数platform_id不能为空");
  48. }
  49. // $zxinfoNo= isset($this->post['zxinfoNo'])&& $this->post['zxinfoNo'] !=="" ? trim($this->post['zxinfoNo']) :"";
  50. // if($zxinfoNo=="" &&$order_type!==1){
  51. // return error_show(1002,"参数 zxinfoNo 不能为空");
  52. // }
  53. $platform_order =isset($this->post['platform_order']) && $this->post['platform_order'] !=="" ?trim($this->post['platform_order']):"";
  54. if($platform_order==''){
  55. return error_show(1004,"参数platform_order不能为空");
  56. }
  57. $good_code =isset($this->post['good_code']) && $this->post['good_code'] !=="" ?trim($this->post['good_code']):"";
  58. if($good_code==''){
  59. return error_show(1004,"参数good_code不能为空");
  60. }
  61. $good_num =isset($this->post['good_num']) && $this->post['good_num'] !=="" ?intval($this->post['good_num']):"";
  62. if($good_num===''){
  63. return error_show(1004,"参数good_num不能为空");
  64. }
  65. $arrtime = isset($this->post['arrtime'])&&$this->post['arrtime']!="" ?$this->post['arrtime']:"";
  66. if($arrtime==""){
  67. return error_show(1004,"参数arrtime不能为空");
  68. }
  69. $ct = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
  70. ->where(['a.skuCode' => $good_code])->find();
  71. if ($ct == false) {
  72. return error_show(1002, "未找到商品数据");
  73. }
  74. $goodinfo=$ct;
  75. $is_stock=$ct['is_stock'];
  76. $spuCode = $ct['spuCode'];
  77. $skuCode = $ct['skuCode'];
  78. $cgd=[
  79. "supplierNo"=>$ct['supplierNo'],
  80. "companyNo"=>$supplierNo,
  81. "orderCode"=>$orderCode,
  82. "spuCode"=>$ct['spuCode'],
  83. "skuCode"=>$ct['skuCode'],
  84. "good_name"=>$ct['good_name'],
  85. "sale_price"=>$ct['sale_price'],
  86. "total_fee"=>$ct['total_fee'],
  87. "pakge_fee"=>$ct['packing_fee'],
  88. "cert_fee"=>$ct['cert_fee'],
  89. "open_fee"=>$ct['open_fee'],
  90. "cost_fee"=>$ct['cost_fee'],
  91. "mark_fee"=>$ct['mark_fee'],
  92. "demo_fee"=>$ct['demo_fee'],
  93. "good_num"=>$good_num,
  94. "good_type"=>$goodtype,
  95. "order_type"=>$order_type,
  96. ];
  97. $is_activity= isset($this->post['is_activity'])&&$this->post['is_activity']!=="" ?$this->post['is_activity']:"";
  98. if($order_type==1){
  99. if($is_activity===""){
  100. return error_show(1002, "参数is_activity不能为空");
  101. }
  102. }
  103. $addrlist = isset($this->post['addrlist']) && $this->post['addrlist'] !=="" ?$this->post['addrlist']:"";
  104. if($sendtype==1){
  105. if($addrlist=="" || empty($addrlist) ||!is_array($addrlist)){
  106. return error_show(1004,"参数addrlist不能为空");
  107. }
  108. }
  109. $remark =isset($this->post['remark']) && $this->post['remark'] !=="" ?trim($this->post['remark']):"";
  110. $proofid= isset($this->post['proof_id'])&&$this->post['proof_id']===""?intval($this->post['proof_id']):"0";
  111. $apply_id =GetUserInfo($token);
  112. if(empty($apply_id)||$apply_id['code']!=0){
  113. return error_show(1002,"申请人数据不存在");
  114. }
  115. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  116. $ri= isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  117. Db::startTrans();
  118. try {
  119. $data=[
  120. "orderCode"=>$orderCode,
  121. "good_code"=>$spuCode,
  122. "skuCode"=>$skuCode,
  123. "customer_code"=>$customer_code,
  124. "good_name"=>isset($goodinfo['good_name'])&&$goodinfo['good_name']!==''?$goodinfo['good_name']:'',
  125. "good_num"=>$good_num,
  126. "cat_id"=>$goodinfo['cat_id'],
  127. "apply_id"=>$rm,
  128. "apply_name"=>$ri,
  129. "origin_price"=>$goodinfo['total_fee'],
  130. "sale_price"=>$goodinfo['sale_price'],
  131. "post_fee"=>0,
  132. "status"=>0,
  133. "send_num"=>0,
  134. "wsend_num"=>$good_num,
  135. "send_status"=>1,
  136. "good_type"=>$goodtype,
  137. "send_type"=>$sendtype,
  138. "supplierNo"=>$supplierNo,
  139. "is_del"=>0,
  140. "zxNo"=>"",
  141. "platform_order"=>$platform_order,
  142. "platform_id"=>$platform_id,
  143. "remark"=>$remark,
  144. "is_stock"=>$is_stock,
  145. "is_activity"=>$is_activity===""?0:$is_activity,
  146. "proof_id"=>$proofid,
  147. "order_type"=>$order_type,
  148. "addtime"=>date("Y-m-d H:i:s"),
  149. "updatetime"=>date("Y-m-d H:i:s"),
  150. 'total_price'=>round($goodinfo['sale_price']*$good_num,2),
  151. ];
  152. $datainfo = Db::name('sale')->insert($data,true);
  153. if($datainfo>0){
  154. if($is_stock==0){
  155. $bol=$this->createCgd($cgd);
  156. if($bol==false){
  157. Db::rollback();
  158. return error_show(1002,"咨询订单创建失败");
  159. }
  160. }
  161. if($sendtype==1){
  162. foreach ($addrlist as $value){
  163. $temp=[];
  164. $addrs=[];
  165. if($value['addr_code']!==''&&is_array($value['addr_code'])){
  166. $addrs['provice_code'] = $value['addr_code'][0];
  167. $addrs['city_code'] = $value['addr_code'][1];
  168. $addrs['area_code'] = $value['addr_code'][2];
  169. $addr = json_encode($addrs);
  170. }else{
  171. $addr = isset($value['addr_code'])?$value['addr_code']:'';
  172. }
  173. $temp['orderCode']=$orderCode;
  174. $temp['contactor']=$value['contactor'];
  175. $temp['mobile'] = $value['mobile'];
  176. $temp['addr'] = $value['addr'];
  177. $temp['addr_code']=$addr;
  178. $temp['customer_code'] =$customer_code;
  179. $temp['receipt_quantity']=$value['receipt_quantity'];
  180. $temp['post_fee'] =0;
  181. $temp['is_del'] =0;
  182. $temp['addtime'] =date("Y-m-d H:i:s");
  183. $temp['updatetime'] =date("Y-m-d H:i:s");
  184. $temp['arrive_time']=$arrtime;
  185. $vmp = Db::name('order_addr')->insert($temp,true);
  186. if($vmp>0){
  187. $outCode=makeNo("CK");
  188. $out=[
  189. "orderCode"=>$orderCode,
  190. "outCode"=>$outCode,
  191. "apply_id"=>$rm,
  192. "apply_name"=>$ri,
  193. "addrid"=>$vmp,
  194. "post_name"=>"",
  195. "post_code"=>"",
  196. "post_fee"=>0,
  197. "sendtime"=>date("Y-m-d H:i:s"),
  198. "send_num"=>$value['receipt_quantity'],
  199. "check_num"=>0,
  200. "error_num"=>0,
  201. "wsm_code"=>"",
  202. "order_type"=>$order_type,
  203. "status"=>0,
  204. "addtime"=>date("Y-m-d H:i:s"),
  205. "updatetime"=>date("Y-m-d H:i:s")
  206. ];
  207. $ou =Db::name("order_out")->insert($out);
  208. if($ou==false){
  209. Db::rollback();
  210. return error_show(1002,"发货地址添加创建失败");
  211. }
  212. if($is_stock==0){
  213. $order =Db::name("order_num")->where(["orderCode"=>$orderCode,"status"=>1])->where([["wsend_num",">=",0]])
  214. ->find();
  215. if($order==false){
  216. Db::rollback();
  217. return error_show(1006,"采购单关联数据未找到");
  218. }
  219. $order['send_num']+=$value['receipt_quantity'];
  220. $order['wsend_num']-=$value['receipt_quantity'];
  221. if($order['wsend_num']<0){
  222. Db::rollback();
  223. return error_show(1002,"发货数量已超出总数");
  224. }
  225. $ups = Db::name("order_num")->save($order);
  226. if($ups){
  227. $tep=[
  228. "cgdNo"=>$order['cgdNo'],
  229. "outCode"=>$outCode,
  230. "send_num"=>$value['receipt_quantity'],
  231. "status"=>1,
  232. "addtime"=>date("Y-m-d H:i:s"),
  233. "updatetime"=>date("Y-m-d H:i:s")
  234. ];
  235. $sen=Db::name("order_send")->save($tep);
  236. if($sen==false){
  237. Db::rollback();
  238. return error_show(1002,"发货地址添加创建失败");
  239. }
  240. }
  241. }
  242. }else{
  243. Db::rollback();
  244. return error_show(1002,"发货地址添加创建失败");
  245. }
  246. }
  247. }
  248. Db::commit();
  249. return error_show(0,"咨询订单创建成功",["order_code"=>$orderCode]);
  250. }
  251. Db::rollback();
  252. return error_show(1002,"咨询订单创建失败");
  253. }catch(\Exception $e){
  254. Db::rollback();
  255. return error_show(1005,$e->getMessage());
  256. }
  257. }
  258. public function createCgd($data){
  259. $cgdCode = makeNo("CG");
  260. $supplier=Db::name("supplier")->where(["code"=>$data['supplierNo'],"is_del"=>0])->find();
  261. //echo Db::name("supplier")->getLastSql();
  262. if($supplier==false){
  263. return false;
  264. }
  265. $wsm= Db::name("warehouse_info")->where(["supplierNo"=>$data["supplierNo"],"companyNo"=>$data['companyNo'],"is_del"=>0])->find();
  266. if($wsm==false){
  267. $wsm_code = makeNo("WSM");
  268. $inwsm=[
  269. "wsm_code"=>$wsm_code,
  270. "name"=>$supplier['name'],
  271. "wsm_type"=>2,
  272. "supplierNo"=>$supplier['code'],
  273. "addr"=>"",
  274. "addrs_code"=>"",
  275. "contactor"=>0,
  276. "contactor_name"=>0,
  277. "mobile"=>"",
  278. "position"=>"",
  279. "companyNo"=>$data['companyNo'],
  280. "status"=>1,
  281. "is_del"=>0,
  282. "addtime"=>date("Y-m-d H:i:s"),
  283. "updatetime"=>date("Y-m-d H:i:s")
  284. ];
  285. $in = Db::name("warehouse_info")->insert($inwsm);
  286. if($in==false){
  287. return false;
  288. }
  289. }else{
  290. $wsm_code =$wsm['wsm_code'];
  291. }
  292. $cg =["cgdNo"=>$cgdCode,
  293. "bkcode"=>"",
  294. "wsm_code"=>$wsm_code,
  295. "cgder"=>$supplier['person'],
  296. "cgder_id"=>$supplier['personid'],
  297. "spuCode"=>$data['spuCode'],
  298. "skuCode"=>$data['skuCode'],
  299. "good_name"=>$data['good_name'],
  300. "good_num"=>$data['good_num'],
  301. "good_price"=>$data['sale_price'],
  302. "total_fee"=>$data['total_fee'],
  303. "pakge_fee"=>$data['pakge_fee'],
  304. "cert_fee"=>$data['cert_fee'],
  305. "open_fee"=>$data['open_fee'],
  306. "teach_fee"=>$data['cost_fee'],
  307. "mark_fee"=>$data['mark_fee'],
  308. "demo_fee"=>$data['demo_fee'],
  309. #"weight"=>$data['weight'],
  310. "diff_weight"=>"0",
  311. "diff_fee"=>"0",
  312. "gold_price"=>"0",
  313. "supplierNo"=>$data['supplierNo'],
  314. "supplier_name"=>$supplier['name'],
  315. "companyNo"=>$data['companyNo'],
  316. "send_status"=>1,
  317. "send_num"=>"0",
  318. "wsend_num"=>$data['good_num'],
  319. "remark"=>"",
  320. "status"=>0,
  321. "lasttime"=>date("Y-m-d H:i:s"),
  322. "is_del"=>0,
  323. "order_type"=>$data['order_type'],
  324. "good_type"=>$data['good_type'],
  325. "addtime"=>date("Y-m-d H:i:s"),
  326. "updatetime"=>date("Y-m-d H:i:s")
  327. ];
  328. $up =Db::name("purchease_order")->insert($cg);
  329. if($up){
  330. $rela=[
  331. "orderCode"=>$data['orderCode'],
  332. "cgdNo"=>$cgdCode,
  333. "spuCode"=>$data['spuCode'],
  334. "good_num"=>$data['good_num'],
  335. "wsend_num"=>$data['good_num'],
  336. "send_num"=>0,
  337. "wait_num"=>0,
  338. "status"=>1,
  339. "source"=>2
  340. ];
  341. $re =Db::name("order_num")->save($rela);
  342. if($re==false){
  343. return false;
  344. }else{
  345. return true;
  346. }
  347. }else{
  348. return false;
  349. }
  350. }
  351. public function addAddr(){
  352. $orderCode = isset($this->post['orderCode'])&&$this->post['orderCode']!=""? trim($this->post['orderCode']):"";
  353. $etid = Db::name("sale")->where(["orderCode" => $orderCode, "is_del" => 0])->find();
  354. if (empty($etid)) {
  355. return error_show(1002, "未找到数据");
  356. }
  357. $arrtime = isset($this->post['arrtime'])&&$this->post['arrtime']!="" ?$this->post['arrtime']:"";
  358. if($arrtime==""){
  359. return error_show(1004,"参数arrtime不能为空");
  360. }
  361. $order =Db::name("order_num")->where(["orderCode"=>$orderCode,"status"=>1])->where([["wsend_num",">=",0]])
  362. ->select()->toArray();
  363. if(empty($order)){
  364. return error_show(1004,"未找到可以发货得采购单数据");
  365. }
  366. $token = isset($this->post['token']) && $this->post['token'] !=="" ?trim($this->post['token']):"";
  367. $apply_id =GetUserInfo($token);
  368. if(empty($apply_id)||$apply_id['code']!=0){
  369. return error_show(1002,"申请人数据不存在");
  370. }
  371. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  372. $ri= isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  373. $addrlist = isset($this->post['addrlist']) && $this->post['addrlist'] !=="" ?$this->post['addrlist']:"";
  374. if($addrlist=="" || empty($addrlist) ||!is_array($addrlist)){
  375. return error_show(1004,"参数addrlist不能为空");
  376. }
  377. Db::startTrans();
  378. try{
  379. foreach ($addrlist as $value){
  380. $temp=[];
  381. $addrs=[];
  382. if($value['addr_code']!==''&&is_array($value['addr_code'])){
  383. $addrs['provice_code'] = $value['addr_code'][0];
  384. $addrs['city_code'] = $value['addr_code'][1];
  385. $addrs['area_code'] = $value['addr_code'][2];
  386. $addr = json_encode($addrs);
  387. }else{
  388. $addr = isset($value['addr_code'])?$value['addr_code']:'';
  389. }
  390. $temp['orderCode']=$orderCode;
  391. $temp['contactor']=$value['contactor'];
  392. $temp['mobile'] = $value['mobile'];
  393. $temp['addr'] = $value['addr'];
  394. $temp['addr_code']=$addr;
  395. $temp['customer_code'] =$etid['customer_code'];
  396. $temp['receipt_quantity']=$value['receipt_quantity'];
  397. $temp['post_fee'] =0;
  398. $temp['is_del'] =0;
  399. $temp['addtime'] =date("Y-m-d H:i:s");
  400. $temp['updatetime'] =date("Y-m-d H:i:s");
  401. $temp['arrive_time']=$arrtime;
  402. $vmp = Db::name('order_addr')->insert($temp,true);
  403. if($vmp>0){
  404. $outCode=makeNo("CK");
  405. $out=[
  406. "orderCode"=>$orderCode,
  407. "outCode"=>$outCode,
  408. "apply_id"=>$rm,
  409. "apply_name"=>$ri,
  410. "addrid"=>$vmp,
  411. "post_name"=>"",
  412. "post_code"=>"",
  413. "post_fee"=>0,
  414. "sendtime"=>date("Y-m-d H:i:s"),
  415. "send_num"=>$value['receipt_quantity'],
  416. "check_num"=>0,
  417. "error_num"=>0,
  418. "wsm_code"=>"",
  419. "order_type"=>$etid['order_type'],
  420. "status"=>0,
  421. "addtime"=>date("Y-m-d H:i:s"),
  422. "updatetime"=>date("Y-m-d H:i:s")
  423. ];
  424. $ou =Db::name("order_out")->insert($out);
  425. if($ou==false){
  426. Db::rollback();
  427. return error_show(1002,"发货地址添加创建失败");
  428. }
  429. $num = $value['receipt_quantity'];
  430. $orsend=[];
  431. foreach ($order as $val){
  432. $tep=[];$ornum=0;
  433. if($val['wsend_num']>=$num){
  434. $val['wsend_num']-=$num;
  435. $val['send_num']+=$num;
  436. $ornum =$num;
  437. $num=0;
  438. }else{
  439. $num-=$val['wsend_num'];
  440. $val['send_num']+=$val['wsend_num'];
  441. $ornum =$val['wsend_num'];
  442. $val['wsend_num']=0;
  443. }
  444. $or =Db::name("order_num")->save($val);
  445. if($or==false){
  446. Db::rollback();
  447. return error_show(1002,"发货地址添加创建失败");
  448. }
  449. $tep=[
  450. "cgdNo"=>$val['cgdNo'],
  451. "outCode"=>$outCode,
  452. "send_num"=>$ornum,
  453. "status"=>1,
  454. "addtime"=>date("Y-m-d H:i:s"),
  455. "updatetime"=>date("Y-m-d H:i:s")
  456. ];
  457. $sen=Db::name("order_send")->save($tep);
  458. if($sen==false){
  459. Db::rollback();
  460. return error_show(1002,"发货地址添加创建失败");
  461. }
  462. if($num==0){
  463. break;
  464. }
  465. }
  466. }else{
  467. Db::rollback();
  468. return error_show(1002,"发货地址添加创建失败");
  469. }
  470. }
  471. Db::commit();
  472. return app_show(0,"发货地址添加完成");
  473. }catch(\Exception $e){
  474. Db::rollback();
  475. return error_show(1002,$e->getMessage());
  476. }
  477. }
  478. public function consultOrder(){
  479. $bidNo =isset($this->post['bidNo'])&&$this->post['bidNo']!="" ? trim($this->post['bidNo']):"";
  480. if($bidNo==""){
  481. return error_show(1003,"参数bidNo不能为空");
  482. }
  483. $zxinfo = Db::name("consult_bids")->where(["bidNo"=>$bidNo,"is_del"=>0])->find();
  484. if($zxinfo==false){
  485. return error_show(1003,"未找到咨询单商品信息");
  486. }
  487. if($zxinfo['status']!=6){
  488. return error_show(1003,"咨询单状态有误无法转单");
  489. }
  490. $zx =Db::name("consult_info")->where(["infoNo"=>$zxinfo['infoNo'],"is_del"=>0])->find();
  491. if($zx==false){
  492. return error_show(1003,"未找到咨询单信息");
  493. }
  494. if($zx['status']!=4){
  495. return error_show(1003,"咨询单状态有误无法转单");
  496. }
  497. $zxorder =Db::name("consult_order")->where(["zxNo"=>$zx["zxNo"],"is_del"=>0])->find();
  498. if($zxorder==false){
  499. return error_show(1003,"未找到咨询单信息");
  500. }
  501. $good_num =isset($this->post['good_num'])&&$this->post['good_num']!="" ? intval($this->post['good_num']):"";
  502. if($good_num===""){
  503. return error_show(1003,"参数 good_num 不能为空");
  504. }
  505. $sendtype = isset($this->post['sendtype'])&&$this->post['sendtype']!="" ? intval($this->post['sendtype']):"";
  506. if($sendtype==""){
  507. return error_show(1003,"参数sendtype不能为空");
  508. }
  509. $orderCode = makeNo("QR");
  510. $spuCode = $zxinfo['spuCode'];
  511. $skuCode = "";
  512. $is_stock=0;
  513. $cgd=[
  514. "supplierNo"=>$zxinfo['supplierNo'],
  515. "companyNo"=>$zxorder['companyNo'],
  516. "spuCode"=>$spuCode,
  517. "skuCode"=>$skuCode,
  518. "orderCode"=>$orderCode,
  519. "good_name"=>$zxinfo['good_name'],
  520. "sale_price"=>$zxinfo['sale_price'],
  521. "total_fee"=>$zxinfo['total_fee'],
  522. "pakge_fee"=>$zxinfo['pakge_fee'],
  523. "cert_fee"=>$zxinfo['cert_fee'],
  524. "open_fee"=>$zxinfo['open_fee'],
  525. "cost_fee"=>$zxinfo['cost_fee'],
  526. "mark_fee"=>$zxinfo['mark_fee'],
  527. "demo_fee"=>$zxinfo['demo_fee'],
  528. "good_num"=>$good_num,
  529. "good_type"=>1,
  530. "is_diff"=>$zxinfo['is_diff'],
  531. "order_type"=>3,
  532. ];
  533. $token=isset($this->post['token'])&&$this->post['token']!=""? trim($this->post['token']):"";
  534. if($token==""){
  535. return error_show(102, "参数token不能为空");
  536. }
  537. $apply_id = GetUserInfo($token);
  538. if (empty($apply_id) || $apply_id['code'] != 0) {
  539. return error_show(102, "申请人数据不存在");
  540. }
  541. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  542. $ri = isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  543. $va = isset($this->post['order_addr']) && $this->post['order_addr'] !== "" ? $this->post['order_addr'] : "";
  544. if($sendtype==1){
  545. if ($va == "") {
  546. return error_show(1002, "参数order_addr不能为空");
  547. }
  548. }
  549. $arrtime=isset($this->post['arrtime'])&&$this->post['arrtime']!="" ?$this->post['arrtime']:"";
  550. if($arrtime==""){
  551. return error_show(1002, "参数arrtime不能为空");
  552. }
  553. Db::startTrans();
  554. try{
  555. $data=[
  556. "orderCode"=>$orderCode,
  557. "good_code"=>$spuCode,
  558. "skuCode"=>$skuCode,
  559. "customer_code"=>$zxorder['khNo'],
  560. "good_name"=>isset($zxinfo['good_name'])&&$zxinfo['good_name']!==''?$zxinfo['good_name']:'',
  561. "good_num"=>$good_num,
  562. "cat_id"=>$zxinfo['cat_id'],
  563. "apply_id"=>$rm,
  564. "apply_name"=>$ri,
  565. "origin_price"=>$zxinfo['nake_fee'],
  566. "sale_price"=>$zxinfo['sale_price'],
  567. "post_fee"=>0,
  568. "status"=>0,
  569. "send_num"=>0,
  570. "wsend_num"=>$good_num,
  571. "send_status"=>1,
  572. "good_type"=>1,
  573. "send_type"=>$sendtype,
  574. "supplierNo"=>$zxorder['companyNo'],
  575. "is_del"=>0,
  576. "zxNo"=>$bidNo,
  577. "platform_order"=>"",
  578. "platform_id"=>0,
  579. "remark"=>"",
  580. "arrivetime"=>$arrtime,
  581. "is_stock"=>0,
  582. "is_activity"=>0,
  583. "proof_id"=>0,
  584. "order_type"=>3,
  585. "addtime"=>date("Y-m-d H:i:s"),
  586. "updatetime"=>date("Y-m-d H:i:s"),
  587. 'total_price'=>round($zxinfo['sale_price']*$good_num,2),
  588. ];
  589. $datainfo = Db::name('sale')->insert($data, true);
  590. if($datainfo>0){
  591. $zx['status']=5;
  592. $zx['updatetime']=date("Y-m-d H:i:s");
  593. $sa=Db::name("consult_info")->save($zx);
  594. if($sa==false){
  595. Db::rollback();
  596. return error_show(1002,"咨询单修改失败");
  597. }
  598. $bol=$this->createCgd($cgd);
  599. if($bol==false){
  600. Db::rollback();
  601. return error_show(1002,"咨询订单创建失败");
  602. }
  603. $limt=[
  604. "spuCode"=>$zxinfo['spuCode'],
  605. "good_name"=>$zxinfo['good_name'],
  606. "brand_id"=>$zxinfo['brand_id'],
  607. "good_unit"=>$zxinfo['good_name'],
  608. "cat_id"=>$zxinfo['cat_id'],
  609. "good_type"=>0,
  610. "moq"=>1,
  611. "customized"=>$zxinfo['work_day'],
  612. "tax"=>$zxinfo['tax'],
  613. "supplierNo"=>$zxinfo["supplierNo"],
  614. "is_auth"=>0,
  615. "craft_desc"=>$zxinfo['good_name'],
  616. "good_remark"=>"",
  617. "good_img"=>$zxinfo['good_img'],
  618. "good_thumb_img"=>"",
  619. "good_info_img"=>"",
  620. "status"=>1,
  621. "is_del"=>0,
  622. "createrid"=>$rm,
  623. "creater"=>$ri,
  624. "addtime"=>date("Y-m-d H:i:s"),
  625. "updatetime"=>date("Y-m-d H:i:s")
  626. ];
  627. $good = Db::name("good_zixun")->insert($limt);
  628. if(!$good){
  629. Db::rollback();
  630. return error_show(1006,"咨询商品录入失败");
  631. }
  632. if(!empty($va)){
  633. $order =Db::name("order_num")->where(["orderCode"=>$orderCode,"status"=>1])->where([["wsend_num",">=",0]])
  634. ->find();
  635. if($order==false){
  636. Db::rollback();
  637. return error_show(1006,"采购单关联数据未找到");
  638. }
  639. foreach ($va as $value){
  640. $temp=[];
  641. $addrs=[];
  642. if($value['addr_code']!==''&&is_array($value['addr_code'])){
  643. $addrs['provice_code'] = $value['addr_code'][0];
  644. $addrs['city_code'] = $value['addr_code'][1];
  645. $addrs['area_code'] = $value['addr_code'][2];
  646. $addr = json_encode($addrs);
  647. }else{
  648. $addr = isset($value['addr_code'])?$value['addr_code']:'';
  649. }
  650. $temp['orderCode']=$orderCode;
  651. $temp['contactor']=$value['contactor'];
  652. $temp['mobile'] = $value['mobile'];
  653. $temp['addr'] = $value['addr'];
  654. $temp['addr_code']=$addr;
  655. $temp['customer_code'] =$zxorder['khNo'];
  656. $temp['receipt_quantity']=$value['receipt_quantity'];
  657. $temp['post_fee'] =0;
  658. $temp['is_del'] =0;
  659. $temp['addtime'] =date("Y-m-d H:i:s");
  660. $temp['updatetime'] =date("Y-m-d H:i:s");
  661. $temp['arrive_time']=$arrtime;
  662. $vmp = Db::name('order_addr')->insert($temp,true);
  663. if($vmp>0){
  664. $outCode=makeNo("CK");
  665. $out=[
  666. "orderCode"=>$orderCode,
  667. "outCode"=>$outCode,
  668. "apply_id"=>$rm,
  669. "apply_name"=>$ri,
  670. "addrid"=>$vmp,
  671. "post_name"=>"",
  672. "post_code"=>"",
  673. "post_fee"=>0,
  674. "sendtime"=>date("Y-m-d H:i:s"),
  675. "send_num"=>$value['receipt_quantity'],
  676. "check_num"=>0,
  677. "error_num"=>0,
  678. "wsm_code"=>"",
  679. "order_type"=>3,
  680. "status"=>0,
  681. "addtime"=>date("Y-m-d H:i:s"),
  682. "updatetime"=>date("Y-m-d H:i:s")
  683. ];
  684. $ou =Db::name("order_out")->insert($out);
  685. if($ou==false){
  686. Db::rollback();
  687. return error_show(1002,"发货地址添加创建失败");
  688. }
  689. $order['send_num']+=$value['receipt_quantity'];
  690. $order['wsend_num']-=$value['receipt_quantity'];
  691. if($order['wsend_num']<0){
  692. Db::rollback();
  693. return error_show(1002,"发货数量已超出总数");
  694. }
  695. $ups = Db::name("order_num")->save($order);
  696. if($ups){
  697. $tep=[
  698. "cgdNo"=>$order['cgdNo'],
  699. "outCode"=>$outCode,
  700. "send_num"=>$value['receipt_quantity'],
  701. "status"=>1,
  702. "addtime"=>date("Y-m-d H:i:s"),
  703. "updatetime"=>date("Y-m-d H:i:s")
  704. ];
  705. $sen=Db::name("order_send")->save($tep);
  706. if($sen==false){
  707. Db::rollback();
  708. return error_show(1002,"发货地址添加创建失败");
  709. }
  710. }
  711. }else{
  712. Db::rollback();
  713. return error_show(1002,"发货地址添加创建失败");
  714. }
  715. }
  716. }
  717. Db::commit();
  718. return error_show(0,"咨询订单创建成功",["order_code"=>$orderCode]);
  719. }
  720. Db::rollback();
  721. return error_show(1002,"咨询订单创建失败");
  722. }catch(\Exception $e){
  723. Db::rollback();
  724. return error_show(1003,$e->getMessage());
  725. }
  726. }
  727. /**
  728. * @return \think\response\Json|void
  729. * @throws \think\db\exception\DataNotFoundException
  730. * @throws \think\db\exception\DbException
  731. * @throws \think\db\exception\ModelNotFoundException
  732. */
  733. public function projectCreate(){
  734. $planNo =isset($this->post['planNo'])&&$this->post['planNo']!=""?trim($this->post['planNo']):"";
  735. if($planNo==""){
  736. return error_show(1004,"参数planNo不能为空");
  737. }
  738. $plan =Db::name("project_plan")->where(["planNo"=>$planNo,"is_del"=>0])->find();
  739. if($plan==false){
  740. return error_show(1004,"未找到方案信息");
  741. }
  742. $feedbackid = Db::name("project_plan_rela")->where(["planNo"=>$planNo,"is_del"=>0])->column("feedback_id,sale_price,sale_num");
  743. if($feedbackid==false){
  744. return error_show(1004,"未找到方案反馈信息");
  745. }
  746. $project = Db::name("project")->where(["projectNo"=>$plan['projectNo'],"is_del"=>0])->find();
  747. if($project==false){
  748. return error_show(1004,"未找到方案信息");
  749. }
  750. $arrtime=isset($this->post['arrtime'])&&$this->post['arrtime']!="" ?$this->post['arrtime']:"";
  751. if($arrtime==""){
  752. return error_show(1002, "参数arrtime不能为空");
  753. }
  754. $planinfo =isset($this->post['planinfo'])&&!empty($this->post['planinfo']) ?$this->post['planinfo']:"";
  755. if($planinfo==""){
  756. return error_show(1002, "参数planinfo不能为空");
  757. }
  758. $token=isset($this->post['token'])&&$this->post['token']!=""? trim($this->post['token']):"";
  759. if($token==""){
  760. return error_show(102, "参数token不能为空");
  761. }
  762. $apply_id = GetUserInfo($token);
  763. if (empty($apply_id) || $apply_id['code'] != 0) {
  764. return error_show(102, "申请人数据不存在");
  765. }
  766. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  767. $ri = isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  768. Db::startTrans();
  769. try {
  770. $feedid = array_column($feedbackid,"feedback_id");
  771. foreach ($planinfo as $value){
  772. $good=[];
  773. $feedback = Db::name("project_feedback")->where(["id"=>$value['feedback_id'],"projectNo"=>$plan['projectNo'],
  774. "is_del"=>0])->find();
  775. if($feedback==false){
  776. Db::rollback();
  777. return error_show(1002, "反馈数据未找到");
  778. }
  779. $key =array_search($feedback['id'],$feedid);
  780. $price = $feedbackid[$key];
  781. $good['spuCode'] = $feedback['spuCode'];
  782. $good['skuCode'] = $feedback['skuCode'];
  783. $good['good_num'] = $price['sale_num'];
  784. $good['sendtype'] = $value['sendtype'];
  785. $good['sale_price']=$price['sale_price'];
  786. $good['origin_price']=$feedback['origin_price'];
  787. $good['companyNo']=$project['companyNo'];
  788. $good['customerNo']=$project['khNo'];
  789. $good['pgNo']=$feedback['pgNo'];
  790. $good['arrtime']=$arrtime;
  791. $good['rm']=$rm;
  792. $good['ri']=$ri;
  793. if($value['sendtype']==1){
  794. if(!isset($value['addrlist'])||empty($value['addrlist'])){
  795. Db::rollback();
  796. return error_show(1002, "订单地址不能为空");
  797. }
  798. $good['addrlist'] = $value['addrlist'];
  799. }
  800. if($feedback['data_source']==1){
  801. $feed=$this->project_good($good);
  802. }else{
  803. $feed=$this->project_zx($good);
  804. }
  805. if($feed==false){
  806. Db::rollback();
  807. return error_show(1002, "咨询订单生成失败");
  808. }
  809. $feedback['status']=2;
  810. $feedback['updatetime']=date("Y-m-d H:i:s");
  811. $fed =Db::name("project_feedback")->save($feedback);
  812. if($fed==false){
  813. Db::rollback();
  814. return error_show(1002, "项目订单生成失败");
  815. }
  816. }
  817. $plan['status']=2;
  818. $plan['updatetime']=date("Y-m-d H:i:s");
  819. $in =Db::name("project_plan")->save($plan);
  820. if($in==false){
  821. Db::rollback();
  822. return error_show(1002, "项目订单生成失败");
  823. }
  824. $project["status"]=6;
  825. $project['updatetime']=date("Y-m-d H:i:s");
  826. $pr =Db::name("project")->save($project);
  827. if($pr==false){
  828. Db::rollback();
  829. return error_show(1002, "项目订单生成失败");
  830. }
  831. Db::commit();
  832. return app_show(0, "咨询订单生成成功");
  833. }catch (\Exception $e){
  834. Db::rollback();
  835. return error_show(1002, $e->getMessage());
  836. }
  837. }
  838. /**
  839. * @param $data
  840. * @return false
  841. * @throws \think\db\exception\DataNotFoundException
  842. * @throws \think\db\exception\DbException
  843. * @throws \think\db\exception\ModelNotFoundException
  844. *
  845. */
  846. public function project_zx($data){
  847. $goodinfo = Db::name("consult_bids")->where(["spuCode"=>$data['spuCode'],"is_del"=>0])->find();
  848. if($goodinfo==false){
  849. return false;
  850. }
  851. $orderCode=makeNo("QR");
  852. $cgd=[
  853. "supplierNo"=>$goodinfo['supplierNo'],
  854. "companyNo"=>$data['companyNo'],
  855. "spuCode"=>$data['spuCode'],
  856. "skuCode"=>"",
  857. "orderCode"=>$orderCode,
  858. "good_name"=>$goodinfo['good_name'],
  859. "sale_price"=>$data['origin_price'],
  860. "total_fee"=>$data['origin_price']*$data['good_num'],
  861. "pakge_fee"=>$goodinfo['pakge_fee'],
  862. "cert_fee"=>$goodinfo['cert_fee'],
  863. "open_fee"=>$goodinfo['open_fee'],
  864. "cost_fee"=>$goodinfo['cost_fee'],
  865. "mark_fee"=>$goodinfo['mark_fee'],
  866. "demo_fee"=>$goodinfo['demo_fee'],
  867. "good_num"=>$data['good_num'],
  868. "good_type"=>1,
  869. "order_type"=>4,
  870. ];
  871. $datas=[
  872. "orderCode"=>$orderCode,
  873. "good_code"=>$data['spuCode'],
  874. "skuCode"=>"",
  875. "customer_code"=>$data['customerNo'],
  876. "good_name"=>isset($goodinfo['good_name'])&&$goodinfo['good_name']!==''?$goodinfo['good_name']:'',
  877. "good_num"=>$data['good_num'],
  878. "cat_id"=>$goodinfo['cat_id'],
  879. "apply_id"=>$data['rm'],
  880. "apply_name"=>$data['ri'],
  881. "origin_price"=>$goodinfo['nake_fee'],
  882. "sale_price"=>$data['sale_price'],
  883. "post_fee"=>0,
  884. "status"=>0,
  885. "send_num"=>0,
  886. "wsend_num"=>$data['good_num'],
  887. "send_status"=>1,
  888. "good_type"=>1,
  889. "send_type"=>$data['sendtype'],
  890. "supplierNo"=>$data['companyNo'],
  891. "is_del"=>0,
  892. "zxNo"=>$data["pgNo"],
  893. "platform_order"=>"",
  894. "platform_id"=>0,
  895. "remark"=>"",
  896. "is_stock"=>0,
  897. "is_activity"=>0,
  898. "proof_id"=>0,
  899. "order_type"=>4,
  900. "addtime"=>date("Y-m-d H:i:s"),
  901. "updatetime"=>date("Y-m-d H:i:s"),
  902. 'total_price'=>round($data['sale_price']*$data['good_num'],2),
  903. ];
  904. $datainfo = Db::name('sale')->insert($datas, true);
  905. if($datainfo>0){
  906. $bol = $this->createCgd($cgd);
  907. if ($bol == false) {
  908. return false;
  909. }
  910. $goodinfo['status']=6;
  911. $goodinfo['updatetime']=date("Y-m-d H:i:s");
  912. $sa=Db::name("consult_bids")->save($goodinfo);
  913. if($sa==false){
  914. return false;
  915. }
  916. if ($data['sendtype']==1&&!empty($data['addrlist'])) {
  917. $order = Db::name("order_num")->where(["orderCode" => $orderCode, "status" => 1])->where([["wsend_num", ">=", 0]])
  918. ->find();
  919. if ($order == false) {
  920. return false;
  921. }
  922. foreach ($data['addrlist'] as $value) {
  923. $temp = [];
  924. $addrs = [];
  925. if ($value['addr_code'] !== '' && is_array($value['addr_code'])) {
  926. $addrs['provice_code'] = $value['addr_code'][0];
  927. $addrs['city_code'] = $value['addr_code'][1];
  928. $addrs['area_code'] = $value['addr_code'][2];
  929. $addr = json_encode($addrs);
  930. } else {
  931. $addr = isset($value['addr_code']) ? $value['addr_code'] : '';
  932. }
  933. $temp['orderCode'] = $orderCode;
  934. $temp['contactor'] = $value['contactor'];
  935. $temp['mobile'] = $value['mobile'];
  936. $temp['addr'] = $value['addr'];
  937. $temp['addr_code'] = $addr;
  938. $temp['customer_code'] = $data['companyNo'];
  939. $temp['receipt_quantity'] = $value['receipt_quantity'];
  940. $temp['post_fee'] = 0;
  941. $temp['is_del'] = 0;
  942. $temp['addtime'] = date("Y-m-d H:i:s");
  943. $temp['updatetime'] = date("Y-m-d H:i:s");
  944. $temp['arrive_time'] = $data['arrtime'];
  945. $vmp = Db::name('order_addr')->insert($temp, true);
  946. if ($vmp > 0) {
  947. $outCode = makeNo("CK");
  948. $out = [
  949. "orderCode" => $orderCode,
  950. "outCode" => $outCode,
  951. "apply_id"=>$data['rm'],
  952. "apply_name"=>$data['ri'],
  953. "addrid" => $vmp,
  954. "post_name" => "",
  955. "post_code" => "",
  956. "post_fee" => 0,
  957. "sendtime" => date("Y-m-d H:i:s"),
  958. "send_num" => $value['receipt_quantity'],
  959. "check_num" => 0,
  960. "error_num" => 0,
  961. "wsm_code" => "",
  962. "order_type" => 4,
  963. "status" => 0,
  964. "addtime" => date("Y-m-d H:i:s"),
  965. "updatetime" => date("Y-m-d H:i:s")
  966. ];
  967. $ou = Db::name("order_out")->insert($out);
  968. if ($ou == false) {
  969. return false;
  970. }
  971. $order['send_num'] += $value['receipt_quantity'];
  972. $order['wsend_num'] -= $value['receipt_quantity'];
  973. if ($order['wsend_num'] < 0) {
  974. return false;
  975. }
  976. $ups = Db::name("order_num")->save($order);
  977. if ($ups) {
  978. $tep = [
  979. "cgdNo" => $order['cgdNo'],
  980. "outCode" => $outCode,
  981. "send_num" => $value['receipt_quantity'],
  982. "status" => 1,
  983. "addtime" => date("Y-m-d H:i:s"),
  984. "updatetime" => date("Y-m-d H:i:s")
  985. ];
  986. $sen = Db::name("order_send")->save($tep);
  987. if ($sen == false) {
  988. return false;
  989. }
  990. }
  991. } else {
  992. return false;
  993. }
  994. }
  995. }
  996. }
  997. return true;
  998. }
  999. /**
  1000. * @param $data
  1001. * @return bool
  1002. * @throws \think\db\exception\DataNotFoundException
  1003. * @throws \think\db\exception\DbException
  1004. * @throws \think\db\exception\ModelNotFoundException
  1005. */
  1006. public function project_good($data){
  1007. $good=Db::name('good')->alias("a")->leftJoin("good_platform b","a.spuCode=b.spuCode")->where(["b.skuCode"=>$data['skuCode'],"a.is_del"=>0,"b.is_del"=>0])->find();
  1008. if($good==false){
  1009. return false;
  1010. }
  1011. $orderCode=makeNo("QR");
  1012. $datas=[
  1013. "orderCode"=>$orderCode,
  1014. "good_code"=>$data['spuCode'],
  1015. "skuCode"=>$data['skuCode'],
  1016. "customer_code"=>$data['customerNo'],
  1017. "good_name"=>isset($good['good_name'])&&$good['good_name']!==''?$good['good_name']:'',
  1018. "good_num"=>$data['good_num'],
  1019. "cat_id"=>$good['cat_id'],
  1020. "apply_id"=>$data['rm'],
  1021. "apply_name"=>$data['ri'],
  1022. "origin_price"=>$good['nake_price'],
  1023. "sale_price"=>$data['sale_price'],
  1024. "post_fee"=>0,
  1025. "status"=>0,
  1026. "send_num"=>0,
  1027. "wsend_num"=>$data['good_num'],
  1028. "send_status"=>1,
  1029. "good_type"=>1,
  1030. "send_type"=>$data['sendtype'],
  1031. "supplierNo"=>$data['companyNo'],
  1032. "is_del"=>0,
  1033. "zxNo"=>$data["pgNo"],
  1034. "platform_order"=>"",
  1035. "platform_id"=>0,
  1036. "remark"=>"",
  1037. "is_stock"=>$good['is_stock'],
  1038. "is_activity"=>0,
  1039. "proof_id"=>0,
  1040. "order_type"=>$good['is_stock']==1?2:4,
  1041. "addtime"=>date("Y-m-d H:i:s"),
  1042. "updatetime"=>date("Y-m-d H:i:s"),
  1043. 'total_price'=>round($data['sale_price']*$data['good_num'],2),
  1044. ];
  1045. $datainfo = Db::name('sale')->insert($datas, true);
  1046. if($datainfo>0) {
  1047. $cgd=[
  1048. "supplierNo"=>$good['supplierNo'],
  1049. "companyNo"=>$data['companyNo'],
  1050. "orderCode"=>$orderCode,
  1051. "spuCode"=>$good['spuCode'],
  1052. "skuCode"=>$good['skuCode'],
  1053. "good_name"=>$good['good_name'],
  1054. "sale_price"=>$data['origin_price'],
  1055. "total_fee"=>$data['origin_price']*$data['good_num'],
  1056. "pakge_fee"=>$good['packing_fee'],
  1057. "cert_fee"=>$good['cert_fee'],
  1058. "open_fee"=>$good['open_fee'],
  1059. "cost_fee"=>$good['cost_fee'],
  1060. "mark_fee"=>$good['mark_fee'],
  1061. "demo_fee"=>$good['demo_fee'],
  1062. "good_num"=>$data['good_num'],
  1063. "good_type"=>1,
  1064. "order_type"=>2,
  1065. ];
  1066. if($good['is_stock']==0) {
  1067. $bol = $this->createCgd($cgd);
  1068. if ($bol == false) {
  1069. return false;
  1070. }
  1071. }
  1072. if ($data['sendtype']==1&&!empty($data['addrlist'])) {
  1073. $order = Db::name("order_num")->where(["orderCode" => $orderCode, "status" => 1])->where([["wsend_num", ">=", 0]])
  1074. ->find();
  1075. if ($order == false) {
  1076. return false;
  1077. }
  1078. foreach ($data['addrlist'] as $value) {
  1079. $temp = [];
  1080. $addrs = [];
  1081. if ($value['addr_code'] !== '' && is_array($value['addr_code'])) {
  1082. $addrs['provice_code'] = $value['addr_code'][0];
  1083. $addrs['city_code'] = $value['addr_code'][1];
  1084. $addrs['area_code'] = $value['addr_code'][2];
  1085. $addr = json_encode($addrs);
  1086. } else {
  1087. $addr = isset($value['addr_code']) ? $value['addr_code'] : '';
  1088. }
  1089. $temp['orderCode'] = $orderCode;
  1090. $temp['contactor'] = $value['contactor'];
  1091. $temp['mobile'] = $value['mobile'];
  1092. $temp['addr'] = $value['addr'];
  1093. $temp['addr_code'] = $addr;
  1094. $temp['customer_code'] =$data['companyNo'];
  1095. $temp['receipt_quantity'] = $value['receipt_quantity'];
  1096. $temp['post_fee'] = 0;
  1097. $temp['is_del'] = 0;
  1098. $temp['addtime'] = date("Y-m-d H:i:s");
  1099. $temp['updatetime'] = date("Y-m-d H:i:s");
  1100. $temp['arrive_time'] = $data['arrtime'];
  1101. $vmp = Db::name('order_addr')->insert($temp, true);
  1102. if ($vmp > 0) {
  1103. if($good['is_stock']!=1){
  1104. $outCode = makeNo("CK");
  1105. $out = [
  1106. "orderCode" => $orderCode,
  1107. "outCode" => $outCode,
  1108. "apply_id"=>$data['rm'],
  1109. "apply_name"=>$data['ri'],
  1110. "addrid" => $vmp,
  1111. "post_name" => "",
  1112. "post_code" => "",
  1113. "post_fee" => 0,
  1114. "sendtime" => date("Y-m-d H:i:s"),
  1115. "send_num" => $value['receipt_quantity'],
  1116. "check_num" => 0,
  1117. "error_num" => 0,
  1118. "wsm_code" => "",
  1119. "order_type" => 4,
  1120. "status" => 0,
  1121. "addtime" => date("Y-m-d H:i:s"),
  1122. "updatetime" => date("Y-m-d H:i:s")
  1123. ];
  1124. $ou = Db::name("order_out")->insert($out);
  1125. if ($ou == false) {
  1126. return false;
  1127. }
  1128. $order['send_num'] += $value['receipt_quantity'];
  1129. $order['wsend_num'] -= $value['receipt_quantity'];
  1130. if ($order['wsend_num'] < 0) {
  1131. return false;
  1132. }
  1133. $ups = Db::name("order_num")->save($order);
  1134. if ($ups) {
  1135. $tep = [
  1136. "cgdNo" => $order['cgdNo'],
  1137. "outCode" => $outCode,
  1138. "send_num" => $value['receipt_quantity'],
  1139. "status" => 1,
  1140. "addtime" => date("Y-m-d H:i:s"),
  1141. "updatetime" => date("Y-m-d H:i:s")
  1142. ];
  1143. $sen = Db::name("order_send")->insert($tep);
  1144. if ($sen == false) {
  1145. return false;
  1146. }
  1147. }
  1148. }
  1149. } else {
  1150. return false;
  1151. }
  1152. }
  1153. }
  1154. }
  1155. return true;
  1156. }
  1157. public function list()
  1158. {
  1159. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  1160. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  1161. $where[] = ['is_del', "=", 0];
  1162. $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !== "" ? trim($this->post['orderCode']) : "";
  1163. if ($orderCode !== "") {
  1164. $where[] = ['orderCode', "like", "%$orderCode%"];
  1165. }
  1166. $apply_name = isset($this->post['apply_name']) && $this->post['apply_name'] !== "" ? trim($this->post['apply_name'])
  1167. : "";
  1168. if ($apply_name !== "") {
  1169. $where[] = ['apply_name', "like", "%$apply_name%"];
  1170. }
  1171. $good_name = isset($this->post['good_name']) && $this->post['good_name'] !== "" ? trim($this->post['good_name'])
  1172. : "";
  1173. if ($good_name !== "") {
  1174. $where[] = ['good_name', "like", "%$good_name%"];
  1175. }
  1176. $good_code = isset($this->post['good_code']) && $this->post['good_code'] !== "" ? trim($this->post['good_code']) : "";
  1177. if ($good_code !== "") {
  1178. $where[] = ['good_code', "like", "%$good_code%"];
  1179. }
  1180. $customer_code = isset($this->post['customer_code']) && $this->post['customer_code'] !== "" ? trim($this->post['customer_code']) : "";
  1181. if ($customer_code !== "") {
  1182. $where[] = ['customer_code', "like", "%$customer_code%"];
  1183. }
  1184. $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !== "" ? trim($this->post['supplierNo']) : "";
  1185. if ($supplierNo !== "") {
  1186. $where[] = ['supplierNo', "like", "%$supplierNo%"];
  1187. }
  1188. $ordertype = isset($this->post['order_type']) && $this->post['order_type'] !== "" ? intval($this->post['order_type'])
  1189. : "";
  1190. if ($ordertype !== "") {
  1191. $where[] = ['order_type', "=", $ordertype];
  1192. }
  1193. $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  1194. if ($status !== "") {
  1195. $where[] = ['status', "=", $status];
  1196. }
  1197. $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
  1198. if ($start != "") {
  1199. $where[] = ["addtime", '>=', $start];
  1200. }
  1201. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
  1202. if ($end != "") {
  1203. $where[] = ["addtime", '<=', $end];
  1204. }
  1205. $count = Db::name('sale')->where($where)->count();
  1206. $total = ceil($count / $size);
  1207. $page = $page >= $total ? $total : $page;
  1208. $list = Db::name('sale')->where($where)->order("addtime desc")->page($page, $size)->select();
  1209. $data = [];
  1210. foreach ($list as $value) {
  1211. if($value['order_type']==3|| $value['order_type']==4){
  1212. $var = Db::name("good_zixun")->where(["spuCode"=>$value['good_code'],"is_del"=>0])->find();
  1213. }else {
  1214. $var = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
  1215. ->where(['a.skuCode' => $value['sku_code']])->find();
  1216. }
  1217. $value['can'] = isset($var['cat_id']) && $var['cat_id'] != 0 ? made($var['cat_id']) : [];
  1218. $value['supplierName'] = '';
  1219. if ($value['supplierNo'] != "") {
  1220. $supplier = Db::name("business")->where(["companyNo" => $value['supplierNo']])->find();
  1221. $value['supplierName'] = isset($supplier['company']) ? $supplier['company'] : "";
  1222. }
  1223. $value['customerName'] = '';
  1224. if ($value['customer_code'] != "") {
  1225. $supplier = Db::name("customer_info")->where(["companyNo" => $value['customer_code']])->find();
  1226. $value['customerName'] = isset($supplier['companyName']) ? $supplier['companyName'] : "";
  1227. }
  1228. $data[] = $value;
  1229. }
  1230. return app_show(0, "获取成功", ['list' => $data, 'count' => $count]);
  1231. }
  1232. public function edit()
  1233. {
  1234. $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
  1235. $id = isset($this->post['id']) && $this->post['id'] !== "" ? trim($this->post['id']) : "";
  1236. if ($id == "") {
  1237. return error_show(1002, "参数id不能为空");
  1238. }
  1239. $etid = Db::name("sale")->where(["id" => $id, "is_del" => 0])->find();
  1240. if (empty($etid)) {
  1241. return error_show(1002, "未找到数据");
  1242. }
  1243. // $orderCode=isset($this->post['orderCode']) && $this->post['orderCode'] !=="" ? trim($this->post['orderCode']) :"";
  1244. // if($orderCode==""){
  1245. // return error_show(1002,"销售单code不能为空");
  1246. // }
  1247. $good_code = isset($this->post['good_code']) && $this->post['good_code'] !== "" ? trim($this->post['good_code']) : "";
  1248. if ($good_code == "") {
  1249. return error_show(1002, "商品code不能为空");
  1250. }
  1251. $ct = Db::name('good')->alias('a')->join('good_type b', 'b.good_code=a.good_code', 'left')
  1252. ->where(['b.type_code' => $good_code])->find();
  1253. if ($ct == "") {
  1254. return error_show(1002, "未找到商品数据");
  1255. }
  1256. $customer_code = isset($this->post['customer_code']) && $this->post['customer_code'] !== "" ? trim($this->post['customer_code']) : "";
  1257. if ($customer_code == "") {
  1258. return error_show(1002, "客户code不能为空");
  1259. }
  1260. $customer = Db::name("customer_info")->where(["companyNo" => $customer_code])->find();
  1261. if ($customer == false) {
  1262. return error_show(1004, "未找到客户数据");
  1263. }
  1264. $supplierNo = $this->post['supplierNo'] && $this->post['supplierNo'] !== "" ? trim($this->post['supplierNo']) : "";
  1265. if ($supplierNo == "") {
  1266. return error_show(1002, "参数supplierNo不能为空");
  1267. }
  1268. $supplier = Db::name("supplier")->where(["code" => $supplierNo])->find();
  1269. if ($supplier == false) {
  1270. return error_show(1004, "未找到平台供应商数据");
  1271. }
  1272. $apply_id = GetUserInfo($token);
  1273. if (empty($apply_id) || $apply_id['code'] != 0) {
  1274. return error_show(1002, "申请人数据不存在");
  1275. }
  1276. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1277. $ri = isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  1278. // $good_name = isset($this->post['good_name']) && $this->post['good_name'] !== "" ? trim
  1279. //($this->post['good_name']) : "";
  1280. // $good_num = isset($this->post['good_num']) && $this->post['good_num'] !== "" ? intval
  1281. //($this->post['good_num']) : "";
  1282. // $origin_price = isset($this->post['origin_price']) && $this->post['origin_price'] !== "" ? intval
  1283. // ($this->post['origin_price']) : "";
  1284. // $sale_price = isset($this->post['sale_price']) && $this->post['sale_price'] !== "" ? trim($this->post['sale_price']) : "";
  1285. // $total_price = isset($this->post['total_price']) && $this->post['total_price'] !== "" ? trim($this->post['total_price']) : "";
  1286. // $post_fee = isset($this->post['post_fee']) && $this->post['post_fee'] !== "" ? trim($this->post['post_fee']) : "";
  1287. // $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  1288. $vr = isset($this->post['order_addr']) && $this->post['order_addr'] !== "" ? $this->post['order_addr'] : "";
  1289. if ($vr == "") {
  1290. return error_show(1002, "参数order_addr不能为空");
  1291. }
  1292. $vi = isset($this->post['good_stock']) && $this->post['good_stock'] !== "" ? $this->post['good_stock'] : "";
  1293. if ($vi == "") {
  1294. return error_show(1002, "参数good_stock不能为空");
  1295. }
  1296. $good_num = intval(array_sum(array_column($vi, "num")));
  1297. Db::startTrans();
  1298. try {
  1299. $datn = [
  1300. "id" => $id,
  1301. "good_code" => $good_code,
  1302. "customer_code" => $customer_code,
  1303. "good_num" => $good_num,
  1304. "supplierNo" => $supplierNo,
  1305. "apply_id" => $rm,
  1306. "apply_name" => $ri,
  1307. "is_del" => 0,
  1308. "updatetime" => date("Y-m-d H:i:s")
  1309. ];
  1310. $datninfo = Db::name('sale')->where(['id' => $id, 'is_del' => 0])->save($datn);
  1311. if ($datninfo > 0) {
  1312. $stn = ["order_code"=>$etid['orderCode'],"status"=>$etid['status'],"action_remark"=>'',"action_type"=>"edit"];
  1313. ActionLog::logAdd($this->post['token'],$stn,"XSQRD",$etid['status'],$datn);
  1314. $order=["order_type"=>'XSQRD',"order_code"=>$etid['orderCode'],"order_id"=>$id,"order_status"=>$etid['status']];
  1315. ProcessOrder::AddProcess($this->post['token'],$order);
  1316. foreach ($vi as $ion) {
  1317. $iten = [];
  1318. isset($ion['id']) && $ion['id'] !== "" ? $iten['id'] = $ion['id'] : '';
  1319. $iten['orderCode'] = $etid['orderCode'];
  1320. $iten['wsm_code'] = $ion['wsm_code'];
  1321. $iten['stock_id'] = 0;
  1322. $iten['num'] = $ion['num'];
  1323. $iten['status'] = 1;
  1324. $iten['sale_price'] = $ct['original_price'];
  1325. isset($ion['id']) && $ion['id'] !== "" ? '' : $iten['addtime'] = date("Y-m-d H:i:s");
  1326. $iten['updatetime'] = date("Y-m-d H:i:s");
  1327. $vp = Db::name('sale_info')->save($iten);
  1328. if ($vp == false)
  1329. {
  1330. Db::rollback();
  1331. return error_show(1002, "更新失败");
  1332. }
  1333. }
  1334. foreach ($vr as $value) {
  1335. $temp = [];
  1336. isset($value['id']) && $value['id'] !== "" ? $temp['id'] = $value['id'] : '';
  1337. $temp['orderCode'] = $etid['orderCode'];
  1338. $temp['contactor'] = $value['contactor'];
  1339. $temp['mobile'] = $value['mobile'];
  1340. $temp['addr'] = $value['addr'];
  1341. $temp['addr_code'] = $value['addr_code'];
  1342. $temp['customer_code'] = $customer_code;
  1343. $temp['receipt_quantity'] = $value['receipt_quantity'];
  1344. $temp['post_fee'] = 0;
  1345. $temp['is_del'] = $value['is_del'];
  1346. isset($value['id']) && $value['id'] !== "" ? '' : $temp['addtime'] = date("Y-m-d H:i:s");
  1347. $temp['updatetime'] = date("Y-m-d H:i:s");
  1348. $temp['arrive_time'] = date("Y-m-d H:i:s");
  1349. $dat = Db::name('order_addr')->save($temp);
  1350. if ($dat == false) {
  1351. Db::rollback();
  1352. return error_show(1002, "更新失败");
  1353. }
  1354. }
  1355. Db::commit();
  1356. return error_show(0, "更新成功");
  1357. }
  1358. Db::rollback();
  1359. return error_show(1002, "更新失败");
  1360. } catch (Exception $e) {
  1361. Db::rollback();
  1362. return error_show(1005, $e->getMessage());
  1363. }
  1364. }
  1365. public function info()
  1366. {
  1367. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  1368. if ($id == "") {
  1369. return error_show(1002, "参数id不能为空");
  1370. }
  1371. //->field('good_code,good_name,good_num,customer_code,orderCode')
  1372. $einfo = Db::name('sale')->where(['id' => $id, 'is_del' => 0])->find();
  1373. if (empty($einfo)) {
  1374. return error_show(1002, "未找到销售订单数据");
  1375. }
  1376. $info = Db::name('sale_diff')->where(['orderCode' => $einfo['orderCode']])->select();
  1377. //$de = Db::name('order_out')->where(['orderCode' => $einfo['orderCode']])->select();
  1378. $dm = Db::name('order_return')->where(['orderCode' => $einfo['orderCode']])->select();
  1379. $dk = Db::name('order_back')->where(['orderCode' => $einfo['orderCode']])->select();
  1380. $sa = Db::name('sale_return')->where(['orderCode' => $einfo['orderCode']])->select();
  1381. if($einfo['order_type']==3|| $einfo['order_type']==4){
  1382. $goon = Db::name("good_zixun")->where(["spuCode"=>$einfo['good_code'],"is_del"=>0])->find();
  1383. }else {
  1384. $goon = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
  1385. ->where(['a.skuCode' => $einfo['sku_code']])->find();
  1386. }
  1387. if ($goon==false) {
  1388. return error_show(1003, "未找到商品数据");
  1389. }
  1390. $int = isset($goon['cat_id']) && $goon['cat_id'] != 0 ? made($goon['cat_id']) : [];
  1391. $in = Db::name('customer_info')->where(['companyNo' => $einfo['customer_code']])->field('companyName')->find();
  1392. // ->field('addr,contactor,mobile,receipt_quantity,arrive_time')
  1393. $einfo['supplierName'] = '';
  1394. if ($einfo['supplierNo'] != "") {
  1395. $supplier = Db::name("bussiness")->where(["companyNo" => $einfo['supplierNo']])->find();
  1396. $einfo['supplierName'] = isset($supplier['company']) ? $supplier['company'] : "";
  1397. }
  1398. $fo = Db::name('order_addr')->where(['orderCode' => $einfo['orderCode'], 'is_del' => 0])->select();
  1399. $bum = Db::name('order_out')->where(['orderCode' => $einfo['orderCode']])->select();
  1400. $ins = [];
  1401. if (!empty($bum)) {
  1402. foreach ($bum as $stn) {
  1403. $so = Db::name('order_addr')->where(['id' => $stn['addrid']])->find();
  1404. $addr = GetAddr($so['addr_code']);
  1405. $stn['addr_info'] = $addr;
  1406. $stn['add_code'] = json_decode($so['addr_code'], true);
  1407. $stn['addr'] = $so['addr'];
  1408. $stn['contact'] = $so['contactor'];
  1409. $stn['mobile'] = $so['mobile'];
  1410. $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b", "a.supplierNo=b.code")
  1411. ->where(["a.wsm_code" => $stn['wsm_code']])->field("a.name as wsm_name,b.name,b.code")->find();
  1412. $stn['wsm_name'] = isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name'] : "";
  1413. $stn['wsm_supplier'] = isset($wsmcode['name']) ? $wsmcode['name'] : "";
  1414. $stn['wsm_supplierNo'] = isset($wsmcode['code']) ? $wsmcode['code'] : "";
  1415. $ins[] = $stn;
  1416. }
  1417. }
  1418. $addrs = [];
  1419. if (!empty($fo)) {
  1420. foreach ($fo as $value) {
  1421. $value['addr_info'] = "";
  1422. $value['send_num'] = 0;
  1423. if ($value['addr_code'] != "") {
  1424. $addr = GetAddr($value['addr_code']);
  1425. $value['addr_info'] = $addr;
  1426. $value['addr_code'] = json_decode($value['addr_code'], true);
  1427. $send = Db::name("order_out")->where(['addrid' => $value['id'], 'orderCode' => $einfo['orderCode']])->sum("send_num");
  1428. $value['send_num'] = $send ?? 0;
  1429. }
  1430. $value['wsend_num'] = $value['receipt_quantity'] - $value['send_num'];
  1431. $addrs[] = $value;
  1432. }
  1433. }
  1434. //->field('num,sale_price,wsm_code,stock_id')
  1435. $st = Db::name('sale_info')->where(['orderCode' => $einfo['orderCode']])->select();
  1436. $data = [];
  1437. if (!empty($fo)) {
  1438. foreach ($st as $value) {
  1439. $value['wsm_name'] = "";
  1440. $value['wsm_supplier'] = "";
  1441. $value['wsm_supplierNo'] = "";
  1442. $value['usable_stock'] = 0;
  1443. $value['send_num'] = 0;
  1444. if ($value['wsm_code'] != "") {
  1445. $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b", "a.supplierNo=b.code")
  1446. ->where(["a.wsm_code" => $value['wsm_code']])->field("a.name as wsm_name,b.name,b.code")->find();
  1447. $value['wsm_name'] = isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name'] : "";
  1448. $value['wsm_supplier'] = isset($wsmcode['name']) ? $wsmcode['name'] : "";
  1449. $value['wsm_supplierNo'] = isset($wsmcode['code']) ? $wsmcode['code'] : "";
  1450. $dn = Db::name('good_stock')->where(['wsm_code' => $value['wsm_code'], 'good_type_code' => $einfo['good_code']])->find();
  1451. $value['usable_stock'] = isset($dn['usable_stock']) ? $dn['usable_stock'] : "0";
  1452. $send = Db::name("order_out")->where(["wsm_code" => $value['wsm_code'], 'orderCode' => $einfo['orderCode']])->sum("send_num");
  1453. $value['send_num'] = $send ?? 0;
  1454. }
  1455. $value['wsend_num'] = $value['num'] - $value['send_num'];
  1456. $data[] = $value;
  1457. }
  1458. }
  1459. $einfo['info'] = $data;
  1460. $einfo['companyName'] = isset($in['companyName']) ? $in['companyName'] : "";
  1461. $einfo['addrs'] = $addrs;
  1462. $einfo['orderout'] = $ins;
  1463. $einfo['can'] = $int;
  1464. $einfo['salediff'] = $info;
  1465. //$einfo['orderout'] = $de;
  1466. $einfo['orderreturn'] = $dm;
  1467. $einfo['orderback'] = $dk;
  1468. $einfo['salereturn'] = $sa;
  1469. if (empty($einfo)) {
  1470. return error_show(1002, "未找到销售订单数据");
  1471. } else {
  1472. return app_show(0, "获取成功", $einfo);
  1473. }
  1474. }
  1475. public function del()
  1476. {
  1477. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  1478. if ($id === "") {
  1479. return error_show(1002, "参数id不能为空");
  1480. }
  1481. $ed = Db::name('sale')->where(['id' => $id, 'is_del' => 0])->find();
  1482. if (empty($ed)) {
  1483. return error_show(1002, "未找到销售订单数据");
  1484. }
  1485. $str = Db::name('sale')->update(['id' => $id, 'is_del' => 1, 'updatetime' => date("Y-m-d H:i:s")]);
  1486. if ($str) {
  1487. $stc = ["order_code"=>$id,"status"=>$ed['status'],"action_remark"=>'',"action_type"=>"delete"];
  1488. ActionLog::logAdd($this->post['token'],$stc,"XSQRD",$ed['status'],['id' => $id, 'is_del' => 1, 'updatetime' => date("Y-m-d H:i:s")]);
  1489. $order=["order_type"=>'XSQRD',"order_code"=>$ed['orderCode'],"order_id"=>$id,"order_status"=>$ed['status']];
  1490. ProcessOrder::workdel($order);
  1491. return error_show(0, "删除成功");
  1492. } else {
  1493. return error_show(1002, "删除失败");
  1494. }
  1495. }
  1496. public function status()
  1497. {
  1498. $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
  1499. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  1500. if ($id == "") {
  1501. return error_show(1002, "参数id不能为空");
  1502. }
  1503. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  1504. if ($status == "") {
  1505. return error_show(1002, "订单状态不能为空");
  1506. }
  1507. $dio = Db::name('sale')->where(['id' => $id, 'is_del' => 0])->find();
  1508. if (empty($dio)) {
  1509. return error_show(1002, "销售单信息未找到");
  1510. }
  1511. if ($status == 1 && $dio['order_type'] == 2) {
  1512. $zxinfo = Db::name("consult")->where(["zxNo" => $dio['zxNo'], "is_del" => 0])->find();
  1513. if ($zxinfo == false) {
  1514. return error_show(1004, "未找到咨询单数据");
  1515. }
  1516. $gold['price'] = 0;
  1517. if ($zxinfo['zx_type'] == 2) {
  1518. if ($zxinfo['metals'] == "") {
  1519. return error_show(1004, "未找到咨询单贵金属类型数据");
  1520. }
  1521. $metals = $zxinfo['metals'] == '18K' ? 1 : ($zxinfo['metals'] == '24K' ? 2 : 3);
  1522. $gold = Db::name("gold_price")->where(["type" => $metals])->order("addtime desc")->find();
  1523. if (empty($gold)) {
  1524. return error_show(1004, "未找到咨询单贵金属类型数据");
  1525. }
  1526. $dio['gold_price'] = $gold['price'];
  1527. }
  1528. $wsm = Db::name("warehouse_info")->where(["supplierNo" => $zxinfo['gysNo'], "wsm_type" => 2])->find();
  1529. if (empty($wsm)) {
  1530. return error_show(1002, "供应商仓库未找到");
  1531. }
  1532. }
  1533. $apply_id = GetUserInfo($token);
  1534. if (empty($apply_id) || $apply_id['code'] != 0) {
  1535. return error_show(1002, "申请人数据不存在");
  1536. }
  1537. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1538. $ri = isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  1539. Db::startTrans();
  1540. try {
  1541. $vmp =$dio['status'];
  1542. $dio['status'] = $status;
  1543. $dio['updatetime'] = date("Y-m-d H:i:s");
  1544. $st = Db::name('sale')->save($dio);
  1545. if ($st) {
  1546. $stn = ["order_code"=>$dio['orderCode'],"status"=>$vmp,"action_remark"=>'',"action_type"=>"status"];
  1547. ActionLog::logAdd($this->post['token'],$stn, $dio['order_type'] == 2?"ZXQRD":"XSQRD",$dio['status'],$dio);
  1548. $order=["order_type"=>$dio['order_type'] == 2?"ZXQRD":"XSQRD","order_code"=>$dio['orderCode'],"order_id"=>$id,"order_status"=>$dio['status']];
  1549. ProcessOrder::AddProcess($this->post['token'],$order);
  1550. if ($status == 3 && $dio['order_type'] == 1) {
  1551. $dn = Db::name('sale_info')->where(['orderCode' => $st['orderCode']])->select();
  1552. foreach ($dn as $value) {
  1553. $dm = Db::name('good_stock')->where(['wsm_code' => $value['wsm_code'], 'good_type_code' => $st['good_code']])->find();
  1554. if ($dm == "") {
  1555. Db::rollback();
  1556. return error_show(1003, "未找到商品数据");
  1557. }
  1558. if ($value['num'] > $dm['usable_stock']) {
  1559. Db::rollback();
  1560. return error_show(1002, "超出库存数量");
  1561. }
  1562. $dm['usable_stock'] -= $value['num'];
  1563. $dm['wait_out_stock'] += $value['num'];
  1564. $send = Db::name("order_out")->where(["wsm_code" => $value['wsm_code']])->sum("send_num");
  1565. $value['send_num'] = $send ?? 0;
  1566. $value['wsend_num'] = $value['num'] - $value['send_num'];
  1567. $Db = Db::name('good_stock')->update($dm);
  1568. $Db['updatetime'] = date('Y-m-d H:i:s');
  1569. if ($Db == false) {
  1570. Db::rollback();
  1571. return error_show(1002, "状态更新失败");
  1572. }
  1573. }
  1574. }
  1575. if ($status == 1 && $dio['order_type'] == 2) {
  1576. $cgd = makeNo("CG");
  1577. $clll = [
  1578. "cgdNo" => $cgd,
  1579. "bkcode" => $dio['orderCode'],
  1580. "wsm_code" => $wsm['wsm_code'],
  1581. "cgder_id" => "0",
  1582. "cgder" => $zxinfo['saler'],
  1583. "good_code" => "GD-" . $zxinfo['cpNo'],
  1584. "good_name" => $zxinfo['cpName'],
  1585. "good_type_code" => $zxinfo['cpNo'],
  1586. "good_num" => $dio['good_num'],
  1587. "good_price" => $zxinfo['total_fee'],
  1588. "total_fee" => round($zxinfo['total_fee'] * $dio['good_num'], 2),
  1589. "pakge_fee" => $zxinfo['package_fee'],
  1590. "cert_fee" => $zxinfo['cert_fee'],
  1591. "open_fee" => $zxinfo['open_fee'],
  1592. "delivery_fee" => $zxinfo['delivery_fee'],
  1593. "mark_fee" => $zxinfo['mark_fee'],
  1594. "teach_fee" => $zxinfo['cost_fee'],
  1595. "demo_fee" => $zxinfo['demo_fee'],
  1596. "nake_fee" => $zxinfo['bare_fee'],
  1597. "weight" => isset($zxinfo['weight']) ? $zxinfo['weight'] : 0,
  1598. "supplierNo" => $zxinfo['gysNo'],
  1599. "supplier_name" => $zxinfo['gysname'],
  1600. "gold_price" => $gold['price'],
  1601. "send_num" => 0,
  1602. "wsend_num" => $dio['good_num'],
  1603. "remark" => '',
  1604. "lasttime" => date("Y-m-d H:i:s"),
  1605. "is_del" => 0,
  1606. "status" => $dio['send_type'] == 1 ? 3 : 0,
  1607. "order_type" => 2,
  1608. "addtime" => date("Y-m-d H:i:s"),
  1609. "updatetime" => date("Y-m-d H:i:s")
  1610. ];
  1611. $cgin = Db::name("purchease_order")->insert($clll);
  1612. // var_dump(Db::name("purchease_order")->getLastSql(),$clll);
  1613. if ($cgin == false) {
  1614. $stb = ["order_code"=>$cgd,"status"=> $clll['status'],"action_remark"=>'',"action_type"=>"create"];
  1615. ActionLog::logAdd($this->post['token'],$stb,"xsd", $clll['status'],$stb);
  1616. Db::rollback();
  1617. return error_show(1002, "咨询采购单创建商品失败");
  1618. }
  1619. if ($dio['send_type'] == 1) {
  1620. $addr = Db::name('order_addr')->where(["orderCode" => $dio['orderCode'], 'is_del' => 0])->select();
  1621. foreach ($addr as $value) {
  1622. $outCode = makeNo("CK");
  1623. $data = [
  1624. "wsm_code" => $wsm['wsm_code'],
  1625. "orderCode" => $dio['orderCode'],
  1626. "outCode" => $outCode,
  1627. "order_type" => $dio['order_type'],
  1628. "apply_id" => $rm,
  1629. "apply_name" => $ri,
  1630. "addrid" => $value['id'],
  1631. "post_name" => '',
  1632. "post_code" => '',
  1633. "post_fee" => '',
  1634. "sendtime" => date("Y-m-d H:i:s"),
  1635. "send_num" => $value['receipt_quantity'],
  1636. "check_num" => 0,
  1637. "error_num" => 0,
  1638. "status" => 0,
  1639. "addtime" => date("Y-m-d H:i:s"),
  1640. "updatetime" => date("Y-m-d H:i:s")
  1641. ];
  1642. $datainfo = Db::name('order_out')->insert($data);
  1643. if (!$datainfo) {
  1644. $sti = ["order_code"=>$dio['orderCode'],"status"=> 0,"action_remark"=>'',"action_type"=>"create"];
  1645. ActionLog::logAdd($this->post['token'],$sti,"xsd",0,$sti);
  1646. Db::rollback();
  1647. return error_show(1003, "创建失败");
  1648. }
  1649. }
  1650. $wsm_in_code = makeNo("IC");
  1651. $orin = [
  1652. "wsm_in_code" => $wsm_in_code,
  1653. "cgdNo" => $cgd,
  1654. "wsm_code" => $wsm['wsm_code'],
  1655. "wsm_reaper" => "",
  1656. "send_num" => $dio['good_num'],
  1657. "post_company" => '',
  1658. "post_code" => '',
  1659. "post_fee" => '',
  1660. "sendtime" => date("Y-m-d H:i:s"),
  1661. "apply_id" => $rm,
  1662. "apply_name" => $ri,
  1663. "wait_num" => 0,
  1664. "status" => 4,
  1665. "addtime" => date("Y-m-d H:i:s"),
  1666. "updatetime" => date("Y-m-d H:i:s")
  1667. ];
  1668. $win = Db::name("purchease_in")->insert($orin);
  1669. if (!$win){
  1670. $stv = ["order_code"=>$wsm_in_code,"status"=>4,"action_remark"=>'',"action_type"=>"create"];
  1671. ActionLog::logAdd($this->post['token'],$stv,"xsd",4,$stv);
  1672. Db::rollback();
  1673. return error_show(1003, "创建失败");
  1674. }
  1675. $good = Db::name("good_stock")->where(["wsm_code" => $wsm['wsm_code'], "good_type_code" => $zxinfo['cpNo'], "is_del" => 0])->find();
  1676. if (empty($good)) {
  1677. $good = [
  1678. "good_type_code" => $zxinfo['cpNo'],
  1679. "wsm_code" => $wsm['wsm_code'],
  1680. "usable_stock" => 0,
  1681. "wait_out_stock" => 0,
  1682. "total_stock" => 0,
  1683. "addtime" => date("Y-m-d H:i:s"),
  1684. "updatetime" => date("Y-m-d H:i:s"),
  1685. ];
  1686. }
  1687. $good['wait_out_stock'] += $dio['good_num'];
  1688. $good['total_stock'] = $good['usable_stock'] + $good['wait_out_stock'];
  1689. $good['updatetime'] = date("Y-m-d H:i:s");
  1690. $upd = Db::name("good_stock")->save($good);
  1691. if (!$upd) {
  1692. $ste = ["order_code"=> $zxinfo['cpNo'],"status"=>0,"action_remark"=>'',"action_type"=>"create"];
  1693. ActionLog::logAdd($this->post['token'],$ste,"xsd",0,$ste);
  1694. Db::rollback();
  1695. return error_show(1003, "创建失败");
  1696. }
  1697. }
  1698. }
  1699. }
  1700. Db::commit();
  1701. return error_show(0, "订单状态更新成功");
  1702. } catch (Exception $e) {
  1703. Db::rollback();
  1704. return error_show(1005, $e->getMessage());
  1705. }
  1706. }
  1707. public function fee()
  1708. {
  1709. $id = isset($this->post['id']) && $this->post['id'] !== "" ? trim($this->post['id']) : "";
  1710. if ($id == "") {
  1711. return error_show(1002, "参数id不能为空");
  1712. }
  1713. $etid = Db::name("sale")->where(["id" => $id, "is_del" => 0])->find();
  1714. if (empty($etid)) {
  1715. return error_show(1002, "未找到数据");
  1716. }
  1717. $vr = isset($this->post['order_addr']) && $this->post['order_addr'] !== "" ? $this->post['order_addr'] : "";
  1718. if ($vr == "") {
  1719. return error_show(1002, "参数order_addr不能为空");
  1720. }
  1721. Db::startTrans();
  1722. try {
  1723. $data = [
  1724. "id" => $id,
  1725. "status" => 2,
  1726. "is_del" => 0,
  1727. "updatetime" => date("Y-m-d H:i:s")
  1728. ];
  1729. $datainfo = Db::name('sale')->where(['id' => $id, 'is_del' => 0])->save($data);
  1730. if ($datainfo) {
  1731. $stx = ["order_code"=> $etid['orderCode'],"status"=>$etid['status'],"action_remark"=>'',
  1732. "action_type"=>"edit"];
  1733. ActionLog::logAdd($this->post['token'],$stx,$etid['order_type'] == 2?"ZXQRD":"XSQRD",2,$data);
  1734. $order=["order_type"=>$etid['order_type'] == 2?"ZXQRD":"XSQRD","order_code"=>$etid['orderCode'],"order_id"=>$id,"order_status"=>$data['status']];
  1735. ProcessOrder::AddProcess($this->post['token'],$order);
  1736. foreach ($vr as $value) {
  1737. $tm = [];
  1738. $tm['id'] = $value['id'];
  1739. $tm['orderCode'] = $etid['orderCode'];
  1740. $tm['post_fee'] = $value['post_fee'];
  1741. $tm['updatetime'] = date("Y-m-d H:i:s");
  1742. $dn = Db::name('order_addr')->save($tm);
  1743. if ($dn == false) {
  1744. Db::rollback();
  1745. return error_show(1002, "更新失败");
  1746. }
  1747. }
  1748. Db::commit();
  1749. return error_show(0, "更新成功");
  1750. }
  1751. Db::rollback();
  1752. return error_show(1003, "更新失败");
  1753. } catch (Exception $e) {
  1754. Db::rollback();
  1755. return error_show(1005, $e->getMessage());
  1756. }
  1757. }
  1758. public function out()
  1759. {
  1760. $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
  1761. $outCode = makeNo("CK");
  1762. $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !== "" ? trim($this->post['orderCode']) : "";
  1763. if ($orderCode == "") {
  1764. return error_show(1002, "参数orderCoder不能为空");
  1765. }
  1766. $der = Db::name('sale')->where(['orderCode' => $orderCode])->find();
  1767. if ($der == "") {
  1768. return error_show(1002, "未找到出库订单单号");
  1769. }
  1770. // $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code'] !== "" ? trim($this->post['wsm_code']) : "";
  1771. // if ($wsm_code == "") {
  1772. // return error_show(1002, "参数wsm_code不能为空");
  1773. // }
  1774. // $wsm = Db::name('sale_info')->where(['wsm_code' => $wsm_code, 'orderCode' => $der['orderCode']])->find();
  1775. // if ($wsm == "") {
  1776. // return error_show(1002, "未找到仓库编码");
  1777. // }
  1778. $post_name = isset($this->post['post_name']) && $this->post['post_name'] !== "" ? trim($this->post['post_name']) : "";
  1779. if ($post_name == "") {
  1780. return error_show(1002, "物流公司不能为空");
  1781. }
  1782. $post_code = isset($this->post['post_code']) && $this->post['post_code'] !== "" ? trim($this->post['post_code']) : "";
  1783. if ($post_code == "") {
  1784. return error_show(1002, "物流单号不能为空");
  1785. }
  1786. $post_fee = isset($this->post['post_fee']) && $this->post['post_fee'] !== "" ? intval($this->post['post_fee']) : "";
  1787. if ($post_fee == "") {
  1788. return error_show(1002, "物流费不能为空");
  1789. }
  1790. $send_num = isset($this->post['send_num']) && $this->post['send_num'] !== "" ? $this->post['send_num'] : "";
  1791. if ($send_num == "") {
  1792. return error_show(1002, "发货数量不能为空");
  1793. }
  1794. if ($send_num > $der['wsend_num']) {
  1795. return error_show(1002, "超出可发货数量");
  1796. }
  1797. $apply_id = GetUserInfo($token);
  1798. if (empty($apply_id) || $apply_id['code'] != 0) {
  1799. return error_show(1002, "申请人数据不存在");
  1800. }
  1801. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1802. $ri = isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  1803. $addrid = isset($this->post['addrid']) && $this->post['addrid'] !== "" ? intval($this->post['addrid']) : "";
  1804. $dr = Db::name('order_addr')->where(['id' => $addrid, 'is_del' => 0])->find();
  1805. if (empty($dr)) {
  1806. return error_show(1003, "收货人信息未找到");
  1807. }
  1808. if ($dr['orderCode'] !== $orderCode) {
  1809. return error_show(1002, "订单code不存在");
  1810. }
  1811. $sendtime = isset($this->post['sendtime']) && $this->post['sendtime'] !== "" ? $this->post['sendtime'] : date("Y-m-d H:i:s");
  1812. // $check_num = isset($this->post['check_num']) && $this->post['check_num'] !=="" ? $this->post['check_num'] :"";
  1813. // $error_num = isset($this->post['error_num']) && $this->post['error_num'] !=="" ? $this->post['error_num'] :"";
  1814. $status = isset($this->post['status']) && $this->post['status'] !== "" ? $this->post['status'] : "1";
  1815. //$order_type = isset($this->post['order_type']) && $this->post['order_type'] !=="" ? $this->post['order_type'] :"1";
  1816. //$dn=Db::name('sale_info')->where(['wsm_code'=>$outCode])->find();
  1817. Db::startTrans();
  1818. try {
  1819. $data = [
  1820. "wsm_code" => "",
  1821. "orderCode" => $orderCode,
  1822. "outCode" => $outCode,
  1823. "order_type" => $der['order_type'],
  1824. "apply_id" => $rm,
  1825. "apply_name" => $ri,
  1826. "addrid" => $dr['id'],
  1827. "post_name" => $post_name,
  1828. "post_code" => $post_code,
  1829. "post_fee" => $post_fee,
  1830. "sendtime" => $sendtime,
  1831. "send_num" => $send_num,
  1832. "check_num" => 0,
  1833. "error_num" => 0,
  1834. "status" => $status,
  1835. "addtime" => date("Y-m-d H:i:s"),
  1836. "updatetime" => date("Y-m-d H:i:s")
  1837. ];
  1838. $datainfo = Db::name('order_out')->insert($data,true);
  1839. if ($datainfo>0) {
  1840. $stx = ["order_code"=>$outCode,"status"=>$status,"action_remark"=>'',"action_type"=>"create"];
  1841. ActionLog::logAdd($this->post['token'],$stx,$der['order_type']==1?"CKD":'ZXCKD',$status,$data);
  1842. $order=["order_type"=>$der['order_type']==1?"CKD":'ZXCKD',"order_code"=>$outCode,"order_id"=>$datainfo,"order_status"=>$data['status']];
  1843. ProcessOrder::AddProcess($this->post['token'],$order);
  1844. if ($status == 1) {
  1845. $var = Db::name('sale_info')->where(['orderCode' => $orderCode, 'wsm_code' => $wsm_code])->find();
  1846. if ($var == "") {
  1847. return error_show(1002, "未找到数据");
  1848. }
  1849. // $send = Db::name("order_out")->where(["wsm_code" => $wsm_code, 'orderCode' => $orderCode])->sum
  1850. //("send_num");
  1851. $item =$der['status'];
  1852. $der['send_num'] += $send_num;
  1853. $der['wsend_num'] -= $send_num;//($der['send_num'])?$der['wsend_num'] =="" ? $der['send']
  1854. $der['send_status'] = $der['send_num'] == 0 ? 1 : $der['wsend_num'] == 0 ? 3 : 2;
  1855. $der['status'] = $der['send_num'] == 0 ? 3 : $der['wsend_num'] == 0 ? 5 : 4;
  1856. $der['updatetime'] = date("Y-m-d H:i:s");
  1857. $si = Db::name('sale')->save($der);
  1858. if ($si == false) {
  1859. Db::rollback();
  1860. return error_show(1003, "更新失败");
  1861. }
  1862. $stx = ["order_code"=>$orderCode,"status"=>$item,"action_remark"=>'',"action_type"=>"edit"];
  1863. ActionLog::logAdd($this->post['token'],$stx,$der['order_type'] == 2?"ZXQRD":"XSQRD",$der['status'],$der);
  1864. $order=["order_type"=>$der['order_type'] == 2?"ZXQRD":"XSQRD","order_code"=>$orderCode,"order_id"=>$der['id'],"order_status"=>$data['status']];
  1865. ProcessOrder::AddProcess($this->post['token'],$order);
  1866. $str = Db::name('good_stock')->where(['wsm_code' => $var['wsm_code'], 'good_type_code' => $der['good_code']])->find();
  1867. if ($str == false) {
  1868. Db::rollback();
  1869. return error_show(1002, "商品数据未找到");
  1870. }
  1871. if ($send_num > $str['wait_out_stock']) {
  1872. Db::rollback();
  1873. return error_show(1002, "超出库存数量");
  1874. }
  1875. $str['wait_out_stock'] -= $send_num;
  1876. $str['intra_stock'] += $send_num;
  1877. $str['updatetime'] = date("Y-m-d H:i:s");
  1878. $stre = Db::name('good_stock')->save($str);
  1879. if ($stre == false) {
  1880. Db::rollback();
  1881. return error_show(1002, "状态更新失败");
  1882. }
  1883. $good_data[]= ["stock_id"=>$str['id'],"type"=>2,'stock'=>$send_num,"stock_name"=>"wait_out_stock"];
  1884. $good_data[]= ["stock_id"=>$str['id'],"type"=>1,'stock'=>$send_num,"stock_name"=>"intra_stock"];
  1885. GoodLog::LogAdd($this->post['token'],$good_data,$der['order_type'] == 2?"ZXQRD":"XSQRD");
  1886. }
  1887. Db::commit();
  1888. return error_show(0, "创建成功");
  1889. } else {
  1890. Db::rollback();
  1891. return error_show(1003, "创建失败");
  1892. }
  1893. } catch (Exception $e) {
  1894. Db::rollback();
  1895. return error_show(1005, $e->getMessage());
  1896. }
  1897. }
  1898. public function customer()
  1899. {
  1900. $outCode = isset($this->post['outCode']) && $this->post['outCode'] !== "" ? trim($this->post['outCode']) : "";
  1901. if (empty($outCode)) {
  1902. return error_show(1002, "销售订单编号不能为空");
  1903. }
  1904. $codeinfo = Db::name('order_out')->where(['outCode' => $outCode])->find();
  1905. if ($codeinfo == "") {
  1906. return error_show(1003, "未找到订单数据");
  1907. }
  1908. // $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !=="" ? trim($this->post['orderCode']) :"";
  1909. // if($orderCode==""){
  1910. // return error_show(1002,"参数orderCoder不能为空");
  1911. // }
  1912. $dr = Db::name('sale')->where(['orderCode' => $codeinfo['orderCode']])->find();
  1913. if ($dr == "") {
  1914. return error_show(1002, "未找到销售订单");
  1915. }
  1916. $status = isset($this->post['status']) && $this->post['status'] !== "" ? $this->post['status'] : "";
  1917. if ($status == "") {
  1918. return error_show(10002, "状态不能为空");
  1919. }
  1920. Db::startTrans();
  1921. try {
  1922. $time = $codeinfo['status'];
  1923. $codeinfo['status'] = $status;
  1924. $codeinfo['updatetime'] = date("Y-m-d H:i:s");
  1925. $cust = Db::name('order_out')->save($codeinfo);
  1926. if ($cust) {
  1927. $stx = ["order_code"=>$outCode,"status"=>$time,"action_remark"=>'',"action_type"=>"status"];
  1928. ActionLog::logAdd($this->post['token'],$stx,$codeinfo['order_type'] == 2?"ZXCKD":"CKD",$codeinfo['status'],$codeinfo);
  1929. $order=["order_type"=>$codeinfo['order_type'] == 2?"ZXCKD":"CKD","order_code"=>$outCode,
  1930. "order_id"=>$codeinfo['id'],"order_status"=>$codeinfo['status']];
  1931. ProcessOrder::AddProcess($this->post['token'],$order);
  1932. if ($status == 1) {
  1933. $var = Db::name('sale_info')->where(['orderCode' =>$codeinfo['orderCode'], 'wsm_code' =>$codeinfo['wsm_code']])->find();
  1934. //var_dump(Db::name('sale_info')->getLastSql());
  1935. if ($var == "") {
  1936. return error_show(1002, "未找到数据");
  1937. }
  1938. // $send = Db::name("order_out")->where(["wsm_code" => $wsm_code, 'orderCode' => $orderCode])->sum
  1939. //("send_num");
  1940. $item =$dr['status'];
  1941. $dr['send_num'] +=$codeinfo['send_num'];
  1942. $dr['wsend_num'] -= $codeinfo['send_num'];//($der['send_num'])?$der['wsend_num'] =="" ? $der['send']
  1943. $dr['send_status'] = $dr['send_num'] == 0 ? 1 : $dr['wsend_num'] == 0 ? 3 : 2;
  1944. $dr['status'] = $dr['send_num'] == 0 ? 3 : $dr['wsend_num'] == 0 ? 5 : 4;
  1945. $dr['updatetime'] = date("Y-m-d H:i:s");
  1946. $si = Db::name('sale')->save($dr);
  1947. if ($si == false) {
  1948. Db::rollback();
  1949. return error_show(1003, "更新失败");
  1950. }
  1951. $stx = ["order_code"=>$dr['orderCode'],"status"=>$item,"action_remark"=>'',"action_type"=>"edit"];
  1952. ActionLog::logAdd($this->post['token'],$stx,$dr['order_type'] == 2?"ZXQRD":"XSQRD",$dr['status'],
  1953. $dr);
  1954. $order=["order_type"=>$dr['order_type'] == 2?"ZXQRD":"XSQRD","order_code"=>$dr['orderCode'],"order_id"=>$dr['id'],"order_status"=>$dr['status']];
  1955. ProcessOrder::AddProcess($this->post['token'],$order);
  1956. $str = Db::name('good_stock')->where(['wsm_code' => $var['wsm_code'], 'good_type_code' => $dr['good_code']])->find();
  1957. if ($str == false) {
  1958. Db::rollback();
  1959. return error_show(1002, "商品数据未找到");
  1960. }
  1961. if ($codeinfo['send_num'] > $str['wait_out_stock']) {
  1962. Db::rollback();
  1963. return error_show(1002, "超出库存数量");
  1964. }
  1965. $str['wait_out_stock'] -= $codeinfo['send_num'];
  1966. $str['intra_stock'] += $codeinfo['send_num'];
  1967. $str['updatetime'] = date("Y-m-d H:i:s");
  1968. $stre = Db::name('good_stock')->save($str);
  1969. if ($stre == false) {
  1970. Db::rollback();
  1971. return error_show(1002, "状态更新失败");
  1972. }
  1973. $good_data[]= ["stock_id"=>$str['id'],"type"=>2,'stock'=>$codeinfo['send_num'],"stock_name"=>"wait_out_stock"];
  1974. $good_data[]= ["stock_id"=>$str['id'],"type"=>1,'stock'=>$codeinfo['send_num'],"stock_name"=>"intra_stock"];
  1975. GoodLog::LogAdd($this->post['token'],$good_data,'CKD');
  1976. }
  1977. if ($status == 2) {
  1978. $ct = Db::name('sale_info')->where(['orderCode' => $dr['orderCode'], 'wsm_code' => $codeinfo['wsm_code']])->find();
  1979. if ($ct == false) {
  1980. return error_show(1002, "未找到数据");
  1981. }
  1982. $var = Db::name('good_stock')->where(['wsm_code' => $codeinfo['wsm_code'], 'good_type_code' => $dr['good_code']])->find();
  1983. if ($var == false) {
  1984. Db::rollback();
  1985. return error_show(1002, "未找到商品数据");
  1986. }
  1987. if ($ct['num'] > $var['intra_stock']) {
  1988. Db::rollback();
  1989. return error_show(1003, "超出库存数量");
  1990. }
  1991. $var['intra_stock'] -= $codeinfo['send_num'];
  1992. $var['updatetime'] = date("Y-m-d H:i:s");
  1993. $stre = Db::name('good_stock')->save($var);
  1994. $good_data[]= ["stock_id"=>$var['id'],"type"=>2,'stock'=>$codeinfo['send_num'],"stock_name"=>"intra_stock"];
  1995. GoodLog::LogAdd($this->post['token'],$good_data,$codeinfo['order_type'] == 2?"ZXCKD":"CKD");
  1996. if ($stre == false) {
  1997. Db::rollback();
  1998. return error_show(1002, "状态更新失败");
  1999. }
  2000. }
  2001. Db::commit();
  2002. return error_show(0, "出库订单更新成功");
  2003. } else {
  2004. Db::rollback();
  2005. return error_show(1003, "出库订单更新失败");
  2006. }
  2007. } catch (Exception $e) {
  2008. Db::rollback();
  2009. return error_show(1005, $e->getMessage());
  2010. }
  2011. }
  2012. public function difflist()
  2013. {
  2014. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  2015. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  2016. $where = [];
  2017. $cgdNo = isset($this->post['orderCode']) && $this->post['orderCode'] != "" ? trim($this->post['orderCode']) : "";
  2018. if ($cgdNo != "") {
  2019. $where[] = ['a.orderCode', "like", "%$cgdNo%"];
  2020. }
  2021. $diffNo = isset($this->post['diffCode']) && $this->post['diffCode'] != "" ? trim($this->post['diffCode']) : "";
  2022. if ($diffNo != "") {
  2023. $where[] = ['a.diffCode', "like", "%$diffNo%"];
  2024. }
  2025. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  2026. if ($status !== "") {
  2027. $where[] = ['a.status', "=", $status];
  2028. }
  2029. $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
  2030. if ($start != "") {
  2031. $where[] = ["a.addtime", '>=', $start];
  2032. }
  2033. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
  2034. if ($end != "") {
  2035. $where[] = ["a.addtime", '<=', $end];
  2036. }
  2037. // $apply_name = isset($this->post['apply_name']) && $this->post['apply_name'] !==""? intval($this->post['apply_name']):"";
  2038. // if($apply_name!==""){
  2039. // $where[]=['a.apply_name',"like","%$apply_name%"];
  2040. // }
  2041. $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !== "" ? trim($this->post['supplierNo']) : "";
  2042. if ($supplierNo != "") {
  2043. $supplier = Db::name("supplier")->where([['code', "like", "%$supplierNo%"]])->column('code');
  2044. // if(empty($supplier)){
  2045. // return error_show(1004,"未找到供应商信息");
  2046. // }
  2047. $wsmcode = Db::name("sale")->where([
  2048. "is_del" => 0, "supplierNo" => $supplier])->column("orderCode");
  2049. $where[] = ['a.orderCode', "in", $wsmcode];
  2050. }
  2051. $companyNo =isset($this->post['companyNo']) &&$this->post['companyNo'] !=="" ? trim($this->post['companyNo']):"";
  2052. if($companyNo!=""){
  2053. $where[]=['c.customer_code',"like","%$companyNo%"];
  2054. }
  2055. $count = Db::name('sale_diff')->alias('a')
  2056. ->join("sale c", "c.orderCode=a.orderCode", "left")
  2057. ->join("customer_info v", "v.companyNo=c.customer_code", "left")
  2058. ->join("good b", "b.good_code=a.good_code", "left")
  2059. ->where($where)->count();
  2060. $total = ceil($count / $size);
  2061. $page = $page >= $total ? $total : $page;
  2062. //var_dump( Db::name('sale_diff')->getLastSql());
  2063. $list = Db::name('sale_diff')->alias('a')
  2064. ->join("sale c", "c.orderCode=a.orderCode", "left")
  2065. ->join("customer_info v", "v.companyNo=c.customer_code", "left")
  2066. ->join("good b", "b.good_code=a.good_kode", "left")
  2067. ->where($where)->page($page, $size)->field("a.*,b.cat_id,c.customer_code,v.companyName")
  2068. ->order("a.addtime desc")->select();
  2069. $data = [];
  2070. foreach ($list as $value) {
  2071. $value['can'] = isset($value['cat_id']) && $value['cat_id'] != 0 ? made($value['cat_id']) : [];
  2072. $wsm = Db::name("sale")->alias("a")->Join("supplier b", "a.supplierNo=b.code", "left")->where
  2073. (['a.orderCode' => $value['orderCode'], "a.is_del" => 0])->field("b.code,b.name")->find();
  2074. $value['supplierNo'] = isset($wsm['code']) ? $wsm['code'] : "";
  2075. $value['supplierName'] = isset($wsm['name']) ? $wsm['name'] : "";
  2076. $data[] = $value;
  2077. }
  2078. return app_show(0, "获取成功", ['list' => $data, 'count' => $count]);
  2079. }
  2080. /**
  2081. * @return \think\response\Json|void
  2082. * @throws \think\db\exception\DataNotFoundException
  2083. * @throws \think\db\exception\DbException
  2084. * @throws \think\db\exception\ModelNotFoundException
  2085. */
  2086. public function diffcheck()
  2087. {
  2088. $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
  2089. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  2090. if ($id === "") {
  2091. return error_show(1004, "参数id不能为空");
  2092. }
  2093. $info = Db::name("sale_diff")->where(["id" => $id])->find();
  2094. if (empty($info)) {
  2095. return error_show(1004, "订单数据未找到");
  2096. }
  2097. $is_act = isset($this->post['is_act']) && $this->post['is_act'] !== "" ? intval($this->post['is_act']) : "";
  2098. if ($is_act === '') {
  2099. return error_show(1004, "参数is_act不能为空");
  2100. }
  2101. $customer_remark = isset($this->post['customer_remark']) && $this->post['customer_remark'] !== "" ? trim($this->post['customer_remark']) : "";
  2102. if ($customer_remark === '') {
  2103. return error_show(1004, "参数customer_remark不能为空");
  2104. }
  2105. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "2";
  2106. $remark = isset($this->post['remark']) && $this->post['remark'] !== "" ? trim($this->post['remark']) : "";
  2107. $item = $info['status'];
  2108. $info['is_act'] = $is_act;
  2109. $info['customer_remark'] = $customer_remark;
  2110. $info['status'] = $status;
  2111. $info['remark'] = $remark;
  2112. $info['updatetime'] = date("Y-m-d H:i:s");
  2113. $up = Db::name("sale_diff")->save($info);
  2114. if ($up) {
  2115. $stx = ["order_code"=>$info["orderCode"],"status"=>$item,"action_remark"=>'',"action_type"=>"edit"];
  2116. ActionLog::logAdd($this->post['token'],$stx,"QRGCD",$info['status'],$info);
  2117. $order=["order_type"=>"QRGCD","order_code"=>$info["orderCode"],"order_id"=>$info['id'],"order_status"=>$info['status']];
  2118. ProcessOrder::AddProcess($this->post['token'],$order);
  2119. return app_show(0, "更新成功");
  2120. } else {
  2121. return error_show(1003, "更新失败");
  2122. }
  2123. }
  2124. /**
  2125. * @return \think\response\Json|void
  2126. * @throws \think\db\exception\DataNotFoundException
  2127. * @throws \think\db\exception\DbException
  2128. * @throws \think\db\exception\ModelNotFoundException
  2129. */
  2130. public function diffstatus()
  2131. {
  2132. $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
  2133. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  2134. if ($id === "") {
  2135. return error_show(1004, "参数id不能为空");
  2136. }
  2137. $info = Db::name("sale_diff")->where(["id" => $id])->find();
  2138. if (empty($info)) {
  2139. return error_show(1004, "订单数据未找到");
  2140. }
  2141. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "3";
  2142. $remark = isset($this->post['remark']) && $this->post['remark'] !== "" ? trim($this->post['remark']) : "";
  2143. $ite=$info['status'];
  2144. $info['status'] = $status;
  2145. $info['remark'] = $remark;
  2146. $info['updatetime'] = date("Y-m-d H:i:s");
  2147. $up = Db::name("sale_diff")->save($info);
  2148. if ($up) {
  2149. $stx = ["order_code"=>$info["orderCode"],"status"=>$ite,"action_remark"=>'',"action_type"=>"status"];
  2150. ActionLog::logAdd($this->post['token'],$stx,"QRGCD",$info['status'],$info);
  2151. $order=["order_type"=>"QRGCD","order_code"=>$info["orderCode"],"order_id"=>$info['id'],"order_status"=>$info['status']];
  2152. ProcessOrder::AddProcess($this->post['token'],$order);
  2153. return app_show(0, "更新成功");
  2154. } else {
  2155. return error_show(1003, "更新失败");
  2156. }
  2157. }
  2158. /**
  2159. * @return \think\response\Json|void
  2160. * @throws \think\db\exception\DataNotFoundException
  2161. * @throws \think\db\exception\DbException
  2162. * @throws \think\db\exception\ModelNotFoundException
  2163. */
  2164. public function diffinfo()
  2165. {
  2166. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  2167. if ($id === "") {
  2168. return error_show(1004, "参数id不能为空");
  2169. }
  2170. $info = Db::name('sale_diff')->alias('a')->join("good b", "b.good_code=a.good_kode", "left")->where
  2171. (["a.id" => $id])->field("a.*,b.cat_id")->find();
  2172. if (empty($info)) {
  2173. return error_show(1004, "订单数据未找到");
  2174. }
  2175. $info['can'] = isset($info['cat_id']) && $info['cat_id'] !== 0 ? made($info['cat_id']) : [];
  2176. return app_show(0, "获取成功", $info);
  2177. }
  2178. public function saleout(){
  2179. $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']):"1";
  2180. $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']) :"10";
  2181. $where= [];
  2182. $orderCode=isset($this->post['orderCode']) && $this->post['orderCode'] !=="" ? trim($this->post['orderCode'])
  2183. :"";
  2184. if($orderCode !==""){
  2185. $where[]=['a.orderCode',"like","%$orderCode%"];
  2186. }
  2187. $order_type=isset($this->post['order_type']) && $this->post['order_type'] !=="" ? trim($this->post['order_type'])
  2188. :"";
  2189. if($order_type !==""){
  2190. $where[]=['a.order_type',"=",$order_type];
  2191. }
  2192. $outCode=isset($this->post['outCode']) && $this->post['outCode'] !=="" ? trim($this->post['outCode'])
  2193. :"";
  2194. if($outCode !==""){
  2195. $where[]=['a.outCode',"like","%$outCode%"];
  2196. }
  2197. $apply_name=isset($this->post['apply_name']) && $this->post['apply_name'] !=="" ? trim($this->post['apply_name'])
  2198. :"";
  2199. if($apply_name !==""){
  2200. $where[]=['a.apply_name',"like","%$apply_name%"];
  2201. }
  2202. $good_code=isset($this->post['good_code']) && $this->post['good_code'] !=="" ? trim($this->post['good_code'])
  2203. :"";
  2204. if($good_code !==""){
  2205. $where[]=['b.good_code',"like","%$good_code%"];
  2206. }
  2207. $good_name=isset($this->post['good_name']) && $this->post['good_name'] !=="" ? trim($this->post['good_name'])
  2208. :"";
  2209. if($good_name !==""){
  2210. $where[]=['b.good_name',"like","%$good_name%"];
  2211. }
  2212. $status=isset($this->post['status']) && $this->post['status'] !=="" ? trim($this->post['status']):"";
  2213. if($status !==""){
  2214. $where[]=['a.status',"=",$status];
  2215. }
  2216. $start = isset($this->post['start']) && $this->post['start'] !=="" ? $this->post['start'] :"";
  2217. if($start !=""){
  2218. $where[]= ["a.addtime",'>=',$start];
  2219. }
  2220. $end = isset($this->post['end']) && $this->post['end'] !=="" ? $this->post['end'] :"";
  2221. if($end !=""){
  2222. $where[]= ["a.addtime",'<=',$end];
  2223. }
  2224. $companyNo =isset($this->post['companyNo']) &&$this->post['companyNo'] !=="" ? trim($this->post['companyNo']):"";
  2225. if($companyNo!=""){
  2226. $where[]=['b.customer_code',"like","%$companyNo%"];
  2227. }
  2228. $count = Db::name('order_out')->alias('a')
  2229. ->join("sale b", "b.orderCode=a.orderCode", "left")
  2230. ->join("customer_info v", "v.companyNo=b.customer_code", "left")
  2231. //->join("good n","n.good_code=b.good_code","left")
  2232. ->where($where)->count();
  2233. $total = ceil($count / $size);
  2234. $page = $page >= $total ? $total : $page;
  2235. $list = Db::name('order_out')->alias('a')->join("sale b", "b.orderCode=a.orderCode", "left")
  2236. ->join("customer_info v", "v.companyNo=b.customer_code", "left")
  2237. //->join("good n","n.good_code=b.good_code","left")
  2238. ->field("a.*,b.good_name,b.good_code,b.supplierNo,b.customer_code,v.companyName,b.origin_price,b.sale_price,b.total_price")
  2239. ->where($where)->order("addtime desc")->page($page, $size)->select();
  2240. $data=[];
  2241. foreach ($list as $value) {
  2242. $wsmcode = Db::name("warehouse_info")->alias("k")->leftJoin("supplier c", "k.supplierNo=c.code")
  2243. ->where(["k.wsm_code" => $value['wsm_code']])->field("k.name as wsm_name,c.name,c.code")->find();
  2244. $addr = Db::name("order_addr")->where(["id" => $value['addrid']])->find();
  2245. $good = Db::name("good_type")->alias("b")->join("good a", "a.good_code = b.good_code", "left")
  2246. ->where(["type_code" => $value['good_code']])->field('cat_id')->find();
  2247. $value['wsm_name'] = isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name'] : "";
  2248. $value['wsm_supplier'] = isset($wsmcode['name']) ? $wsmcode['name'] : "";
  2249. $value['wsm_supplierNo'] = isset($wsmcode['code']) ? $wsmcode['code'] : "";
  2250. $value['addr'] = isset($addr['addr']) ? $addr['addr'] : "";
  2251. $value['contactor'] = isset($addr['contactor']) ? $addr['contactor'] : "";
  2252. $value['mobile'] = isset($addr['mobile']) ? $addr['mobile'] : "";
  2253. $value['can'] = isset($good['cat_id']) && $good['cat_id'] != 0 ? made($good['cat_id']) : [];
  2254. $data[] = $value;
  2255. }
  2256. return app_show(0, "获取成功", ['list' => $data, 'count' => $count]);
  2257. }
  2258. public function outinfo()
  2259. {
  2260. $outCode = isset($this->post['outCode']) && $this->post['outCode'] !== "" ? trim($this->post['outCode']) : "";
  2261. if ($outCode == "") {
  2262. return error_show(1002, "参数outcode不能为空");
  2263. }
  2264. $codeinfo = Db::name("order_out")->where(['outCode' => $outCode])->find();
  2265. if (empty($codeinfo)) {
  2266. return error_show(1002, "未找到出库数据");
  2267. }
  2268. $item = Db::name("sale")->where(['orderCode' => $codeinfo['orderCode']])->find();
  2269. if($item['order_type']==3|| $item['order_type']==4){
  2270. // $good=Db::name("good_zixun")->where(["spuCode"=>$good_code])->find();
  2271. // if($good==false){
  2272. // return error_show(1004,"未找到商品数据");
  2273. // }
  2274. $goodinfo = Db::name("consult_bids")->where(["spuCode"=>$item['good_code'],"is_del"=>0])->find();
  2275. if($goodinfo==false){
  2276. return error_show(1004,"未找到商品数据");
  2277. }
  2278. }else{
  2279. $goodinfo = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
  2280. ->where(['a.skuCode' =>$item['sku_code']])->find();
  2281. if ($goodinfo == false) {
  2282. return error_show(1002, "未找到商品数据");
  2283. }
  2284. }
  2285. $int = isset($goodinfo['cat_id']) && $goodinfo['cat_id'] != 0 ? made($goodinfo['cat_id']) : [];
  2286. // $wsmcode = Db::name("warehouse_info")->alias("k")->leftJoin("supplier c", "k.supplierNo=c.code")
  2287. // ->where(["k.wsm_code" => $codeinfo['wsm_code']])->field("k.name as wsm_name,c.name,c.code")->find();
  2288. $addr = Db::name("order_addr")->where(["id" => $codeinfo['addrid']])->find();
  2289. //$item = Db::name("sale")->where(['orderCode' => $codeinfo['orderCode']])->find();
  2290. $codeinfo['good_name'] = isset($item['good_name']) ? $item['good_name'] : "";
  2291. $codeinfo['good_num'] = isset($item['good_num']) ? $item['good_num'] : "";
  2292. $codeinfo['good_code'] = isset($item['good_code']) ? $item['good_code'] : "";
  2293. $codeinfo['origin_price'] = isset($item['origin_price']) ? $item['origin_price'] : "";
  2294. $codeinfo['sale_price'] = isset($item['sale_price']) ? $item['sale_price'] : "";
  2295. $codeinfo['total_price'] = isset($item['total_price']) ? $item['total_price'] : "";
  2296. // $codeinfo['wsm_name'] = isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name'] : "";
  2297. // $codeinfo['wsm_supplier'] = isset($wsmcode['name']) ? $wsmcode['name'] : "";
  2298. // $codeinfo['wsm_supplierNo'] = isset($wsmcode['code']) ? $wsmcode['code'] : "";
  2299. $codeinfo['addr'] = GetAddr($addr['addr_code']);
  2300. $codeinfo['addr'] .= isset($addr['addr']) ? $addr['addr'] : "";
  2301. $codeinfo['addr_code'] = isset($addr['addr_code']) ? $addr['addr_code'] : "";
  2302. $codeinfo['contactor'] = isset($addr['contactor']) ? $addr['contactor'] : "";
  2303. $codeinfo['mobile'] = isset($addr['mobile']) ? $addr['mobile'] : "";
  2304. $codeinfo['can'] = $int;
  2305. return app_show(0, "获取成功", $codeinfo);
  2306. }
  2307. public function outadd(){
  2308. $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
  2309. $outCode = makeNo("CK");
  2310. $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !== "" ? trim($this->post['orderCode']) : "";
  2311. if ($orderCode == "") {
  2312. return error_show(1002, "参数orderCoder不能为空");
  2313. }
  2314. $der = Db::name('sale')->where(['orderCode' => $orderCode])->find();
  2315. if ($der == "") {
  2316. return error_show(1002, "未找到出库订单单号");
  2317. }
  2318. $send_num = isset($this->post['send_num']) && $this->post['send_num'] !== "" ? $this->post['send_num'] : "";
  2319. if ($send_num == "") {
  2320. return error_show(1002, "发货数量不能为空");
  2321. }
  2322. if ($send_num > $der['wsend_num']) {
  2323. return error_show(1002, "超出可发货数量");
  2324. }
  2325. $contactor = isset($this->post['contactor'])&&$this->post['contactor']!="" ? trim($this->post['contactor']):"";
  2326. if($contactor==""){
  2327. return error_show(1002, "参数contactor不能为空");
  2328. }
  2329. $mobile = isset($this->post['mobile'])&&$this->post['mobile']!="" ? trim($this->post['mobile']):"";
  2330. if($mobile==""){
  2331. return error_show(1002, "参数mobile不能为空");
  2332. }
  2333. $addr = isset($this->post['addr'])&&$this->post['addr']!="" ? trim($this->post['addr']):"";
  2334. if($addr==""){
  2335. return error_show(1002, "参数addr不能为空");
  2336. }
  2337. $addr_code = isset($this->post['addr_code'])&&$this->post['addr_code']!="" ? trim($this->post['addr_code']):"";
  2338. if($addr_code==""){
  2339. return error_show(1002, "参数addr_code不能为空");
  2340. }
  2341. $apply_id = GetUserInfo($token);
  2342. if (empty($apply_id) || $apply_id['code'] != 0) {
  2343. return error_show(1002, "申请人数据不存在");
  2344. }
  2345. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  2346. $ri = isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  2347. // $addrid = isset($this->post['addrid']) && $this->post['addrid'] !== "" ? intval($this->post['addrid']) : "";
  2348. // $dr = Db::name('order_addr')->where(['id' => $addrid, 'is_del' => 0])->find();
  2349. // if (empty($dr)) {
  2350. // return error_show(1003, "收货人信息未找到");
  2351. // }
  2352. // if ($dr['orderCode'] !== $orderCode) {
  2353. // return error_show(1002, "订单code不存在");
  2354. // }
  2355. $sendtime = isset($this->post['sendtime']) && $this->post['sendtime'] !== "" ? $this->post['sendtime'] : date("Y-m-d H:i:s");
  2356. $order =Db::name("order_num")->where(["orderCode"=>$orderCode,"status"=>1])->where([["wsend_num",">=",0]])
  2357. ->select()->toArray();
  2358. if(empty($order)){
  2359. return error_show(1004,"未找到可以发货得采购单数据");
  2360. }
  2361. Db::startTrans();
  2362. try {
  2363. $addrlst =[
  2364. "orderCode"=>$orderCode,
  2365. "addr"=>$addr,
  2366. "addr_code"=>json_encode($addr_code),
  2367. "contactor"=>$contactor,
  2368. "mobile"=>$mobile,
  2369. "customer_code"=>$der['customer_code'],
  2370. "post_fee"=>$der['post_fee'],
  2371. "arrive_time"=>$sendtime,
  2372. "receipt_quantity"=>$send_num,
  2373. "is_del"=>0,
  2374. "addtime"=>date("Y-m-d H:i:s"),
  2375. "updatetime"=>date("Y-m-d H:i:s")
  2376. ];
  2377. $addrid = Db::name("order_addr")->insert($addrlst,true);
  2378. if($addrid>0){
  2379. $data = [
  2380. "wsm_code" => "",
  2381. "orderCode" => $orderCode,
  2382. "outCode" => $outCode,
  2383. "order_type" => $der['order_type'],
  2384. "apply_id" => $rm,
  2385. "apply_name" => $ri,
  2386. "addrid" => $addrid,
  2387. "post_name" => "",
  2388. "post_code" =>"",
  2389. "post_fee" => "",
  2390. "sendtime" => $sendtime,
  2391. "send_num" => $send_num,
  2392. "check_num" => 0,
  2393. "error_num" => 0,
  2394. "status" => 1,
  2395. "addtime" => date("Y-m-d H:i:s"),
  2396. "updatetime" => date("Y-m-d H:i:s")
  2397. ];
  2398. $datainfo = Db::name('order_out')->insert($data,true);
  2399. if($datainfo>0){
  2400. $num = $send_num;
  2401. foreach ($order as $val){
  2402. $tep=[];
  2403. $ornum=0;
  2404. if($val['wsend_num']>=$num){
  2405. $val['wsend_num']-=$num;
  2406. $val['send_num']+=$num;
  2407. $ornum =$num;
  2408. $num=0;
  2409. }else{
  2410. $num-=$val['wsend_num'];
  2411. $val['send_num']+=$val['wsend_num'];
  2412. $ornum =$val['wsend_num'];
  2413. $val['wsend_num']=0;
  2414. }
  2415. $or =Db::name("order_num")->save($val);
  2416. if($or==false){
  2417. Db::rollback();
  2418. return error_show(1002,"发货地址添加创建失败");
  2419. }
  2420. $tep=[
  2421. "cgdNo"=>$val['cgdNo'],
  2422. "outCode"=>$outCode,
  2423. "send_num"=>$ornum,
  2424. "status"=>1,
  2425. "addtime"=>date("Y-m-d H:i:s"),
  2426. "updatetime"=>date("Y-m-d H:i:s")
  2427. ];
  2428. $sen=Db::name("order_send")->save($tep);
  2429. if($sen==false){
  2430. Db::rollback();
  2431. return error_show(1002,"发货地址添加创建失败");
  2432. }
  2433. if($num==0){
  2434. break;
  2435. }
  2436. }
  2437. Db::commit();
  2438. return app_show(0,"出库单新建成功",["outCode"=>$outCode]);
  2439. }
  2440. }
  2441. Db::rollback();
  2442. return error_show(1004,"出库单新建失败");
  2443. } catch (Exception $e) {
  2444. Db::rollback();
  2445. return error_show(1005, $e->getMessage());
  2446. }
  2447. }
  2448. public function outSend(){
  2449. $outCode=isset($this->post['outCode'])&& $this->post['outCode']!=""? trim($this->post['outCode']):"";
  2450. if($outCode==""){
  2451. return error_show(1004,"参数outCode不能为空");
  2452. }
  2453. $outinfo = Db::name("order_out")->where(["outCode"=>$outCode])->find();
  2454. if($outinfo==false){
  2455. return error_show(1004,"发货数据未找到");
  2456. }
  2457. $post_name = isset($this->post['post_name']) &&$this->post['post_name']!="" ? trim($this->post['post_name']):"";
  2458. if($post_name==""){
  2459. return error_show(1004,"参数post_name不能为空");
  2460. }
  2461. $post_code = isset($this->post['post_code']) &&$this->post['post_code']!="" ? trim($this->post['post_code']):"";
  2462. if($post_code==""){
  2463. return error_show(1004,"参数post_code不能为空");
  2464. }
  2465. $post_fee = isset($this->post['post_fee']) && $this->post['post_fee']!="" ? floatval($this->post['post_fee']):"";
  2466. $outinfo['post_name'] = $post_name;
  2467. $outinfo['post_code'] = $post_code;
  2468. $outinfo['post_fee'] = $post_fee;
  2469. $outinfo['sendtime'] = date("Y-m-d H:i:s");
  2470. $outinfo['status'] = 2;
  2471. $outinfo['updatetime'] = date("Y-m-d H:i:s");
  2472. $up =Db::name("order_out")->save($outinfo);
  2473. if($up){
  2474. // $dbol =$this->RelaCgd($outinfo);
  2475. // if($dbol==false){
  2476. // Db::rollback();
  2477. // return error_show(1004,"采购关联失败");
  2478. // }
  2479. return app_show(0,"发货成功");
  2480. }else{
  2481. return error_show(1004,"发货失败");
  2482. }
  2483. }
  2484. public function RelaCgd($outinfo){
  2485. $der = Db::name('sale')->where(['orderCode' => $outinfo['orderCode']])->find();
  2486. if ($der == "") {
  2487. return false;
  2488. }
  2489. if($der['is_stock']==1){
  2490. $cgd = Db::name("order_bk")->where([["spuCode","=",$der['spuCode']],["is_del","=",0],["balance_num",">",0]])
  2491. ->select()->toArray();
  2492. if(empty($cgd)){
  2493. return false;
  2494. }
  2495. $send =$outinfo['send_num'];
  2496. $outsend=[];
  2497. foreach ($cgd as $value){
  2498. $temp=[];
  2499. if($value['balance_num']>=$send){
  2500. $value['balance_num']-=$send;
  2501. $value['merge_num']+=$send;
  2502. $send=0;
  2503. $temp['send_num'] =$send;
  2504. }else{
  2505. $value['balance_num'] =0;
  2506. $value['merge_num']+=$value['balance_num'];
  2507. $send -= $value['balance_num'];
  2508. $temp['send_num'] =$value['balance_num'];
  2509. }
  2510. $value['status'] = $value['balance_num']==0 ?2:$value['merge_num']==0?0:1 ;
  2511. $value['updatetime'] = date("Y-m-d H:i:s");
  2512. $bk = Db::name("order_bk")->save($value);
  2513. if($bk==false){
  2514. return false;
  2515. }
  2516. $temp['cgdNo'] = $value['cgdNo'];
  2517. $temp['outCode'] = $outinfo['outCode'];
  2518. $temp['status'] = 1;
  2519. $temp['addtime']=date("Y-m-d H:i:s");
  2520. $temp['updatetime']=date("Y-m-d H:i:s");
  2521. $outsend[]=$temp;
  2522. $order = Db::name("order_num")->where(["orderCode"=>$der['orderCode'],"cgdNo"=>$value['cgdNo'],"spuCode"=>$der['spuCode'],"status"=>1])->find();
  2523. if($order==false){
  2524. $order=[
  2525. "orderCode"=>$der['orderCode'],
  2526. "cgdNo"=>$value['cgdNo'],
  2527. "spuCode"=>$der['spuCode'],
  2528. "good_num"=>$der['good_num'],
  2529. "wsend_num"=>$der['good_num']-$temp['send_num'],
  2530. "send_num"=>$temp['send_num'],
  2531. "status"=>1,
  2532. "source"=>1
  2533. ];
  2534. }else{
  2535. $order['wsend_num']-=$temp['send_num'];
  2536. $order['send_num']+=$temp['send_num'];
  2537. }
  2538. if($order['wsend_num']<0){
  2539. return false;
  2540. }
  2541. $up =Db::name("order_num")->save($order);
  2542. if($up==false){
  2543. return false;
  2544. }
  2545. if($send==0){
  2546. break;
  2547. }
  2548. }
  2549. if(empty($temp)){
  2550. return false;
  2551. }
  2552. $insert = Db::name("order_send")->insertAll($outsend);
  2553. if($insert){
  2554. return true;
  2555. }else{
  2556. return false;
  2557. }
  2558. }else{
  2559. $order = Db::name("order_num")->where(["orderCode"=>$der['orderCode'],"spuCode"=>$der['spuCode'],
  2560. "status"=>1])->find();
  2561. if($order==false){
  2562. return false;
  2563. }else{
  2564. if($outinfo['send_num']> $order['wsend_num']){
  2565. return false;
  2566. }
  2567. $order['wsend_num']-=$outinfo['send_num'];
  2568. $order['send_num']+=$outinfo['send_num'];
  2569. if($order['wsend_num']<0){
  2570. return false;
  2571. }
  2572. $up =Db::name("order_num")->save($order);
  2573. if($up==false){
  2574. return false;
  2575. }
  2576. $temp=[];
  2577. $temp['cgdNo'] = $order['cgdNo'];
  2578. $temp['outCode'] = $outinfo['outCode'];
  2579. $temp['send_num'] =$outinfo['send_num'];
  2580. $temp['status'] = 1;
  2581. $temp['addtime']=date("Y-m-d H:i:s");
  2582. $temp['updatetime']=date("Y-m-d H:i:s");
  2583. $insert = Db::name("order_send")->insert($temp);
  2584. if($insert){
  2585. return true;
  2586. }else{
  2587. return false;
  2588. }
  2589. }
  2590. }
  2591. }
  2592. }