Sale.php 125 KB

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