Sale.php 134 KB

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