Sale.php 108 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238
  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. $arrtime=isset($this->post['arrtime'])&&$this->post['arrtime']!="" ?$this->post['arrtime']:"";
  709. if($arrtime==""){
  710. return error_show(1002, "参数arrtime不能为空");
  711. }
  712. $planinfo =isset($this->post['planinfo'])&&!empty($this->post['planinfo']) ?$this->post['planinfo']:"";
  713. if($planinfo==""){
  714. return error_show(1002, "参数planinfo不能为空");
  715. }
  716. foreach ($planinfo as $value){
  717. $feedback = Db::name("project_plan")->where(["pgNo"=>$value['pgNo'],"projectNo"=>$plan['project'],"is_del"=>0])->find();
  718. if($feedback==false){
  719. return error_show(1002, "反馈数据未找到");
  720. }
  721. if($feedback['data_source']==1){
  722. $feed=$this->project_good($feedback);
  723. if($feed==false){
  724. return error_show(1002, "咨询订单生成失败");
  725. }
  726. }
  727. }
  728. }
  729. public function project_zx($data){}
  730. public function project_good($data){}
  731. public function list()
  732. {
  733. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  734. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  735. $where[] = ['is_del', "=", 0];
  736. $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !== "" ? trim($this->post['orderCode']) : "";
  737. if ($orderCode !== "") {
  738. $where[] = ['orderCode', "like", "%$orderCode%"];
  739. }
  740. $apply_name = isset($this->post['apply_name']) && $this->post['apply_name'] !== "" ? trim($this->post['apply_name'])
  741. : "";
  742. if ($apply_name !== "") {
  743. $where[] = ['apply_name', "like", "%$apply_name%"];
  744. }
  745. $good_name = isset($this->post['good_name']) && $this->post['good_name'] !== "" ? trim($this->post['good_name'])
  746. : "";
  747. if ($good_name !== "") {
  748. $where[] = ['good_name', "like", "%$good_name%"];
  749. }
  750. $good_code = isset($this->post['good_code']) && $this->post['good_code'] !== "" ? trim($this->post['good_code']) : "";
  751. if ($good_code !== "") {
  752. $where[] = ['good_code', "like", "%$good_code%"];
  753. }
  754. $customer_code = isset($this->post['customer_code']) && $this->post['customer_code'] !== "" ? trim($this->post['customer_code']) : "";
  755. if ($customer_code !== "") {
  756. $where[] = ['customer_code', "like", "%$customer_code%"];
  757. }
  758. $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !== "" ? trim($this->post['supplierNo']) : "";
  759. if ($supplierNo !== "") {
  760. $where[] = ['supplierNo', "like", "%$supplierNo%"];
  761. }
  762. $ordertype = isset($this->post['order_type']) && $this->post['order_type'] !== "" ? intval($this->post['order_type'])
  763. : "";
  764. if ($ordertype !== "") {
  765. $where[] = ['order_type', "=", $ordertype];
  766. }
  767. $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  768. if ($status !== "") {
  769. $where[] = ['status', "=", $status];
  770. }
  771. $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
  772. if ($start != "") {
  773. $where[] = ["addtime", '>=', $start];
  774. }
  775. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
  776. if ($end != "") {
  777. $where[] = ["addtime", '<=', $end];
  778. }
  779. $count = Db::name('sale')->where($where)->count();
  780. $total = ceil($count / $size);
  781. $page = $page >= $total ? $total : $page;
  782. $list = Db::name('sale')->where($where)->order("addtime desc")->page($page, $size)->select();
  783. $data = [];
  784. foreach ($list as $value) {
  785. if($value['order_type']==3|| $value['order_type']==4){
  786. $var = Db::name("good_zixun")->where(["spuCode"=>$value['good_code'],"is_del"=>0])->find();
  787. }else {
  788. $var = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
  789. ->where(['a.skuCode' => $value['sku_code']])->find();
  790. }
  791. $value['can'] = isset($var['cat_id']) && $var['cat_id'] != 0 ? made($var['cat_id']) : [];
  792. $value['supplierName'] = '';
  793. if ($value['supplierNo'] != "") {
  794. $supplier = Db::name("business")->where(["companyNo" => $value['supplierNo']])->find();
  795. $value['supplierName'] = isset($supplier['company']) ? $supplier['company'] : "";
  796. }
  797. $value['customerName'] = '';
  798. if ($value['customer_code'] != "") {
  799. $supplier = Db::name("customer_info")->where(["companyNo" => $value['customer_code']])->find();
  800. $value['customerName'] = isset($supplier['companyName']) ? $supplier['companyName'] : "";
  801. }
  802. $data[] = $value;
  803. }
  804. return app_show(0, "获取成功", ['list' => $data, 'count' => $count]);
  805. }
  806. public function edit()
  807. {
  808. $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
  809. $id = isset($this->post['id']) && $this->post['id'] !== "" ? trim($this->post['id']) : "";
  810. if ($id == "") {
  811. return error_show(1002, "参数id不能为空");
  812. }
  813. $etid = Db::name("sale")->where(["id" => $id, "is_del" => 0])->find();
  814. if (empty($etid)) {
  815. return error_show(1002, "未找到数据");
  816. }
  817. // $orderCode=isset($this->post['orderCode']) && $this->post['orderCode'] !=="" ? trim($this->post['orderCode']) :"";
  818. // if($orderCode==""){
  819. // return error_show(1002,"销售单code不能为空");
  820. // }
  821. $good_code = isset($this->post['good_code']) && $this->post['good_code'] !== "" ? trim($this->post['good_code']) : "";
  822. if ($good_code == "") {
  823. return error_show(1002, "商品code不能为空");
  824. }
  825. $ct = Db::name('good')->alias('a')->join('good_type b', 'b.good_code=a.good_code', 'left')
  826. ->where(['b.type_code' => $good_code])->find();
  827. if ($ct == "") {
  828. return error_show(1002, "未找到商品数据");
  829. }
  830. $customer_code = isset($this->post['customer_code']) && $this->post['customer_code'] !== "" ? trim($this->post['customer_code']) : "";
  831. if ($customer_code == "") {
  832. return error_show(1002, "客户code不能为空");
  833. }
  834. $customer = Db::name("customer_info")->where(["companyNo" => $customer_code])->find();
  835. if ($customer == false) {
  836. return error_show(1004, "未找到客户数据");
  837. }
  838. $supplierNo = $this->post['supplierNo'] && $this->post['supplierNo'] !== "" ? trim($this->post['supplierNo']) : "";
  839. if ($supplierNo == "") {
  840. return error_show(1002, "参数supplierNo不能为空");
  841. }
  842. $supplier = Db::name("supplier")->where(["code" => $supplierNo])->find();
  843. if ($supplier == false) {
  844. return error_show(1004, "未找到平台供应商数据");
  845. }
  846. $apply_id = GetUserInfo($token);
  847. if (empty($apply_id) || $apply_id['code'] != 0) {
  848. return error_show(1002, "申请人数据不存在");
  849. }
  850. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  851. $ri = isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  852. // $good_name = isset($this->post['good_name']) && $this->post['good_name'] !== "" ? trim
  853. //($this->post['good_name']) : "";
  854. // $good_num = isset($this->post['good_num']) && $this->post['good_num'] !== "" ? intval
  855. //($this->post['good_num']) : "";
  856. // $origin_price = isset($this->post['origin_price']) && $this->post['origin_price'] !== "" ? intval
  857. // ($this->post['origin_price']) : "";
  858. // $sale_price = isset($this->post['sale_price']) && $this->post['sale_price'] !== "" ? trim($this->post['sale_price']) : "";
  859. // $total_price = isset($this->post['total_price']) && $this->post['total_price'] !== "" ? trim($this->post['total_price']) : "";
  860. // $post_fee = isset($this->post['post_fee']) && $this->post['post_fee'] !== "" ? trim($this->post['post_fee']) : "";
  861. // $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  862. $vr = isset($this->post['order_addr']) && $this->post['order_addr'] !== "" ? $this->post['order_addr'] : "";
  863. if ($vr == "") {
  864. return error_show(1002, "参数order_addr不能为空");
  865. }
  866. $vi = isset($this->post['good_stock']) && $this->post['good_stock'] !== "" ? $this->post['good_stock'] : "";
  867. if ($vi == "") {
  868. return error_show(1002, "参数good_stock不能为空");
  869. }
  870. $good_num = intval(array_sum(array_column($vi, "num")));
  871. Db::startTrans();
  872. try {
  873. $datn = [
  874. "id" => $id,
  875. "good_code" => $good_code,
  876. "customer_code" => $customer_code,
  877. "good_num" => $good_num,
  878. "supplierNo" => $supplierNo,
  879. "apply_id" => $rm,
  880. "apply_name" => $ri,
  881. "is_del" => 0,
  882. "updatetime" => date("Y-m-d H:i:s")
  883. ];
  884. $datninfo = Db::name('sale')->where(['id' => $id, 'is_del' => 0])->save($datn);
  885. if ($datninfo > 0) {
  886. $stn = ["order_code"=>$etid['orderCode'],"status"=>$etid['status'],"action_remark"=>'',"action_type"=>"edit"];
  887. ActionLog::logAdd($this->post['token'],$stn,"XSQRD",$etid['status'],$datn);
  888. $order=["order_type"=>'XSQRD',"order_code"=>$etid['orderCode'],"order_id"=>$id,"order_status"=>$etid['status']];
  889. ProcessOrder::AddProcess($this->post['token'],$order);
  890. foreach ($vi as $ion) {
  891. $iten = [];
  892. isset($ion['id']) && $ion['id'] !== "" ? $iten['id'] = $ion['id'] : '';
  893. $iten['orderCode'] = $etid['orderCode'];
  894. $iten['wsm_code'] = $ion['wsm_code'];
  895. $iten['stock_id'] = 0;
  896. $iten['num'] = $ion['num'];
  897. $iten['status'] = 1;
  898. $iten['sale_price'] = $ct['original_price'];
  899. isset($ion['id']) && $ion['id'] !== "" ? '' : $iten['addtime'] = date("Y-m-d H:i:s");
  900. $iten['updatetime'] = date("Y-m-d H:i:s");
  901. $vp = Db::name('sale_info')->save($iten);
  902. if ($vp == false)
  903. {
  904. Db::rollback();
  905. return error_show(1002, "更新失败");
  906. }
  907. }
  908. foreach ($vr as $value) {
  909. $temp = [];
  910. isset($value['id']) && $value['id'] !== "" ? $temp['id'] = $value['id'] : '';
  911. $temp['orderCode'] = $etid['orderCode'];
  912. $temp['contactor'] = $value['contactor'];
  913. $temp['mobile'] = $value['mobile'];
  914. $temp['addr'] = $value['addr'];
  915. $temp['addr_code'] = $value['addr_code'];
  916. $temp['customer_code'] = $customer_code;
  917. $temp['receipt_quantity'] = $value['receipt_quantity'];
  918. $temp['post_fee'] = 0;
  919. $temp['is_del'] = $value['is_del'];
  920. isset($value['id']) && $value['id'] !== "" ? '' : $temp['addtime'] = date("Y-m-d H:i:s");
  921. $temp['updatetime'] = date("Y-m-d H:i:s");
  922. $temp['arrive_time'] = date("Y-m-d H:i:s");
  923. $dat = Db::name('order_addr')->save($temp);
  924. if ($dat == false) {
  925. Db::rollback();
  926. return error_show(1002, "更新失败");
  927. }
  928. }
  929. Db::commit();
  930. return error_show(0, "更新成功");
  931. }
  932. Db::rollback();
  933. return error_show(1002, "更新失败");
  934. } catch (Exception $e) {
  935. Db::rollback();
  936. return error_show(1005, $e->getMessage());
  937. }
  938. }
  939. public function info()
  940. {
  941. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  942. if ($id == "") {
  943. return error_show(1002, "参数id不能为空");
  944. }
  945. //->field('good_code,good_name,good_num,customer_code,orderCode')
  946. $einfo = Db::name('sale')->where(['id' => $id, 'is_del' => 0])->find();
  947. if (empty($einfo)) {
  948. return error_show(1002, "未找到销售订单数据");
  949. }
  950. $info = Db::name('sale_diff')->where(['orderCode' => $einfo['orderCode']])->select();
  951. //$de = Db::name('order_out')->where(['orderCode' => $einfo['orderCode']])->select();
  952. $dm = Db::name('order_return')->where(['orderCode' => $einfo['orderCode']])->select();
  953. $dk = Db::name('order_back')->where(['orderCode' => $einfo['orderCode']])->select();
  954. $sa = Db::name('sale_return')->where(['orderCode' => $einfo['orderCode']])->select();
  955. if($einfo['order_type']==3|| $einfo['order_type']==4){
  956. $goon = Db::name("good_zixun")->where(["spuCode"=>$einfo['good_code'],"is_del"=>0])->find();
  957. }else {
  958. $goon = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
  959. ->where(['a.skuCode' => $einfo['sku_code']])->find();
  960. }
  961. if ($goon==false) {
  962. return error_show(1003, "未找到商品数据");
  963. }
  964. $int = isset($goon['cat_id']) && $goon['cat_id'] != 0 ? made($goon['cat_id']) : [];
  965. $in = Db::name('customer_info')->where(['companyNo' => $einfo['customer_code']])->field('companyName')->find();
  966. // ->field('addr,contactor,mobile,receipt_quantity,arrive_time')
  967. $einfo['supplierName'] = '';
  968. if ($einfo['supplierNo'] != "") {
  969. $supplier = Db::name("bussiness")->where(["companyNo" => $einfo['supplierNo']])->find();
  970. $einfo['supplierName'] = isset($supplier['company']) ? $supplier['company'] : "";
  971. }
  972. $fo = Db::name('order_addr')->where(['orderCode' => $einfo['orderCode'], 'is_del' => 0])->select();
  973. $bum = Db::name('order_out')->where(['orderCode' => $einfo['orderCode']])->select();
  974. $ins = [];
  975. if (!empty($bum)) {
  976. foreach ($bum as $stn) {
  977. $so = Db::name('order_addr')->where(['id' => $stn['addrid']])->find();
  978. $addr = GetAddr($so['addr_code']);
  979. $stn['addr_info'] = $addr;
  980. $stn['add_code'] = json_decode($so['addr_code'], true);
  981. $stn['addr'] = $so['addr'];
  982. $stn['contact'] = $so['contactor'];
  983. $stn['mobile'] = $so['mobile'];
  984. $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b", "a.supplierNo=b.code")
  985. ->where(["a.wsm_code" => $stn['wsm_code']])->field("a.name as wsm_name,b.name,b.code")->find();
  986. $stn['wsm_name'] = isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name'] : "";
  987. $stn['wsm_supplier'] = isset($wsmcode['name']) ? $wsmcode['name'] : "";
  988. $stn['wsm_supplierNo'] = isset($wsmcode['code']) ? $wsmcode['code'] : "";
  989. $ins[] = $stn;
  990. }
  991. }
  992. $addrs = [];
  993. if (!empty($fo)) {
  994. foreach ($fo as $value) {
  995. $value['addr_info'] = "";
  996. $value['send_num'] = 0;
  997. if ($value['addr_code'] != "") {
  998. $addr = GetAddr($value['addr_code']);
  999. $value['addr_info'] = $addr;
  1000. $value['addr_code'] = json_decode($value['addr_code'], true);
  1001. $send = Db::name("order_out")->where(['addrid' => $value['id'], 'orderCode' => $einfo['orderCode']])->sum("send_num");
  1002. $value['send_num'] = $send ?? 0;
  1003. }
  1004. $value['wsend_num'] = $value['receipt_quantity'] - $value['send_num'];
  1005. $addrs[] = $value;
  1006. }
  1007. }
  1008. //->field('num,sale_price,wsm_code,stock_id')
  1009. $st = Db::name('sale_info')->where(['orderCode' => $einfo['orderCode']])->select();
  1010. $data = [];
  1011. if (!empty($fo)) {
  1012. foreach ($st as $value) {
  1013. $value['wsm_name'] = "";
  1014. $value['wsm_supplier'] = "";
  1015. $value['wsm_supplierNo'] = "";
  1016. $value['usable_stock'] = 0;
  1017. $value['send_num'] = 0;
  1018. if ($value['wsm_code'] != "") {
  1019. $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b", "a.supplierNo=b.code")
  1020. ->where(["a.wsm_code" => $value['wsm_code']])->field("a.name as wsm_name,b.name,b.code")->find();
  1021. $value['wsm_name'] = isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name'] : "";
  1022. $value['wsm_supplier'] = isset($wsmcode['name']) ? $wsmcode['name'] : "";
  1023. $value['wsm_supplierNo'] = isset($wsmcode['code']) ? $wsmcode['code'] : "";
  1024. $dn = Db::name('good_stock')->where(['wsm_code' => $value['wsm_code'], 'good_type_code' => $einfo['good_code']])->find();
  1025. $value['usable_stock'] = isset($dn['usable_stock']) ? $dn['usable_stock'] : "0";
  1026. $send = Db::name("order_out")->where(["wsm_code" => $value['wsm_code'], 'orderCode' => $einfo['orderCode']])->sum("send_num");
  1027. $value['send_num'] = $send ?? 0;
  1028. }
  1029. $value['wsend_num'] = $value['num'] - $value['send_num'];
  1030. $data[] = $value;
  1031. }
  1032. }
  1033. $einfo['info'] = $data;
  1034. $einfo['companyName'] = isset($in['companyName']) ? $in['companyName'] : "";
  1035. $einfo['addrs'] = $addrs;
  1036. $einfo['orderout'] = $ins;
  1037. $einfo['can'] = $int;
  1038. $einfo['salediff'] = $info;
  1039. //$einfo['orderout'] = $de;
  1040. $einfo['orderreturn'] = $dm;
  1041. $einfo['orderback'] = $dk;
  1042. $einfo['salereturn'] = $sa;
  1043. if (empty($einfo)) {
  1044. return error_show(1002, "未找到销售订单数据");
  1045. } else {
  1046. return app_show(0, "获取成功", $einfo);
  1047. }
  1048. }
  1049. public function del()
  1050. {
  1051. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  1052. if ($id === "") {
  1053. return error_show(1002, "参数id不能为空");
  1054. }
  1055. $ed = Db::name('sale')->where(['id' => $id, 'is_del' => 0])->find();
  1056. if (empty($ed)) {
  1057. return error_show(1002, "未找到销售订单数据");
  1058. }
  1059. $str = Db::name('sale')->update(['id' => $id, 'is_del' => 1, 'updatetime' => date("Y-m-d H:i:s")]);
  1060. if ($str) {
  1061. $stc = ["order_code"=>$id,"status"=>$ed['status'],"action_remark"=>'',"action_type"=>"delete"];
  1062. ActionLog::logAdd($this->post['token'],$stc,"XSQRD",$ed['status'],['id' => $id, 'is_del' => 1, 'updatetime' => date("Y-m-d H:i:s")]);
  1063. $order=["order_type"=>'XSQRD',"order_code"=>$ed['orderCode'],"order_id"=>$id,"order_status"=>$ed['status']];
  1064. ProcessOrder::workdel($order);
  1065. return error_show(0, "删除成功");
  1066. } else {
  1067. return error_show(1002, "删除失败");
  1068. }
  1069. }
  1070. public function status()
  1071. {
  1072. $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
  1073. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  1074. if ($id == "") {
  1075. return error_show(1002, "参数id不能为空");
  1076. }
  1077. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  1078. if ($status == "") {
  1079. return error_show(1002, "订单状态不能为空");
  1080. }
  1081. $dio = Db::name('sale')->where(['id' => $id, 'is_del' => 0])->find();
  1082. if (empty($dio)) {
  1083. return error_show(1002, "销售单信息未找到");
  1084. }
  1085. if ($status == 1 && $dio['order_type'] == 2) {
  1086. $zxinfo = Db::name("consult")->where(["zxNo" => $dio['zxNo'], "is_del" => 0])->find();
  1087. if ($zxinfo == false) {
  1088. return error_show(1004, "未找到咨询单数据");
  1089. }
  1090. $gold['price'] = 0;
  1091. if ($zxinfo['zx_type'] == 2) {
  1092. if ($zxinfo['metals'] == "") {
  1093. return error_show(1004, "未找到咨询单贵金属类型数据");
  1094. }
  1095. $metals = $zxinfo['metals'] == '18K' ? 1 : ($zxinfo['metals'] == '24K' ? 2 : 3);
  1096. $gold = Db::name("gold_price")->where(["type" => $metals])->order("addtime desc")->find();
  1097. if (empty($gold)) {
  1098. return error_show(1004, "未找到咨询单贵金属类型数据");
  1099. }
  1100. $dio['gold_price'] = $gold['price'];
  1101. }
  1102. $wsm = Db::name("warehouse_info")->where(["supplierNo" => $zxinfo['gysNo'], "wsm_type" => 2])->find();
  1103. if (empty($wsm)) {
  1104. return error_show(1002, "供应商仓库未找到");
  1105. }
  1106. }
  1107. $apply_id = GetUserInfo($token);
  1108. if (empty($apply_id) || $apply_id['code'] != 0) {
  1109. return error_show(1002, "申请人数据不存在");
  1110. }
  1111. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1112. $ri = isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  1113. Db::startTrans();
  1114. try {
  1115. $vmp =$dio['status'];
  1116. $dio['status'] = $status;
  1117. $dio['updatetime'] = date("Y-m-d H:i:s");
  1118. $st = Db::name('sale')->save($dio);
  1119. if ($st) {
  1120. $stn = ["order_code"=>$dio['orderCode'],"status"=>$vmp,"action_remark"=>'',"action_type"=>"status"];
  1121. ActionLog::logAdd($this->post['token'],$stn, $dio['order_type'] == 2?"ZXQRD":"XSQRD",$dio['status'],$dio);
  1122. $order=["order_type"=>$dio['order_type'] == 2?"ZXQRD":"XSQRD","order_code"=>$dio['orderCode'],"order_id"=>$id,"order_status"=>$dio['status']];
  1123. ProcessOrder::AddProcess($this->post['token'],$order);
  1124. if ($status == 3 && $dio['order_type'] == 1) {
  1125. $dn = Db::name('sale_info')->where(['orderCode' => $st['orderCode']])->select();
  1126. foreach ($dn as $value) {
  1127. $dm = Db::name('good_stock')->where(['wsm_code' => $value['wsm_code'], 'good_type_code' => $st['good_code']])->find();
  1128. if ($dm == "") {
  1129. Db::rollback();
  1130. return error_show(1003, "未找到商品数据");
  1131. }
  1132. if ($value['num'] > $dm['usable_stock']) {
  1133. Db::rollback();
  1134. return error_show(1002, "超出库存数量");
  1135. }
  1136. $dm['usable_stock'] -= $value['num'];
  1137. $dm['wait_out_stock'] += $value['num'];
  1138. $send = Db::name("order_out")->where(["wsm_code" => $value['wsm_code']])->sum("send_num");
  1139. $value['send_num'] = $send ?? 0;
  1140. $value['wsend_num'] = $value['num'] - $value['send_num'];
  1141. $Db = Db::name('good_stock')->update($dm);
  1142. $Db['updatetime'] = date('Y-m-d H:i:s');
  1143. if ($Db == false) {
  1144. Db::rollback();
  1145. return error_show(1002, "状态更新失败");
  1146. }
  1147. }
  1148. }
  1149. if ($status == 1 && $dio['order_type'] == 2) {
  1150. $cgd = makeNo("CG");
  1151. $clll = [
  1152. "cgdNo" => $cgd,
  1153. "bkcode" => $dio['orderCode'],
  1154. "wsm_code" => $wsm['wsm_code'],
  1155. "cgder_id" => "0",
  1156. "cgder" => $zxinfo['saler'],
  1157. "good_code" => "GD-" . $zxinfo['cpNo'],
  1158. "good_name" => $zxinfo['cpName'],
  1159. "good_type_code" => $zxinfo['cpNo'],
  1160. "good_num" => $dio['good_num'],
  1161. "good_price" => $zxinfo['total_fee'],
  1162. "total_fee" => round($zxinfo['total_fee'] * $dio['good_num'], 2),
  1163. "pakge_fee" => $zxinfo['package_fee'],
  1164. "cert_fee" => $zxinfo['cert_fee'],
  1165. "open_fee" => $zxinfo['open_fee'],
  1166. "delivery_fee" => $zxinfo['delivery_fee'],
  1167. "mark_fee" => $zxinfo['mark_fee'],
  1168. "teach_fee" => $zxinfo['cost_fee'],
  1169. "demo_fee" => $zxinfo['demo_fee'],
  1170. "nake_fee" => $zxinfo['bare_fee'],
  1171. "weight" => isset($zxinfo['weight']) ? $zxinfo['weight'] : 0,
  1172. "supplierNo" => $zxinfo['gysNo'],
  1173. "supplier_name" => $zxinfo['gysname'],
  1174. "gold_price" => $gold['price'],
  1175. "send_num" => 0,
  1176. "wsend_num" => $dio['good_num'],
  1177. "remark" => '',
  1178. "lasttime" => date("Y-m-d H:i:s"),
  1179. "is_del" => 0,
  1180. "status" => $dio['send_type'] == 1 ? 3 : 0,
  1181. "order_type" => 2,
  1182. "addtime" => date("Y-m-d H:i:s"),
  1183. "updatetime" => date("Y-m-d H:i:s")
  1184. ];
  1185. $cgin = Db::name("purchease_order")->insert($clll);
  1186. // var_dump(Db::name("purchease_order")->getLastSql(),$clll);
  1187. if ($cgin == false) {
  1188. $stb = ["order_code"=>$cgd,"status"=> $clll['status'],"action_remark"=>'',"action_type"=>"create"];
  1189. ActionLog::logAdd($this->post['token'],$stb,"xsd", $clll['status'],$stb);
  1190. Db::rollback();
  1191. return error_show(1002, "咨询采购单创建商品失败");
  1192. }
  1193. if ($dio['send_type'] == 1) {
  1194. $addr = Db::name('order_addr')->where(["orderCode" => $dio['orderCode'], 'is_del' => 0])->select();
  1195. foreach ($addr as $value) {
  1196. $outCode = makeNo("CK");
  1197. $data = [
  1198. "wsm_code" => $wsm['wsm_code'],
  1199. "orderCode" => $dio['orderCode'],
  1200. "outCode" => $outCode,
  1201. "order_type" => $dio['order_type'],
  1202. "apply_id" => $rm,
  1203. "apply_name" => $ri,
  1204. "addrid" => $value['id'],
  1205. "post_name" => '',
  1206. "post_code" => '',
  1207. "post_fee" => '',
  1208. "sendtime" => date("Y-m-d H:i:s"),
  1209. "send_num" => $value['receipt_quantity'],
  1210. "check_num" => 0,
  1211. "error_num" => 0,
  1212. "status" => 0,
  1213. "addtime" => date("Y-m-d H:i:s"),
  1214. "updatetime" => date("Y-m-d H:i:s")
  1215. ];
  1216. $datainfo = Db::name('order_out')->insert($data);
  1217. if (!$datainfo) {
  1218. $sti = ["order_code"=>$dio['orderCode'],"status"=> 0,"action_remark"=>'',"action_type"=>"create"];
  1219. ActionLog::logAdd($this->post['token'],$sti,"xsd",0,$sti);
  1220. Db::rollback();
  1221. return error_show(1003, "创建失败");
  1222. }
  1223. }
  1224. $wsm_in_code = makeNo("IC");
  1225. $orin = [
  1226. "wsm_in_code" => $wsm_in_code,
  1227. "cgdNo" => $cgd,
  1228. "wsm_code" => $wsm['wsm_code'],
  1229. "wsm_reaper" => "",
  1230. "send_num" => $dio['good_num'],
  1231. "post_company" => '',
  1232. "post_code" => '',
  1233. "post_fee" => '',
  1234. "sendtime" => date("Y-m-d H:i:s"),
  1235. "apply_id" => $rm,
  1236. "apply_name" => $ri,
  1237. "wait_num" => 0,
  1238. "status" => 4,
  1239. "addtime" => date("Y-m-d H:i:s"),
  1240. "updatetime" => date("Y-m-d H:i:s")
  1241. ];
  1242. $win = Db::name("purchease_in")->insert($orin);
  1243. if (!$win){
  1244. $stv = ["order_code"=>$wsm_in_code,"status"=>4,"action_remark"=>'',"action_type"=>"create"];
  1245. ActionLog::logAdd($this->post['token'],$stv,"xsd",4,$stv);
  1246. Db::rollback();
  1247. return error_show(1003, "创建失败");
  1248. }
  1249. $good = Db::name("good_stock")->where(["wsm_code" => $wsm['wsm_code'], "good_type_code" => $zxinfo['cpNo'], "is_del" => 0])->find();
  1250. if (empty($good)) {
  1251. $good = [
  1252. "good_type_code" => $zxinfo['cpNo'],
  1253. "wsm_code" => $wsm['wsm_code'],
  1254. "usable_stock" => 0,
  1255. "wait_out_stock" => 0,
  1256. "total_stock" => 0,
  1257. "addtime" => date("Y-m-d H:i:s"),
  1258. "updatetime" => date("Y-m-d H:i:s"),
  1259. ];
  1260. }
  1261. $good['wait_out_stock'] += $dio['good_num'];
  1262. $good['total_stock'] = $good['usable_stock'] + $good['wait_out_stock'];
  1263. $good['updatetime'] = date("Y-m-d H:i:s");
  1264. $upd = Db::name("good_stock")->save($good);
  1265. if (!$upd) {
  1266. $ste = ["order_code"=> $zxinfo['cpNo'],"status"=>0,"action_remark"=>'',"action_type"=>"create"];
  1267. ActionLog::logAdd($this->post['token'],$ste,"xsd",0,$ste);
  1268. Db::rollback();
  1269. return error_show(1003, "创建失败");
  1270. }
  1271. }
  1272. }
  1273. }
  1274. Db::commit();
  1275. return error_show(0, "订单状态更新成功");
  1276. } catch (Exception $e) {
  1277. Db::rollback();
  1278. return error_show(1005, $e->getMessage());
  1279. }
  1280. }
  1281. public function fee()
  1282. {
  1283. $id = isset($this->post['id']) && $this->post['id'] !== "" ? trim($this->post['id']) : "";
  1284. if ($id == "") {
  1285. return error_show(1002, "参数id不能为空");
  1286. }
  1287. $etid = Db::name("sale")->where(["id" => $id, "is_del" => 0])->find();
  1288. if (empty($etid)) {
  1289. return error_show(1002, "未找到数据");
  1290. }
  1291. $vr = isset($this->post['order_addr']) && $this->post['order_addr'] !== "" ? $this->post['order_addr'] : "";
  1292. if ($vr == "") {
  1293. return error_show(1002, "参数order_addr不能为空");
  1294. }
  1295. Db::startTrans();
  1296. try {
  1297. $data = [
  1298. "id" => $id,
  1299. "status" => 2,
  1300. "is_del" => 0,
  1301. "updatetime" => date("Y-m-d H:i:s")
  1302. ];
  1303. $datainfo = Db::name('sale')->where(['id' => $id, 'is_del' => 0])->save($data);
  1304. if ($datainfo) {
  1305. $stx = ["order_code"=> $etid['orderCode'],"status"=>$etid['status'],"action_remark"=>'',
  1306. "action_type"=>"edit"];
  1307. ActionLog::logAdd($this->post['token'],$stx,$etid['order_type'] == 2?"ZXQRD":"XSQRD",2,$data);
  1308. $order=["order_type"=>$etid['order_type'] == 2?"ZXQRD":"XSQRD","order_code"=>$etid['orderCode'],"order_id"=>$id,"order_status"=>$data['status']];
  1309. ProcessOrder::AddProcess($this->post['token'],$order);
  1310. foreach ($vr as $value) {
  1311. $tm = [];
  1312. $tm['id'] = $value['id'];
  1313. $tm['orderCode'] = $etid['orderCode'];
  1314. $tm['post_fee'] = $value['post_fee'];
  1315. $tm['updatetime'] = date("Y-m-d H:i:s");
  1316. $dn = Db::name('order_addr')->save($tm);
  1317. if ($dn == false) {
  1318. Db::rollback();
  1319. return error_show(1002, "更新失败");
  1320. }
  1321. }
  1322. Db::commit();
  1323. return error_show(0, "更新成功");
  1324. }
  1325. Db::rollback();
  1326. return error_show(1003, "更新失败");
  1327. } catch (Exception $e) {
  1328. Db::rollback();
  1329. return error_show(1005, $e->getMessage());
  1330. }
  1331. }
  1332. public function out()
  1333. {
  1334. $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
  1335. $outCode = makeNo("CK");
  1336. $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !== "" ? trim($this->post['orderCode']) : "";
  1337. if ($orderCode == "") {
  1338. return error_show(1002, "参数orderCoder不能为空");
  1339. }
  1340. $der = Db::name('sale')->where(['orderCode' => $orderCode])->find();
  1341. if ($der == "") {
  1342. return error_show(1002, "未找到出库订单单号");
  1343. }
  1344. // $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code'] !== "" ? trim($this->post['wsm_code']) : "";
  1345. // if ($wsm_code == "") {
  1346. // return error_show(1002, "参数wsm_code不能为空");
  1347. // }
  1348. // $wsm = Db::name('sale_info')->where(['wsm_code' => $wsm_code, 'orderCode' => $der['orderCode']])->find();
  1349. // if ($wsm == "") {
  1350. // return error_show(1002, "未找到仓库编码");
  1351. // }
  1352. $post_name = isset($this->post['post_name']) && $this->post['post_name'] !== "" ? trim($this->post['post_name']) : "";
  1353. if ($post_name == "") {
  1354. return error_show(1002, "物流公司不能为空");
  1355. }
  1356. $post_code = isset($this->post['post_code']) && $this->post['post_code'] !== "" ? trim($this->post['post_code']) : "";
  1357. if ($post_code == "") {
  1358. return error_show(1002, "物流单号不能为空");
  1359. }
  1360. $post_fee = isset($this->post['post_fee']) && $this->post['post_fee'] !== "" ? intval($this->post['post_fee']) : "";
  1361. if ($post_fee == "") {
  1362. return error_show(1002, "物流费不能为空");
  1363. }
  1364. $send_num = isset($this->post['send_num']) && $this->post['send_num'] !== "" ? $this->post['send_num'] : "";
  1365. if ($send_num == "") {
  1366. return error_show(1002, "发货数量不能为空");
  1367. }
  1368. if ($send_num > $der['wsend_num']) {
  1369. return error_show(1002, "超出可发货数量");
  1370. }
  1371. $apply_id = GetUserInfo($token);
  1372. if (empty($apply_id) || $apply_id['code'] != 0) {
  1373. return error_show(1002, "申请人数据不存在");
  1374. }
  1375. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1376. $ri = isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  1377. $addrid = isset($this->post['addrid']) && $this->post['addrid'] !== "" ? intval($this->post['addrid']) : "";
  1378. $dr = Db::name('order_addr')->where(['id' => $addrid, 'is_del' => 0])->find();
  1379. if (empty($dr)) {
  1380. return error_show(1003, "收货人信息未找到");
  1381. }
  1382. if ($dr['orderCode'] !== $orderCode) {
  1383. return error_show(1002, "订单code不存在");
  1384. }
  1385. $sendtime = isset($this->post['sendtime']) && $this->post['sendtime'] !== "" ? $this->post['sendtime'] : date("Y-m-d H:i:s");
  1386. // $check_num = isset($this->post['check_num']) && $this->post['check_num'] !=="" ? $this->post['check_num'] :"";
  1387. // $error_num = isset($this->post['error_num']) && $this->post['error_num'] !=="" ? $this->post['error_num'] :"";
  1388. $status = isset($this->post['status']) && $this->post['status'] !== "" ? $this->post['status'] : "1";
  1389. //$order_type = isset($this->post['order_type']) && $this->post['order_type'] !=="" ? $this->post['order_type'] :"1";
  1390. //$dn=Db::name('sale_info')->where(['wsm_code'=>$outCode])->find();
  1391. Db::startTrans();
  1392. try {
  1393. $data = [
  1394. "wsm_code" => "",
  1395. "orderCode" => $orderCode,
  1396. "outCode" => $outCode,
  1397. "order_type" => $der['order_type'],
  1398. "apply_id" => $rm,
  1399. "apply_name" => $ri,
  1400. "addrid" => $dr['id'],
  1401. "post_name" => $post_name,
  1402. "post_code" => $post_code,
  1403. "post_fee" => $post_fee,
  1404. "sendtime" => $sendtime,
  1405. "send_num" => $send_num,
  1406. "check_num" => 0,
  1407. "error_num" => 0,
  1408. "status" => $status,
  1409. "addtime" => date("Y-m-d H:i:s"),
  1410. "updatetime" => date("Y-m-d H:i:s")
  1411. ];
  1412. $datainfo = Db::name('order_out')->insert($data,true);
  1413. if ($datainfo>0) {
  1414. $stx = ["order_code"=>$outCode,"status"=>$status,"action_remark"=>'',"action_type"=>"create"];
  1415. ActionLog::logAdd($this->post['token'],$stx,$der['order_type']==1?"CKD":'ZXCKD',$status,$data);
  1416. $order=["order_type"=>$der['order_type']==1?"CKD":'ZXCKD',"order_code"=>$outCode,"order_id"=>$datainfo,"order_status"=>$data['status']];
  1417. ProcessOrder::AddProcess($this->post['token'],$order);
  1418. if ($status == 1) {
  1419. $var = Db::name('sale_info')->where(['orderCode' => $orderCode, 'wsm_code' => $wsm_code])->find();
  1420. if ($var == "") {
  1421. return error_show(1002, "未找到数据");
  1422. }
  1423. // $send = Db::name("order_out")->where(["wsm_code" => $wsm_code, 'orderCode' => $orderCode])->sum
  1424. //("send_num");
  1425. $item =$der['status'];
  1426. $der['send_num'] += $send_num;
  1427. $der['wsend_num'] -= $send_num;//($der['send_num'])?$der['wsend_num'] =="" ? $der['send']
  1428. $der['send_status'] = $der['send_num'] == 0 ? 1 : $der['wsend_num'] == 0 ? 3 : 2;
  1429. $der['status'] = $der['send_num'] == 0 ? 3 : $der['wsend_num'] == 0 ? 5 : 4;
  1430. $der['updatetime'] = date("Y-m-d H:i:s");
  1431. $si = Db::name('sale')->save($der);
  1432. if ($si == false) {
  1433. Db::rollback();
  1434. return error_show(1003, "更新失败");
  1435. }
  1436. $stx = ["order_code"=>$orderCode,"status"=>$item,"action_remark"=>'',"action_type"=>"edit"];
  1437. ActionLog::logAdd($this->post['token'],$stx,$der['order_type'] == 2?"ZXQRD":"XSQRD",$der['status'],$der);
  1438. $order=["order_type"=>$der['order_type'] == 2?"ZXQRD":"XSQRD","order_code"=>$orderCode,"order_id"=>$der['id'],"order_status"=>$data['status']];
  1439. ProcessOrder::AddProcess($this->post['token'],$order);
  1440. $str = Db::name('good_stock')->where(['wsm_code' => $var['wsm_code'], 'good_type_code' => $der['good_code']])->find();
  1441. if ($str == false) {
  1442. Db::rollback();
  1443. return error_show(1002, "商品数据未找到");
  1444. }
  1445. if ($send_num > $str['wait_out_stock']) {
  1446. Db::rollback();
  1447. return error_show(1002, "超出库存数量");
  1448. }
  1449. $str['wait_out_stock'] -= $send_num;
  1450. $str['intra_stock'] += $send_num;
  1451. $str['updatetime'] = date("Y-m-d H:i:s");
  1452. $stre = Db::name('good_stock')->save($str);
  1453. if ($stre == false) {
  1454. Db::rollback();
  1455. return error_show(1002, "状态更新失败");
  1456. }
  1457. $good_data[]= ["stock_id"=>$str['id'],"type"=>2,'stock'=>$send_num,"stock_name"=>"wait_out_stock"];
  1458. $good_data[]= ["stock_id"=>$str['id'],"type"=>1,'stock'=>$send_num,"stock_name"=>"intra_stock"];
  1459. GoodLog::LogAdd($this->post['token'],$good_data,$der['order_type'] == 2?"ZXQRD":"XSQRD");
  1460. }
  1461. Db::commit();
  1462. return error_show(0, "创建成功");
  1463. } else {
  1464. Db::rollback();
  1465. return error_show(1003, "创建失败");
  1466. }
  1467. } catch (Exception $e) {
  1468. Db::rollback();
  1469. return error_show(1005, $e->getMessage());
  1470. }
  1471. }
  1472. public function customer()
  1473. {
  1474. $outCode = isset($this->post['outCode']) && $this->post['outCode'] !== "" ? trim($this->post['outCode']) : "";
  1475. if (empty($outCode)) {
  1476. return error_show(1002, "销售订单编号不能为空");
  1477. }
  1478. $codeinfo = Db::name('order_out')->where(['outCode' => $outCode])->find();
  1479. if ($codeinfo == "") {
  1480. return error_show(1003, "未找到订单数据");
  1481. }
  1482. // $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !=="" ? trim($this->post['orderCode']) :"";
  1483. // if($orderCode==""){
  1484. // return error_show(1002,"参数orderCoder不能为空");
  1485. // }
  1486. $dr = Db::name('sale')->where(['orderCode' => $codeinfo['orderCode']])->find();
  1487. if ($dr == "") {
  1488. return error_show(1002, "未找到销售订单");
  1489. }
  1490. $status = isset($this->post['status']) && $this->post['status'] !== "" ? $this->post['status'] : "";
  1491. if ($status == "") {
  1492. return error_show(10002, "状态不能为空");
  1493. }
  1494. Db::startTrans();
  1495. try {
  1496. $time = $codeinfo['status'];
  1497. $codeinfo['status'] = $status;
  1498. $codeinfo['updatetime'] = date("Y-m-d H:i:s");
  1499. $cust = Db::name('order_out')->save($codeinfo);
  1500. if ($cust) {
  1501. $stx = ["order_code"=>$outCode,"status"=>$time,"action_remark"=>'',"action_type"=>"status"];
  1502. ActionLog::logAdd($this->post['token'],$stx,$codeinfo['order_type'] == 2?"ZXCKD":"CKD",$codeinfo['status'],$codeinfo);
  1503. $order=["order_type"=>$codeinfo['order_type'] == 2?"ZXCKD":"CKD","order_code"=>$outCode,
  1504. "order_id"=>$codeinfo['id'],"order_status"=>$codeinfo['status']];
  1505. ProcessOrder::AddProcess($this->post['token'],$order);
  1506. if ($status == 1) {
  1507. $var = Db::name('sale_info')->where(['orderCode' =>$codeinfo['orderCode'], 'wsm_code' =>$codeinfo['wsm_code']])->find();
  1508. //var_dump(Db::name('sale_info')->getLastSql());
  1509. if ($var == "") {
  1510. return error_show(1002, "未找到数据");
  1511. }
  1512. // $send = Db::name("order_out")->where(["wsm_code" => $wsm_code, 'orderCode' => $orderCode])->sum
  1513. //("send_num");
  1514. $item =$dr['status'];
  1515. $dr['send_num'] +=$codeinfo['send_num'];
  1516. $dr['wsend_num'] -= $codeinfo['send_num'];//($der['send_num'])?$der['wsend_num'] =="" ? $der['send']
  1517. $dr['send_status'] = $dr['send_num'] == 0 ? 1 : $dr['wsend_num'] == 0 ? 3 : 2;
  1518. $dr['status'] = $dr['send_num'] == 0 ? 3 : $dr['wsend_num'] == 0 ? 5 : 4;
  1519. $dr['updatetime'] = date("Y-m-d H:i:s");
  1520. $si = Db::name('sale')->save($dr);
  1521. if ($si == false) {
  1522. Db::rollback();
  1523. return error_show(1003, "更新失败");
  1524. }
  1525. $stx = ["order_code"=>$dr['orderCode'],"status"=>$item,"action_remark"=>'',"action_type"=>"edit"];
  1526. ActionLog::logAdd($this->post['token'],$stx,$dr['order_type'] == 2?"ZXQRD":"XSQRD",$dr['status'],
  1527. $dr);
  1528. $order=["order_type"=>$dr['order_type'] == 2?"ZXQRD":"XSQRD","order_code"=>$dr['orderCode'],"order_id"=>$dr['id'],"order_status"=>$dr['status']];
  1529. ProcessOrder::AddProcess($this->post['token'],$order);
  1530. $str = Db::name('good_stock')->where(['wsm_code' => $var['wsm_code'], 'good_type_code' => $dr['good_code']])->find();
  1531. if ($str == false) {
  1532. Db::rollback();
  1533. return error_show(1002, "商品数据未找到");
  1534. }
  1535. if ($codeinfo['send_num'] > $str['wait_out_stock']) {
  1536. Db::rollback();
  1537. return error_show(1002, "超出库存数量");
  1538. }
  1539. $str['wait_out_stock'] -= $codeinfo['send_num'];
  1540. $str['intra_stock'] += $codeinfo['send_num'];
  1541. $str['updatetime'] = date("Y-m-d H:i:s");
  1542. $stre = Db::name('good_stock')->save($str);
  1543. if ($stre == false) {
  1544. Db::rollback();
  1545. return error_show(1002, "状态更新失败");
  1546. }
  1547. $good_data[]= ["stock_id"=>$str['id'],"type"=>2,'stock'=>$codeinfo['send_num'],"stock_name"=>"wait_out_stock"];
  1548. $good_data[]= ["stock_id"=>$str['id'],"type"=>1,'stock'=>$codeinfo['send_num'],"stock_name"=>"intra_stock"];
  1549. GoodLog::LogAdd($this->post['token'],$good_data,'CKD');
  1550. }
  1551. if ($status == 2) {
  1552. $ct = Db::name('sale_info')->where(['orderCode' => $dr['orderCode'], 'wsm_code' => $codeinfo['wsm_code']])->find();
  1553. if ($ct == false) {
  1554. return error_show(1002, "未找到数据");
  1555. }
  1556. $var = Db::name('good_stock')->where(['wsm_code' => $codeinfo['wsm_code'], 'good_type_code' => $dr['good_code']])->find();
  1557. if ($var == false) {
  1558. Db::rollback();
  1559. return error_show(1002, "未找到商品数据");
  1560. }
  1561. if ($ct['num'] > $var['intra_stock']) {
  1562. Db::rollback();
  1563. return error_show(1003, "超出库存数量");
  1564. }
  1565. $var['intra_stock'] -= $codeinfo['send_num'];
  1566. $var['updatetime'] = date("Y-m-d H:i:s");
  1567. $stre = Db::name('good_stock')->save($var);
  1568. $good_data[]= ["stock_id"=>$var['id'],"type"=>2,'stock'=>$codeinfo['send_num'],"stock_name"=>"intra_stock"];
  1569. GoodLog::LogAdd($this->post['token'],$good_data,$codeinfo['order_type'] == 2?"ZXCKD":"CKD");
  1570. if ($stre == false) {
  1571. Db::rollback();
  1572. return error_show(1002, "状态更新失败");
  1573. }
  1574. }
  1575. Db::commit();
  1576. return error_show(0, "出库订单更新成功");
  1577. } else {
  1578. Db::rollback();
  1579. return error_show(1003, "出库订单更新失败");
  1580. }
  1581. } catch (Exception $e) {
  1582. Db::rollback();
  1583. return error_show(1005, $e->getMessage());
  1584. }
  1585. }
  1586. public function difflist()
  1587. {
  1588. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  1589. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  1590. $where = [];
  1591. $cgdNo = isset($this->post['orderCode']) && $this->post['orderCode'] != "" ? trim($this->post['orderCode']) : "";
  1592. if ($cgdNo != "") {
  1593. $where[] = ['a.orderCode', "like", "%$cgdNo%"];
  1594. }
  1595. $diffNo = isset($this->post['diffCode']) && $this->post['diffCode'] != "" ? trim($this->post['diffCode']) : "";
  1596. if ($diffNo != "") {
  1597. $where[] = ['a.diffCode', "like", "%$diffNo%"];
  1598. }
  1599. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  1600. if ($status !== "") {
  1601. $where[] = ['a.status', "=", $status];
  1602. }
  1603. $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
  1604. if ($start != "") {
  1605. $where[] = ["a.addtime", '>=', $start];
  1606. }
  1607. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
  1608. if ($end != "") {
  1609. $where[] = ["a.addtime", '<=', $end];
  1610. }
  1611. // $apply_name = isset($this->post['apply_name']) && $this->post['apply_name'] !==""? intval($this->post['apply_name']):"";
  1612. // if($apply_name!==""){
  1613. // $where[]=['a.apply_name',"like","%$apply_name%"];
  1614. // }
  1615. $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !== "" ? trim($this->post['supplierNo']) : "";
  1616. if ($supplierNo != "") {
  1617. $supplier = Db::name("supplier")->where([['code', "like", "%$supplierNo%"]])->column('code');
  1618. // if(empty($supplier)){
  1619. // return error_show(1004,"未找到供应商信息");
  1620. // }
  1621. $wsmcode = Db::name("sale")->where([
  1622. "is_del" => 0, "supplierNo" => $supplier])->column("orderCode");
  1623. $where[] = ['a.orderCode', "in", $wsmcode];
  1624. }
  1625. $companyNo =isset($this->post['companyNo']) &&$this->post['companyNo'] !=="" ? trim($this->post['companyNo']):"";
  1626. if($companyNo!=""){
  1627. $where[]=['c.customer_code',"like","%$companyNo%"];
  1628. }
  1629. $count = Db::name('sale_diff')->alias('a')
  1630. ->join("sale c", "c.orderCode=a.orderCode", "left")
  1631. ->join("customer_info v", "v.companyNo=c.customer_code", "left")
  1632. ->join("good b", "b.good_code=a.good_code", "left")
  1633. ->where($where)->count();
  1634. $total = ceil($count / $size);
  1635. $page = $page >= $total ? $total : $page;
  1636. //var_dump( Db::name('sale_diff')->getLastSql());
  1637. $list = Db::name('sale_diff')->alias('a')
  1638. ->join("sale c", "c.orderCode=a.orderCode", "left")
  1639. ->join("customer_info v", "v.companyNo=c.customer_code", "left")
  1640. ->join("good b", "b.good_code=a.good_kode", "left")
  1641. ->where($where)->page($page, $size)->field("a.*,b.cat_id,c.customer_code,v.companyName")
  1642. ->order("a.addtime desc")->select();
  1643. $data = [];
  1644. foreach ($list as $value) {
  1645. $value['can'] = isset($value['cat_id']) && $value['cat_id'] != 0 ? made($value['cat_id']) : [];
  1646. $wsm = Db::name("sale")->alias("a")->Join("supplier b", "a.supplierNo=b.code", "left")->where
  1647. (['a.orderCode' => $value['orderCode'], "a.is_del" => 0])->field("b.code,b.name")->find();
  1648. $value['supplierNo'] = isset($wsm['code']) ? $wsm['code'] : "";
  1649. $value['supplierName'] = isset($wsm['name']) ? $wsm['name'] : "";
  1650. $data[] = $value;
  1651. }
  1652. return app_show(0, "获取成功", ['list' => $data, 'count' => $count]);
  1653. }
  1654. /**
  1655. * @return \think\response\Json|void
  1656. * @throws \think\db\exception\DataNotFoundException
  1657. * @throws \think\db\exception\DbException
  1658. * @throws \think\db\exception\ModelNotFoundException
  1659. */
  1660. public function diffcheck()
  1661. {
  1662. $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
  1663. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  1664. if ($id === "") {
  1665. return error_show(1004, "参数id不能为空");
  1666. }
  1667. $info = Db::name("sale_diff")->where(["id" => $id])->find();
  1668. if (empty($info)) {
  1669. return error_show(1004, "订单数据未找到");
  1670. }
  1671. $is_act = isset($this->post['is_act']) && $this->post['is_act'] !== "" ? intval($this->post['is_act']) : "";
  1672. if ($is_act === '') {
  1673. return error_show(1004, "参数is_act不能为空");
  1674. }
  1675. $customer_remark = isset($this->post['customer_remark']) && $this->post['customer_remark'] !== "" ? trim($this->post['customer_remark']) : "";
  1676. if ($customer_remark === '') {
  1677. return error_show(1004, "参数customer_remark不能为空");
  1678. }
  1679. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "2";
  1680. $remark = isset($this->post['remark']) && $this->post['remark'] !== "" ? trim($this->post['remark']) : "";
  1681. $item = $info['status'];
  1682. $info['is_act'] = $is_act;
  1683. $info['customer_remark'] = $customer_remark;
  1684. $info['status'] = $status;
  1685. $info['remark'] = $remark;
  1686. $info['updatetime'] = date("Y-m-d H:i:s");
  1687. $up = Db::name("sale_diff")->save($info);
  1688. if ($up) {
  1689. $stx = ["order_code"=>$info["orderCode"],"status"=>$item,"action_remark"=>'',"action_type"=>"edit"];
  1690. ActionLog::logAdd($this->post['token'],$stx,"QRGCD",$info['status'],$info);
  1691. $order=["order_type"=>"QRGCD","order_code"=>$info["orderCode"],"order_id"=>$info['id'],"order_status"=>$info['status']];
  1692. ProcessOrder::AddProcess($this->post['token'],$order);
  1693. return app_show(0, "更新成功");
  1694. } else {
  1695. return error_show(1003, "更新失败");
  1696. }
  1697. }
  1698. /**
  1699. * @return \think\response\Json|void
  1700. * @throws \think\db\exception\DataNotFoundException
  1701. * @throws \think\db\exception\DbException
  1702. * @throws \think\db\exception\ModelNotFoundException
  1703. */
  1704. public function diffstatus()
  1705. {
  1706. $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
  1707. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  1708. if ($id === "") {
  1709. return error_show(1004, "参数id不能为空");
  1710. }
  1711. $info = Db::name("sale_diff")->where(["id" => $id])->find();
  1712. if (empty($info)) {
  1713. return error_show(1004, "订单数据未找到");
  1714. }
  1715. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "3";
  1716. $remark = isset($this->post['remark']) && $this->post['remark'] !== "" ? trim($this->post['remark']) : "";
  1717. $ite=$info['status'];
  1718. $info['status'] = $status;
  1719. $info['remark'] = $remark;
  1720. $info['updatetime'] = date("Y-m-d H:i:s");
  1721. $up = Db::name("sale_diff")->save($info);
  1722. if ($up) {
  1723. $stx = ["order_code"=>$info["orderCode"],"status"=>$ite,"action_remark"=>'',"action_type"=>"status"];
  1724. ActionLog::logAdd($this->post['token'],$stx,"QRGCD",$info['status'],$info);
  1725. $order=["order_type"=>"QRGCD","order_code"=>$info["orderCode"],"order_id"=>$info['id'],"order_status"=>$info['status']];
  1726. ProcessOrder::AddProcess($this->post['token'],$order);
  1727. return app_show(0, "更新成功");
  1728. } else {
  1729. return error_show(1003, "更新失败");
  1730. }
  1731. }
  1732. /**
  1733. * @return \think\response\Json|void
  1734. * @throws \think\db\exception\DataNotFoundException
  1735. * @throws \think\db\exception\DbException
  1736. * @throws \think\db\exception\ModelNotFoundException
  1737. */
  1738. public function diffinfo()
  1739. {
  1740. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  1741. if ($id === "") {
  1742. return error_show(1004, "参数id不能为空");
  1743. }
  1744. $info = Db::name('sale_diff')->alias('a')->join("good b", "b.good_code=a.good_kode", "left")->where
  1745. (["a.id" => $id])->field("a.*,b.cat_id")->find();
  1746. if (empty($info)) {
  1747. return error_show(1004, "订单数据未找到");
  1748. }
  1749. $info['can'] = isset($info['cat_id']) && $info['cat_id'] !== 0 ? made($info['cat_id']) : [];
  1750. return app_show(0, "获取成功", $info);
  1751. }
  1752. public function saleout(){
  1753. $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']):"1";
  1754. $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']) :"10";
  1755. $where= [];
  1756. $orderCode=isset($this->post['orderCode']) && $this->post['orderCode'] !=="" ? trim($this->post['orderCode'])
  1757. :"";
  1758. if($orderCode !==""){
  1759. $where[]=['a.orderCode',"like","%$orderCode%"];
  1760. }
  1761. $order_type=isset($this->post['order_type']) && $this->post['order_type'] !=="" ? trim($this->post['order_type'])
  1762. :"";
  1763. if($order_type !==""){
  1764. $where[]=['a.order_type',"=",$order_type];
  1765. }
  1766. $outCode=isset($this->post['outCode']) && $this->post['outCode'] !=="" ? trim($this->post['outCode'])
  1767. :"";
  1768. if($outCode !==""){
  1769. $where[]=['a.outCode',"like","%$outCode%"];
  1770. }
  1771. $apply_name=isset($this->post['apply_name']) && $this->post['apply_name'] !=="" ? trim($this->post['apply_name'])
  1772. :"";
  1773. if($apply_name !==""){
  1774. $where[]=['a.apply_name',"like","%$apply_name%"];
  1775. }
  1776. $good_code=isset($this->post['good_code']) && $this->post['good_code'] !=="" ? trim($this->post['good_code'])
  1777. :"";
  1778. if($good_code !==""){
  1779. $where[]=['b.good_code',"like","%$good_code%"];
  1780. }
  1781. $good_name=isset($this->post['good_name']) && $this->post['good_name'] !=="" ? trim($this->post['good_name'])
  1782. :"";
  1783. if($good_name !==""){
  1784. $where[]=['b.good_name',"like","%$good_name%"];
  1785. }
  1786. $status=isset($this->post['status']) && $this->post['status'] !=="" ? trim($this->post['status']):"";
  1787. if($status !==""){
  1788. $where[]=['a.status',"=",$status];
  1789. }
  1790. $start = isset($this->post['start']) && $this->post['start'] !=="" ? $this->post['start'] :"";
  1791. if($start !=""){
  1792. $where[]= ["a.addtime",'>=',$start];
  1793. }
  1794. $end = isset($this->post['end']) && $this->post['end'] !=="" ? $this->post['end'] :"";
  1795. if($end !=""){
  1796. $where[]= ["a.addtime",'<=',$end];
  1797. }
  1798. $companyNo =isset($this->post['companyNo']) &&$this->post['companyNo'] !=="" ? trim($this->post['companyNo']):"";
  1799. if($companyNo!=""){
  1800. $where[]=['b.customer_code',"like","%$companyNo%"];
  1801. }
  1802. $count = Db::name('order_out')->alias('a')
  1803. ->join("sale b", "b.orderCode=a.orderCode", "left")
  1804. ->join("customer_info v", "v.companyNo=b.customer_code", "left")
  1805. //->join("good n","n.good_code=b.good_code","left")
  1806. ->where($where)->count();
  1807. $total = ceil($count / $size);
  1808. $page = $page >= $total ? $total : $page;
  1809. $list = Db::name('order_out')->alias('a')->join("sale b", "b.orderCode=a.orderCode", "left")
  1810. ->join("customer_info v", "v.companyNo=b.customer_code", "left")
  1811. //->join("good n","n.good_code=b.good_code","left")
  1812. ->field("a.*,b.good_name,b.good_code,b.supplierNo,b.customer_code,v.companyName,b.origin_price,b.sale_price,b.total_price")
  1813. ->where($where)->order("addtime desc")->page($page, $size)->select();
  1814. $data=[];
  1815. foreach ($list as $value) {
  1816. $wsmcode = Db::name("warehouse_info")->alias("k")->leftJoin("supplier c", "k.supplierNo=c.code")
  1817. ->where(["k.wsm_code" => $value['wsm_code']])->field("k.name as wsm_name,c.name,c.code")->find();
  1818. $addr = Db::name("order_addr")->where(["id" => $value['addrid']])->find();
  1819. $good = Db::name("good_type")->alias("b")->join("good a", "a.good_code = b.good_code", "left")
  1820. ->where(["type_code" => $value['good_code']])->field('cat_id')->find();
  1821. $value['wsm_name'] = isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name'] : "";
  1822. $value['wsm_supplier'] = isset($wsmcode['name']) ? $wsmcode['name'] : "";
  1823. $value['wsm_supplierNo'] = isset($wsmcode['code']) ? $wsmcode['code'] : "";
  1824. $value['addr'] = isset($addr['addr']) ? $addr['addr'] : "";
  1825. $value['contactor'] = isset($addr['contactor']) ? $addr['contactor'] : "";
  1826. $value['mobile'] = isset($addr['mobile']) ? $addr['mobile'] : "";
  1827. $value['can'] = isset($good['cat_id']) && $good['cat_id'] != 0 ? made($good['cat_id']) : [];
  1828. $data[] = $value;
  1829. }
  1830. return app_show(0, "获取成功", ['list' => $data, 'count' => $count]);
  1831. }
  1832. public function outinfo()
  1833. {
  1834. $outCode = isset($this->post['outCode']) && $this->post['outCode'] !== "" ? trim($this->post['outCode']) : "";
  1835. if ($outCode == "") {
  1836. return error_show(1002, "参数outcode不能为空");
  1837. }
  1838. $codeinfo = Db::name("order_out")->where(['outCode' => $outCode])->find();
  1839. if (empty($codeinfo)) {
  1840. return error_show(1002, "未找到出库数据");
  1841. }
  1842. $item = Db::name("sale")->where(['orderCode' => $codeinfo['orderCode']])->find();
  1843. if($item['order_type']==3|| $item['order_type']==4){
  1844. // $good=Db::name("good_zixun")->where(["spuCode"=>$good_code])->find();
  1845. // if($good==false){
  1846. // return error_show(1004,"未找到商品数据");
  1847. // }
  1848. $goodinfo = Db::name("consult_bids")->where(["spuCode"=>$item['good_code'],"is_del"=>0])->find();
  1849. if($goodinfo==false){
  1850. return error_show(1004,"未找到商品数据");
  1851. }
  1852. }else{
  1853. $goodinfo = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
  1854. ->where(['a.skuCode' =>$item['sku_code']])->find();
  1855. if ($goodinfo == false) {
  1856. return error_show(1002, "未找到商品数据");
  1857. }
  1858. }
  1859. $int = isset($goodinfo['cat_id']) && $goodinfo['cat_id'] != 0 ? made($goodinfo['cat_id']) : [];
  1860. // $wsmcode = Db::name("warehouse_info")->alias("k")->leftJoin("supplier c", "k.supplierNo=c.code")
  1861. // ->where(["k.wsm_code" => $codeinfo['wsm_code']])->field("k.name as wsm_name,c.name,c.code")->find();
  1862. $addr = Db::name("order_addr")->where(["id" => $codeinfo['addrid']])->find();
  1863. //$item = Db::name("sale")->where(['orderCode' => $codeinfo['orderCode']])->find();
  1864. $codeinfo['good_name'] = isset($item['good_name']) ? $item['good_name'] : "";
  1865. $codeinfo['good_num'] = isset($item['good_num']) ? $item['good_num'] : "";
  1866. $codeinfo['good_code'] = isset($item['good_code']) ? $item['good_code'] : "";
  1867. $codeinfo['origin_price'] = isset($item['origin_price']) ? $item['origin_price'] : "";
  1868. $codeinfo['sale_price'] = isset($item['sale_price']) ? $item['sale_price'] : "";
  1869. $codeinfo['total_price'] = isset($item['total_price']) ? $item['total_price'] : "";
  1870. // $codeinfo['wsm_name'] = isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name'] : "";
  1871. // $codeinfo['wsm_supplier'] = isset($wsmcode['name']) ? $wsmcode['name'] : "";
  1872. // $codeinfo['wsm_supplierNo'] = isset($wsmcode['code']) ? $wsmcode['code'] : "";
  1873. $codeinfo['addr'] = GetAddr($addr['addr_code']);
  1874. $codeinfo['addr'] .= isset($addr['addr']) ? $addr['addr'] : "";
  1875. $codeinfo['addr_code'] = isset($addr['addr_code']) ? $addr['addr_code'] : "";
  1876. $codeinfo['contactor'] = isset($addr['contactor']) ? $addr['contactor'] : "";
  1877. $codeinfo['mobile'] = isset($addr['mobile']) ? $addr['mobile'] : "";
  1878. $codeinfo['can'] = $int;
  1879. return app_show(0, "获取成功", $codeinfo);
  1880. }
  1881. public function outadd(){
  1882. $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
  1883. $outCode = makeNo("CK");
  1884. $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !== "" ? trim($this->post['orderCode']) : "";
  1885. if ($orderCode == "") {
  1886. return error_show(1002, "参数orderCoder不能为空");
  1887. }
  1888. $der = Db::name('sale')->where(['orderCode' => $orderCode])->find();
  1889. if ($der == "") {
  1890. return error_show(1002, "未找到出库订单单号");
  1891. }
  1892. $send_num = isset($this->post['send_num']) && $this->post['send_num'] !== "" ? $this->post['send_num'] : "";
  1893. if ($send_num == "") {
  1894. return error_show(1002, "发货数量不能为空");
  1895. }
  1896. if ($send_num > $der['wsend_num']) {
  1897. return error_show(1002, "超出可发货数量");
  1898. }
  1899. $contactor = isset($this->post['contactor'])&&$this->post['contactor']!="" ? trim($this->post['contactor']):"";
  1900. if($contactor==""){
  1901. return error_show(1002, "参数contactor不能为空");
  1902. }
  1903. $mobile = isset($this->post['mobile'])&&$this->post['mobile']!="" ? trim($this->post['mobile']):"";
  1904. if($mobile==""){
  1905. return error_show(1002, "参数mobile不能为空");
  1906. }
  1907. $addr = isset($this->post['addr'])&&$this->post['addr']!="" ? trim($this->post['addr']):"";
  1908. if($addr==""){
  1909. return error_show(1002, "参数addr不能为空");
  1910. }
  1911. $addr_code = isset($this->post['addr_code'])&&$this->post['addr_code']!="" ? trim($this->post['addr_code']):"";
  1912. if($addr_code==""){
  1913. return error_show(1002, "参数addr_code不能为空");
  1914. }
  1915. $apply_id = GetUserInfo($token);
  1916. if (empty($apply_id) || $apply_id['code'] != 0) {
  1917. return error_show(1002, "申请人数据不存在");
  1918. }
  1919. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1920. $ri = isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  1921. // $addrid = isset($this->post['addrid']) && $this->post['addrid'] !== "" ? intval($this->post['addrid']) : "";
  1922. // $dr = Db::name('order_addr')->where(['id' => $addrid, 'is_del' => 0])->find();
  1923. // if (empty($dr)) {
  1924. // return error_show(1003, "收货人信息未找到");
  1925. // }
  1926. // if ($dr['orderCode'] !== $orderCode) {
  1927. // return error_show(1002, "订单code不存在");
  1928. // }
  1929. $sendtime = isset($this->post['sendtime']) && $this->post['sendtime'] !== "" ? $this->post['sendtime'] : date("Y-m-d H:i:s");
  1930. $order =Db::name("order_num")->where(["orderCode"=>$orderCode,"status"=>1])->where([["wsend_num",">=",0]])
  1931. ->select()->toArray();
  1932. if(empty($order)){
  1933. return error_show(1004,"未找到可以发货得采购单数据");
  1934. }
  1935. Db::startTrans();
  1936. try {
  1937. $addrlst =[
  1938. "orderCode"=>$orderCode,
  1939. "addr"=>$addr,
  1940. "addr_code"=>json_encode($addr_code),
  1941. "contactor"=>$contactor,
  1942. "mobile"=>$mobile,
  1943. "customer_code"=>$der['customer_code'],
  1944. "post_fee"=>$der['post_fee'],
  1945. "arrive_time"=>$sendtime,
  1946. "receipt_quantity"=>$send_num,
  1947. "is_del"=>0,
  1948. "addtime"=>date("Y-m-d H:i:s"),
  1949. "updatetime"=>date("Y-m-d H:i:s")
  1950. ];
  1951. $addrid = Db::name("order_addr")->insert($addrlst,true);
  1952. if($addrid>0){
  1953. $data = [
  1954. "wsm_code" => "",
  1955. "orderCode" => $orderCode,
  1956. "outCode" => $outCode,
  1957. "order_type" => $der['order_type'],
  1958. "apply_id" => $rm,
  1959. "apply_name" => $ri,
  1960. "addrid" => $addrid,
  1961. "post_name" => "",
  1962. "post_code" =>"",
  1963. "post_fee" => "",
  1964. "sendtime" => $sendtime,
  1965. "send_num" => $send_num,
  1966. "check_num" => 0,
  1967. "error_num" => 0,
  1968. "status" => 1,
  1969. "addtime" => date("Y-m-d H:i:s"),
  1970. "updatetime" => date("Y-m-d H:i:s")
  1971. ];
  1972. $datainfo = Db::name('order_out')->insert($data,true);
  1973. if($datainfo>0){
  1974. $num = $send_num;
  1975. foreach ($order as $val){
  1976. $tep=[];
  1977. $ornum=0;
  1978. if($val['wsend_num']>=$num){
  1979. $val['wsend_num']-=$num;
  1980. $val['send_num']+=$num;
  1981. $ornum =$num;
  1982. $num=0;
  1983. }else{
  1984. $num-=$val['wsend_num'];
  1985. $val['send_num']+=$val['wsend_num'];
  1986. $ornum =$val['wsend_num'];
  1987. $val['wsend_num']=0;
  1988. }
  1989. $or =Db::name("order_num")->save($val);
  1990. if($or==false){
  1991. Db::rollback();
  1992. return error_show(1002,"发货地址添加创建失败");
  1993. }
  1994. $tep=[
  1995. "cgdNo"=>$val['cgdNo'],
  1996. "outCode"=>$outCode,
  1997. "send_num"=>$ornum,
  1998. "status"=>1,
  1999. "addtime"=>date("Y-m-d H:i:s"),
  2000. "updatetime"=>date("Y-m-d H:i:s")
  2001. ];
  2002. $sen=Db::name("order_send")->save($tep);
  2003. if($sen==false){
  2004. Db::rollback();
  2005. return error_show(1002,"发货地址添加创建失败");
  2006. }
  2007. if($num==0){
  2008. break;
  2009. }
  2010. }
  2011. Db::commit();
  2012. return app_show(0,"出库单新建成功",["outCode"=>$outCode]);
  2013. }
  2014. }
  2015. Db::rollback();
  2016. return error_show(1004,"出库单新建失败");
  2017. } catch (Exception $e) {
  2018. Db::rollback();
  2019. return error_show(1005, $e->getMessage());
  2020. }
  2021. }
  2022. public function outSend(){
  2023. $outCode=isset($this->post['outCode'])&& $this->post['outCode']!=""? trim($this->post['outCode']):"";
  2024. if($outCode==""){
  2025. return error_show(1004,"参数outCode不能为空");
  2026. }
  2027. $outinfo = Db::name("order_out")->where(["outCode"=>$outCode])->find();
  2028. if($outinfo==false){
  2029. return error_show(1004,"发货数据未找到");
  2030. }
  2031. $post_name = isset($this->post['post_name']) &&$this->post['post_name']!="" ? trim($this->post['post_name']):"";
  2032. if($post_name==""){
  2033. return error_show(1004,"参数post_name不能为空");
  2034. }
  2035. $post_code = isset($this->post['post_code']) &&$this->post['post_code']!="" ? trim($this->post['post_code']):"";
  2036. if($post_code==""){
  2037. return error_show(1004,"参数post_code不能为空");
  2038. }
  2039. $post_fee = isset($this->post['post_fee']) && $this->post['post_fee']!="" ? floatval($this->post['post_fee']):"";
  2040. $outinfo['post_name'] = $post_name;
  2041. $outinfo['post_code'] = $post_code;
  2042. $outinfo['post_fee'] = $post_fee;
  2043. $outinfo['sendtime'] = date("Y-m-d H:i:s");
  2044. $outinfo['status'] = 2;
  2045. $outinfo['updatetime'] = date("Y-m-d H:i:s");
  2046. $up =Db::name("order_out")->save($outinfo);
  2047. if($up){
  2048. $dbol =$this->RelaCgd($outinfo);
  2049. if($dbol==false){
  2050. Db::rollback();
  2051. return error_show(1004,"采购关联失败");
  2052. }
  2053. return app_show(0,"发货成功");
  2054. }else{
  2055. return error_show(1004,"发货失败");
  2056. }
  2057. }
  2058. public function RelaCgd($outinfo){
  2059. $der = Db::name('sale')->where(['orderCode' => $outinfo['orderCode']])->find();
  2060. if ($der == "") {
  2061. return false;
  2062. }
  2063. if($der['is_stock']==1){
  2064. $cgd = Db::name("order_bk")->where([["spuCode","=",$der['spuCode']],["is_del","=",0],["balance_num",">",0]])
  2065. ->select()->toArray();
  2066. if(empty($cgd)){
  2067. return false;
  2068. }
  2069. $send =$outinfo['send_num'];
  2070. $outsend=[];
  2071. foreach ($cgd as $value){
  2072. $temp=[];
  2073. if($value['balance_num']>=$send){
  2074. $value['balance_num']-=$send;
  2075. $value['merge_num']+=$send;
  2076. $send=0;
  2077. $temp['send_num'] =$send;
  2078. }else{
  2079. $value['balance_num'] =0;
  2080. $value['merge_num']+=$value['balance_num'];
  2081. $send -= $value['balance_num'];
  2082. $temp['send_num'] =$value['balance_num'];
  2083. }
  2084. $value['status'] = $value['balance_num']==0 ?2:$value['merge_num']==0?0:1 ;
  2085. $value['updatetime'] = date("Y-m-d H:i:s");
  2086. $bk = Db::name("order_bk")->save($value);
  2087. if($bk==false){
  2088. return false;
  2089. }
  2090. $temp['cgdNo'] = $value['cgdNo'];
  2091. $temp['outCode'] = $outinfo['outCode'];
  2092. $temp['status'] = 1;
  2093. $temp['addtime']=date("Y-m-d H:i:s");
  2094. $temp['updatetime']=date("Y-m-d H:i:s");
  2095. $outsend[]=$temp;
  2096. $order = Db::name("order_num")->where(["orderCode"=>$der['orderCode'],"cgdNo"=>$value['cgdNo'],"spuCode"=>$der['spuCode'],"status"=>1])->find();
  2097. if($order==false){
  2098. $order=[
  2099. "orderCode"=>$der['orderCode'],
  2100. "cgdNo"=>$value['cgdNo'],
  2101. "spuCode"=>$der['spuCode'],
  2102. "good_num"=>$der['good_num'],
  2103. "wsend_num"=>$der['good_num']-$temp['send_num'],
  2104. "send_num"=>$temp['send_num'],
  2105. "status"=>1,
  2106. "source"=>1
  2107. ];
  2108. }else{
  2109. $order['wsend_num']-=$temp['send_num'];
  2110. $order['send_num']+=$temp['send_num'];
  2111. }
  2112. if($order['wsend_num']<0){
  2113. return false;
  2114. }
  2115. $up =Db::name("order_num")->save($order);
  2116. if($up==false){
  2117. return false;
  2118. }
  2119. if($send==0){
  2120. break;
  2121. }
  2122. }
  2123. if(empty($temp)){
  2124. return false;
  2125. }
  2126. $insert = Db::name("order_send")->insertAll($outsend);
  2127. if($insert){
  2128. return true;
  2129. }else{
  2130. return false;
  2131. }
  2132. }else{
  2133. $order = Db::name("order_num")->where(["orderCode"=>$der['orderCode'],"spuCode"=>$der['spuCode'],
  2134. "status"=>1])->find();
  2135. if($order==false){
  2136. return false;
  2137. }else{
  2138. if($outinfo['send_num']> $order['wsend_num']){
  2139. return false;
  2140. }
  2141. $order['wsend_num']-=$outinfo['send_num'];
  2142. $order['send_num']+=$outinfo['send_num'];
  2143. if($order['wsend_num']<0){
  2144. return false;
  2145. }
  2146. $up =Db::name("order_num")->save($order);
  2147. if($up==false){
  2148. return false;
  2149. }
  2150. $temp=[];
  2151. $temp['cgdNo'] = $order['cgdNo'];
  2152. $temp['outCode'] = $outinfo['outCode'];
  2153. $temp['send_num'] =$outinfo['send_num'];
  2154. $temp['status'] = 1;
  2155. $temp['addtime']=date("Y-m-d H:i:s");
  2156. $temp['updatetime']=date("Y-m-d H:i:s");
  2157. $insert = Db::name("order_send")->insert($temp);
  2158. if($insert){
  2159. return true;
  2160. }else{
  2161. return false;
  2162. }
  2163. }
  2164. }
  2165. }
  2166. }