Sale.php 143 KB

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