Sale.php 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039
  1. <?php
  2. namespace app\admin\controller;
  3. use app\BaseController;
  4. use think\App;
  5. use think\facade\Db;
  6. class Sale extends BaseController
  7. {
  8. public $post="";
  9. public function __construct(App $app)
  10. {
  11. parent::__construct($app);
  12. $this->post=$this->request->post();
  13. }
  14. public function create(){
  15. $token = isset($this->post['token']) && $this->post['token'] !=="" ?trim($this->post['token']):"";
  16. $orderCode=makeNo("CX");
  17. $good_code = $this->post['good_code'] && $this->post['good_code'] !=="" ? trim($this->post['good_code']) :"";
  18. if($good_code==""){
  19. return error_show(1002,"商品code不能为空");
  20. }
  21. $ct = Db::name('good')->alias('a')->join('good_type b','b.good_code=a.good_code','left')
  22. ->where(['b.type_code'=>$good_code])->find();
  23. if($ct==""){
  24. return error_show(1002,"未找到商品数据");
  25. }
  26. $customer_code= $this->post['customer_code'] && $this->post['customer_code'] !=="" ? trim($this->post['customer_code']) :"";
  27. if($customer_code==""){
  28. return error_show(1002,"客户code不能为空");
  29. }
  30. $customer=Db::name("customer_info")->where(["companyNo"=>$customer_code])->find();
  31. if($customer==false){
  32. return error_show(1004,"未找到客户数据");
  33. }
  34. $supplierNo= $this->post['supplierNo'] && $this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']) :"";
  35. if($supplierNo==""){
  36. return error_show(1002,"参数supplierNo不能为空");
  37. }
  38. $supplier=Db::name("supplier")->where(["code"=>$supplierNo])->find();
  39. if($supplier==false){
  40. return error_show(1004,"未找到平台供应商数据");
  41. }
  42. $apply_id =GetUserInfo($token);
  43. if(empty($apply_id)||$apply_id['code']!=0){
  44. return error_show(1002,"申请人数据不存在");
  45. }
  46. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  47. $ri= isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  48. // $good_name=isset($this->post['good_name']) && $this->post['good_name'] !=="" ? trim($this->post['good_name']) :"";
  49. //$good_num=isset($this->post['good_num']) && $this->post['good_num'] !=="" ? intval($this->post['good_num']) :"";
  50. // if($good_num==""){
  51. // return error_show(1002,"参数good_num不能为空");
  52. //}
  53. // $origin_price = isset($this->post['origin_price']) && $this->post['origin_price'] !=="" ? intval($this->post['origin_price']) :"";
  54. //$sale_price=isset($this->post['sale_price']) && $this->post['sale_price'] !=="" ? trim($this->post['sale_price']) :"";
  55. // $total_price=isset($this->post['total_price']) && $this->post['total_price'] !=="" ? trim($this->post['total_price']) :"";
  56. $post_fee=isset($this->post['post_fee']) && $this->post['post_fee'] !=="" ? trim($this->post['post_fee']) :"";
  57. $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']) :"";
  58. // $send_num = isset($this->post['send_num']) && $this->post['send_num'] !=="" ? intval($this->post['send_num']) :"";
  59. // $wsend_num = isset($this->post['wsend_num']) && $this->post['wsend_num'] !=="" ? intval($this->post['wsend_num']) :"";
  60. // $send_status = isset($this->post['send_status']) && $this->post['send_status'] !=="" ? intval($this->post['send_status']) :"";
  61. $va= isset($this->post['order_addr']) && $this->post['order_addr'] !=="" ? $this->post['order_addr']:"";
  62. if($va==""){
  63. return error_show(1002,"参数order_addr不能为空");
  64. }
  65. $vi= isset($this->post['good_stock']) && $this->post['good_stock'] !=="" ? $this->post['good_stock']:"";
  66. if($vi==""){
  67. return error_show(1002,"参数good_stock不能为空");
  68. }
  69. $good_num = intval(array_sum(array_column($vi,"num")));
  70. Db::startTrans();
  71. try {
  72. $data=[
  73. "orderCode"=>$orderCode,
  74. "good_code"=>$good_code,
  75. "customer_code"=>$customer_code,
  76. "good_name"=>$ct['good_name'],
  77. "good_num"=>$good_num,
  78. "apply_id"=>$rm,
  79. "apply_name"=>$ri,
  80. "origin_price"=>$ct['original_price'],
  81. "sale_price"=>$ct['original_price'],
  82. "post_fee"=>$post_fee,
  83. "status"=>$status,
  84. "supplierNo"=>$supplierNo,
  85. "send_num"=>0,
  86. "wsend_num"=>$good_num,
  87. "send_status"=>1,
  88. "is_del"=>0,
  89. "addtime"=>date("Y-m-d H:i:s"),
  90. "updatetime"=>date("Y-m-d H:i:s"),
  91. 'total_price'=>$ct['original_price']*$good_num,
  92. ];
  93. $datainfo = Db::name('sale')->insert($data,true);
  94. $vat=[];
  95. $inn=[];
  96. if($datainfo>0){
  97. foreach ($vi as $ion){
  98. $iten=[];
  99. $iten['orderCode']=$orderCode;
  100. $iten['wsm_code']=$ion['wsm_code'];
  101. $iten['stock_id']="";
  102. $iten['num']=$ion['num'];
  103. $iten['status']=0;
  104. $iten['sale_price']=$ct['original_price'];
  105. $iten['addtime'] =date("Y-m-d H:i:s");
  106. $iten['updatetime'] =date("Y-m-d H:i:s");
  107. $inn[]=$iten;
  108. }
  109. // if($vi['usable_stock']<$iten['num']){
  110. // Db::rollback();
  111. // return error_show(1002,"超出库存数量");
  112. // }
  113. $vp= Db::name('sale_info')->insertAll($inn);
  114. if($vp==""){
  115. Db::rollback();
  116. return error_show(1002,"添加失败");
  117. }
  118. foreach ($va as $value){
  119. $temp=[];
  120. $addrs=[];
  121. if($value['addr_code']!==''&&is_array($value['addr_code'])){
  122. $addrs['provice_code'] = $value['addr_code'][0];
  123. $addrs['city_code'] = $value['addr_code'][1];
  124. $addrs['area_code'] = $value['addr_code'][2];
  125. $addr = json_encode($addrs);
  126. }else{
  127. $addr = isset($value['addr_code'])?$value['addr_code']:'';
  128. }
  129. $temp['orderCode']=$orderCode;
  130. $temp['contactor']=$value['contactor'];
  131. $temp['mobile'] = $value['mobile'];
  132. $temp['addr'] = $value['addr'];
  133. $temp['addr_code']=$addr;
  134. $temp['customer_code'] =$customer_code;
  135. $temp['receipt_quantity']=$value['receipt_quantity'];
  136. $temp['post_fee'] =0;
  137. $temp['is_del'] =0;
  138. $temp['addtime'] =date("Y-m-d H:i:s");
  139. $temp['updatetime'] =date("Y-m-d H:i:s");
  140. $temp['arrive_time']=date("Y-m-d H:i:s");
  141. $vat[]=$temp;
  142. }
  143. $vmp = Db::name('order_addr')->insertAll($vat);
  144. if($vmp){
  145. Db::commit();
  146. return error_show(0,"销售订单创建成功");
  147. }
  148. }
  149. Db::rollback();
  150. return error_show(1002,"销售订单创建失败");
  151. }catch(\Exception $e){
  152. Db::rollback();
  153. return error_show(1005,$e->getMessage());
  154. }
  155. }
  156. public function list(){
  157. $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']):"1";
  158. $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']) :"10";
  159. $where[] = ['is_del',"=",0];
  160. $orderCode=isset($this->post['orderCode']) && $this->post['orderCode'] !=="" ? trim($this->post['orderCode']):"";
  161. if($orderCode !==""){
  162. $where[]=['orderCode',"=",$orderCode];
  163. }
  164. $apply_name=isset($this->post['apply_name']) && $this->post['apply_name'] !=="" ? trim($this->post['apply_name'])
  165. :"";
  166. if($apply_name !==""){
  167. $where[]=['apply_name',"like","%$apply_name%"];
  168. }
  169. $good_name=isset($this->post['good_name']) && $this->post['good_name'] !=="" ? trim($this->post['good_name'])
  170. :"";
  171. if($good_name !==""){
  172. $where[]=['good_name',"like","%$good_name%"];
  173. }
  174. $good_code=isset($this->post['good_code']) && $this->post['good_code'] !=="" ? trim($this->post['good_code']):"";
  175. if($good_code !==""){
  176. $where[]=['good_code',"like","%$good_code%"];
  177. }
  178. $customer_code=isset($this->post['customer_code']) && $this->post['customer_code'] !=="" ? trim($this->post['customer_code']):"";
  179. if($customer_code !==""){
  180. $where[]=['customer_code',"like","%$customer_code%"];
  181. }
  182. $supplierNo=isset($this->post['supplierNo']) && $this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']):"";
  183. if($supplierNo !==""){
  184. $where[]=['supplierNo',"like","%$supplierNo%"];
  185. }
  186. $ordertype=isset($this->post['order_type']) && $this->post['order_type'] !=="" ? intval($this->post['order_type'])
  187. :"";
  188. if($ordertype !==""){
  189. $where[]=['order_type',"=",$ordertype];
  190. }
  191. $status=isset($this->post['status']) && $this->post['status'] !=="" ? trim($this->post['status']):"";
  192. if($status !==""){
  193. $where[]=['status',"=",$status];
  194. }
  195. $start = isset($this->post['start']) && $this->post['start'] !=="" ? $this->post['start'] :"";
  196. if($start !=""){
  197. $where[]= ["addtime",'>=',$start];
  198. }
  199. $end = isset($this->post['end']) && $this->post['end'] !=="" ? $this->post['end'] :"";
  200. if($end !=""){
  201. $where[]= ["addtime",'<=',$end];
  202. }
  203. $count = Db::name('sale')->where($where)->count();
  204. $total = ceil($count/$size);
  205. $page = $page >= $total ? $total : $page;
  206. $list= Db::name('sale')->where($where)->order("addtime desc")->page($page,$size)->select();
  207. $data=[];
  208. foreach ($list as $value){
  209. $var = Db::name('good_type')->alias('b')->join("good a","a.good_code=b.good_code","left")
  210. ->where(['b.type_code'=>$value['good_code'],'a.is_del'=>0])->field('a.good_code,a.good_name,a.cat_id')->find();;
  211. $value['can']= isset($var['cat_id']) && $var['cat_id'] !=0 ? made($var['cat_id']):[];
  212. $value['supplierName']='';
  213. if($value['supplierNo']!=""){
  214. $supplier=Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  215. $value['supplierName']=isset($supplier['name']) ? $supplier['name']:"";
  216. }
  217. $value['customerName']='';
  218. if($value['customer_code']!=""){
  219. $supplier=Db::name("customer_info")->where(["companyNo"=>$value['customer_code']])->find();
  220. $value['customerName']=isset($supplier['companyName']) ? $supplier['companyName']:"";
  221. }
  222. $data[]=$value;
  223. }
  224. return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
  225. }
  226. public function edit(){
  227. $token = isset($this->post['token']) && $this->post['token'] !=="" ? trim($this->post['token']) :"";
  228. $id = isset($this->post['id']) && $this->post['id'] !=="" ? trim($this->post['id']) :"";
  229. if($id==""){
  230. return error_show(1002,"参数id不能为空");
  231. }
  232. $etid = Db::name("sale")->where(["id"=>$id,"is_del"=>0])->find();
  233. if(empty($etid)){
  234. return error_show(1002,"未找到数据");
  235. }
  236. // $orderCode=isset($this->post['orderCode']) && $this->post['orderCode'] !=="" ? trim($this->post['orderCode']) :"";
  237. // if($orderCode==""){
  238. // return error_show(1002,"销售单code不能为空");
  239. // }
  240. $good_code = isset($this->post['good_code']) && $this->post['good_code'] !=="" ? trim($this->post['good_code']) :"";
  241. if($good_code==""){
  242. return error_show(1002,"商品code不能为空");
  243. }
  244. $customer_code=isset($this->post['customer_code']) && $this->post['customer_code'] !=="" ? trim($this->post['customer_code']):"";
  245. if($customer_code==""){
  246. return error_show(1002,"客户code不能为空");
  247. }
  248. $apply_id =GetUserInfo($token);
  249. if(empty($apply_id)||$apply_id['code']!=0){
  250. return error_show(1002,"申请人数据不存在");
  251. }
  252. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  253. $ri= isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  254. $good_name=isset($this->post['good_name']) && $this->post['good_name'] !=="" ? trim($this->post['good_name']) :"";
  255. $good_num=isset($this->post['good_num']) && $this->post['good_num'] !=="" ? intval($this->post['good_num']) :"";
  256. $origin_price = isset($this->post['origin_price']) && $this->post['origin_price'] !=="" ? intval($this->post['origin_price']) :"";
  257. $sale_price=isset($this->post['sale_price']) && $this->post['sale_price'] !=="" ? trim($this->post['sale_price']) :"";
  258. $total_price=isset($this->post['total_price']) && $this->post['total_price'] !=="" ? trim($this->post['total_price']) :"";
  259. $post_fee=isset($this->post['post_fee']) && $this->post['post_fee'] !=="" ? trim($this->post['post_fee']) :"";
  260. $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']) :"";
  261. $vr= isset($this->post['order_addr']) && $this->post['order_addr'] !=="" ? $this->post['order_addr']:"";
  262. if($vr=="" ){
  263. return error_show(1002,"参数order_addr不能为空");
  264. }
  265. $vi= isset($this->post['good_stock']) && $this->post['good_stock'] !=="" ? $this->post['good_stock']:"";
  266. if($vi==""){
  267. return error_show(1002,"参数good_stock不能为空");
  268. }
  269. Db::startTrans();
  270. try {
  271. $datn=[
  272. "id"=>$id,
  273. "good_code"=>$good_code,
  274. "customer_code"=>$customer_code,
  275. "good_name"=>$good_name,
  276. "good_num"=>$good_num,
  277. "apply_id"=>$rm,
  278. "apply_name"=>$ri,
  279. "origin_price"=>$origin_price,
  280. "sale_price"=>$sale_price,
  281. "total_price"=>$total_price,
  282. "post_fee"=>$post_fee,
  283. "status"=>$status,
  284. "is_del"=>0,
  285. "updatetime"=>date("Y-m-d H:i:s")
  286. ];
  287. $datninfo = Db::name('sale')->where(['id'=>$id,'is_del'=>0])->save($datn);
  288. if($datninfo>0){
  289. foreach ($vi as $ion) {
  290. $iten = [];
  291. isset($ion['id']) && $ion['id'] !== "" ? $iten['id'] = $ion['id'] : '';
  292. $iten['orderCode'] = $etid['orderCode'];
  293. $iten['wsm_code'] = $ion['wsm_code'];
  294. $iten['stock_id'] =0;
  295. $iten['num'] = $ion['num'];
  296. $iten['status'] = 1;
  297. $iten['sale_price'] = $ion['sale_price'];
  298. isset($ion['id']) && $ion['id'] !== "" ? '' : $iten['addtime'] = date("Y-m-d H:i:s");
  299. $iten['updatetime'] = date("Y-m-d H:i:s");
  300. //$inn[]=$iten;
  301. $vp = Db::name('sale_info')->save($iten);
  302. if ($vp == false) {
  303. Db::rollback();
  304. return error_show(1002, "更新失败");
  305. }
  306. }
  307. foreach ($vr as $value) {
  308. $temp = [];
  309. isset($value['id']) && $value['id'] !== "" ? $temp['id'] = $value['id'] : '';
  310. $temp['orderCode'] = $etid['orderCode'];
  311. $temp['contactor'] = $value['contactor'];
  312. $temp['mobile'] = $value['mobile'];
  313. $temp['addr'] = $value['addr'];
  314. $temp['addr_code'] = $value['addr_code'];
  315. $temp['customer_code'] = $customer_code;
  316. $temp['receipt_quantity'] = $value['receipt_quantity'];
  317. $temp['post_fee'] = 0;
  318. $temp['is_del'] = $value['is_del'];
  319. isset($value['id']) && $value['id'] !== "" ? '' : $temp['addtime'] = date("Y-m-d H:i:s");
  320. $temp['updatetime'] = date("Y-m-d H:i:s");
  321. $temp['arrive_time'] = date("Y-m-d H:i:s");
  322. $dat = Db::name('order_addr')->save($temp);
  323. if ($dat == false) {
  324. Db::rollback();
  325. return error_show(1002, "更新失败");
  326. }
  327. }
  328. Db::commit();
  329. return error_show(0,"更新成功");
  330. }
  331. Db::rollback();
  332. return error_show(1002,"更新失败");
  333. }catch(\Exception $e){
  334. Db::rollback();
  335. return error_show(1005,$e->getMessage());
  336. }
  337. }
  338. public function info(){
  339. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']):"";
  340. if($id==""){
  341. return error_show(1002,"参数id不能为空");
  342. }
  343. //->field('good_code,good_name,good_num,customer_code,orderCode')
  344. $einfo = Db::name('sale')->where(['id'=>$id,'is_del'=>0])->find();
  345. if(empty($einfo)){
  346. return error_show(1002,"未找到销售订单数据");
  347. }
  348. $goon = Db::name('good')->alias('b')->join("good_type a","a.good_code=b.good_code","left")
  349. ->where(['a.type_code'=> $einfo['good_code']])->find();
  350. if(empty($goon)){
  351. return error_show(1003,"未找到商品数据");
  352. }
  353. $int= isset($goon['cat_id']) && $goon['cat_id'] !=0 ? made($goon['cat_id']):[];
  354. $in= Db::name('customer_info')->where(['companyNo'=>$einfo['customer_code']])->field('companyName')->find();
  355. // ->field('addr,contactor,mobile,receipt_quantity,arrive_time')
  356. $einfo['supplierName']='';
  357. if($einfo['supplierNo']!=""){
  358. $supplier=Db::name("supplier")->where(["code"=>$einfo['supplierNo']])->find();
  359. $einfo['supplierName']=isset($supplier['name']) ? $supplier['name']:"";
  360. }
  361. $fo = Db::name('order_addr')->where(['orderCode'=>$einfo['orderCode'],'is_del'=>0])->select();
  362. $bum = Db::name('order_out')->where(['orderCode'=>$einfo['orderCode']])->select();
  363. $ins=[];
  364. if(!empty($bum)){
  365. foreach ($bum as $stn){
  366. $so = Db::name('order_addr')->where(['id'=>$stn['addrid']])->find();
  367. $addr = GetAddr($so['addr_code']);
  368. $stn['addr_info']=$addr;
  369. $stn['add_code']=json_decode($so['addr_code'],true);
  370. $stn['addr']=$so['addr'];
  371. $stn['contact']=$so['contactor'];
  372. $stn['mobile']=$so['mobile'];
  373. $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b", "a.supplierNo=b.code")
  374. ->where(["a.wsm_code" => $stn['wsm_code']])->field("a.name as wsm_name,b.name,b.code")->find();
  375. $stn['wsm_name'] = isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name'] : "";
  376. $stn['wsm_supplier'] = isset($wsmcode['name']) ? $wsmcode['name'] : "";
  377. $stn['wsm_supplierNo'] = isset($wsmcode['code']) ? $wsmcode['code'] : "";
  378. $ins[]=$stn;
  379. }
  380. }
  381. $addrs=[];
  382. if(!empty($fo)){
  383. foreach ($fo as $value){
  384. $value['addr_info']="";
  385. $value['send_num']=0;
  386. if($value['addr_code']!=""){
  387. $addr=GetAddr($value['addr_code']);
  388. $value['addr_info'] = $addr;
  389. $value['addr_code'] = json_decode($value['addr_code'],true);
  390. $send = Db::name("order_out")->where(['addrid'=>$value['id'],'orderCode' => $einfo['orderCode']])->sum("send_num");
  391. $value['send_num'] = $send ?? 0;
  392. }
  393. $value['wsend_num']=$value['receipt_quantity']-$value['send_num'];
  394. $addrs[]=$value;
  395. }
  396. }
  397. //->field('num,sale_price,wsm_code,stock_id')
  398. $st = Db::name('sale_info')->where(['orderCode'=>$einfo['orderCode']])->select();
  399. $data=[];
  400. if(!empty($fo)) {
  401. foreach ($st as $value) {
  402. $value['wsm_name'] = "";
  403. $value['wsm_supplier'] = "";
  404. $value['wsm_supplierNo'] = "";
  405. $value['usable_stock'] = 0;
  406. $value['send_num'] = 0;
  407. if ($value['wsm_code'] != "") {
  408. $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b", "a.supplierNo=b.code")
  409. ->where(["a.wsm_code" => $value['wsm_code']])->field("a.name as wsm_name,b.name,b.code")->find();
  410. $value['wsm_name'] = isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name'] : "";
  411. $value['wsm_supplier'] = isset($wsmcode['name']) ? $wsmcode['name'] : "";
  412. $value['wsm_supplierNo'] = isset($wsmcode['code']) ? $wsmcode['code'] : "";
  413. $dn = Db::name('good_stock')->where(['wsm_code' => $value['wsm_code'], 'good_type_code' => $einfo['good_code']])->find();
  414. $value['usable_stock'] = isset($dn['usable_stock']) ? $dn['usable_stock'] : "0";
  415. $send = Db::name("order_out")->where(["wsm_code" => $value['wsm_code'], 'orderCode' => $einfo['orderCode']])->sum("send_num");
  416. $value['send_num'] = $send ?? 0;
  417. }
  418. $value['wsend_num'] = $value['num'] - $value['send_num'];
  419. $data[] = $value;
  420. }
  421. }
  422. $einfo['info']=$data;
  423. $einfo['companyName']=isset($in['companyName']) ? $in['companyName']:"";
  424. $einfo['addrs']=$addrs;
  425. $einfo['bum']=$ins;
  426. $einfo['can']=$int;
  427. if(empty($einfo)){
  428. return error_show(1002,"未找到销售订单数据");
  429. }else{
  430. return app_show(0,"获取成功",$einfo);
  431. }
  432. }
  433. public function del(){
  434. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
  435. if($id===""){
  436. return error_show(1002,"参数id不能为空");
  437. }
  438. $ed = Db::name('sale')->where(['id'=>$id,'is_del'=>0])->find();
  439. if(empty($ed)){
  440. return error_show(1002,"未找到销售订单数据");
  441. }
  442. $str =Db::name('sale')->update(['id'=>$id,'is_del'=>1,'updatetime'=>date("Y-m-d H:i:s")]);
  443. if($str){
  444. return error_show(0,"删除成功");
  445. }else{
  446. return error_show(1002,"删除失败");
  447. }
  448. }
  449. public function status(){
  450. $token= isset($this->post['token']) && $this->post['token'] !=="" ? trim($this->post['token']) :"";
  451. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
  452. if($id==""){
  453. return error_show(1002,"参数id不能为空");
  454. }
  455. $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']) :"";
  456. if($status==""){
  457. return error_show(1002,"订单状态不能为空");
  458. }
  459. $dio = Db::name('sale')->where(['id'=>$id,'is_del'=>0])->find();
  460. if(empty($dio)){
  461. return error_show(1002,"销售单信息未找到");
  462. }
  463. if($status==1 && $dio['order_type']==2) {
  464. $zxinfo = Db::name("consult")->where(["zxNo" => $dio['zxNo'], "is_del" => 0])->find();
  465. if ($zxinfo == false) {
  466. return error_show(1004, "未找到咨询单数据");
  467. }
  468. $gold['price']=0;
  469. if ($zxinfo['zx_type'] == 2) {
  470. if ($zxinfo['metals'] == "") {
  471. return error_show(1004, "未找到咨询单贵金属类型数据");
  472. }
  473. $metals = $zxinfo['metals'] == '18K' ? 1 : ($zxinfo['metals'] == '24K' ? 2 : 3);
  474. $gold = Db::name("gold_price")->where(["type" => $metals])->order("addtime desc")->find();
  475. if (empty($gold)) {
  476. return error_show(1004, "未找到咨询单贵金属类型数据");
  477. }
  478. $dio['gold_price']=$gold['price'];
  479. }
  480. $wsm = Db::name("warehouse_info")->where(["supplierNo" => $zxinfo['gysNo'], "wsm_type" => 2])->find();
  481. if (empty($wsm)) {
  482. return error_show(1002, "供应商仓库未找到");
  483. }
  484. }
  485. $apply_id =GetUserInfo($token);
  486. if(empty($apply_id)||$apply_id['code']!=0){
  487. return error_show(1002,"申请人数据不存在");
  488. }
  489. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  490. $ri= isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  491. Db::startTrans();
  492. try {
  493. $dio['status']=$status;
  494. $dio['updatetime']=date("Y-m-d H:i:s");
  495. $st = Db::name('sale')->save($dio);
  496. if($st) {
  497. if($status==3){
  498. $dn = Db::name('sale_info')->where(['orderCode' => $st['orderCode']])->select();
  499. foreach ($dn as $value) {
  500. $dm = Db::name('good_stock')->where(['wsm_code' => $value['wsm_code'], 'good_type_code' => $st['good_code']])->find();
  501. if($dm==""){
  502. Db::rollback();
  503. return error_show(1003,"未找到商品数据");
  504. }
  505. if($value['num']>$dm['usable_stock']){
  506. Db::rollback();
  507. return error_show(1002,"超出库存数量");
  508. }
  509. $dm['usable_stock']-=$value['num'];
  510. $dm['wait_out_stock']+=$value['num'];
  511. $send =Db::name("order_out")->where(["wsm_code"=>$value['wsm_code']])->sum("send_num");
  512. $value['send_num'] = $send??0;
  513. $value['wsend_num']=$value['num']-$value['send_num'];
  514. $Db = Db::name('good_stock')->update($dm);
  515. $Db['updatetime']= date('Y-m-d H:i:s');
  516. if($Db==false){
  517. Db::rollback();
  518. return error_show(1002,"状态更新失败");
  519. }
  520. }
  521. }
  522. if($status==1 && $dio['order_type']==2){
  523. $cgd =makeNo("CG");
  524. $clll=[
  525. "cgdNo"=>$cgd,
  526. "bkcode"=>$dio['orderCode'],
  527. "wsm_code"=>$wsm['wsm_code'],
  528. "cgder_id"=>"0",
  529. "cgder"=>$zxinfo['saler'],
  530. "good_code"=>"GD-".$zxinfo['cpNo'],
  531. "good_name"=>$zxinfo['cpName'],
  532. "good_type_code"=>$zxinfo['cpNo'],
  533. "good_num"=>$dio['good_num'],
  534. "good_price"=>$zxinfo['total_fee'],
  535. "total_fee"=>round($zxinfo['total_fee']*$dio['good_num'],2),
  536. "pakge_fee"=>$zxinfo['package_fee'],
  537. "cert_fee"=>$zxinfo['cert_fee'],
  538. "open_fee"=>$zxinfo['open_fee'],
  539. "delivery_fee"=>$zxinfo['delivery_fee'],
  540. "mark_fee"=>$zxinfo['mark_fee'],
  541. "teach_fee"=>$zxinfo['cost_fee'],
  542. "demo_fee"=>$zxinfo['demo_fee'],
  543. "nake_fee"=>$zxinfo['bare_fee'],
  544. "weight"=>isset($zxinfo['weight'])?$zxinfo['weight']:0,
  545. "supplierNo"=>$zxinfo['gysNo'],
  546. "supplier_name"=>$zxinfo['gysname'],
  547. "gold_price"=>$gold['price'],
  548. "send_num"=>0,
  549. "wsend_num"=>$dio['good_num'],
  550. "remark"=>'',
  551. "lasttime"=>date("Y-m-d H:i:s"),
  552. "is_del"=>0,
  553. "status"=>$dio['send_type']==1?1:0,
  554. "order_type"=>2,
  555. "addtime"=>date("Y-m-d H:i:s"),
  556. "updatetime"=>date("Y-m-d H:i:s")
  557. ];
  558. $cgin = Db::name("purchease_order")->insert($clll);
  559. // var_dump(Db::name("purchease_order")->getLastSql(),$clll);
  560. if($cgin==false){
  561. Db::rollback();
  562. return error_show(1002,"咨询采购单创建商品失败");
  563. }
  564. if($dio['send_type']==1){
  565. $addr = Db::name('order_addr')->where(["orderCode"=>$dio['orderCode'],'is_del'=>0])->select();
  566. foreach ($addr as $value){
  567. $outCode=makeNo("CK");
  568. $data=[
  569. "wsm_code"=>$wsm['wsm_code'],
  570. "orderCode"=>$dio['orderCode'],
  571. "outCode"=>$outCode,
  572. "order_type"=>$dio['order_type'],
  573. "apply_id"=>$rm,
  574. "apply_name"=>$ri,
  575. "addrid"=>$value['id'],
  576. "post_name"=>'',
  577. "post_code"=>'',
  578. "post_fee"=>'',
  579. "sendtime"=>date("Y-m-d H:i:s"),
  580. "send_num"=>$value['receipt_quantity'],
  581. "check_num"=>0,
  582. "error_num"=>0,
  583. "status"=>0,
  584. "addtime"=>date("Y-m-d H:i:s"),
  585. "updatetime"=>date("Y-m-d H:i:s")
  586. ];
  587. $datainfo = Db::name('order_out')->insert($data);
  588. if(!$datainfo){
  589. Db::rollback();
  590. return error_show(1003,"创建失败");
  591. }
  592. }
  593. }
  594. }
  595. }
  596. Db::commit();
  597. return error_show(0,"订单状态更新成功");
  598. }catch (\Exception $e) {
  599. Db::rollback();
  600. return error_show(1005, $e->getMessage());
  601. }
  602. }
  603. public function fee(){
  604. $id = isset($this->post['id']) && $this->post['id'] !=="" ? trim($this->post['id']) :"";
  605. if($id==""){
  606. return error_show(1002,"参数id不能为空");
  607. }
  608. $etid = Db::name("sale")->where(["id"=>$id,"is_del"=>0])->find();
  609. if(empty($etid)){
  610. return error_show(1002,"未找到数据");
  611. }
  612. $vr= isset($this->post['order_addr']) && $this->post['order_addr'] !=="" ? $this->post['order_addr']:"";
  613. if($vr==""){
  614. return error_show(1002,"参数order_addr不能为空");
  615. }
  616. Db::startTrans();
  617. try {
  618. $data=[
  619. "id"=>$id,
  620. "status"=>2,
  621. "is_del"=>0,
  622. "updatetime"=>date("Y-m-d H:i:s")
  623. ];
  624. $datainfo = Db::name('sale')->where(['id'=>$id,'is_del'=>0])->save($data);
  625. if($datainfo){
  626. foreach ($vr as $value){
  627. $tm=[];
  628. $tm['id'] = $value['id'];
  629. $tm['orderCode']=$etid['orderCode'];
  630. $tm['post_fee']=$value['post_fee'];
  631. $tm['updatetime']=date("Y-m-d H:i:s");
  632. $dn = Db::name('order_addr')->save($tm);
  633. if($dn==false){
  634. Db::rollback();
  635. return error_show(1002,"更新失败");
  636. }
  637. }
  638. Db::commit();
  639. return error_show(0,"更新成功");
  640. }
  641. Db::rollback();
  642. return error_show(1003,"更新失败");
  643. }catch(\Exception $e){
  644. Db::rollback();
  645. return error_show(1005,$e->getMessage());
  646. }
  647. }
  648. public function out(){
  649. $token= isset($this->post['token']) && $this->post['token'] !=="" ? trim($this->post['token']) :"";
  650. $outCode=makeNo("CK");
  651. $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !=="" ? trim($this->post['orderCode']) :"";
  652. if($orderCode==""){
  653. return error_show(1002,"参数orderCoder不能为空");
  654. }
  655. $der = Db::name('sale')->where(['orderCode'=>$orderCode])->find();
  656. if($der==""){
  657. return error_show(1002,"未找到出库订单单号");
  658. }
  659. $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code'] !=="" ? trim($this->post['wsm_code']) :"";
  660. if($wsm_code==""){
  661. return error_show(1002,"参数wsm_code不能为空");
  662. }
  663. $wsm= Db::name('sale_info')->where(['wsm_code'=>$wsm_code,'orderCode'=>$der['orderCode']])->find();
  664. if($wsm==""){
  665. return error_show(1002,"未找到仓库编码");
  666. }
  667. $post_name= isset($this->post['post_name']) && $this->post['post_name'] !=="" ? trim($this->post['post_name']) :"";
  668. if($post_name==""){
  669. return error_show(1002,"物流公司不能为空");
  670. }
  671. $post_code = isset($this->post['post_code']) && $this->post['post_code'] !=="" ? trim($this->post['post_code']) :"";
  672. if($post_code==""){
  673. return error_show(1002,"物流单号不能为空");
  674. }
  675. $post_fee = isset($this->post['post_fee']) && $this->post['post_fee'] !=="" ? intval($this->post['post_fee']) :"";
  676. if($post_fee==""){
  677. return error_show(1002,"物流费不能为空");
  678. }
  679. $send_num = isset($this->post['send_num']) && $this->post['send_num'] !=="" ? $this->post['send_num'] :"";
  680. if($send_num==""){
  681. return error_show(1002,"发货数量不能为空");
  682. }
  683. if($send_num>$wsm['num']){
  684. return error_show(1002,"超出可发货数量");
  685. }
  686. $apply_id =GetUserInfo($token);
  687. if(empty($apply_id)||$apply_id['code']!=0){
  688. return error_show(1002,"申请人数据不存在");
  689. }
  690. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  691. $ri= isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  692. $addrid = isset($this->post['addrid']) && $this->post['addrid'] !=="" ? intval($this->post['addrid']) :"";
  693. $dr = Db::name('order_addr')->where(['id'=>$addrid,'is_del'=>0])->find();
  694. if(empty($dr)){
  695. return error_show(1003,"收货人信息未找到");
  696. }
  697. if($dr['orderCode']!== $orderCode){
  698. return error_show(1002,"订单code不存在");
  699. }
  700. $sendtime = isset($this->post['sendtime']) && $this->post['sendtime'] !=="" ? $this->post['sendtime']:date("Y-m-d H:i:s");
  701. // $check_num = isset($this->post['check_num']) && $this->post['check_num'] !=="" ? $this->post['check_num'] :"";
  702. // $error_num = isset($this->post['error_num']) && $this->post['error_num'] !=="" ? $this->post['error_num'] :"";
  703. $status = isset($this->post['status']) && $this->post['status'] !=="" ? $this->post['status'] :"1";
  704. //$order_type = isset($this->post['order_type']) && $this->post['order_type'] !=="" ? $this->post['order_type'] :"1";
  705. //$dn=Db::name('sale_info')->where(['wsm_code'=>$outCode])->find();
  706. Db::startTrans();
  707. try {
  708. $data=[
  709. "wsm_code"=>$wsm_code,
  710. "orderCode"=>$orderCode,
  711. "outCode"=>$outCode,
  712. "order_type"=>$der['order_type'],
  713. "apply_id"=>$rm,
  714. "apply_name"=>$ri,
  715. "addrid"=>$dr['id'],
  716. "post_name"=>$post_name,
  717. "post_code"=>$post_code,
  718. "post_fee"=>$post_fee,
  719. "sendtime"=>$sendtime,
  720. "send_num"=>$send_num,
  721. "check_num"=>0,
  722. "error_num"=>0,
  723. "status"=>$status,
  724. "addtime"=>date("Y-m-d H:i:s"),
  725. "updatetime"=>date("Y-m-d H:i:s")
  726. ];
  727. $datainfo = Db::name('order_out')->insert($data);
  728. if($datainfo) {
  729. if ($status==1) {
  730. $var = Db::name('sale_info')->where(['orderCode' =>$orderCode,'wsm_code'=>$wsm_code])->find();
  731. //var_dump(Db::name('sale_info')->getLastSql());
  732. if($var==""){
  733. return error_show(1002,"未找到数据");
  734. }
  735. $send =Db::name("order_out")->where(["wsm_code"=>$wsm_code,'orderCode'=>$orderCode])->sum("send_num");
  736. $der['send_num']+= $send;
  737. $der['wsend_num']-=$send ;//($der['send_num'])?$der['wsend_num'] =="" ? $der['send']
  738. $der['send_status']=$der['send_num']==0 ? 1 :$der['wsend_num']==0?3:2;
  739. $der['status']=$der['send_num']==0 ? 3 :$der['wsend_num']==0?5:4;
  740. $der['updatetime'] = date("Y-m-d H:i:s");
  741. $si = Db::name('sale')->save($der);
  742. if($si==false){
  743. Db::rollback();
  744. return error_show(1003,"更新失败");
  745. }
  746. $str = Db::name('good_stock')->where(['wsm_code' => $var['wsm_code'],'good_type_code'=>$der['good_code']])->find();
  747. if ($str == false) {
  748. Db::rollback();
  749. return error_show(1002, "商品数据未找到");
  750. }
  751. if ($var['num'] > $str['wait_out_stock']) {
  752. Db::rollback();
  753. return error_show(1002, "超出库存数量");
  754. }
  755. $str['wait_out_stock'] -= $var['num'];
  756. $str['intra_stock'] += $var['num'];
  757. $str['updatetime'] = date("Y-m-d H:i:s");
  758. $stre = Db::name('good_stock')->save($str);
  759. if ($stre == false) {
  760. Db::rollback();
  761. return error_show(1002, "状态更新失败");
  762. }
  763. }
  764. Db::commit();
  765. return error_show(0,"创建成功");
  766. }else{
  767. Db::rollback();
  768. return error_show(1003,"创建失败");
  769. }
  770. }catch (\Exception $e) {
  771. Db::rollback();
  772. return error_show(1005, $e->getMessage());
  773. }
  774. }
  775. public function customer(){
  776. $outCode= isset($this->post['outCode']) && $this->post['outCode'] !=="" ? trim($this->post['outCode']) :"";
  777. if(empty($outCode)){
  778. return error_show(1002,"销售订单编号不能为空");
  779. }
  780. $codeinfo = Db::name('order_out')->where(['outCode'=>$outCode])->find();
  781. if($codeinfo==""){
  782. return error_show(1003,"未找到订单数据");
  783. }
  784. // $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !=="" ? trim($this->post['orderCode']) :"";
  785. // if($orderCode==""){
  786. // return error_show(1002,"参数orderCoder不能为空");
  787. // }
  788. $dr = Db::name('sale')->where(['orderCode'=>$codeinfo['orderCode']])->find();
  789. if($dr==""){
  790. return error_show(1002,"未找到销售订单");
  791. }
  792. $status = isset($this->post['status']) && $this->post['status'] !== "" ? $this->post['status'] :"";
  793. if($status==""){
  794. return error_show(10002,"状态不能为空");
  795. }
  796. Db::startTrans();
  797. try {
  798. $codeinfo['status']=$status;
  799. $codeinfo['updatetime']=date("Y-m-d H:i:s");
  800. $cust = Db::name('order_out')->save($codeinfo);
  801. if($cust){
  802. if($status==2){
  803. $ct =Db::name('sale_info')->where(['orderCode' => $dr['orderCode'],'wsm_code'=>$codeinfo['wsm_code']])->find();
  804. if($ct==false){
  805. return error_show(1002,"未找到数据");
  806. }
  807. $var = Db::name('good_stock')->where(['wsm_code'=>$codeinfo['wsm_code'],'good_type_code'=>$dr['good_code']])->find();
  808. if($var==false){
  809. Db::rollback();
  810. return error_show(1002,"未找到商品数据");
  811. }
  812. if($ct['num']>$var['intra_stock']){
  813. Db::rollback();
  814. return error_show(1003,"超出库存数量");
  815. }
  816. $var['intra_stock']-=$codeinfo['send_num'];
  817. $var['updatetime']=date("Y-m-d H:i:s");
  818. $stre = Db::name('good_stock')->save($var);
  819. if ($stre == false) {
  820. Db::rollback();
  821. return error_show(1002, "状态更新失败");
  822. }
  823. }
  824. Db::commit();
  825. return error_show(0,"出库订单更新成功");
  826. }else{
  827. Db::rollback();
  828. return error_show(1003,"出库订单更新失败");
  829. }
  830. }catch (\Exception $e) {
  831. Db::rollback();
  832. return error_show(1005, $e->getMessage());
  833. }
  834. }
  835. public function difflist(){
  836. $page = isset($this->post['page']) && $this->post['page'] !==""? intval($this->post['page']):"1";
  837. $size = isset($this->post['size']) && $this->post['size'] !==""? intval($this->post['size']):"10";
  838. $where = [];
  839. $cgdNo = isset($this->post['orderCode']) && $this->post['orderCode']!="" ? trim($this->post['orderCode']):"";
  840. if($cgdNo!=""){
  841. $where[]=['a.orderCode',"like", "%$cgdNo%"];
  842. }
  843. $diffNo = isset($this->post['diffCode']) && $this->post['diffCode']!="" ? trim($this->post['diffCode']):"";
  844. if($diffNo!=""){
  845. $where[]=['a.diffCode',"like", "%$diffNo%"];
  846. }
  847. $status = isset($this->post['status']) && $this->post['status'] !==""? intval($this->post['status']):"";
  848. if($status!==""){
  849. $where[]=['a.status',"=",$status];
  850. }
  851. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  852. if ($start !="") {
  853. $where[]= ["a.addtime",'>=',$start];
  854. }
  855. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  856. if($end !=""){
  857. $where[]= ["a.addtime",'<=',$end];
  858. }
  859. // $apply_name = isset($this->post['apply_name']) && $this->post['apply_name'] !==""? intval($this->post['apply_name']):"";
  860. // if($apply_name!==""){
  861. // $where[]=['a.apply_name',"like","%$apply_name%"];
  862. // }
  863. $supplierNo =isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']):"";
  864. if($supplierNo!=""){
  865. $supplier = Db::name("supplier")->where([['code',"like","%$supplierNo%"]])->column('code');
  866. // if(empty($supplier)){
  867. // return error_show(1004,"未找到供应商信息");
  868. // }
  869. $wsmcode = Db::name("sale")->where([
  870. "is_del"=>0,"supplierNo"=>$supplier])->column("orderCode");
  871. $where[]=['orderCode',"in",$wsmcode];
  872. }
  873. $count = Db::name('sale_diff')->alias('a')->join("good b","b.good_code=a.good_code","left")
  874. ->where($where)->count();
  875. $total = ceil($count/$size);
  876. $page = $page >= $total ? $total : $page;
  877. $list = Db::name('sale_diff')->alias('a')->join("good b","b.good_code=a.good_kode","left")
  878. ->where($where)->page($page,$size)->field("a.*,b.cat_id")->order("a.addtime desc")->select();
  879. $data=[];
  880. foreach ($list as $value){
  881. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  882. $wsm = Db::name("sale")->alias("a")->Join("supplier b","a.supplierNo=b.code","left")->where
  883. (['a.orderCode'=>$value['orderCode'],"a.is_del"=>0])->field("b.code,b.name")->find();
  884. $value['code']=isset($wsm['code'])? $wsm['code']:"";
  885. $value['name']=isset($wsm['name']) ? $wsm['name']:"";
  886. $data[]=$value;
  887. }
  888. return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
  889. }
  890. /**
  891. * @return \think\response\Json|void
  892. * @throws \think\db\exception\DataNotFoundException
  893. * @throws \think\db\exception\DbException
  894. * @throws \think\db\exception\ModelNotFoundException
  895. */
  896. public function diffcheck(){
  897. $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']):"";
  898. if($id===""){
  899. return error_show(1004,"参数id不能为空");
  900. }
  901. $info = Db::name("sale_diff")->where(["id"=>$id])->find();
  902. if(empty($info)){
  903. return error_show(1004,"订单数据未找到");
  904. }
  905. $is_act = isset($this->post['is_act']) && $this->post['is_act'] !==""? intval($this->post['is_act']):"";
  906. if($is_act===''){
  907. return error_show(1004,"参数is_act不能为空");
  908. }
  909. $customer_remark = isset($this->post['customer_remark']) && $this->post['customer_remark'] !==""? trim($this->post['customer_remark']):"";
  910. if($customer_remark===''){
  911. return error_show(1004,"参数customer_remark不能为空");
  912. }
  913. $status = isset($this->post['status']) && $this->post['status'] !==""? intval($this->post['status']):"2";
  914. $remark = isset($this->post['remark']) && $this->post['remark'] !==""? trim($this->post['remark']):"";
  915. $info['is_act'] =$is_act;
  916. $info['customer_remark'] =$customer_remark;
  917. $info['status'] =$status;
  918. $info['remark'] =$remark;
  919. $info['updatetime'] =date("Y-m-d H:i:s");
  920. $up = Db::name("sale_diff")->save($info);
  921. if($up){
  922. return app_show(0,"更新成功");
  923. }else{
  924. return error_show(1003,"更新失败");
  925. }
  926. }
  927. /**
  928. * @return \think\response\Json|void
  929. * @throws \think\db\exception\DataNotFoundException
  930. * @throws \think\db\exception\DbException
  931. * @throws \think\db\exception\ModelNotFoundException
  932. */
  933. public function diffstatus(){
  934. $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']):"";
  935. if($id===""){
  936. return error_show(1004,"参数id不能为空");
  937. }
  938. $info = Db::name("sale_diff")->where(["id"=>$id])->find();
  939. if(empty($info)){
  940. return error_show(1004,"订单数据未找到");
  941. }
  942. $status = isset($this->post['status']) && $this->post['status'] !==""? intval($this->post['status']):"3";
  943. $remark = isset($this->post['remark']) && $this->post['remark'] !==""? trim($this->post['remark']):"";
  944. $info['status'] =$status;
  945. $info['remark'] =$remark;
  946. $info['updatetime'] =date("Y-m-d H:i:s");
  947. $up = Db::name("sale_diff")->save($info);
  948. if($up){
  949. return app_show(0,"更新成功");
  950. }else{
  951. return error_show(1003,"更新失败");
  952. }
  953. }
  954. /**
  955. * @return \think\response\Json|void
  956. * @throws \think\db\exception\DataNotFoundException
  957. * @throws \think\db\exception\DbException
  958. * @throws \think\db\exception\ModelNotFoundException
  959. */
  960. public function diffinfo(){
  961. $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']):"";
  962. if($id===""){
  963. return error_show(1004,"参数id不能为空");
  964. }
  965. $info = Db::name('sale_diff')->alias('a')->join("good b","b.good_code=a.good_kode","left")->where
  966. (["a.id"=>$id])->field("a.*,b.cat_id")->find();
  967. if(empty($info)){
  968. return error_show(1004,"订单数据未找到");
  969. }
  970. $info['can']= isset($info['cat_id']) && $info['cat_id'] !==0 ? made($info['cat_id']):[];
  971. return app_show(0,"获取成功",$info);
  972. }
  973. public function saleout(){
  974. $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']):"1";
  975. $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']) :"10";
  976. $where= [];
  977. $orderCode=isset($this->post['orderCode']) && $this->post['orderCode'] !=="" ? trim($this->post['orderCode'])
  978. :"";
  979. if($orderCode !==""){
  980. $where[]=['orderCode',"like","%$orderCode%"];
  981. }
  982. $apply_name=isset($this->post['apply_name']) && $this->post['apply_name'] !=="" ? trim($this->post['apply_name'])
  983. :"";
  984. if($apply_name !==""){
  985. $where[]=['apply_name',"like","%$apply_name%"];
  986. }
  987. $status=isset($this->post['status']) && $this->post['status'] !=="" ? trim($this->post['status']):"";
  988. if($status !==""){
  989. $where[]=['status',"=",$status];
  990. }
  991. $start = isset($this->post['start']) && $this->post['start'] !=="" ? $this->post['start'] :"";
  992. if($start !=""){
  993. $where[]= ["addtime",'>=',$start];
  994. }
  995. $end = isset($this->post['end']) && $this->post['end'] !=="" ? $this->post['end'] :"";
  996. if($end !=""){
  997. $where[]= ["addtime",'<=',$end];
  998. }
  999. $count = Db::name('order_out')->where($where)->count();
  1000. $total = ceil($count/$size);
  1001. $page = $page >= $total ? $total : $page;
  1002. $list= Db::name('order_out')->where($where)->order("addtime desc")->page($page,$size)->select();
  1003. foreach ($list as $value){
  1004. $wsmcode = Db::name("warehouse_info")->alias("k")->leftJoin("supplier c","k.supplierNo=c.code")
  1005. ->where(["k.wsm_code"=>$value['wsm_code']])->field("k.name as wsm_name,c.name,c.code")->find();
  1006. $addr = Db::name("order_addr")->where(["id"=>$value['addrid']])->find();
  1007. $value['wsm_name'] =isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
  1008. $value['wsm_supplier'] =isset($wsmcode['name']) ? $wsmcode['name']:"";
  1009. $value['wsm_supplierNo'] = isset($wsmcode['code']) ? $wsmcode['code']:"";
  1010. $value['addr']=isset($addr['addr']) ? $addr['addr']:"";
  1011. $value['contactor']=isset($addr['contactor']) ? $addr['contactor']:"";
  1012. $value['mobile']=isset($addr['mobile']) ? $addr['mobile']:"";
  1013. $data[]=$value;
  1014. }
  1015. return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
  1016. }
  1017. }