Sale.php 149 KB

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