Sale.php 150 KB

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