Sale.php 149 KB

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