Sale.php 146 KB

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