Sale.php 146 KB

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