Sale.php 142 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969
  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. "arrive_time"=>$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. "good_info_img"=>"",
  717. "specinfo"=>$zxinfo['specinfo'],
  718. "work_day"=>$zxinfo['work_day'],
  719. "noble_metal"=>$zxinfo['metal_id'],
  720. "is_gold_price"=>$zxinfo['is_gold_price'],
  721. "config"=>$zxinfo['config'],
  722. "other_config"=>$zxinfo['other_config'],
  723. "weight"=>$zxinfo['weight'],
  724. "is_diff"=>$zxinfo['is_diff'],
  725. "supply_area"=>$zxinfo['supply_area'],
  726. "pay_way"=>$zxinfo['pay_way'],
  727. "send_way"=>$zxinfo['send_way'],
  728. "status"=>1,
  729. "is_del"=>0,
  730. "createrid"=>$rm,
  731. "creater"=>$ri,
  732. "addtime"=>date("Y-m-d H:i:s"),
  733. "updatetime"=>date("Y-m-d H:i:s")
  734. ];
  735. $good = Db::name("good_zixun")->insert($limt);
  736. if(!$good){
  737. Db::rollback();
  738. return error_show(1006,"咨询商品录入失败");
  739. }
  740. if(!empty($va)){
  741. $order =Db::name("order_num")->where(["orderCode"=>$orderCode,"status"=>1])->where([["wsend_num",">=",0]])
  742. ->find();
  743. if($order==false){
  744. Db::rollback();
  745. return error_show(1006,"采购单关联数据未找到");
  746. }
  747. foreach ($va as $value){
  748. $temp=[];
  749. $addrs=[];
  750. if($value['addr_code']!==''&&is_array($value['addr_code'])){
  751. $addrs['provice_code'] = $value['addr_code'][0];
  752. $addrs['city_code'] = $value['addr_code'][1];
  753. $addrs['area_code'] = $value['addr_code'][2];
  754. $addr = json_encode($addrs);
  755. }else{
  756. $addr = isset($value['addr_code'])?$value['addr_code']:'';
  757. }
  758. $temp['orderCode']=$orderCode;
  759. $temp['contactor']=$value['contactor'];
  760. $temp['mobile'] = $value['mobile'];
  761. $temp['addr'] = $value['addr'];
  762. $temp['addr_code']=$addr;
  763. $temp['customer_code'] =$zxorder['khNo'];
  764. $temp['receipt_quantity']=$value['receipt_quantity'];
  765. $temp['post_fee'] =0;
  766. $temp['is_del'] =0;
  767. $temp['addtime'] =date("Y-m-d H:i:s");
  768. $temp['updatetime'] =date("Y-m-d H:i:s");
  769. $temp['arrive_time']=$arrtime;
  770. $vmp = Db::name('order_addr')->insert($temp,true);
  771. if($vmp>0){
  772. $outCode=makeNo("CK");
  773. $out=[
  774. "orderCode"=>$orderCode,
  775. "outCode"=>$outCode,
  776. "apply_id"=>$rm,
  777. "apply_name"=>$ri,
  778. "addrid"=>$vmp,
  779. "post_name"=>"",
  780. "post_code"=>"",
  781. "post_fee"=>0,
  782. "sendtime"=>date("Y-m-d H:i:s"),
  783. "send_num"=>$value['receipt_quantity'],
  784. "check_num"=>0,
  785. "error_num"=>0,
  786. "wsm_code"=>"",
  787. "order_type"=>3,
  788. "status"=>0,
  789. "addtime"=>date("Y-m-d H:i:s"),
  790. "updatetime"=>date("Y-m-d H:i:s")
  791. ];
  792. $ou =Db::name("order_out")->insert($out);
  793. if($ou==false){
  794. Db::rollback();
  795. return error_show(1002,"发货地址添加创建失败");
  796. }
  797. $order['send_num']+=$value['receipt_quantity'];
  798. $order['wsend_num']-=$value['receipt_quantity'];
  799. if($order['wsend_num']<0){
  800. Db::rollback();
  801. return error_show(1002,"发货数量已超出总数");
  802. }
  803. $ups = Db::name("order_num")->save($order);
  804. if($ups){
  805. $tep=[
  806. "cgdNo"=>$order['cgdNo'],
  807. "outCode"=>$outCode,
  808. "send_num"=>$value['receipt_quantity'],
  809. "status"=>1,
  810. "addtime"=>date("Y-m-d H:i:s"),
  811. "updatetime"=>date("Y-m-d H:i:s")
  812. ];
  813. $sen=Db::name("order_send")->save($tep);
  814. if($sen==false){
  815. Db::rollback();
  816. return error_show(1002,"发货地址添加创建失败");
  817. }
  818. }
  819. }else{
  820. Db::rollback();
  821. return error_show(1002,"发货地址添加创建失败");
  822. }
  823. }
  824. }
  825. Db::commit();
  826. return error_show(0,"咨询订单创建成功",["order_code"=>$orderCode]);
  827. }
  828. Db::rollback();
  829. return error_show(1002,"咨询订单创建失败");
  830. }catch(\Exception $e){
  831. Db::rollback();
  832. return error_show(1003,$e->getMessage());
  833. }
  834. }
  835. /**
  836. * @return \think\response\Json|void
  837. * @throws \think\db\exception\DataNotFoundException
  838. * @throws \think\db\exception\DbException
  839. * @throws \think\db\exception\ModelNotFoundException
  840. */
  841. public function projectCreate(){
  842. $planNo =isset($this->post['planNo'])&&$this->post['planNo']!=""?trim($this->post['planNo']):"";
  843. if($planNo==""){
  844. return error_show(1004,"参数planNo不能为空");
  845. }
  846. $plan =Db::name("project_plan")->where(["planNo"=>$planNo,"is_del"=>0])->find();
  847. if($plan==false){
  848. return error_show(1004,"未找到方案信息");
  849. }
  850. $feedbackid = Db::name("project_plan_rela")->where(["planNo"=>$planNo,"is_del"=>0])->column("feedback_id,sale_price,sale_num");
  851. if($feedbackid==false){
  852. return error_show(1004,"未找到方案反馈信息");
  853. }
  854. $project = Db::name("project")->where(["projectNo"=>$plan['projectNo'],"is_del"=>0])->find();
  855. if($project==false){
  856. return error_show(1004,"未找到方案信息");
  857. }
  858. $arrtime=isset($this->post['arrtime'])&&$this->post['arrtime']!="" ?$this->post['arrtime']:"";
  859. if($arrtime==""){
  860. return error_show(1002, "参数arrtime不能为空");
  861. }
  862. $planinfo =isset($this->post['planinfo'])&&!empty($this->post['planinfo']) ?$this->post['planinfo']:"";
  863. if($planinfo==""){
  864. return error_show(1002, "参数planinfo不能为空");
  865. }
  866. $token=isset($this->post['token'])&&$this->post['token']!=""? trim($this->post['token']):"";
  867. if($token==""){
  868. return error_show(102, "参数token不能为空");
  869. }
  870. $apply_id = GetUserInfo($token);
  871. if (empty($apply_id) || $apply_id['code'] != 0) {
  872. return error_show(102, "申请人数据不存在");
  873. }
  874. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  875. $ri = isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  876. Db::startTrans();
  877. try {
  878. $feedid = array_column($feedbackid,"feedback_id");
  879. foreach ($planinfo as $value){
  880. $good=[];
  881. $feedback = Db::name("project_feedback")->where(["id"=>$value['feedback_id'],"projectNo"=>$plan['projectNo'],
  882. "is_del"=>0])->find();
  883. if($feedback==false){
  884. Db::rollback();
  885. return error_show(1002, "反馈数据未找到");
  886. }
  887. $key =array_search($feedback['id'],$feedid);
  888. $price = $feedbackid[$key];
  889. $good['spuCode'] = $feedback['spuCode'];
  890. $good['skuCode'] = $feedback['skuCode'];
  891. $good['good_num'] = $price['sale_num'];
  892. $good['sendtype'] = $value['sendtype'];
  893. $good['sale_price']=$price['sale_price'];
  894. $good['origin_price']=$feedback['origin_price'];
  895. $good['companyNo']=$project['companyNo'];
  896. $good['customerNo']=$project['khNo'];
  897. $good['pgNo']=$feedback['pgNo'];
  898. $good['arrtime']=$arrtime;
  899. $good['rm']=$rm;
  900. $good['ri']=$ri;
  901. if($value['sendtype']==1){
  902. if(!isset($value['addrlist'])||empty($value['addrlist'])){
  903. Db::rollback();
  904. return error_show(1002, "订单地址不能为空");
  905. }
  906. $good['addrlist'] = $value['addrlist'];
  907. }
  908. if($feedback['data_source']==1){
  909. $feed=$this->project_good($good);
  910. }else{
  911. $feed=$this->project_zx($good);
  912. }
  913. if($feed==false){
  914. Db::rollback();
  915. return error_show(1002, "咨询订单生成失败");
  916. }
  917. $feedback['status']=2;
  918. $feedback['updatetime']=date("Y-m-d H:i:s");
  919. $fed =Db::name("project_feedback")->save($feedback);
  920. if($fed==false){
  921. Db::rollback();
  922. return error_show(1002, "项目订单生成失败");
  923. }
  924. }
  925. $plan['status']=2;
  926. $plan['updatetime']=date("Y-m-d H:i:s");
  927. $in =Db::name("project_plan")->save($plan);
  928. if($in==false){
  929. Db::rollback();
  930. return error_show(1002, "项目订单生成失败");
  931. }
  932. $project["status"]=6;
  933. $project['updatetime']=date("Y-m-d H:i:s");
  934. $pr =Db::name("project")->save($project);
  935. if($pr==false){
  936. Db::rollback();
  937. return error_show(1002, "项目订单生成失败");
  938. }
  939. Db::commit();
  940. return app_show(0, "咨询订单生成成功");
  941. }catch (\Exception $e){
  942. Db::rollback();
  943. return error_show(1002, $e->getMessage());
  944. }
  945. }
  946. /**
  947. * @param $data
  948. * @return false
  949. * @throws \think\db\exception\DataNotFoundException
  950. * @throws \think\db\exception\DbException
  951. * @throws \think\db\exception\ModelNotFoundException
  952. *
  953. */
  954. public function project_zx($data){
  955. $goodinfo = Db::name("consult_bids")->where(["spuCode"=>$data['spuCode'],"is_del"=>0])->find();
  956. if($goodinfo==false){
  957. return false;
  958. }
  959. $orderCode=makeNo("QR");
  960. $cgd=[
  961. "supplierNo"=>$goodinfo['supplierNo'],
  962. "companyNo"=>$data['companyNo'],
  963. "spuCode"=>$data['spuCode'],
  964. "skuCode"=>"",
  965. "orderCode"=>$orderCode,
  966. "good_name"=>$goodinfo['good_name'],
  967. "sale_price"=>$data['origin_price'],
  968. "total_fee"=>$data['origin_price']*$data['good_num'],
  969. "pakge_fee"=>$goodinfo['pakge_fee'],
  970. "cert_fee"=>$goodinfo['cert_fee'],
  971. "open_fee"=>$goodinfo['open_fee'],
  972. "cost_fee"=>$goodinfo['cost_fee'],
  973. "mark_fee"=>$goodinfo['mark_fee'],
  974. "demo_fee"=>$goodinfo['demo_fee'],
  975. "good_num"=>$data['good_num'],
  976. "good_type"=>1,
  977. "order_type"=>4,
  978. ];
  979. $datas=[
  980. "orderCode"=>$orderCode,
  981. "good_code"=>$data['spuCode'],
  982. "skuCode"=>"",
  983. "customer_code"=>$data['customerNo'],
  984. "good_name"=>isset($goodinfo['good_name'])&&$goodinfo['good_name']!==''?$goodinfo['good_name']:'',
  985. "good_num"=>$data['good_num'],
  986. "cat_id"=>$goodinfo['cat_id'],
  987. "apply_id"=>$data['rm'],
  988. "apply_name"=>$data['ri'],
  989. "origin_price"=>$goodinfo['nake_fee'],
  990. "sale_price"=>$data['sale_price'],
  991. "post_fee"=>0,
  992. "status"=>0,
  993. "send_num"=>0,
  994. "wsend_num"=>$data['good_num'],
  995. "send_status"=>1,
  996. "good_type"=>1,
  997. "send_type"=>$data['sendtype'],
  998. "supplierNo"=>$data['companyNo'],
  999. "is_del"=>0,
  1000. "zxNo"=>$data["pgNo"],
  1001. "platform_order"=>"",
  1002. "platform_id"=>0,
  1003. "remark"=>"",
  1004. "is_stock"=>0,
  1005. "is_activity"=>0,
  1006. "proof_id"=>0,
  1007. "order_type"=>4,
  1008. "addtime"=>date("Y-m-d H:i:s"),
  1009. "updatetime"=>date("Y-m-d H:i:s"),
  1010. 'total_price'=>round($data['sale_price']*$data['good_num'],2),
  1011. ];
  1012. $datainfo = Db::name('sale')->insert($datas, true);
  1013. if($datainfo>0){
  1014. $bol = $this->createCgd($cgd);
  1015. if ($bol == false) {
  1016. return false;
  1017. }
  1018. $goodinfo['status']=6;
  1019. $goodinfo['updatetime']=date("Y-m-d H:i:s");
  1020. $sa=Db::name("consult_bids")->save($goodinfo);
  1021. if($sa==false){
  1022. return false;
  1023. }
  1024. if ($data['sendtype']==1&&!empty($data['addrlist'])) {
  1025. $order = Db::name("order_num")->where(["orderCode" => $orderCode, "status" => 1])->where([["wsend_num", ">=", 0]])
  1026. ->find();
  1027. if ($order == false) {
  1028. return false;
  1029. }
  1030. foreach ($data['addrlist'] as $value) {
  1031. $temp = [];
  1032. $addrs = [];
  1033. if ($value['addr_code'] !== '' && is_array($value['addr_code'])) {
  1034. $addrs['provice_code'] = $value['addr_code'][0];
  1035. $addrs['city_code'] = $value['addr_code'][1];
  1036. $addrs['area_code'] = $value['addr_code'][2];
  1037. $addr = json_encode($addrs);
  1038. } else {
  1039. $addr = isset($value['addr_code']) ? $value['addr_code'] : '';
  1040. }
  1041. $temp['orderCode'] = $orderCode;
  1042. $temp['contactor'] = $value['contactor'];
  1043. $temp['mobile'] = $value['mobile'];
  1044. $temp['addr'] = $value['addr'];
  1045. $temp['addr_code'] = $addr;
  1046. $temp['customer_code'] = $data['companyNo'];
  1047. $temp['receipt_quantity'] = $value['receipt_quantity'];
  1048. $temp['post_fee'] = 0;
  1049. $temp['is_del'] = 0;
  1050. $temp['addtime'] = date("Y-m-d H:i:s");
  1051. $temp['updatetime'] = date("Y-m-d H:i:s");
  1052. $temp['arrive_time'] = $data['arrtime'];
  1053. $vmp = Db::name('order_addr')->insert($temp, true);
  1054. if ($vmp > 0) {
  1055. // $outCode = makeNo("CK");
  1056. // $out = [
  1057. // "orderCode" => $orderCode,
  1058. // "outCode" => $outCode,
  1059. // "apply_id"=>$data['rm'],
  1060. // "apply_name"=>$data['ri'],
  1061. // "addrid" => $vmp,
  1062. // "post_name" => "",
  1063. // "post_code" => "",
  1064. // "post_fee" => 0,
  1065. // "sendtime" => date("Y-m-d H:i:s"),
  1066. // "send_num" => $value['receipt_quantity'],
  1067. // "check_num" => 0,
  1068. // "error_num" => 0,
  1069. // "wsm_code" => "",
  1070. // "order_type" => 4,
  1071. // "status" => 0,
  1072. // "addtime" => date("Y-m-d H:i:s"),
  1073. // "updatetime" => date("Y-m-d H:i:s")
  1074. // ];
  1075. // $ou = Db::name("order_out")->insert($out);
  1076. // if ($ou == false) {
  1077. // return false;
  1078. // }
  1079. // $order['send_num'] += $value['receipt_quantity'];
  1080. // $order['wsend_num'] -= $value['receipt_quantity'];
  1081. // if ($order['wsend_num'] < 0) {
  1082. // return false;
  1083. // }
  1084. // $ups = Db::name("order_num")->save($order);
  1085. // if ($ups) {
  1086. // $tep = [
  1087. // "cgdNo" => $order['cgdNo'],
  1088. // "outCode" => $outCode,
  1089. // "send_num" => $value['receipt_quantity'],
  1090. // "status" => 1,
  1091. // "addtime" => date("Y-m-d H:i:s"),
  1092. // "updatetime" => date("Y-m-d H:i:s")
  1093. // ];
  1094. // $sen = Db::name("order_send")->save($tep);
  1095. // if ($sen == false) {
  1096. // return false;
  1097. // }
  1098. // }
  1099. } else {
  1100. return false;
  1101. }
  1102. }
  1103. }
  1104. }
  1105. return true;
  1106. }
  1107. /**
  1108. * @param $data
  1109. * @return bool
  1110. * @throws \think\db\exception\DataNotFoundException
  1111. * @throws \think\db\exception\DbException
  1112. * @throws \think\db\exception\ModelNotFoundException
  1113. */
  1114. public function project_good($data){
  1115. $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();
  1116. if($good==false){
  1117. return false;
  1118. }
  1119. $goodlass = Db::name("good_ladder")->where(["skuCode"=>$data['skuCode'],"is_del"=>0,"status"=>1])->where([["min_num",
  1120. "<=",$data['good_num']]])->order("min_num desc")->find();
  1121. if($goodlass==false){
  1122. return false;
  1123. }
  1124. $sale_price = $goodlass['sale_price'];
  1125. $origin = Db::name("good_nake")->where([["spuCode","=",$data['spuCode']],["min_num","<=",$data['good_num']],
  1126. ["is_del","=",0]])->order("min_num desc")->find();
  1127. if($origin==false){
  1128. return false;
  1129. }
  1130. $origin_price = $origin['nake_fee'];
  1131. $orderCode=makeNo("QR");
  1132. $datas=[
  1133. "orderCode"=>$orderCode,
  1134. "good_code"=>$data['spuCode'],
  1135. "skuCode"=>$data['skuCode'],
  1136. "customer_code"=>$data['customerNo'],
  1137. "good_name"=>isset($good['good_name'])&&$good['good_name']!==''?$good['good_name']:'',
  1138. "good_num"=>$data['good_num'],
  1139. "cat_id"=>$good['cat_id'],
  1140. "apply_id"=>$data['rm'],
  1141. "apply_name"=>$data['ri'],
  1142. "origin_price"=>$origin_price,
  1143. "sale_price"=>$sale_price,
  1144. "post_fee"=>0,
  1145. "status"=>0,
  1146. "send_num"=>0,
  1147. "wsend_num"=>$data['good_num'],
  1148. "send_status"=>1,
  1149. "good_type"=>1,
  1150. "send_type"=>$data['sendtype'],
  1151. "supplierNo"=>$data['companyNo'],
  1152. "is_del"=>0,
  1153. "zxNo"=>$data["pgNo"],
  1154. "platform_order"=>"",
  1155. "platform_id"=>0,
  1156. "remark"=>"",
  1157. "is_stock"=>$good['is_stock'],
  1158. "is_activity"=>0,
  1159. "proof_id"=>0,
  1160. "order_type"=>2,
  1161. "addtime"=>date("Y-m-d H:i:s"),
  1162. "updatetime"=>date("Y-m-d H:i:s"),
  1163. 'total_price'=>round($sale_price*$data['good_num'],2),
  1164. ];
  1165. $datainfo = Db::name('sale')->insert($datas, true);
  1166. if($datainfo>0) {
  1167. $cgd=[
  1168. "supplierNo"=>$good['supplierNo'],
  1169. "companyNo"=>$data['companyNo'],
  1170. "orderCode"=>$orderCode,
  1171. "spuCode"=>$good['spuCode'],
  1172. "skuCode"=>$good['skuCode'],
  1173. "good_name"=>$good['good_name'],
  1174. "sale_price"=>$origin_price,
  1175. "total_fee"=>$origin_price*$data['good_num'],
  1176. "pakge_fee"=>$good['packing_fee'],
  1177. "cert_fee"=>$good['cert_fee'],
  1178. "open_fee"=>$good['open_fee'],
  1179. "cost_fee"=>$good['cost_fee'],
  1180. "mark_fee"=>$good['mark_fee'],
  1181. "demo_fee"=>$good['demo_fee'],
  1182. "good_num"=>$data['good_num'],
  1183. "good_type"=>1,
  1184. "order_type"=>2,
  1185. ];
  1186. if($good['is_stock']==0) {
  1187. $bol = $this->createCgd($cgd);
  1188. if ($bol == false) {
  1189. return false;
  1190. }
  1191. }
  1192. if ($data['sendtype']==1&&!empty($data['addrlist'])) {
  1193. $order = Db::name("order_num")->where(["orderCode" => $orderCode, "status" => 1])->where([["wsend_num", ">=", 0]])
  1194. ->find();
  1195. if ($order == false) {
  1196. return false;
  1197. }
  1198. foreach ($data['addrlist'] as $value) {
  1199. $temp = [];
  1200. $addrs = [];
  1201. if ($value['addr_code'] !== '' && is_array($value['addr_code'])) {
  1202. $addrs['provice_code'] = $value['addr_code'][0];
  1203. $addrs['city_code'] = $value['addr_code'][1];
  1204. $addrs['area_code'] = $value['addr_code'][2];
  1205. $addr = json_encode($addrs);
  1206. } else {
  1207. $addr = isset($value['addr_code']) ? $value['addr_code'] : '';
  1208. }
  1209. $temp['orderCode'] = $orderCode;
  1210. $temp['contactor'] = $value['contactor'];
  1211. $temp['mobile'] = $value['mobile'];
  1212. $temp['addr'] = $value['addr'];
  1213. $temp['addr_code'] = $addr;
  1214. $temp['customer_code'] =$data['companyNo'];
  1215. $temp['receipt_quantity'] = $value['receipt_quantity'];
  1216. $temp['post_fee'] = 0;
  1217. $temp['is_del'] = 0;
  1218. $temp['addtime'] = date("Y-m-d H:i:s");
  1219. $temp['updatetime'] = date("Y-m-d H:i:s");
  1220. $temp['arrive_time'] = $data['arrtime'];
  1221. $vmp = Db::name('order_addr')->insert($temp, true);
  1222. if ($vmp > 0) {
  1223. // if($good['is_stock']!=1){
  1224. // $outCode = makeNo("CK");
  1225. // $out = [
  1226. // "orderCode" => $orderCode,
  1227. // "outCode" => $outCode,
  1228. // "apply_id"=>$data['rm'],
  1229. // "apply_name"=>$data['ri'],
  1230. // "addrid" => $vmp,
  1231. // "post_name" => "",
  1232. // "post_code" => "",
  1233. // "post_fee" => 0,
  1234. // "sendtime" => date("Y-m-d H:i:s"),
  1235. // "send_num" => $value['receipt_quantity'],
  1236. // "check_num" => 0,
  1237. // "error_num" => 0,
  1238. // "wsm_code" => "",
  1239. // "order_type" => 4,
  1240. // "status" => 0,
  1241. // "addtime" => date("Y-m-d H:i:s"),
  1242. // "updatetime" => date("Y-m-d H:i:s")
  1243. // ];
  1244. // $ou = Db::name("order_out")->insert($out);
  1245. // if ($ou == false) {
  1246. // return false;
  1247. // }
  1248. // $order['send_num'] += $value['receipt_quantity'];
  1249. // $order['wsend_num'] -= $value['receipt_quantity'];
  1250. // if ($order['wsend_num'] < 0) {
  1251. // return false;
  1252. // }
  1253. // $ups = Db::name("order_num")->save($order);
  1254. // if ($ups) {
  1255. // $tep = [
  1256. // "cgdNo" => $order['cgdNo'],
  1257. // "outCode" => $outCode,
  1258. // "send_num" => $value['receipt_quantity'],
  1259. // "status" => 1,
  1260. // "addtime" => date("Y-m-d H:i:s"),
  1261. // "updatetime" => date("Y-m-d H:i:s")
  1262. // ];
  1263. // $sen = Db::name("order_send")->insert($tep);
  1264. // if ($sen == false) {
  1265. // return false;
  1266. // }
  1267. // }
  1268. // }
  1269. } else {
  1270. return false;
  1271. }
  1272. }
  1273. }
  1274. }
  1275. return true;
  1276. }
  1277. public function list()
  1278. {
  1279. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  1280. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  1281. $where[] = ['is_del', "=", 0];
  1282. $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !== "" ? trim($this->post['orderCode']) : "";
  1283. if ($orderCode !== "") {
  1284. $where[] = ['orderCode', "like", "%$orderCode%"];
  1285. }
  1286. $apply_name = isset($this->post['apply_name']) && $this->post['apply_name'] !== "" ? trim($this->post['apply_name'])
  1287. : "";
  1288. if ($apply_name !== "") {
  1289. $where[] = ['apply_name', "like", "%$apply_name%"];
  1290. }
  1291. $good_name = isset($this->post['good_name']) && $this->post['good_name'] !== "" ? trim($this->post['good_name'])
  1292. : "";
  1293. if ($good_name !== "") {
  1294. $where[] = ['good_name', "like", "%$good_name%"];
  1295. }
  1296. $good_code = isset($this->post['good_code']) && $this->post['good_code'] !== "" ? trim($this->post['good_code']) : "";
  1297. if ($good_code !== "") {
  1298. $where[] = ['good_code', "like", "%$good_code%"];
  1299. }
  1300. $customer_code = isset($this->post['customer_code']) && $this->post['customer_code'] !== "" ? trim($this->post['customer_code']) : "";
  1301. if ($customer_code !== "") {
  1302. $where[] = ['customer_code', "like", "%$customer_code%"];
  1303. }
  1304. $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !== "" ? trim($this->post['supplierNo']) : "";
  1305. if ($supplierNo !== "") {
  1306. $where[] = ['supplierNo', "like", "%$supplierNo%"];
  1307. }
  1308. $ordertype = isset($this->post['order_type']) && $this->post['order_type'] !== "" ? intval($this->post['order_type'])
  1309. : "";
  1310. if ($ordertype !== "") {
  1311. $where[] = ['order_type', "=", $ordertype];
  1312. }
  1313. $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  1314. if ($status !== "") {
  1315. $where[] = ['status', "=", $status];
  1316. }
  1317. $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
  1318. if ($start != "") {
  1319. $where[] = ["addtime", '>=', $start];
  1320. }
  1321. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
  1322. if ($end != "") {
  1323. $where[] = ["addtime", '<=', $end];
  1324. }
  1325. $count = Db::name('sale')->where($where)->count();
  1326. $total = ceil($count / $size);
  1327. $page = $page >= $total ? $total : $page;
  1328. $list = Db::name('sale')->where($where)->order("addtime desc")->page($page, $size)->select();
  1329. $data = [];
  1330. foreach ($list as $value) {
  1331. if($value['order_type']==3|| $value['order_type']==4){
  1332. $var = Db::name("good_zixun")->where(["spuCode"=>$value['good_code'],"is_del"=>0])->find();
  1333. }else {
  1334. $var = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
  1335. ->where(['a.skuCode' => $value['skuCode']])->find();
  1336. }
  1337. $value['can'] = isset($var['cat_id']) && $var['cat_id'] != 0 ? made($var['cat_id']) : [];
  1338. $value['supplierName'] = '';
  1339. if ($value['supplierNo'] != "") {
  1340. $supplier = Db::name("business")->where(["companyNo" => $value['supplierNo']])->find();
  1341. $value['supplierName'] = isset($supplier['company']) ? $supplier['company'] : "";
  1342. }
  1343. $value['customerName'] = '';
  1344. if ($value['customer_code'] != "") {
  1345. $supplier = Db::name("customer_info")->where(["companyNo" => $value['customer_code']])->find();
  1346. $value['customerName'] = isset($supplier['companyName']) ? $supplier['companyName'] : "";
  1347. }
  1348. $value['useage']="";
  1349. if($value['use_order']!=0){
  1350. $use =Db::name("order_use")->where(["id"=>$value['use_order']])->find();
  1351. $value['useage'] = isset($use['order_use']) ?$use['order_use']:"";
  1352. }else{
  1353. $value['use_order']='';
  1354. }
  1355. $data[] = $value;
  1356. }
  1357. return app_show(0, "获取成功", ['list' => $data, 'count' => $count]);
  1358. }
  1359. public function edit()
  1360. {
  1361. $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
  1362. $id = isset($this->post['id']) && $this->post['id'] !== "" ? trim($this->post['id']) : "";
  1363. if ($id == "") {
  1364. return error_show(1002, "参数id不能为空");
  1365. }
  1366. $etid = Db::name("sale")->where(["id" => $id, "is_del" => 0])->find();
  1367. if (empty($etid)) {
  1368. return error_show(1002, "未找到数据");
  1369. }
  1370. // $orderCode=isset($this->post['orderCode']) && $this->post['orderCode'] !=="" ? trim($this->post['orderCode']) :"";
  1371. // if($orderCode==""){
  1372. // return error_show(1002,"销售单code不能为空");
  1373. // }
  1374. $good_code = isset($this->post['good_code']) && $this->post['good_code'] !== "" ? trim($this->post['good_code']) : "";
  1375. if ($good_code == "") {
  1376. return error_show(1002, "商品code不能为空");
  1377. }
  1378. $ct = Db::name('good')->alias('a')->join('good_type b', 'b.good_code=a.good_code', 'left')
  1379. ->where(['b.type_code' => $good_code])->find();
  1380. if ($ct == "") {
  1381. return error_show(1002, "未找到商品数据");
  1382. }
  1383. $customer_code = isset($this->post['customer_code']) && $this->post['customer_code'] !== "" ? trim($this->post['customer_code']) : "";
  1384. if ($customer_code == "") {
  1385. return error_show(1002, "客户code不能为空");
  1386. }
  1387. $customer = Db::name("customer_info")->where(["companyNo" => $customer_code])->find();
  1388. if ($customer == false) {
  1389. return error_show(1004, "未找到客户数据");
  1390. }
  1391. $supplierNo = $this->post['supplierNo'] && $this->post['supplierNo'] !== "" ? trim($this->post['supplierNo']) : "";
  1392. if ($supplierNo == "") {
  1393. return error_show(1002, "参数supplierNo不能为空");
  1394. }
  1395. $supplier = Db::name("supplier")->where(["code" => $supplierNo])->find();
  1396. if ($supplier == false) {
  1397. return error_show(1004, "未找到平台供应商数据");
  1398. }
  1399. $apply_id = GetUserInfo($token);
  1400. if (empty($apply_id) || $apply_id['code'] != 0) {
  1401. return error_show(1002, "申请人数据不存在");
  1402. }
  1403. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1404. $ri = isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  1405. // $good_name = isset($this->post['good_name']) && $this->post['good_name'] !== "" ? trim
  1406. //($this->post['good_name']) : "";
  1407. // $good_num = isset($this->post['good_num']) && $this->post['good_num'] !== "" ? intval
  1408. //($this->post['good_num']) : "";
  1409. // $origin_price = isset($this->post['origin_price']) && $this->post['origin_price'] !== "" ? intval
  1410. // ($this->post['origin_price']) : "";
  1411. // $sale_price = isset($this->post['sale_price']) && $this->post['sale_price'] !== "" ? trim($this->post['sale_price']) : "";
  1412. // $total_price = isset($this->post['total_price']) && $this->post['total_price'] !== "" ? trim($this->post['total_price']) : "";
  1413. // $post_fee = isset($this->post['post_fee']) && $this->post['post_fee'] !== "" ? trim($this->post['post_fee']) : "";
  1414. // $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  1415. $vr = isset($this->post['order_addr']) && $this->post['order_addr'] !== "" ? $this->post['order_addr'] : "";
  1416. if ($vr == "") {
  1417. return error_show(1002, "参数order_addr不能为空");
  1418. }
  1419. $vi = isset($this->post['good_stock']) && $this->post['good_stock'] !== "" ? $this->post['good_stock'] : "";
  1420. if ($vi == "") {
  1421. return error_show(1002, "参数good_stock不能为空");
  1422. }
  1423. $good_num = intval(array_sum(array_column($vi, "num")));
  1424. Db::startTrans();
  1425. try {
  1426. $datn = [
  1427. "id" => $id,
  1428. "good_code" => $good_code,
  1429. "customer_code" => $customer_code,
  1430. "good_num" => $good_num,
  1431. "supplierNo" => $supplierNo,
  1432. "apply_id" => $rm,
  1433. "apply_name" => $ri,
  1434. "is_del" => 0,
  1435. "updatetime" => date("Y-m-d H:i:s")
  1436. ];
  1437. $datninfo = Db::name('sale')->where(['id' => $id, 'is_del' => 0])->save($datn);
  1438. if ($datninfo > 0) {
  1439. $stn = ["order_code"=>$etid['orderCode'],"status"=>$etid['status'],"action_remark"=>'',"action_type"=>"edit"];
  1440. ActionLog::logAdd($this->post['token'],$stn,"XSQRD",$etid['status'],$datn);
  1441. $order=["order_type"=>'XSQRD',"order_code"=>$etid['orderCode'],"order_id"=>$id,"order_status"=>$etid['status']];
  1442. ProcessOrder::AddProcess($this->post['token'],$order);
  1443. foreach ($vi as $ion) {
  1444. $iten = [];
  1445. isset($ion['id']) && $ion['id'] !== "" ? $iten['id'] = $ion['id'] : '';
  1446. $iten['orderCode'] = $etid['orderCode'];
  1447. $iten['wsm_code'] = $ion['wsm_code'];
  1448. $iten['stock_id'] = 0;
  1449. $iten['num'] = $ion['num'];
  1450. $iten['status'] = 1;
  1451. $iten['sale_price'] = $ct['original_price'];
  1452. isset($ion['id']) && $ion['id'] !== "" ? '' : $iten['addtime'] = date("Y-m-d H:i:s");
  1453. $iten['updatetime'] = date("Y-m-d H:i:s");
  1454. $vp = Db::name('sale_info')->save($iten);
  1455. if ($vp == false)
  1456. {
  1457. Db::rollback();
  1458. return error_show(1002, "更新失败");
  1459. }
  1460. }
  1461. foreach ($vr as $value) {
  1462. $temp = [];
  1463. isset($value['id']) && $value['id'] !== "" ? $temp['id'] = $value['id'] : '';
  1464. $temp['orderCode'] = $etid['orderCode'];
  1465. $temp['contactor'] = $value['contactor'];
  1466. $temp['mobile'] = $value['mobile'];
  1467. $temp['addr'] = $value['addr'];
  1468. $temp['addr_code'] = $value['addr_code'];
  1469. $temp['customer_code'] = $customer_code;
  1470. $temp['receipt_quantity'] = $value['receipt_quantity'];
  1471. $temp['post_fee'] = 0;
  1472. $temp['is_del'] = $value['is_del'];
  1473. isset($value['id']) && $value['id'] !== "" ? '' : $temp['addtime'] = date("Y-m-d H:i:s");
  1474. $temp['updatetime'] = date("Y-m-d H:i:s");
  1475. $temp['arrive_time'] = date("Y-m-d H:i:s");
  1476. $dat = Db::name('order_addr')->save($temp);
  1477. if ($dat == false) {
  1478. Db::rollback();
  1479. return error_show(1002, "更新失败");
  1480. }
  1481. }
  1482. Db::commit();
  1483. return error_show(0, "更新成功");
  1484. }
  1485. Db::rollback();
  1486. return error_show(1002, "更新失败");
  1487. } catch (Exception $e) {
  1488. Db::rollback();
  1489. return error_show(1005, $e->getMessage());
  1490. }
  1491. }
  1492. public function info()
  1493. {
  1494. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  1495. if ($id == "") {
  1496. return error_show(1002, "参数id不能为空");
  1497. }
  1498. $einfo = Db::name('sale')->where(['id' => $id, 'is_del' => 0])->find();
  1499. if (empty($einfo)) {
  1500. return error_show(1002, "未找到销售订单数据");
  1501. }
  1502. if($einfo['order_type']==3|| $einfo['order_type']==4){
  1503. $goon = Db::name("good_zixun")->where(["spuCode"=>$einfo['good_code'],"is_del"=>0])->find();
  1504. }else {
  1505. $goon = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
  1506. ->where(['a.skuCode' => $einfo['skuCode']])->find();
  1507. }
  1508. if ($goon==false) {
  1509. return error_show(1003, "未找到商品数据");
  1510. }else{
  1511. $goon['exclusive']=isset($goon['is_exclusive'])?makeExcluse($goon['is_exclusive']):"";
  1512. $unit =Db::name("unit")->where(["id"=>$goon['good_unit']])->find();
  1513. $goon['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1514. $spec = Db::name("good_spec")->where(["spuCode"=>$goon['spuCode'],"is_del"=>0])->select()->toArray();
  1515. $speclist=[];
  1516. if(!empty($spec)){
  1517. foreach ($spec as $value){
  1518. $temp=[];
  1519. $temp['id']=$value['id'];
  1520. $temp['spuCode']=$value['spuCode'];
  1521. $temp['spec_id']=$value['spec_id'];
  1522. $temp['spec_value_id']=$value['spec_value_id'];
  1523. $temp['is_del']=$value['is_del'];
  1524. $sp = Db::name("specs")->where(["id"=>$value['spec_id']])->find();
  1525. $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
  1526. $spv = Db::name("spec_value")->where(["id"=>$value['spec_value_id']])->find();
  1527. $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
  1528. $speclist[]=$temp;
  1529. }
  1530. }
  1531. $goon["speclist"]=empty($speclist)?[]:$speclist;
  1532. $proof =Db::name("good_proof")->where(["spuCode"=>$goon['spuCode'],"is_del"=>0])->order("updatetime desc")->field("id,proof_type,proof_url")->find();
  1533. $goon['proof'] = isset($proof)&&$proof!=false? $proof:[];
  1534. $goon['origin_place_cn']="";
  1535. $goon['delivery_place_cn']="";
  1536. if(isset($goon['delivery_place'])&&$goon['delivery_place']!==""){
  1537. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  1538. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$goon['delivery_place']);
  1539. $goon['delivery_place_cn']=GetAddr(json_encode($place));
  1540. }
  1541. if(isset($goon['delivery_place'])&&$goon['origin_place']!==""){
  1542. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  1543. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$goon['origin_place']);
  1544. $goon['origin_place_cn']=GetAddr(json_encode($place));
  1545. }
  1546. if($goon['brand_id']!=0){
  1547. $brand=Db::name("brand")->where(["id"=>$goon['brand_id']])->find();
  1548. $goon["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1549. }else{
  1550. $goon["brand_name"]="";
  1551. $goon["brand_id"]="";
  1552. }
  1553. $supplier = Db::name("supplier")->where(["code"=>$goon['supplierNo']])->find();
  1554. $goon['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  1555. $goon['noble_name']=isset($goon['noble_metal'])&&$goon['noble_metal']!=0?$this->noble[$goon['noble_metal']] :"";
  1556. if(isset($goon['companyNo'])&&$goon['companyNo']!=""){
  1557. $company = Db::name("business")->where(["companyNo"=>$goon['companyNo']])->find();
  1558. }
  1559. $goon['company'] = isset($company['company'])?$company['company']:"";
  1560. }
  1561. $int = isset($goon['cat_id']) && $goon['cat_id'] != 0 ? made($goon['cat_id']) : [];
  1562. $in = Db::name('customer_info')->where(['companyNo' => $einfo['customer_code']])->field('companyName')->find();
  1563. $einfo['supplierName'] = '';
  1564. if ($einfo['supplierNo'] != "") {
  1565. $supplier = Db::name("business")->where(["companyNo" => $einfo['supplierNo']])->find();
  1566. $einfo['supplierName'] = isset($supplier['company']) ? $supplier['company'] : "";
  1567. }
  1568. $fo = Db::name('order_addr')->alias("a")->leftJoin("order_out b","a.id=b.addrid")
  1569. ->where(['a.orderCode' => $einfo['orderCode'], 'a.is_del' => 0])->field("a.*,b.post_name,b.post_code,
  1570. 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")
  1571. ->select();
  1572. $addrs = [];
  1573. if (!empty($fo)) {
  1574. foreach ($fo as $value) {
  1575. $value['addr_info'] = "";
  1576. $value['send_num'] = 0;
  1577. if ($value['addr_code'] != "") {
  1578. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  1579. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$value['addr_code']);
  1580. $addr = GetAddr(json_encode($place));
  1581. $value['addr_info'] = $addr;
  1582. }
  1583. $value['wsm_name']="";
  1584. if(isset($value['wsm_code'])&&$value['wsm_code']!=""){
  1585. $wsmcode = Db::name("warehouse_info")->where(["wsm_code" => $value['wsm_code']])->find();
  1586. $value['wsm_name'] =isset($wsmcode['name'])?$wsmcode['name']:"";
  1587. }
  1588. $addrs[] = $value;
  1589. }
  1590. }
  1591. $einfo['useage']="";
  1592. if($einfo['use_order']!=0){
  1593. $use =Db::name("order_use")->where(["id"=>$einfo['use_order']])->find();
  1594. $einfo['useage'] = isset($use['order_use']) ?$use['order_use']:"";
  1595. }else{
  1596. $einfo['use_order']='';
  1597. }
  1598. $einfo['platform_name']='';
  1599. if($einfo['platform_id']!=0){
  1600. $plat=Db::name("platform")->where(['id'=>$einfo['platform_id']])->find();
  1601. $einfo['platform_name']=isset($plat['platform_name'])?$plat['platform_name']:"";
  1602. }
  1603. $einfo['companyName'] = isset($in['companyName']) ? $in['companyName'] : "";
  1604. $einfo['addrs'] = $addrs;
  1605. $einfo['can'] = $int;
  1606. $einfo['goodinfo'] = $goon;
  1607. if (empty($einfo)) {
  1608. return error_show(1002, "未找到销售订单数据");
  1609. } else {
  1610. return app_show(0, "获取成功", $einfo);
  1611. }
  1612. }
  1613. public function del()
  1614. {
  1615. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  1616. if ($id === "") {
  1617. return error_show(1002, "参数id不能为空");
  1618. }
  1619. $ed = Db::name('sale')->where(['id' => $id, 'is_del' => 0])->find();
  1620. if (empty($ed)) {
  1621. return error_show(1002, "未找到销售订单数据");
  1622. }
  1623. $str = Db::name('sale')->update(['id' => $id, 'is_del' => 1, 'updatetime' => date("Y-m-d H:i:s")]);
  1624. if ($str) {
  1625. $stc = ["order_code"=>$id,"status"=>$ed['status'],"action_remark"=>'',"action_type"=>"delete"];
  1626. ActionLog::logAdd($this->post['token'],$stc,"XSQRD",$ed['status'],['id' => $id, 'is_del' => 1, 'updatetime' => date("Y-m-d H:i:s")]);
  1627. $order=["order_type"=>'XSQRD',"order_code"=>$ed['orderCode'],"order_id"=>$id,"order_status"=>$ed['status']];
  1628. ProcessOrder::workdel($order);
  1629. return error_show(0, "删除成功");
  1630. } else {
  1631. return error_show(1002, "删除失败");
  1632. }
  1633. }
  1634. public function status()
  1635. {
  1636. $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
  1637. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  1638. if ($id == "") {
  1639. return error_show(1002, "参数id不能为空");
  1640. }
  1641. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  1642. if ($status == "") {
  1643. return error_show(1002, "订单状态不能为空");
  1644. }
  1645. $dio = Db::name('sale')->where(['id' => $id, 'is_del' => 0])->find();
  1646. if (empty($dio)) {
  1647. return error_show(1002, "销售单信息未找到");
  1648. }
  1649. if ($status == 1 && $dio['order_type'] == 2) {
  1650. $zxinfo = Db::name("consult")->where(["zxNo" => $dio['zxNo'], "is_del" => 0])->find();
  1651. if ($zxinfo == false) {
  1652. return error_show(1004, "未找到咨询单数据");
  1653. }
  1654. $gold['price'] = 0;
  1655. if ($zxinfo['zx_type'] == 2) {
  1656. if ($zxinfo['metals'] == "") {
  1657. return error_show(1004, "未找到咨询单贵金属类型数据");
  1658. }
  1659. $metals = $zxinfo['metals'] == '18K' ? 1 : ($zxinfo['metals'] == '24K' ? 2 : 3);
  1660. $gold = Db::name("gold_price")->where(["type" => $metals])->order("addtime desc")->find();
  1661. if (empty($gold)) {
  1662. return error_show(1004, "未找到咨询单贵金属类型数据");
  1663. }
  1664. $dio['gold_price'] = $gold['price'];
  1665. }
  1666. $wsm = Db::name("warehouse_info")->where(["supplierNo" => $zxinfo['gysNo'], "wsm_type" => 2])->find();
  1667. if (empty($wsm)) {
  1668. return error_show(1002, "供应商仓库未找到");
  1669. }
  1670. }
  1671. $apply_id = GetUserInfo($token);
  1672. if (empty($apply_id) || $apply_id['code'] != 0) {
  1673. return error_show(1002, "申请人数据不存在");
  1674. }
  1675. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1676. $ri = isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  1677. Db::startTrans();
  1678. try {
  1679. $vmp =$dio['status'];
  1680. $dio['status'] = $status;
  1681. $dio['updatetime'] = date("Y-m-d H:i:s");
  1682. $st = Db::name('sale')->save($dio);
  1683. if ($st) {
  1684. $stn = ["order_code"=>$dio['orderCode'],"status"=>$vmp,"action_remark"=>'',"action_type"=>"status"];
  1685. ActionLog::logAdd($this->post['token'],$stn, $dio['order_type'] == 2?"ZXQRD":"XSQRD",$dio['status'],$dio);
  1686. $order=["order_type"=>$dio['order_type'] == 2?"ZXQRD":"XSQRD","order_code"=>$dio['orderCode'],"order_id"=>$id,"order_status"=>$dio['status']];
  1687. ProcessOrder::AddProcess($this->post['token'],$order);
  1688. if ($status == 3 && $dio['order_type'] == 1) {
  1689. $dn = Db::name('sale_info')->where(['orderCode' => $st['orderCode']])->select();
  1690. foreach ($dn as $value) {
  1691. $dm = Db::name('good_stock')->where(['wsm_code' => $value['wsm_code'], 'good_type_code' => $st['good_code']])->find();
  1692. if ($dm == "") {
  1693. Db::rollback();
  1694. return error_show(1003, "未找到商品数据");
  1695. }
  1696. if ($value['num'] > $dm['usable_stock']) {
  1697. Db::rollback();
  1698. return error_show(1002, "超出库存数量");
  1699. }
  1700. $dm['usable_stock'] -= $value['num'];
  1701. $dm['wait_out_stock'] += $value['num'];
  1702. $send = Db::name("order_out")->where(["wsm_code" => $value['wsm_code']])->sum("send_num");
  1703. $value['send_num'] = $send ?? 0;
  1704. $value['wsend_num'] = $value['num'] - $value['send_num'];
  1705. $Db = Db::name('good_stock')->update($dm);
  1706. $Db['updatetime'] = date('Y-m-d H:i:s');
  1707. if ($Db == false) {
  1708. Db::rollback();
  1709. return error_show(1002, "状态更新失败");
  1710. }
  1711. }
  1712. }
  1713. if ($status == 1 && $dio['order_type'] == 2) {
  1714. $cgd = makeNo("CG");
  1715. $clll = [
  1716. "cgdNo" => $cgd,
  1717. "bkcode" => $dio['orderCode'],
  1718. "wsm_code" => $wsm['wsm_code'],
  1719. "cgder_id" => "0",
  1720. "cgder" => $zxinfo['saler'],
  1721. "good_code" => "GD-" . $zxinfo['cpNo'],
  1722. "good_name" => $zxinfo['cpName'],
  1723. "good_type_code" => $zxinfo['cpNo'],
  1724. "good_num" => $dio['good_num'],
  1725. "good_price" => $zxinfo['total_fee'],
  1726. "total_fee" => round($zxinfo['total_fee'] * $dio['good_num'], 2),
  1727. "pakge_fee" => $zxinfo['package_fee'],
  1728. "cert_fee" => $zxinfo['cert_fee'],
  1729. "open_fee" => $zxinfo['open_fee'],
  1730. "delivery_fee" => $zxinfo['delivery_fee'],
  1731. "mark_fee" => $zxinfo['mark_fee'],
  1732. "teach_fee" => $zxinfo['cost_fee'],
  1733. "demo_fee" => $zxinfo['demo_fee'],
  1734. "nake_fee" => $zxinfo['bare_fee'],
  1735. "weight" => isset($zxinfo['weight']) ? $zxinfo['weight'] : 0,
  1736. "supplierNo" => $zxinfo['gysNo'],
  1737. "supplier_name" => $zxinfo['gysname'],
  1738. "gold_price" => $gold['price'],
  1739. "send_num" => 0,
  1740. "wsend_num" => $dio['good_num'],
  1741. "remark" => '',
  1742. "lasttime" => date("Y-m-d H:i:s"),
  1743. "is_del" => 0,
  1744. "status" => $dio['send_type'] == 1 ? 3 : 0,
  1745. "order_type" => 2,
  1746. "addtime" => date("Y-m-d H:i:s"),
  1747. "updatetime" => date("Y-m-d H:i:s")
  1748. ];
  1749. $cgin = Db::name("purchease_order")->insert($clll);
  1750. // var_dump(Db::name("purchease_order")->getLastSql(),$clll);
  1751. if ($cgin == false) {
  1752. $stb = ["order_code"=>$cgd,"status"=> $clll['status'],"action_remark"=>'',"action_type"=>"create"];
  1753. ActionLog::logAdd($this->post['token'],$stb,"xsd", $clll['status'],$stb);
  1754. Db::rollback();
  1755. return error_show(1002, "咨询采购单创建商品失败");
  1756. }
  1757. if ($dio['send_type'] == 1) {
  1758. $addr = Db::name('order_addr')->where(["orderCode" => $dio['orderCode'], 'is_del' => 0])->select();
  1759. foreach ($addr as $value) {
  1760. $outCode = makeNo("CK");
  1761. $data = [
  1762. "wsm_code" => $wsm['wsm_code'],
  1763. "orderCode" => $dio['orderCode'],
  1764. "outCode" => $outCode,
  1765. "order_type" => $dio['order_type'],
  1766. "apply_id" => $rm,
  1767. "apply_name" => $ri,
  1768. "addrid" => $value['id'],
  1769. "post_name" => '',
  1770. "post_code" => '',
  1771. "post_fee" => '',
  1772. "sendtime" => date("Y-m-d H:i:s"),
  1773. "send_num" => $value['receipt_quantity'],
  1774. "check_num" => 0,
  1775. "error_num" => 0,
  1776. "status" => 0,
  1777. "addtime" => date("Y-m-d H:i:s"),
  1778. "updatetime" => date("Y-m-d H:i:s")
  1779. ];
  1780. $datainfo = Db::name('order_out')->insert($data);
  1781. if (!$datainfo) {
  1782. $sti = ["order_code"=>$dio['orderCode'],"status"=> 0,"action_remark"=>'',"action_type"=>"create"];
  1783. ActionLog::logAdd($this->post['token'],$sti,"xsd",0,$sti);
  1784. Db::rollback();
  1785. return error_show(1003, "创建失败");
  1786. }
  1787. }
  1788. $wsm_in_code = makeNo("IC");
  1789. $orin = [
  1790. "wsm_in_code" => $wsm_in_code,
  1791. "cgdNo" => $cgd,
  1792. "wsm_code" => $wsm['wsm_code'],
  1793. "wsm_reaper" => "",
  1794. "send_num" => $dio['good_num'],
  1795. "post_company" => '',
  1796. "post_code" => '',
  1797. "post_fee" => '',
  1798. "sendtime" => date("Y-m-d H:i:s"),
  1799. "apply_id" => $rm,
  1800. "apply_name" => $ri,
  1801. "wait_num" => 0,
  1802. "status" => 4,
  1803. "addtime" => date("Y-m-d H:i:s"),
  1804. "updatetime" => date("Y-m-d H:i:s")
  1805. ];
  1806. $win = Db::name("purchease_in")->insert($orin);
  1807. if (!$win){
  1808. $stv = ["order_code"=>$wsm_in_code,"status"=>4,"action_remark"=>'',"action_type"=>"create"];
  1809. ActionLog::logAdd($this->post['token'],$stv,"xsd",4,$stv);
  1810. Db::rollback();
  1811. return error_show(1003, "创建失败");
  1812. }
  1813. $good = Db::name("good_stock")->where(["wsm_code" => $wsm['wsm_code'], "good_type_code" => $zxinfo['cpNo'], "is_del" => 0])->find();
  1814. if (empty($good)) {
  1815. $good = [
  1816. "good_type_code" => $zxinfo['cpNo'],
  1817. "wsm_code" => $wsm['wsm_code'],
  1818. "usable_stock" => 0,
  1819. "wait_out_stock" => 0,
  1820. "total_stock" => 0,
  1821. "addtime" => date("Y-m-d H:i:s"),
  1822. "updatetime" => date("Y-m-d H:i:s"),
  1823. ];
  1824. }
  1825. $good['wait_out_stock'] += $dio['good_num'];
  1826. $good['total_stock'] = $good['usable_stock'] + $good['wait_out_stock'];
  1827. $good['updatetime'] = date("Y-m-d H:i:s");
  1828. $upd = Db::name("good_stock")->save($good);
  1829. if (!$upd) {
  1830. $ste = ["order_code"=> $zxinfo['cpNo'],"status"=>0,"action_remark"=>'',"action_type"=>"create"];
  1831. ActionLog::logAdd($this->post['token'],$ste,"xsd",0,$ste);
  1832. Db::rollback();
  1833. return error_show(1003, "创建失败");
  1834. }
  1835. }
  1836. }
  1837. }
  1838. Db::commit();
  1839. return error_show(0, "订单状态更新成功");
  1840. } catch (Exception $e) {
  1841. Db::rollback();
  1842. return error_show(1005, $e->getMessage());
  1843. }
  1844. }
  1845. public function fee()
  1846. {
  1847. $id = isset($this->post['id']) && $this->post['id'] !== "" ? trim($this->post['id']) : "";
  1848. if ($id == "") {
  1849. return error_show(1002, "参数id不能为空");
  1850. }
  1851. $etid = Db::name("sale")->where(["id" => $id, "is_del" => 0])->find();
  1852. if (empty($etid)) {
  1853. return error_show(1002, "未找到数据");
  1854. }
  1855. $vr = isset($this->post['order_addr']) && $this->post['order_addr'] !== "" ? $this->post['order_addr'] : "";
  1856. if ($vr == "") {
  1857. return error_show(1002, "参数order_addr不能为空");
  1858. }
  1859. Db::startTrans();
  1860. try {
  1861. $data = [
  1862. "id" => $id,
  1863. "status" => 2,
  1864. "is_del" => 0,
  1865. "updatetime" => date("Y-m-d H:i:s")
  1866. ];
  1867. $datainfo = Db::name('sale')->where(['id' => $id, 'is_del' => 0])->save($data);
  1868. if ($datainfo) {
  1869. $stx = ["order_code"=> $etid['orderCode'],"status"=>$etid['status'],"action_remark"=>'',
  1870. "action_type"=>"edit"];
  1871. ActionLog::logAdd($this->post['token'],$stx,$etid['order_type'] == 2?"ZXQRD":"XSQRD",2,$data);
  1872. $order=["order_type"=>$etid['order_type'] == 2?"ZXQRD":"XSQRD","order_code"=>$etid['orderCode'],"order_id"=>$id,"order_status"=>$data['status']];
  1873. ProcessOrder::AddProcess($this->post['token'],$order);
  1874. foreach ($vr as $value) {
  1875. $tm = [];
  1876. $tm['id'] = $value['id'];
  1877. $tm['orderCode'] = $etid['orderCode'];
  1878. $tm['post_fee'] = $value['post_fee'];
  1879. $tm['updatetime'] = date("Y-m-d H:i:s");
  1880. $dn = Db::name('order_addr')->save($tm);
  1881. if ($dn == false) {
  1882. Db::rollback();
  1883. return error_show(1002, "更新失败");
  1884. }
  1885. }
  1886. Db::commit();
  1887. return error_show(0, "更新成功");
  1888. }
  1889. Db::rollback();
  1890. return error_show(1003, "更新失败");
  1891. } catch (Exception $e) {
  1892. Db::rollback();
  1893. return error_show(1005, $e->getMessage());
  1894. }
  1895. }
  1896. public function out()
  1897. {
  1898. $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
  1899. $outCode = makeNo("CK");
  1900. $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !== "" ? trim($this->post['orderCode']) : "";
  1901. if ($orderCode == "") {
  1902. return error_show(1002, "参数orderCoder不能为空");
  1903. }
  1904. $der = Db::name('sale')->where(['orderCode' => $orderCode])->find();
  1905. if ($der == "") {
  1906. return error_show(1002, "未找到出库订单单号");
  1907. }
  1908. // $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code'] !== "" ? trim($this->post['wsm_code']) : "";
  1909. // if ($wsm_code == "") {
  1910. // return error_show(1002, "参数wsm_code不能为空");
  1911. // }
  1912. // $wsm = Db::name('sale_info')->where(['wsm_code' => $wsm_code, 'orderCode' => $der['orderCode']])->find();
  1913. // if ($wsm == "") {
  1914. // return error_show(1002, "未找到仓库编码");
  1915. // }
  1916. $post_name = isset($this->post['post_name']) && $this->post['post_name'] !== "" ? trim($this->post['post_name']) : "";
  1917. if ($post_name == "") {
  1918. return error_show(1002, "物流公司不能为空");
  1919. }
  1920. $post_code = isset($this->post['post_code']) && $this->post['post_code'] !== "" ? trim($this->post['post_code']) : "";
  1921. if ($post_code == "") {
  1922. return error_show(1002, "物流单号不能为空");
  1923. }
  1924. $post_fee = isset($this->post['post_fee']) && $this->post['post_fee'] !== "" ? intval($this->post['post_fee']) : "";
  1925. if ($post_fee == "") {
  1926. return error_show(1002, "物流费不能为空");
  1927. }
  1928. $send_num = isset($this->post['send_num']) && $this->post['send_num'] !== "" ? $this->post['send_num'] : "";
  1929. if ($send_num == "") {
  1930. return error_show(1002, "发货数量不能为空");
  1931. }
  1932. if ($send_num > $der['wsend_num']) {
  1933. return error_show(1002, "超出可发货数量");
  1934. }
  1935. $apply_id = GetUserInfo($token);
  1936. if (empty($apply_id) || $apply_id['code'] != 0) {
  1937. return error_show(1002, "申请人数据不存在");
  1938. }
  1939. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1940. $ri = isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  1941. $addrid = isset($this->post['addrid']) && $this->post['addrid'] !== "" ? intval($this->post['addrid']) : "";
  1942. $dr = Db::name('order_addr')->where(['id' => $addrid, 'is_del' => 0])->find();
  1943. if (empty($dr)) {
  1944. return error_show(1003, "收货人信息未找到");
  1945. }
  1946. if ($dr['orderCode'] !== $orderCode) {
  1947. return error_show(1002, "订单code不存在");
  1948. }
  1949. $sendtime = isset($this->post['sendtime']) && $this->post['sendtime'] !== "" ? $this->post['sendtime'] : date("Y-m-d H:i:s");
  1950. // $check_num = isset($this->post['check_num']) && $this->post['check_num'] !=="" ? $this->post['check_num'] :"";
  1951. // $error_num = isset($this->post['error_num']) && $this->post['error_num'] !=="" ? $this->post['error_num'] :"";
  1952. $status = isset($this->post['status']) && $this->post['status'] !== "" ? $this->post['status'] : "1";
  1953. //$order_type = isset($this->post['order_type']) && $this->post['order_type'] !=="" ? $this->post['order_type'] :"1";
  1954. //$dn=Db::name('sale_info')->where(['wsm_code'=>$outCode])->find();
  1955. Db::startTrans();
  1956. try {
  1957. $data = [
  1958. "wsm_code" => "",
  1959. "orderCode" => $orderCode,
  1960. "outCode" => $outCode,
  1961. "order_type" => $der['order_type'],
  1962. "apply_id" => $rm,
  1963. "apply_name" => $ri,
  1964. "addrid" => $dr['id'],
  1965. "post_name" => $post_name,
  1966. "post_code" => $post_code,
  1967. "post_fee" => $post_fee,
  1968. "sendtime" => $sendtime,
  1969. "send_num" => $send_num,
  1970. "check_num" => 0,
  1971. "error_num" => 0,
  1972. "status" => $status,
  1973. "addtime" => date("Y-m-d H:i:s"),
  1974. "updatetime" => date("Y-m-d H:i:s")
  1975. ];
  1976. $datainfo = Db::name('order_out')->insert($data,true);
  1977. if ($datainfo>0) {
  1978. $stx = ["order_code"=>$outCode,"status"=>$status,"action_remark"=>'',"action_type"=>"create"];
  1979. ActionLog::logAdd($this->post['token'],$stx,$der['order_type']==1?"CKD":'ZXCKD',$status,$data);
  1980. $order=["order_type"=>$der['order_type']==1?"CKD":'ZXCKD',"order_code"=>$outCode,"order_id"=>$datainfo,"order_status"=>$data['status']];
  1981. ProcessOrder::AddProcess($this->post['token'],$order);
  1982. if ($status == 1) {
  1983. $item =$der['status'];
  1984. $der['send_num'] += $send_num;
  1985. $der['wsend_num'] -= $send_num;//($der['send_num'])?$der['wsend_num'] =="" ? $der['send']
  1986. $der['send_status'] = $der['send_num'] == 0 ? 1 : $der['wsend_num'] == 0 ? 3 : 2;
  1987. $der['status'] = $der['send_num'] == 0 ? 3 : $der['wsend_num'] == 0 ? 5 : 4;
  1988. $der['updatetime'] = date("Y-m-d H:i:s");
  1989. $si = Db::name('sale')->save($der);
  1990. if ($si == false) {
  1991. Db::rollback();
  1992. return error_show(1003, "更新失败");
  1993. }
  1994. $stx = ["order_code"=>$orderCode,"status"=>$item,"action_remark"=>'',"action_type"=>"edit"];
  1995. ActionLog::logAdd($this->post['token'],$stx,$der['order_type'] == 2?"ZXQRD":"XSQRD",$der['status'],$der);
  1996. $order=["order_type"=>$der['order_type'] == 2?"ZXQRD":"XSQRD","order_code"=>$orderCode,"order_id"=>$der['id'],"order_status"=>$data['status']];
  1997. ProcessOrder::AddProcess($this->post['token'],$order);
  1998. $str = Db::name('good_stock')->where(['wsm_code' => $var['wsm_code'], 'good_type_code' => $der['good_code']])->find();
  1999. if ($str == false) {
  2000. Db::rollback();
  2001. return error_show(1002, "商品数据未找到");
  2002. }
  2003. if ($send_num > $str['wait_out_stock']) {
  2004. Db::rollback();
  2005. return error_show(1002, "超出库存数量");
  2006. }
  2007. $str['wait_out_stock'] -= $send_num;
  2008. $str['intra_stock'] += $send_num;
  2009. $str['updatetime'] = date("Y-m-d H:i:s");
  2010. $stre = Db::name('good_stock')->save($str);
  2011. if ($stre == false) {
  2012. Db::rollback();
  2013. return error_show(1002, "状态更新失败");
  2014. }
  2015. $good_data[]= ["stock_id"=>$str['id'],"type"=>2,'stock'=>$send_num,"stock_name"=>"wait_out_stock"];
  2016. $good_data[]= ["stock_id"=>$str['id'],"type"=>1,'stock'=>$send_num,"stock_name"=>"intra_stock"];
  2017. GoodLog::LogAdd($this->post['token'],$good_data,$der['order_type'] != 1?"ZXQRD":"XSQRD");
  2018. }
  2019. Db::commit();
  2020. return error_show(0, "创建成功");
  2021. } else {
  2022. Db::rollback();
  2023. return error_show(1003, "创建失败");
  2024. }
  2025. } catch (Exception $e) {
  2026. Db::rollback();
  2027. return error_show(1005, $e->getMessage());
  2028. }
  2029. }
  2030. public function customer()
  2031. {
  2032. $outCode = isset($this->post['outCode']) && $this->post['outCode'] !== "" ? trim($this->post['outCode']) : "";
  2033. if (empty($outCode)) {
  2034. return error_show(1002, "销售订单编号不能为空");
  2035. }
  2036. $codeinfo = Db::name('order_out')->where(['outCode' => $outCode])->find();
  2037. if ($codeinfo == "") {
  2038. return error_show(1003, "未找到订单数据");
  2039. }
  2040. // $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !=="" ? trim($this->post['orderCode']) :"";
  2041. // if($orderCode==""){
  2042. // return error_show(1002,"参数orderCoder不能为空");
  2043. // }
  2044. $dr = Db::name('sale')->where(['orderCode' => $codeinfo['orderCode']])->find();
  2045. if ($dr == "") {
  2046. return error_show(1002, "未找到销售订单");
  2047. }
  2048. $status = isset($this->post['status']) && $this->post['status'] !== "" ? $this->post['status'] : "";
  2049. if ($status == "") {
  2050. return error_show(10002, "状态不能为空");
  2051. }
  2052. Db::startTrans();
  2053. try {
  2054. $time = $codeinfo['status'];
  2055. $codeinfo['status'] = $status;
  2056. $codeinfo['updatetime'] = date("Y-m-d H:i:s");
  2057. $cust = Db::name('order_out')->save($codeinfo);
  2058. if ($cust) {
  2059. $stx = ["order_code"=>$outCode,"status"=>$time,"action_remark"=>'',"action_type"=>"status"];
  2060. ActionLog::logAdd($this->post['token'],$stx,$codeinfo['order_type'] == 2?"ZXCKD":"CKD",$codeinfo['status'],$codeinfo);
  2061. $order=["order_type"=>$codeinfo['order_type'] == 2?"ZXCKD":"CKD","order_code"=>$outCode,
  2062. "order_id"=>$codeinfo['id'],"order_status"=>$codeinfo['status']];
  2063. ProcessOrder::AddProcess($this->post['token'],$order);
  2064. if ($status == 1) {
  2065. $stokc =Db::name("good_stock")->where(['spuCode'=>$codeinfo['spuCode'],"wsm_code"=>$codeinfo['wsm_code'],
  2066. "is_del"=>0])->find();
  2067. if($stokc==false){
  2068. Db::rollback();
  2069. return error_show(1002, "未找库存到数据");
  2070. }else{
  2071. if ($codeinfo['send_num'] > $stokc['usable_stock']) {
  2072. Db::rollback();
  2073. return error_show(1002, "超出库存数量");
  2074. }
  2075. $stokc['wait_out_stock']+=$codeinfo['send_num'];
  2076. $stokc['usable_stock']-=$codeinfo['send_num'];
  2077. $stokc['updatetime']=date("Y-m-d H:i:s");
  2078. }
  2079. $stoc= Db::name("good_stock")->save($stokc);
  2080. if($stoc==false){
  2081. Db::rollback();
  2082. return error_show(1002, "库存更新失败");
  2083. }
  2084. $item =$dr['status'];
  2085. $dr['send_num'] +=$codeinfo['send_num'];
  2086. $dr['wsend_num'] -= $codeinfo['send_num'];//($der['send_num'])?$der['wsend_num'] =="" ? $der['send']
  2087. $dr['send_status'] = $dr['send_num'] == 0 ? 1 : $dr['wsend_num'] == 0 ? 3 : 2;
  2088. $dr['status'] = $dr['send_num'] == 0 ? 3 : $dr['wsend_num'] == 0 ? 5 : 4;
  2089. $dr['updatetime'] = date("Y-m-d H:i:s");
  2090. $si = Db::name('sale')->save($dr);
  2091. if ($si == false) {
  2092. Db::rollback();
  2093. return error_show(1003, "更新失败");
  2094. }
  2095. $stx = ["order_code"=>$dr['orderCode'],"status"=>$item,"action_remark"=>'',"action_type"=>"edit"];
  2096. ActionLog::logAdd($this->post['token'],$stx,$dr['order_type'] == 2?"ZXQRD":"XSQRD",$dr['status'],
  2097. $dr);
  2098. $order=["order_type"=>$dr['order_type'] == 2?"ZXQRD":"XSQRD","order_code"=>$dr['orderCode'],"order_id"=>$dr['id'],"order_status"=>$dr['status']];
  2099. ProcessOrder::AddProcess($this->post['token'],$order);
  2100. $good_data[]= ["stock_id"=>$stoc['id'],"type"=>1,'stock'=>$codeinfo['send_num'],"stock_name"=>"wait_out_stock"];
  2101. $good_data[]= ["stock_id"=>$stoc['id'],"type"=>2,'stock'=>$codeinfo['send_num'],"stock_name"=>"usable_stock"];
  2102. GoodLog::LogAdd($this->post['token'],$good_data,'CKD');
  2103. }
  2104. if ($status == 3) {
  2105. $var = Db::name('good_stock')->where(['wsm_code' => $codeinfo['wsm_code'], 'good_type_code' => $dr['good_code']])->find();
  2106. if ($var == false) {
  2107. Db::rollback();
  2108. return error_show(1002, "未找到商品数据");
  2109. }
  2110. if ($codeinfo['send_num'] > $var['intra_stock']) {
  2111. Db::rollback();
  2112. return error_show(1003, "超出在途库存数量");
  2113. }
  2114. $var['intra_stock'] -= $codeinfo['send_num'];
  2115. $var['updatetime'] = date("Y-m-d H:i:s");
  2116. $stre = Db::name('good_stock')->save($var);
  2117. $good_data[]= ["stock_id"=>$var['id'],"type"=>2,'stock'=>$codeinfo['send_num'],"stock_name"=>"intra_stock"];
  2118. GoodLog::LogAdd($this->post['token'],$good_data,$codeinfo['order_type'] == 2?"ZXCKD":"CKD");
  2119. if ($stre == false) {
  2120. Db::rollback();
  2121. return error_show(1002, "状态更新失败");
  2122. }
  2123. }
  2124. Db::commit();
  2125. return error_show(0, "出库订单更新成功");
  2126. } else {
  2127. Db::rollback();
  2128. return error_show(1003, "出库订单更新失败");
  2129. }
  2130. } catch (Exception $e) {
  2131. Db::rollback();
  2132. return error_show(1005, $e->getMessage());
  2133. }
  2134. }
  2135. public function difflist()
  2136. {
  2137. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  2138. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  2139. $where = [];
  2140. $cgdNo = isset($this->post['orderCode']) && $this->post['orderCode'] != "" ? trim($this->post['orderCode']) : "";
  2141. if ($cgdNo != "") {
  2142. $where[] = ['a.orderCode', "like", "%$cgdNo%"];
  2143. }
  2144. $diffNo = isset($this->post['diffCode']) && $this->post['diffCode'] != "" ? trim($this->post['diffCode']) : "";
  2145. if ($diffNo != "") {
  2146. $where[] = ['a.diffCode', "like", "%$diffNo%"];
  2147. }
  2148. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  2149. if ($status !== "") {
  2150. $where[] = ['a.status', "=", $status];
  2151. }
  2152. $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
  2153. if ($start != "") {
  2154. $where[] = ["a.addtime", '>=', $start];
  2155. }
  2156. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
  2157. if ($end != "") {
  2158. $where[] = ["a.addtime", '<=', $end];
  2159. }
  2160. // $apply_name = isset($this->post['apply_name']) && $this->post['apply_name'] !==""? intval($this->post['apply_name']):"";
  2161. // if($apply_name!==""){
  2162. // $where[]=['a.apply_name',"like","%$apply_name%"];
  2163. // }
  2164. $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !== "" ? trim($this->post['supplierNo']) : "";
  2165. if ($supplierNo != "") {
  2166. $supplier = Db::name("supplier")->where([['code', "like", "%$supplierNo%"]])->column('code');
  2167. // if(empty($supplier)){
  2168. // return error_show(1004,"未找到供应商信息");
  2169. // }
  2170. $wsmcode = Db::name("sale")->where([
  2171. "is_del" => 0, "supplierNo" => $supplier])->column("orderCode");
  2172. $where[] = ['a.orderCode', "in", $wsmcode];
  2173. }
  2174. $companyNo =isset($this->post['companyNo']) &&$this->post['companyNo'] !=="" ? trim($this->post['companyNo']):"";
  2175. if($companyNo!=""){
  2176. $where[]=['c.customer_code',"like","%$companyNo%"];
  2177. }
  2178. $count = Db::name('sale_diff')->alias('a')
  2179. ->join("sale c", "c.orderCode=a.orderCode", "left")
  2180. ->join("customer_info v", "v.companyNo=c.customer_code", "left")
  2181. ->join("good b", "b.good_code=a.good_code", "left")
  2182. ->where($where)->count();
  2183. $total = ceil($count / $size);
  2184. $page = $page >= $total ? $total : $page;
  2185. //var_dump( Db::name('sale_diff')->getLastSql());
  2186. $list = Db::name('sale_diff')->alias('a')
  2187. ->join("sale c", "c.orderCode=a.orderCode", "left")
  2188. ->join("customer_info v", "v.companyNo=c.customer_code", "left")
  2189. ->join("good b", "b.good_code=a.good_kode", "left")
  2190. ->where($where)->page($page, $size)->field("a.*,b.cat_id,c.customer_code,v.companyName")
  2191. ->order("a.addtime desc")->select();
  2192. $data = [];
  2193. foreach ($list as $value) {
  2194. $value['can'] = isset($value['cat_id']) && $value['cat_id'] != 0 ? made($value['cat_id']) : [];
  2195. $wsm = Db::name("sale")->alias("a")->Join("supplier b", "a.supplierNo=b.code", "left")->where
  2196. (['a.orderCode' => $value['orderCode'], "a.is_del" => 0])->field("b.code,b.name")->find();
  2197. $value['supplierNo'] = isset($wsm['code']) ? $wsm['code'] : "";
  2198. $value['supplierName'] = isset($wsm['name']) ? $wsm['name'] : "";
  2199. $data[] = $value;
  2200. }
  2201. return app_show(0, "获取成功", ['list' => $data, 'count' => $count]);
  2202. }
  2203. /**
  2204. * @return \think\response\Json|void
  2205. * @throws \think\db\exception\DataNotFoundException
  2206. * @throws \think\db\exception\DbException
  2207. * @throws \think\db\exception\ModelNotFoundException
  2208. */
  2209. public function diffcheck()
  2210. {
  2211. $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
  2212. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  2213. if ($id === "") {
  2214. return error_show(1004, "参数id不能为空");
  2215. }
  2216. $info = Db::name("sale_diff")->where(["id" => $id])->find();
  2217. if (empty($info)) {
  2218. return error_show(1004, "订单数据未找到");
  2219. }
  2220. $is_act = isset($this->post['is_act']) && $this->post['is_act'] !== "" ? intval($this->post['is_act']) : "";
  2221. if ($is_act === '') {
  2222. return error_show(1004, "参数is_act不能为空");
  2223. }
  2224. $customer_remark = isset($this->post['customer_remark']) && $this->post['customer_remark'] !== "" ? trim($this->post['customer_remark']) : "";
  2225. if ($customer_remark === '') {
  2226. return error_show(1004, "参数customer_remark不能为空");
  2227. }
  2228. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "2";
  2229. $remark = isset($this->post['remark']) && $this->post['remark'] !== "" ? trim($this->post['remark']) : "";
  2230. $item = $info['status'];
  2231. $info['is_act'] = $is_act;
  2232. $info['customer_remark'] = $customer_remark;
  2233. $info['status'] = $status;
  2234. $info['remark'] = $remark;
  2235. $info['updatetime'] = date("Y-m-d H:i:s");
  2236. $up = Db::name("sale_diff")->save($info);
  2237. if ($up) {
  2238. $stx = ["order_code"=>$info["orderCode"],"status"=>$item,"action_remark"=>'',"action_type"=>"edit"];
  2239. ActionLog::logAdd($this->post['token'],$stx,"QRGCD",$info['status'],$info);
  2240. $order=["order_type"=>"QRGCD","order_code"=>$info["orderCode"],"order_id"=>$info['id'],"order_status"=>$info['status']];
  2241. ProcessOrder::AddProcess($this->post['token'],$order);
  2242. return app_show(0, "更新成功");
  2243. } else {
  2244. return error_show(1003, "更新失败");
  2245. }
  2246. }
  2247. /**
  2248. * @return \think\response\Json|void
  2249. * @throws \think\db\exception\DataNotFoundException
  2250. * @throws \think\db\exception\DbException
  2251. * @throws \think\db\exception\ModelNotFoundException
  2252. */
  2253. public function diffstatus()
  2254. {
  2255. $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
  2256. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  2257. if ($id === "") {
  2258. return error_show(1004, "参数id不能为空");
  2259. }
  2260. $info = Db::name("sale_diff")->where(["id" => $id])->find();
  2261. if (empty($info)) {
  2262. return error_show(1004, "订单数据未找到");
  2263. }
  2264. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "3";
  2265. $remark = isset($this->post['remark']) && $this->post['remark'] !== "" ? trim($this->post['remark']) : "";
  2266. $ite=$info['status'];
  2267. $info['status'] = $status;
  2268. $info['remark'] = $remark;
  2269. $info['updatetime'] = date("Y-m-d H:i:s");
  2270. $up = Db::name("sale_diff")->save($info);
  2271. if ($up) {
  2272. $stx = ["order_code"=>$info["orderCode"],"status"=>$ite,"action_remark"=>'',"action_type"=>"status"];
  2273. ActionLog::logAdd($this->post['token'],$stx,"QRGCD",$info['status'],$info);
  2274. $order=["order_type"=>"QRGCD","order_code"=>$info["orderCode"],"order_id"=>$info['id'],"order_status"=>$info['status']];
  2275. ProcessOrder::AddProcess($this->post['token'],$order);
  2276. return app_show(0, "更新成功");
  2277. } else {
  2278. return error_show(1003, "更新失败");
  2279. }
  2280. }
  2281. /**
  2282. * @return \think\response\Json|void
  2283. * @throws \think\db\exception\DataNotFoundException
  2284. * @throws \think\db\exception\DbException
  2285. * @throws \think\db\exception\ModelNotFoundException
  2286. */
  2287. public function diffinfo()
  2288. {
  2289. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  2290. if ($id === "") {
  2291. return error_show(1004, "参数id不能为空");
  2292. }
  2293. $info = Db::name('sale_diff')->alias('a')->join("good b", "b.good_code=a.good_kode", "left")->where
  2294. (["a.id" => $id])->field("a.*,b.cat_id")->find();
  2295. if (empty($info)) {
  2296. return error_show(1004, "订单数据未找到");
  2297. }
  2298. $info['can'] = isset($info['cat_id']) && $info['cat_id'] !== 0 ? made($info['cat_id']) : [];
  2299. return app_show(0, "获取成功", $info);
  2300. }
  2301. public function saleout(){
  2302. $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']):"1";
  2303. $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']) :"10";
  2304. $where= [];
  2305. $orderCode=isset($this->post['orderCode']) && $this->post['orderCode'] !=="" ? trim($this->post['orderCode'])
  2306. :"";
  2307. if($orderCode !==""){
  2308. $where[]=['a.orderCode',"like","%$orderCode%"];
  2309. }
  2310. $order_type=isset($this->post['order_type']) && $this->post['order_type'] !=="" ? trim($this->post['order_type'])
  2311. :"";
  2312. if($order_type !==""){
  2313. $where[]=['a.order_type',"=",$order_type];
  2314. }
  2315. $outCode=isset($this->post['outCode']) && $this->post['outCode'] !=="" ? trim($this->post['outCode'])
  2316. :"";
  2317. if($outCode !==""){
  2318. $where[]=['a.outCode',"like","%$outCode%"];
  2319. }
  2320. $apply_name=isset($this->post['apply_name']) && $this->post['apply_name'] !=="" ? trim($this->post['apply_name'])
  2321. :"";
  2322. if($apply_name !==""){
  2323. $where[]=['a.apply_name',"like","%$apply_name%"];
  2324. }
  2325. $good_code=isset($this->post['good_code']) && $this->post['good_code'] !=="" ? trim($this->post['good_code'])
  2326. :"";
  2327. if($good_code !==""){
  2328. $where[]=['b.good_code',"like","%$good_code%"];
  2329. }
  2330. $good_name=isset($this->post['good_name']) && $this->post['good_name'] !=="" ? trim($this->post['good_name'])
  2331. :"";
  2332. if($good_name !==""){
  2333. $where[]=['b.good_name',"like","%$good_name%"];
  2334. }
  2335. $status=isset($this->post['status']) && $this->post['status'] !=="" ? trim($this->post['status']):"";
  2336. if($status !==""){
  2337. $where[]=['a.status',"=",$status];
  2338. }
  2339. $start = isset($this->post['start']) && $this->post['start'] !=="" ? $this->post['start'] :"";
  2340. if($start !=""){
  2341. $where[]= ["a.addtime",'>=',$start];
  2342. }
  2343. $end = isset($this->post['end']) && $this->post['end'] !=="" ? $this->post['end'] :"";
  2344. if($end !=""){
  2345. $where[]= ["a.addtime",'<=',$end];
  2346. }
  2347. $companyNo =isset($this->post['companyNo']) &&$this->post['companyNo'] !=="" ? trim($this->post['companyNo']):"";
  2348. if($companyNo!=""){
  2349. $where[]=['b.customer_code',"like","%$companyNo%"];
  2350. }
  2351. $count = Db::name('order_out')->alias('a')
  2352. ->join("sale b", "b.orderCode=a.orderCode", "left")
  2353. ->join("customer_info v", "v.companyNo=b.customer_code", "left")
  2354. //->join("good n","n.good_code=b.good_code","left")
  2355. ->where($where)->count();
  2356. $total = ceil($count / $size);
  2357. $page = $page >= $total ? $total : $page;
  2358. $list = Db::name('order_out')->alias('a')->join("sale b", "b.orderCode=a.orderCode", "left")
  2359. ->join("customer_info v", "v.companyNo=b.customer_code", "left")
  2360. //->join("good n","n.good_code=b.good_code","left")
  2361. ->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")
  2362. ->where($where)->order("addtime desc")->page($page, $size)->select();
  2363. $data=[];
  2364. foreach ($list as $value) {
  2365. $wsmcode = Db::name("warehouse_info")->alias("k")->leftJoin("supplier c", "k.supplierNo=c.code")
  2366. ->where(["k.wsm_code" => $value['wsm_code']])->field("k.name as wsm_name,c.name,c.code")->find();
  2367. $addr = Db::name("order_addr")->where(["id" => $value['addrid']])->find();
  2368. if($value['order_type']==3|| $value['order_type']==4){
  2369. $goon = Db::name("good_zixun")->where(["spuCode"=>$value['good_code'],"is_del"=>0])->find();
  2370. }else {
  2371. $goon = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
  2372. ->where(['a.skuCode' => $value['skuCode']])->find();
  2373. }
  2374. $value['wsm_name'] = isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name'] : "";
  2375. $value['wsm_supplier'] = isset($wsmcode['name']) ? $wsmcode['name'] : "";
  2376. $value['wsm_supplierNo'] = isset($wsmcode['code']) ? $wsmcode['code'] : "";
  2377. $value['addr'] = isset($addr['addr']) ? $addr['addr'] : "";
  2378. $value['contactor'] = isset($addr['contactor']) ? $addr['contactor'] : "";
  2379. $value['mobile'] = isset($addr['mobile']) ? $addr['mobile'] : "";
  2380. $value['can'] = isset($goon['cat_id']) && $goon['cat_id'] != 0 ? made($goon['cat_id']) : [];
  2381. $data[] = $value;
  2382. }
  2383. return app_show(0, "获取成功", ['list' => $data, 'count' => $count]);
  2384. }
  2385. public function outinfo()
  2386. {
  2387. $outCode = isset($this->post['outCode']) && $this->post['outCode'] !== "" ? trim($this->post['outCode']) : "";
  2388. if ($outCode == "") {
  2389. return error_show(1002, "参数outcode不能为空");
  2390. }
  2391. $codeinfo = Db::name("order_out")->where(['outCode' => $outCode])->find();
  2392. if (empty($codeinfo)) {
  2393. return error_show(1002, "未找到出库数据");
  2394. }
  2395. $item = Db::name("sale")->where(['orderCode' => $codeinfo['orderCode']])->find();
  2396. if($item['order_type']==3|| $item['order_type']==4){
  2397. $goodinfo = Db::name("good_zixun")->where(["spuCode"=>$item['good_code'],"is_del"=>0])->find();
  2398. if($goodinfo==false){
  2399. return error_show(1004,"未找到商品数据");
  2400. }
  2401. }else{
  2402. $goodinfo = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
  2403. ->where(['a.skuCode' =>$item['skuCode']])->find();
  2404. if ($goodinfo == false) {
  2405. return error_show(1002, "未找到商品数据");
  2406. }
  2407. }
  2408. $int = isset($goodinfo['cat_id']) && $goodinfo['cat_id'] != 0 ? made($goodinfo['cat_id']) : [];
  2409. // $wsmcode = Db::name("warehouse_info")->alias("k")->leftJoin("supplier c", "k.supplierNo=c.code")
  2410. // ->where(["k.wsm_code" => $codeinfo['wsm_code']])->field("k.name as wsm_name,c.name,c.code")->find();
  2411. $addr = Db::name("order_addr")->where(["id" => $codeinfo['addrid']])->find();
  2412. //$item = Db::name("sale")->where(['orderCode' => $codeinfo['orderCode']])->find();
  2413. $codeinfo['good_name'] = isset($item['good_name']) ? $item['good_name'] : "";
  2414. $codeinfo['good_num'] = isset($item['good_num']) ? $item['good_num'] : "";
  2415. $codeinfo['good_code'] = isset($item['good_code']) ? $item['good_code'] : "";
  2416. $codeinfo['origin_price'] = isset($item['origin_price']) ? $item['origin_price'] : "";
  2417. $codeinfo['sale_price'] = isset($item['sale_price']) ? $item['sale_price'] : "";
  2418. $codeinfo['total_price'] = isset($item['total_price']) ? $item['total_price'] : "";
  2419. $codeinfo['skuCode'] = isset($item['skuCode']) ? $item['skuCode'] : "";
  2420. // $codeinfo['wsm_name'] = isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name'] : "";
  2421. // $codeinfo['wsm_supplier'] = isset($wsmcode['name']) ? $wsmcode['name'] : "";
  2422. // $codeinfo['wsm_supplierNo'] = isset($wsmcode['code']) ? $wsmcode['code'] : "";
  2423. $codeinfo['addr'] = GetAddr($addr['addr_code']);
  2424. $codeinfo['addr'] .= isset($addr['addr']) ? $addr['addr'] : "";
  2425. $codeinfo['addr_code'] = isset($addr['addr_code']) ? $addr['addr_code'] : "";
  2426. $codeinfo['contactor'] = isset($addr['contactor']) ? $addr['contactor'] : "";
  2427. $codeinfo['mobile'] = isset($addr['mobile']) ? $addr['mobile'] : "";
  2428. $codeinfo['can'] = $int;
  2429. return app_show(0, "获取成功", $codeinfo);
  2430. }
  2431. public function outadd(){
  2432. $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
  2433. $outCode = makeNo("CK");
  2434. $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !== "" ? trim($this->post['orderCode']) : "";
  2435. if ($orderCode == "") {
  2436. return error_show(1002, "参数orderCoder不能为空");
  2437. }
  2438. $der = Db::name('sale')->where(['orderCode' => $orderCode,"is_del"=>0])->find();
  2439. if ($der == "") {
  2440. return error_show(1002, "未找到出库订单单号");
  2441. }
  2442. $send_num = isset($this->post['send_num']) && $this->post['send_num'] !== "" ? $this->post['send_num'] : "";
  2443. if ($send_num == "") {
  2444. return error_show(1002, "发货数量不能为空");
  2445. }
  2446. if ($send_num > $der['wsend_num']) {
  2447. return error_show(1002, "超出可发货数量");
  2448. }
  2449. $contactor = isset($this->post['contactor'])&&$this->post['contactor']!="" ? trim($this->post['contactor']):"";
  2450. if($contactor==""){
  2451. return error_show(1002, "参数contactor不能为空");
  2452. }
  2453. $mobile = isset($this->post['mobile'])&&$this->post['mobile']!="" ? trim($this->post['mobile']):"";
  2454. if($mobile==""){
  2455. return error_show(1002, "参数mobile不能为空");
  2456. }
  2457. $addr = isset($this->post['addr'])&&$this->post['addr']!="" ? trim($this->post['addr']):"";
  2458. if($addr==""){
  2459. return error_show(1002, "参数addr不能为空");
  2460. }
  2461. $addr_code = isset($this->post['addr_code'])&&$this->post['addr_code']!="" ? trim($this->post['addr_code']):"";
  2462. if($addr_code==""){
  2463. return error_show(1002, "参数addr_code不能为空");
  2464. }
  2465. $apply_id = GetUserInfo($token);
  2466. if (empty($apply_id) || $apply_id['code'] != 0) {
  2467. return error_show(1002, "申请人数据不存在");
  2468. }
  2469. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  2470. $ri = isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  2471. $sendtime = isset($this->post['sendtime']) && $this->post['sendtime'] !== "" ? $this->post['sendtime'] : date("Y-m-d H:i:s");
  2472. $order =Db::name("order_num")->where(["orderCode"=>$orderCode,"status"=>1])->where([["wsend_num",">=",0]])
  2473. ->select()->toArray();
  2474. if(empty($order)){
  2475. return error_show(1004,"未找到可以发货得采购单数据");
  2476. }
  2477. Db::startTrans();
  2478. try {
  2479. $addrlst =[
  2480. "orderCode"=>$orderCode,
  2481. "addr"=>$addr,
  2482. "addr_code"=>json_encode($addr_code),
  2483. "contactor"=>$contactor,
  2484. "mobile"=>$mobile,
  2485. "customer_code"=>$der['customer_code'],
  2486. "post_fee"=>$der['post_fee'],
  2487. "arrive_time"=>$sendtime,
  2488. "receipt_quantity"=>$send_num,
  2489. "is_del"=>0,
  2490. "addtime"=>date("Y-m-d H:i:s"),
  2491. "updatetime"=>date("Y-m-d H:i:s")
  2492. ];
  2493. $addrid = Db::name("order_addr")->insert($addrlst,true);
  2494. if($addrid>0){
  2495. $data = [
  2496. "wsm_code" => "",
  2497. "orderCode" => $orderCode,
  2498. "outCode" => $outCode,
  2499. "order_type" => $der['order_type'],
  2500. "apply_id" => $rm,
  2501. "apply_name" => $ri,
  2502. "addrid" => $addrid,
  2503. "post_name" => "",
  2504. "post_code" =>"",
  2505. "post_fee" => "",
  2506. "sendtime" => $sendtime,
  2507. "send_num" => $send_num,
  2508. "check_num" => 0,
  2509. "error_num" => 0,
  2510. "status" => 1,
  2511. "addtime" => date("Y-m-d H:i:s"),
  2512. "updatetime" => date("Y-m-d H:i:s")
  2513. ];
  2514. $datainfo = Db::name('order_out')->insert($data,true);
  2515. if($datainfo>0){
  2516. $der['send_num'] +=$send_num;
  2517. $der['wsend_num'] -= $send_num;
  2518. $der['send_status'] = $der['send_num'] == 0 ? 1 : $der['wsend_num'] == 0 ? 3 : 2;
  2519. $der['status'] = $der['send_num'] == 0 ? 3 : $der['wsend_num'] == 0 ? 5 : 4;
  2520. $der['updatetime'] = date("Y-m-d H:i:s");
  2521. $si = Db::name('sale')->save($der);
  2522. if($si==false){
  2523. Db::rollback();
  2524. return error_show(1002,"出库单新建失败");
  2525. }
  2526. $num = $send_num;
  2527. foreach ($order as $val){
  2528. $tep=[];
  2529. $ornum=0;
  2530. if($val['wsend_num']>=$num){
  2531. $val['wsend_num']-=$num;
  2532. $val['send_num']+=$num;
  2533. $ornum =$num;
  2534. $num=0;
  2535. }else{
  2536. $num-=$val['wsend_num'];
  2537. $val['send_num']+=$val['wsend_num'];
  2538. $ornum =$val['wsend_num'];
  2539. $val['wsend_num']=0;
  2540. }
  2541. $or =Db::name("order_num")->save($val);
  2542. if($or==false){
  2543. Db::rollback();
  2544. return error_show(1002,"发货地址添加创建失败");
  2545. }
  2546. $tep=[
  2547. "cgdNo"=>$val['cgdNo'],
  2548. "outCode"=>$outCode,
  2549. "send_num"=>$ornum,
  2550. "status"=>1,
  2551. "addtime"=>date("Y-m-d H:i:s"),
  2552. "updatetime"=>date("Y-m-d H:i:s")
  2553. ];
  2554. $sen=Db::name("order_send")->save($tep);
  2555. if($sen==false){
  2556. Db::rollback();
  2557. return error_show(1002,"发货地址添加创建失败");
  2558. }
  2559. if($num==0){
  2560. break;
  2561. }
  2562. }
  2563. Db::commit();
  2564. return app_show(0,"出库单新建成功",["outCode"=>$outCode]);
  2565. }
  2566. }
  2567. Db::rollback();
  2568. return error_show(1004,"出库单新建失败");
  2569. } catch (Exception $e) {
  2570. Db::rollback();
  2571. return error_show(1005, $e->getMessage());
  2572. }
  2573. }
  2574. public function outSend(){
  2575. $outCode=isset($this->post['outCode'])&& $this->post['outCode']!=""? trim($this->post['outCode']):"";
  2576. if($outCode==""){
  2577. return error_show(1004,"参数outCode不能为空");
  2578. }
  2579. $outinfo = Db::name("order_out")->where(["outCode"=>$outCode])->find();
  2580. if($outinfo==false){
  2581. return error_show(1004,"发货数据未找到");
  2582. }
  2583. $einfo = Db::name('sale')->where(['orderCode' => $outinfo['orderCode'], 'is_del' => 0])->find();
  2584. if (empty($einfo)) {
  2585. return error_show(1002, "未找到销售订单数据");
  2586. }
  2587. $post_name = isset($this->post['post_name']) &&$this->post['post_name']!="" ? trim($this->post['post_name']):"";
  2588. if($post_name==""){
  2589. return error_show(1004,"参数post_name不能为空");
  2590. }
  2591. $post_code = isset($this->post['post_code']) &&$this->post['post_code']!="" ? trim($this->post['post_code']):"";
  2592. if($post_code==""){
  2593. return error_show(1004,"参数post_code不能为空");
  2594. }
  2595. $post_fee = isset($this->post['post_fee']) && $this->post['post_fee']!="" ? floatval($this->post['post_fee']):"";
  2596. $outinfo['post_name'] = $post_name;
  2597. $outinfo['post_code'] = $post_code;
  2598. $outinfo['post_fee'] = $post_fee;
  2599. $outinfo['sendtime'] = date("Y-m-d H:i:s");
  2600. $outinfo['status'] = 2;
  2601. $outinfo['updatetime'] = date("Y-m-d H:i:s");
  2602. try{
  2603. $up =Db::name("order_out")->save($outinfo);
  2604. if($up){
  2605. $stokc =Db::name("good_stock")->where(['spuCode'=>$einfo['good_code'],"wsm_code"=>$outinfo['wsm_code'],"is_del"=>0])->find();
  2606. if($stokc==false){
  2607. Db::rollback();
  2608. return error_show(1002, "未找库存到数据");
  2609. }else{
  2610. if ($outinfo['send_num'] > $stokc['wait_out_stock']) {
  2611. Db::rollback();
  2612. return error_show(1002, "超出库存数量");
  2613. }
  2614. $stokc['wait_out_stock']-=$outinfo['send_num'];
  2615. $stokc['intra_stock']+=$outinfo['send_num'];
  2616. $stokc['updatetime']=date("Y-m-d H:i:s");
  2617. }
  2618. $stoc= Db::name("good_stock")->save($stokc);
  2619. if($stoc==false){
  2620. Db::rollback();
  2621. return error_show(1002, "库存更新失败");
  2622. }
  2623. Db::commit();
  2624. return app_show(0,"发货成功");
  2625. }else{
  2626. Db::rollback();
  2627. return error_show(1004,"发货失败");
  2628. }
  2629. }catch (\Exception $e){
  2630. Db::rollback();
  2631. return error_show(1004,$e->getMessage());
  2632. }
  2633. }
  2634. public function RelaCgd($outinfo){
  2635. $der = Db::name('sale')->where(['orderCode' => $outinfo['orderCode']])->find();
  2636. if ($der == "") {
  2637. return false;
  2638. }
  2639. if($der['is_stock']==1){
  2640. $cgd = Db::name("order_bk")->where([["spuCode","=",$der['spuCode']],["is_del","=",0],["balance_num",">",0]])
  2641. ->select()->toArray();
  2642. if(empty($cgd)){
  2643. return false;
  2644. }
  2645. $send =$outinfo['send_num'];
  2646. $outsend=[];
  2647. foreach ($cgd as $value){
  2648. $temp=[];
  2649. if($value['balance_num']>=$send){
  2650. $value['balance_num']-=$send;
  2651. $value['merge_num']+=$send;
  2652. $send=0;
  2653. $temp['send_num'] =$send;
  2654. }else{
  2655. $value['balance_num'] =0;
  2656. $value['merge_num']+=$value['balance_num'];
  2657. $send -= $value['balance_num'];
  2658. $temp['send_num'] =$value['balance_num'];
  2659. }
  2660. $value['status'] = $value['balance_num']==0 ?2:$value['merge_num']==0?0:1 ;
  2661. $value['updatetime'] = date("Y-m-d H:i:s");
  2662. $bk = Db::name("order_bk")->save($value);
  2663. if($bk==false){
  2664. return false;
  2665. }
  2666. $temp['cgdNo'] = $value['cgdNo'];
  2667. $temp['outCode'] = $outinfo['outCode'];
  2668. $temp['status'] = 1;
  2669. $temp['addtime']=date("Y-m-d H:i:s");
  2670. $temp['updatetime']=date("Y-m-d H:i:s");
  2671. $outsend[]=$temp;
  2672. $order = Db::name("order_num")->where(["orderCode"=>$der['orderCode'],"cgdNo"=>$value['cgdNo'],"spuCode"=>$der['spuCode'],"status"=>1])->find();
  2673. if($order==false){
  2674. $order=[
  2675. "orderCode"=>$der['orderCode'],
  2676. "cgdNo"=>$value['cgdNo'],
  2677. "spuCode"=>$der['spuCode'],
  2678. "good_num"=>$der['good_num'],
  2679. "wsend_num"=>$der['good_num']-$temp['send_num'],
  2680. "send_num"=>$temp['send_num'],
  2681. "status"=>1,
  2682. "source"=>1
  2683. ];
  2684. }else{
  2685. $order['wsend_num']-=$temp['send_num'];
  2686. $order['send_num']+=$temp['send_num'];
  2687. }
  2688. if($order['wsend_num']<0){
  2689. return false;
  2690. }
  2691. $up =Db::name("order_num")->save($order);
  2692. if($up==false){
  2693. return false;
  2694. }
  2695. if($send==0){
  2696. break;
  2697. }
  2698. }
  2699. if(empty($temp)){
  2700. return false;
  2701. }
  2702. $insert = Db::name("order_send")->insertAll($outsend);
  2703. if($insert){
  2704. return true;
  2705. }else{
  2706. return false;
  2707. }
  2708. }else{
  2709. $order = Db::name("order_num")->where(["orderCode"=>$der['orderCode'],"spuCode"=>$der['spuCode'],
  2710. "status"=>1])->find();
  2711. if($order==false){
  2712. return false;
  2713. }else{
  2714. if($outinfo['send_num']> $order['wsend_num']){
  2715. return false;
  2716. }
  2717. $order['wsend_num']-=$outinfo['send_num'];
  2718. $order['send_num']+=$outinfo['send_num'];
  2719. if($order['wsend_num']<0){
  2720. return false;
  2721. }
  2722. $up =Db::name("order_num")->save($order);
  2723. if($up==false){
  2724. return false;
  2725. }
  2726. $temp=[];
  2727. $temp['cgdNo'] = $order['cgdNo'];
  2728. $temp['outCode'] = $outinfo['outCode'];
  2729. $temp['send_num'] =$outinfo['send_num'];
  2730. $temp['status'] = 1;
  2731. $temp['addtime']=date("Y-m-d H:i:s");
  2732. $temp['updatetime']=date("Y-m-d H:i:s");
  2733. $insert = Db::name("order_send")->insert($temp);
  2734. if($insert){
  2735. return true;
  2736. }else{
  2737. return false;
  2738. }
  2739. }
  2740. }
  2741. }
  2742. public function addother(){
  2743. $orderCode =isset($this->post['orderCode']) && $this->post['orderCode']!=""?trim($this->post['orderCode']):"";
  2744. if($orderCode==""){
  2745. return error_show(1004,"参数orderCode不能为空");
  2746. }
  2747. $order =Db::name("sale")->where(["orderCode"=>$orderCode,"is_del"=>0])->find();
  2748. if($order==false){
  2749. return error_show(1004,"未找到订单数据");
  2750. }
  2751. $paytime =isset($this->post['paytime'])&&$this->post['paytime']!=""? $this->post['paytime']:"";
  2752. $workNo =isset($this->post['workNo'])&&$this->post['workNo']!=""? trim($this->post['workNo']):"";
  2753. $platform_order =isset($this->post['platform_order'])&&$this->post['platform_order']!=""? trim($this->post['platform_order']):"";
  2754. $paytime==""?"":$order['paytime']=$paytime;
  2755. $order['workNo']=$workNo;
  2756. $order['platform_order']=$platform_order;
  2757. $order['updatetime']=date("Y-m-d H:i:s");
  2758. $sa=Db::name("sale")->save($order);
  2759. if($sa){
  2760. return app_show(0,"更新成功");
  2761. }else{
  2762. return error_show(1004,"更新失败");
  2763. }
  2764. }
  2765. public function getPrice(){
  2766. $skuCode=isset($this->post['skuCode'])&&$this->post['skuCode']!=""?trim($this->post['skuCode']):"";
  2767. if($skuCode===""){
  2768. return error_show(1003,"参数skuCode不能为空");
  2769. }
  2770. $is_activity=isset($this->post['is_activity'])&&$this->post['is_activity']!==""?intval($this->post['is_activity'])
  2771. :"";
  2772. if($is_activity===""){
  2773. return error_show(1003,"参数is_activity不能为空");
  2774. }
  2775. $sale_num=isset($this->post['sale_num'])&&$this->post['sale_num']!==""?intval($this->post['sale_num']):"";
  2776. if($sale_num===""){
  2777. return error_show(1003,"参数sale_num不能为空");
  2778. }
  2779. $ct = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
  2780. ->where(['a.skuCode' =>$skuCode])->find();
  2781. if ($ct == false) {
  2782. return error_show(1002, "未找到商品数据");
  2783. }
  2784. $origin = Db::name("good_nake")->where([["spuCode","=",$ct['spuCode']],["min_num","<=", $sale_num],["is_del","=",
  2785. 0]])->order("min_num desc")->find();
  2786. if($origin==false){
  2787. $origin = Db::name("good_nake")->where([["spuCode","=",$ct['spuCode']],["is_del","=",
  2788. 0]])->order("min_num asc")->find();
  2789. return error_show(1003,"不满足成本最低阶梯数量{$origin['min_num']}");
  2790. }
  2791. $stock=0;
  2792. if($ct['is_stock']==1){
  2793. $good_stock =Db::name("good_stock")->where(["spuCode"=>$ct['spuCode'],"is_del"=>0])->find();
  2794. $stock= isset($good_stock['usable_stock'])?$good_stock['usable_stock']:"0";
  2795. }
  2796. if($is_activity==1){
  2797. $act = Db::name("activity_info")->alias("a")->leftJoin("good_activity b","a.activity_code=b.activity_code")
  2798. ->where(["a.skuCode"=>$skuCode,"a.is_del"=>0,"a.status"=>1,"b.status"=>6,"b.is_del"=>0])->find();
  2799. if($act==false){
  2800. return error_show(1003,"未找到相关活动价");
  2801. }
  2802. if($act['moq_num']>$sale_num){
  2803. return error_show(1003,"商品不满足活动价起订量{$act['moq_num']}");
  2804. }
  2805. if($act['activity_stock']<$sale_num){
  2806. return error_show(1003,"商品活动库存剩余{$act['activity_stock']}");
  2807. }
  2808. return app_show(0,"获取成功",['sale_price'=>$act['activity_price'],"stock"=>$act['activity_stock']]);
  2809. }else{
  2810. $good = Db::name("good_ladder")->where(["skuCode"=>$skuCode,"is_del"=>0,"status"=>1])->order("min_num desc")
  2811. ->select()->toArray();
  2812. if(empty($good)){
  2813. return error_show(1003,"未找到相关阶梯价格");
  2814. }
  2815. $lastnum=0;
  2816. $lastprice=0;
  2817. foreach ($good as $value){
  2818. if($value['min_num']>$sale_num){
  2819. $lastnum=$value['min_num'];
  2820. $lastprice=0;
  2821. continue;
  2822. }else{
  2823. $lastnum=0;
  2824. $lastprice=$value['sale_price'];
  2825. break;
  2826. }
  2827. }
  2828. if($lastnum==0){
  2829. return app_show(0,"获取成功",['sale_price'=>$lastprice,"stock"=>$stock]);
  2830. }else{
  2831. return error_show(1003,"商品不满足起订量{$lastnum}");
  2832. }
  2833. }
  2834. }
  2835. public function saleuse(){
  2836. $orderCode= isset($this->post['orderCode'])&&!empty($this->post['orderCode'])?$this->post['orderCode']:"";
  2837. if($orderCode==""){
  2838. return error_show(1003,"参数orderCode不能为空");
  2839. }
  2840. $order= Db::name("sale")->where(["orderCode"=>$orderCode,"is_del"=>0])->select()->toArray();
  2841. if(empty($order)){
  2842. return error_show(1003,"订单数据未找到");
  2843. }
  2844. $useid= isset($this->post['useid'])&&$this->post['useid']!=""?intval($this->post['useid']):"";
  2845. if($useid==""){
  2846. return error_show(1003,"参数useid不能为空");
  2847. }
  2848. $use =Db::name("order_use")->where(["id"=>$useid,"is_del"=>0])->find();
  2849. if($use==false){
  2850. return error_show(1003,"用途数据未找到");
  2851. }
  2852. $order['use_order'] = $useid;
  2853. $order['updatetime'] = date("Y-m-d H:i:s");
  2854. $up=Db::name("sale")->where(["orderCode"=>$orderCode,"is_del"=>0])->update($order);
  2855. if($up>0){
  2856. return app_show(0,"更新成功");
  2857. }else{
  2858. return error_show(1003,"更新失败");
  2859. }
  2860. }
  2861. public function goodzxinfo(){
  2862. $orderCode= isset($this->post['spuCode'])&&$this->post['spuCode']!=''?trim($this->post['spuCode']):"";
  2863. if($orderCode==""){
  2864. return error_show(1003,"参数spuCode不能为空");
  2865. }
  2866. $order= Db::name("good_zixun")->where(["spuCode"=>$orderCode,"is_del"=>0])->find();
  2867. if(empty($order)){
  2868. return error_show(1003,"订单数据未找到");
  2869. }
  2870. $unit =Db::name("unit")->where(["id"=>$order['good_unit']])->find();
  2871. if($order['brand_id']!=0){
  2872. $brand=Db::name("brand")->where(["id"=>$order['brand_id']])->find();
  2873. $order["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  2874. }else{
  2875. $order["brand_name"]="";
  2876. $order["brand_id"]="";
  2877. }
  2878. $order['specinfo']=json_decode($order['specinfo'],true);
  2879. $order['unit'] = isset($unit['unit'])?$unit['unit']:'';
  2880. $order['cat_info'] = made($order['cat_id'],[]);
  2881. $order['noble_name']=isset($order['noble_metal'])&&$order['noble_metal']!=0?$this->noble[$order['noble_metal']] :"";
  2882. if($order['is_gold_price']==1){
  2883. $price=Db::name("gold_price1")->where(["type"=>$order['noble_metal'],"status"=>1,"is_del"=>0])->order("addtime desc")->find();
  2884. }
  2885. $order["gold_price"] = isset($price['price'])?$price['price']:0;
  2886. return app_show(0,"获取成功",$order);
  2887. }
  2888. }