Sale.php 137 KB

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