Sale.php 141 KB

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