Sale.php 135 KB

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