Purch.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\ActionLog;
  4. use app\admin\model\ProcessOrder;
  5. use think\App;
  6. use think\facade\Db;
  7. use think\facade\Validate;
  8. //采购单相关功能
  9. class Purch extends Base
  10. {
  11. public $noble=[];
  12. public function __construct(App $app)
  13. {
  14. parent::__construct($app);
  15. $this->noble=\think\facade\Config::get("noble");
  16. }
  17. public function list(){
  18. $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']):"1";
  19. $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']):"10";
  20. $where =[['is_del',"=",0]];
  21. $bkcode = isset($this->post['bk_code']) && $this->post['bk_code']!="" ? trim($this->post['bk_code']):"";
  22. if($bkcode!=""){
  23. $where[]=['bkcode',"like", "%{$bkcode}%"];
  24. }
  25. $status = isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
  26. if($status!==""){
  27. // $where['status'] = $status;
  28. $where[]=['status',"=", $status];
  29. }
  30. $cgdNo = isset($this->post['cgdNo']) && $this->post['cgdNo']!="" ? trim($this->post['cgdNo'])
  31. :"";
  32. if($cgdNo!=""){
  33. //$where['cgdNo'] = Db::Raw("like '%{$cgdNo}%'");
  34. $where[]=['cgdNo',"like", "%{$cgdNo}%"];
  35. }
  36. $apply_name = isset($this->post['apply_name']) && $this->post['apply_name']!="" ? trim($this->post['apply_name']):"";
  37. if($apply_name!=""){
  38. // $where['cgder'] =Db::Raw("like '%{$apply_name}%'");
  39. $where[]=['cgder',"like", "%{$apply_name}%"];
  40. }
  41. $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code']!="" ? trim($this->post['wsm_code']):"";
  42. if($wsm_code!=""){
  43. // $where['wsm_code'] = $wsm_code;
  44. $where[]=['wsm_code',"=", $wsm_code];
  45. }
  46. $wsm_in_code = isset($this->post['wsm_in_code']) && $this->post['wsm_in_code']!="" ? trim($this->post['wsm_in_code']):"";
  47. if($wsm_in_code!=""){
  48. $incode = Db::name("purchease_in")->where(["wsm_in_code"=>Db::raw(" like %{$wsm_in_code}%"),"is_del"=>0])->column("cgdNo");
  49. if(empty($incode)){
  50. return error_show(1004,"未找到有关入库单信息");
  51. }
  52. $where[]=['cgdNo',"in", $incode];
  53. }
  54. $good_name = isset($this->post['good_name']) && $this->post['good_name']!="" ? trim($this->post['good_name']):"";
  55. if($good_name!=""){
  56. //$where['good_name'] = Db::raw(" like %{$good_name}%");
  57. $where[]=['good_name',"like", "%{$good_name}%"];
  58. }
  59. $good_code = isset($this->post['good_code']) && $this->post['good_code']!="" ? trim($this->post['good_code'])
  60. :"";
  61. if($good_code!=""){
  62. // $where['good_code'] = Db::raw(" like %{$good_code}%");
  63. $where[]=['spuCode',"like", "%{$good_code}%"];
  64. }
  65. $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo']!="" ? trim($this->post['supplierNo'])
  66. :"";
  67. if($supplierNo!=""){
  68. // $where['good_code'] = Db::raw(" like %{$good_code}%");
  69. $where[]=['supplierNo',"like", "%{$supplierNo}%"];
  70. }
  71. $wsm_supplierNo = isset($this->post['wsm_supplierNo']) && $this->post['wsm_supplierNo']!="" ? trim($this->post['wsm_supplierNo'])
  72. :"";
  73. if($wsm_supplierNo!=""){
  74. $supplier = Db::name("supplier")->where(["code"=>$wsm_supplierNo])->find();
  75. if(empty($supplier)){
  76. return error_show(1004,"未找到供应商信息");
  77. }
  78. $wsmcode = Db::name("warehouse_info")->where(["is_del"=>0,"supplierNo"=>$wsm_supplierNo])->column("wsm_code");
  79. $where[]=['wsm_code',"in", $wsmcode];
  80. }
  81. $start = isset($this->post['start']) && $this->post['start']!="" ?$this->post['start']:"";
  82. if($start!=""){
  83. // $where['addtime'] = Db::raw(" >= '{$start}'");
  84. $where[]=['addtime',">=", $start];
  85. }
  86. $end = isset($this->post['end']) && $this->post['end']!="" ?$this->post['end']:"";
  87. if($end!=""){
  88. $where[]=['addtime',"<=", $end];
  89. }
  90. $last_start = isset($this->post['last_start']) && $this->post['last_start']!="" ?$this->post['last_start']:"";
  91. if($last_start!=""){
  92. //$where['lasttime'] = Db::raw(" >= '{$last_start}'");
  93. $where[]=['lasttime',">=", $last_start];
  94. }
  95. $last_end = isset($this->post['last_end']) && $this->post['last_end']!="" ?$this->post['last_end']:"";
  96. if($last_end!=""){
  97. //$where['lasttime'] = Db::raw(" <= '{$last_end}'");
  98. $where[]=['lasttime',"<=", $last_end];
  99. }
  100. $count=Db::name("purchease_order")->where($where)->count();
  101. $total = ceil($count/$size);
  102. $page = $page >= $total ? $total : $page;
  103. $list = Db::name("purchease_order")->where($where)->page($page,$size)->order("addtime desc")->select();
  104. $data=[];
  105. foreach ($list as $value){
  106. $value['wsm_name']="";
  107. if($value['wsm_code']!=""){
  108. $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code")
  109. ->where(["a.wsm_code"=>$value['wsm_code']])->field("a.name as wsm_name,b.name,b.code")->find();
  110. $value['wsm_name'] =isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
  111. $value['wsm_supplier'] =isset($wsmcode['name']) ? $wsmcode['name']:"";
  112. $value['wsm_supplierNo'] =isset($wsmcode['code']) ? $wsmcode['code']:"";
  113. }
  114. if($value['order_type']==3|| $value['order_type']==4){
  115. $goon = Db::name("good_zixun")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->find();
  116. $value["speclist"]=isset($goon['specinfo'])&&$goon['specinfo']!=""? json_decode($goon['specinfo'],true):"";
  117. }else {
  118. $goon =Db::name('good_basic')->where(['spuCode'=>$value['spuCode']])->find();
  119. $spec = Db::name("good_spec")->where(["spuCode"=>$goon['spuCode'],"is_del"=>0])->select()->toArray();
  120. $speclist=[];
  121. if(!empty($spec)){
  122. foreach ($spec as $val){
  123. $temp=[];
  124. $temp['id']=$val['id'];
  125. $temp['spuCode']=$val['spuCode'];
  126. $temp['spec_id']=$val['spec_id'];
  127. $temp['spec_value_id']=$val['spec_value_id'];
  128. $sp = Db::name("specs")->where(["id"=>$val['spec_id']])->find();
  129. $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
  130. $spv = Db::name("spec_value")->where(["id"=>$val['spec_value_id']])->find();
  131. $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
  132. $speclist[]=$temp;
  133. }
  134. }
  135. $value["speclist"]=empty($speclist)?[]:$speclist;
  136. }
  137. //采购单详情字段order_type 为1或者2时,取线上商品库 商品创建人 order_type 为3或者4时 取采购反馈的商品库 商品反馈人
  138. // $value['cgder_id'] = $goon['createrid'];
  139. // $value['cgder'] = $goon['creater'];
  140. $inorder= Db::name("purchease_in")->where(['cgdNo'=>$value['cgdNo'],"is_del"=>0])->select();
  141. $value['child']=empty($inorder)? [] : $inorder;
  142. $data[]=$value;
  143. }
  144. return app_show(0,"获取成功",["list"=>$data ,"count"=>$count]);
  145. }
  146. public function info(){
  147. $cgdNo = isset($this->post['cgdNo']) && $this->post['cgdNo']!="" ?trim($this->post['cgdNo']):"";
  148. if($cgdNo==""){
  149. return error_show(1004,"参数cgdNo 不能为空");
  150. }
  151. //采购单
  152. $data = Db::name("purchease_order")->where(["cgdNo"=>$cgdNo,"is_del"=>0])->find();
  153. if(empty($data)){
  154. return error_show(1004,"未找到数据");
  155. }
  156. //采购退货单
  157. $im = Db::name('purchease_back')->where(['cgdNo'=>$data['cgdNo'],'is_del'=>0])->select();
  158. $var=[];
  159. foreach ($im as $value){
  160. if($data['order_type']==3|| $data['order_type']==4){
  161. $goo = Db::name("good_zixun")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->find();
  162. }else {
  163. $goo =Db::name('good_basic')->where(['spuCode'=>$value['spuCode']])->find();
  164. }
  165. if($goo==false) {
  166. return error_show(1002, "未找到商品数据");
  167. }
  168. $cat= isset($goo['cat_id']) && $goo['cat_id'] !=0 ? made($goo['cat_id']):[];
  169. $value['cant']=$cat;
  170. $var[]=$value;
  171. }
  172. //采购工差单
  173. $dom = Db::name("purchease_diff")->where(['cgdNo'=>$data['cgdNo'],'is_del'=>0])->find();
  174. if($data['order_type']==3|| $data['order_type']==4){
  175. $goon = Db::name("good_zixun")->where(["spuCode"=>$data['spuCode'],"is_del"=>0])->find();
  176. }else {
  177. $goon =Db::name('good_basic')->where(['spuCode'=>$data['spuCode']])->find();
  178. }
  179. if(empty($goon)){
  180. return error_show(1002,"未找到商品数据");
  181. }else{
  182. $goon['exclusive']=isset($goon['is_exclusive'])?makeExcluse($goon['is_exclusive']):"";
  183. $unit =Db::name("unit")->where(["id"=>$goon['good_unit']])->find();
  184. $goon['unit'] = isset($unit['unit'])?$unit['unit']:'';
  185. $spec = Db::name("good_spec")->where(["spuCode"=>$goon['spuCode'],"is_del"=>0])->select()->toArray();
  186. $speclist=[];
  187. if(!empty($spec)){
  188. foreach ($spec as $value){
  189. $temp=[];
  190. $temp['id']=$value['id'];
  191. $temp['spuCode']=$value['spuCode'];
  192. $temp['spec_id']=$value['spec_id'];
  193. $temp['spec_value_id']=$value['spec_value_id'];
  194. $temp['is_del']=$value['is_del'];
  195. $sp = Db::name("specs")->where(["id"=>$value['spec_id']])->find();
  196. $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
  197. $spv = Db::name("spec_value")->where(["id"=>$value['spec_value_id']])->find();
  198. $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
  199. $speclist[]=$temp;
  200. }
  201. }
  202. $goon["speclist"]=empty($speclist)?[]:$speclist;
  203. $proof =Db::name("good_proof")->where(["spuCode"=>$goon['spuCode'],"is_del"=>0])->order("updatetime desc")->field("id,proof_type,proof_url")->find();
  204. $goon['proof'] = isset($proof)&&$proof!=false? $proof:[];
  205. $goon['origin_place_cn']="";
  206. $goon['delivery_place_cn']="";
  207. if(isset($goon['delivery_place'])&&$goon['delivery_place']!==""){
  208. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  209. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$goon['delivery_place']);
  210. $goon['delivery_place_cn']=GetAddr(json_encode($place));
  211. }
  212. if(isset($goon['delivery_place'])&&$goon['origin_place']!==""){
  213. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  214. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$goon['origin_place']);
  215. $goon['origin_place_cn']=GetAddr(json_encode($place));
  216. }
  217. if($goon['brand_id']!=0){
  218. $brand=Db::name("brand")->where(["id"=>$goon['brand_id']])->find();
  219. $goon["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  220. }else{
  221. $goon["brand_name"]="";
  222. $goon["brand_id"]="";
  223. }
  224. $supplier = Db::name("supplier")->where(["code"=>$goon['supplierNo']])->find();
  225. $goon['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  226. $goon['noble_name']=isset($goon['noble_metal'])&&$goon['noble_metal']!=0?$this->noble[$goon['noble_metal']] :"";
  227. if(isset($goon['companyNo'])&&$goon['companyNo']!=""){
  228. $company = Db::name("business")->where(["companyNo"=>$goon['companyNo']])->find();
  229. }
  230. $goon['company'] = isset($company['company'])?$company['company']:"";
  231. }
  232. $int= isset($goon['cat_id']) && $goon['cat_id'] !=0 ? made($goon['cat_id']):[];
  233. $data['wsm_name']="";
  234. if($data['wsm_code']!=""){
  235. $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code")
  236. ->leftJoin("warehouse_addr c","a.wsm_code=c.wsm_code and c.is_del=0")
  237. ->where(["a.wsm_code"=>$data['wsm_code']])->field("a.name as wsm_name,b.name,b.code,c.wsm_name as wsm_contactor,c.wsm_mobile,c.wsm_addr,c.addr_code")->find();
  238. $data['wsm_name'] =isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
  239. $data['wsm_supplier'] =isset($wsmcode['name']) ? $wsmcode['name']:"";
  240. $data['wsm_supplierNo'] =isset($wsmcode['code']) ? $wsmcode['code']:"";
  241. $data['wsm_contactor'] =isset($wsmcode['wsm_contactor']) ? $wsmcode['wsm_contactor']:"";
  242. $data['wsm_mobile'] =isset($wsmcode['wsm_mobile']) ? $wsmcode['wsm_mobile']:"";
  243. // $data['wsm_addr'] =isset($wsmcode['wsm_addr']) ? $wsmcode['wsm_addr']:"";
  244. $data['addr_code'] =isset($wsmcode['addr_code']) ? $wsmcode['addr_code']:"";
  245. $data['wsm_addr'] =isset($wsmcode['addr_code']) ? GetAddr($wsmcode['addr_code']):"";
  246. $data['wsm_addr'].=isset($wsmcode['wsm_addr']) ? $wsmcode['wsm_addr']:"";
  247. $inorder= Db::name("purchease_in")->where(['cgdNo'=>$data['cgdNo'],"is_del"=>0])->select();
  248. $data['child']=empty($inorder)? [] : $inorder;
  249. }
  250. $data['can'] = $int;
  251. $data['goodinfo'] = $goon;
  252. $data['purcheasediff'] = $dom;
  253. if(isset($data['companyNo'])&&$data['companyNo']!=""){
  254. $company = Db::name("business")->where(["companyNo"=>$data['companyNo']])->find();
  255. }
  256. $data['company'] = isset($company['company'])?$company['company']:"";
  257. //$data['info'] = $var;
  258. $data['purcheaseback'] = $var;
  259. return app_show(0,"获取成功",$data);
  260. }
  261. public function edit(){
  262. $cgdNo = isset($this->post['cgdNo']) && $this->post['cgdNo']!="" ?trim($this->post['cgdNo']):"";
  263. if($cgdNo==""){
  264. return error_show(1004,"参数cgdNo 不能为空");
  265. }
  266. $data = Db::name("purchease_order")->where(["cgdNo"=>$cgdNo,"is_del"=>0])->find();
  267. if(empty($data)){
  268. return error_show(1004,"未找到数据");
  269. }
  270. $order = ["order_code"=>$cgdNo,"status"=> $data['status'] ,"action_remark"=>$this->post['remark'],"action_type"=>"edit"];
  271. $wsm_code = isset($this->post['wsm_code'])&&$this->post['wsm_code']!=""? trim($this->post['wsm_code']):"";
  272. if($wsm_code!=""){
  273. $ware = Db::name("warehouse_info")->where(["wsm_code"=>$wsm_code,"is_del"=>0])->find();
  274. if(empty($ware)){
  275. return error_show(1004,"未找到仓库信息");
  276. }
  277. // $good = Db::name("good_stock")->where(["wsm_code"=>$wsm_code,"good_type_code"=>$data['good_type_code'],"is_del"=>0])->find();
  278. // if(empty($good)){
  279. // return error_show(1004,"未找到仓库下商品信息");
  280. // }
  281. $data['wsm_code'] = $wsm_code;
  282. }
  283. $cgdid = isset($this->post['cgder_id'])&&$this->post['cgder_id']!=""?intval($this->post['cgder_id']):"";
  284. if($cgdid!=''){
  285. $cgduser = GetInfoById($this->post['token'],["id"=>$cgdid]);
  286. if((!empty($cgduser) && $cgduser['code']!=0) ||empty($cgduser) ){
  287. return error_show($cgduser['code'],$cgduser['message']);
  288. }
  289. $userinfo = $cgduser['data'];
  290. $data['cgder_id'] = $cgdid;
  291. $data['cgder'] = $userinfo['nickname'];
  292. }
  293. $good_num = isset($this->post['good_num'])&&$this->post['good_num']!=""?intval($this->post['good_num']):"";
  294. if($good_num!=""){
  295. $data['good_num'] = $good_num;
  296. }
  297. $good_price = isset($this->post['good_price'])&&$this->post['good_price']!=""?$this->post['good_price']:"";
  298. if($good_price!=""){
  299. $data['good_price'] = $good_price;
  300. }
  301. // $total_fee = isset($this->post['total_fee'])&&$this->post['total_fee']!=""?$this->post['total_fee']:"";
  302. // if($total_fee!=""){
  303. // $data['total_fee'] = $total_fee;
  304. // }
  305. $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!=""?$this->post['pakge_fee']:"";
  306. if($pakge_fee!=""){
  307. $data['pakge_fee'] = $pakge_fee;
  308. }
  309. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!=""?$this->post['cert_fee']:"";
  310. if($cert_fee!=""){
  311. $data['cert_fee'] = $cert_fee;
  312. }
  313. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!=""?$this->post['open_fee']:"";
  314. if($open_fee!=""){
  315. $data['open_fee'] = $open_fee;
  316. }
  317. $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!=""?$this->post['delivery_fee']:"";
  318. if($delivery_fee!=""){
  319. $data['delivery_fee'] = $delivery_fee;
  320. }
  321. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!=""?$this->post['mark_fee']:"";
  322. if($mark_fee!=""){
  323. $data['mark_fee'] = $mark_fee;
  324. }
  325. $teach_fee = isset($this->post['teach_fee'])&&$this->post['teach_fee']!=""?$this->post['teach_fee']:"";
  326. if($teach_fee!=""){
  327. $data['teach_fee'] = $teach_fee;
  328. }
  329. $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!=""?$this->post['nake_fee']:"";
  330. if($nake_fee!=""){
  331. $data['nake_fee'] = $nake_fee;
  332. }
  333. $weight = isset($this->post['weight'])&&$this->post['weight']!=""?$this->post['weight']:"";
  334. if($weight!=""){
  335. $data['weight'] = $weight;
  336. }
  337. $diff_weight = isset($this->post['diff_weight'])&&$this->post['diff_weight']!=""?$this->post['diff_weight']:"";
  338. if($diff_weight!=""){
  339. $data['diff_weight'] = $diff_weight;
  340. }
  341. $diff_fee = isset($this->post['diff_fee'])&&$this->post['diff_fee']!=""?$this->post['diff_fee']:"";
  342. if($diff_fee!=""){
  343. $data['diff_fee'] = $diff_fee;
  344. }
  345. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""?trim($this->post['supplierNo'])
  346. :"";
  347. if($supplierNo!=""){
  348. $supplier =Db::name("supplier")->where(['code'=>$supplierNo])->find();
  349. if(empty($supplier)){
  350. return error_show(1004,"未找到供应商信息");
  351. }
  352. $data['supplierNo'] = $supplierNo;
  353. $data['supplier_name'] = $supplier['name'];
  354. }
  355. $remark = isset($this->post['remark'])&&$this->post['remark']!=""?trim($this->post['remark']):"";
  356. if($remark!=""){
  357. $data['remark'] = $remark;
  358. }
  359. $data['good_price'] = round(($data['pakge_fee']+$data['weight']*$data['gold_price']+$data['nake_fee']+$data['mark_fee']+$data['cert_fee']+$data['open_fee']/$data['good_num']
  360. +$data['teach_fee']*$data['weight']+$data['delivery_fee']),2);
  361. $data['total_fee'] = round($data['good_price']*$data['good_num'],2);
  362. $data['updatetime'] =date("Y-m-d H:i:s");
  363. $upd=Db::name("purchease_order")->save($data);
  364. if($upd){
  365. // ActionLog::logAdd($this->post['token'],$order,'cgd',$data['status'],$this->post);
  366. //修改状态,添加待办
  367. ActionLog::logAdd($this->post['token'], $order, "CGD", $data['status'], $this->post);
  368. ProcessOrder::AddProcess($this->post['token'], [
  369. "order_type" => 'CGD',
  370. "order_code" => $cgdNo,//销售单code
  371. "order_id" => $data['id'],
  372. "order_status" => $data['status']
  373. ]);
  374. return app_show(0,"更新成功");
  375. }else{
  376. return error_show(1004,'更新失败');
  377. }
  378. }
  379. public function status(){
  380. $cgdNo = isset($this->post['cgdNo']) && $this->post['cgdNo']!="" ?trim($this->post['cgdNo']):"";
  381. if($cgdNo==""){
  382. return error_show(1004,"参数cgdNo 不能为空");
  383. }
  384. $data = Db::name("purchease_order")->where(["cgdNo"=>$cgdNo,"is_del"=>0])->find();
  385. if(empty($data)){
  386. return error_show(1004,"未找到数据");
  387. }
  388. $remark= isset($this->post['remark']) && $this->post['remark']!="" ?trim($this->post['remark']):"";
  389. $status = isset($this->post['status'])&&$this->post['status']!==""? intval($this->post['status']):"";
  390. if($status===""){
  391. return error_show(1004,"参数status 不能为空");
  392. }
  393. if($data['send_status']>1 && $status==0){
  394. return error_show(1004,"采购单发货中无法取消");
  395. }
  396. $order = ["order_code"=>$cgdNo,"status"=> $data['status'] ,"action_remark"=>$remark,"action_type"=>"status"];
  397. $data['status'] = $status;
  398. $data['remark'] = $remark;
  399. $data['updatetime'] =date("Y-m-d H:i:s");
  400. $upd=Db::name("purchease_order")->save($data);
  401. if($upd){
  402. $process=["order_code"=>$cgdNo,"order_id"=>$data['id'],"order_status"=>$status,"order_type"=>'CGD'];
  403. ProcessOrder::AddProcess($this->post['token'],$process);
  404. ActionLog::logAdd($this->post['token'],$order,'CGD',$status,$this->post);
  405. return app_show(0,"更新成功");
  406. }else{
  407. return error_show(1004,'更新失败');
  408. }
  409. }
  410. public function diffcreat(){
  411. $token = isset($this->post['token']) && $this->post['token'] !=="" ?trim($this->post['token']):"";
  412. //$cgdNo=makeNo("CG");
  413. $cgdNo = $this->post['cgdNo'] && $this->post['cgdNo'] !=="" ? trim($this->post['cgdNo']) :"";
  414. if($cgdNo==""){
  415. return error_show(1002,"参数good_code不能为空");
  416. }
  417. $cg = Db::name('purchease_order')->where(['cgdNo'=>$cgdNo,'is_del'=>0])->find();
  418. if($cg==""){
  419. return error_show(1002,"未找到采购单数据");
  420. }
  421. $gd= Db::name('good')->where(['spuCode'=>$cg['spuCode']])->find();
  422. if($gd==""){
  423. return error_show(1002,"未找到商品数据");
  424. }
  425. $diff_weight = isset($this->post['diff_weight']) && $this->post['diff_weight'] !=="" ? floatval($this->post['diff_weight']) :"";
  426. if($diff_weight===""){
  427. return error_show(1002,"参数diff_weight不能为空");
  428. }
  429. $apply_id =GetUserInfo($token);
  430. if(empty($apply_id)||$apply_id['code']!=0){
  431. return error_show(1002,"申请人数据不存在");
  432. }
  433. $rid= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  434. $rname= isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  435. $diff_price = $diff_weight*$cg['gold_price'];
  436. $data=[
  437. "cgdNo"=>$cgdNo,
  438. "good_code"=>$cg['spuCode'],
  439. "good_name"=>$cg['good_name'],
  440. "sale_price"=>$cg['good_price'],
  441. "good_weight"=>$cg['weight'],
  442. "good_num"=>$cg['good_num'],
  443. "apply_id"=>$rid,
  444. "apply_name"=>$rname,
  445. "diff_weight"=>$diff_weight,
  446. "diff_price"=>$diff_price,
  447. "gold_price"=>$cg['good_price'],
  448. "status"=>1,
  449. "is_del"=>0,
  450. "addtime"=>date("Y-m-d H:i:s"),
  451. "updatetime"=>date("Y-m-d H:i:s")
  452. ];
  453. Db::startTrans();
  454. try{
  455. $item = Db::name("purchease_diff")->insert($data,true);
  456. if($item>0){
  457. // $stm = ["order_code"=>$cgdNo,"status"=>1,"action_remark"=>'',"action_type"=>"create"];
  458. // ActionLog::logAdd($this->post['token'],$stm,"CGGCD",1,$stm);
  459. // $process=["order_code"=>$cgdNo,"order_id"=>$item,"order_status"=>1,"order_type"=>'CGGCD'];
  460. // ProcessOrder::AddProcess($this->post['token'],$process);
  461. $orderCode = Db::name("order_num")->where([["cgdNo","=",$cg['cgdNo']],["status","=",1]])->column("orderCode");
  462. if(!empty($orderCode)){
  463. $order = Db::name("sale")->where("orderCode", 'in', $orderCode)->select()->toArray();
  464. if(empty($order)){
  465. Db::rollback();
  466. return error_show(1002,"未找到确认单信息");
  467. }
  468. foreach ($orderCode as $value){
  469. $data=[
  470. "cgd_diffid"=>$item,
  471. "orderCode"=>$value,
  472. "good_code"=>$cg['spuCode'],
  473. "good_name"=>$cg['good_name'],
  474. "diff_weight"=>$diff_weight,
  475. "diff_price"=>$diff_weight*$cg['good_price'],
  476. "gold_price"=>$cg['good_price'],
  477. "status"=>1,
  478. "addtime"=>date("Y-m-d H:i:s"),
  479. "updatetime"=>date("Y-m-d H:i:s")
  480. ];
  481. $cgd = Db::name('sale_diff')->insert($data,true);
  482. if($cgd==0){
  483. // $sto = ["order_code"=>$cg['bkcode'],"status"=>1,"action_remark"=>'',"action_type"=>"create"];
  484. // ActionLog::logAdd($this->post['token'],$sto,"ZXGCD",1,$sto);
  485. // $process=["order_code"=>$cg['bkcode'],"order_id"=>$cgd,"order_status"=>1,"order_type"=>'ZXGCD'];
  486. // ProcessOrder::AddProcess($this->post['token'],$process);
  487. // Db::commit();
  488. // return error_show(0,"新建成功");
  489. // }else{
  490. Db::rollback();
  491. return error_show(1002,"新建失败");
  492. }
  493. }
  494. }
  495. Db::commit();
  496. return error_show(0,"新建成功");
  497. }else{
  498. Db::rollback();
  499. return error_show(1002,"新建失败");
  500. }
  501. }catch (\Exception $e){
  502. Db::rollback();
  503. return error_show(1002,$e->getMessage());
  504. }
  505. }
  506. public function difflist(){
  507. $page = isset($this->post['page']) && $this->post['page'] !==""? intval($this->post['page']):"1";
  508. $size = isset($this->post['size']) && $this->post['size'] !==""? intval($this->post['size']):"10";
  509. $where = [['a.is_del',"=",0]];
  510. $cgdNo = isset($this->post['cgdNo']) && $this->post['cgdNo']!="" ? trim($this->post['cgdNo']):"";
  511. if($cgdNo!=""){
  512. $where[]=['a.cgdNo',"like", "%$cgdNo%"];
  513. }
  514. $status = isset($this->post['status']) && $this->post['status'] !==""? intval($this->post['status']):"";
  515. if($status!==""){
  516. $where[]=['a.status',"=",$status];
  517. }
  518. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  519. if ($start !="") {
  520. $where[]= ["a.addtime",'>=',$start];
  521. }
  522. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  523. if($end !=""){
  524. $where[]= ["a.addtime",'<=',$end];
  525. }
  526. $apply_name = isset($this->post['apply_name']) && $this->post['apply_name'] !==""? intval($this->post['apply_name']):"";
  527. if($apply_name!==""){
  528. $where[]=['a.apply_name',"like","%$apply_name%"];
  529. }
  530. $count = Db::name('purchease_diff')->alias('a')->join("good b","b.spuCode=a.good_code","left")
  531. ->where($where)->count();
  532. $total = ceil($count/$size);
  533. $page = $page >= $total ? $total : $page;
  534. $list = Db::name('purchease_diff')->alias('a')->join("good b","b.spuCode=a.good_code","left")
  535. ->where($where)->page($page,$size)->order("a.addtime desc")->field("a.*,b.cat_id")->select();
  536. $data=[];
  537. foreach ($list as $value){
  538. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  539. $data[]=$value;
  540. }
  541. return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
  542. }
  543. public function diffinfo(){
  544. $id = isset($this->post['id']) && $this->post['id'] !=="" ? trim($this->post['id']) :"";
  545. if($id==""){
  546. return error_show(1002,"参数id 不能为空");
  547. }
  548. $idinf = Db::name('purchease_diff')->where(['id'=>$id,'is_del'=>0])->find();
  549. if($idinf==false){
  550. return error_show(1002,"未找到采购工差单数据");
  551. }
  552. $dn = Db::name('purchease_order')->where(['cgdNo'=>$idinf['cgdNo'],'is_del'=>0])->find();
  553. if($dn['order_type']==3|| $dn['order_type']==4){
  554. $goon = Db::name("good_zixun")->where(["spuCode"=>$dn['spuCode'],"is_del"=>0])->find();
  555. }else {
  556. $goon =Db::name('good_basic')->where(['spuCode'=>$dn['spuCode']])->find();
  557. }
  558. // $goon = Db::name('good')->where(['spuCode'=>$idinf['good_code']])->find();
  559. if(empty($goon)){
  560. return error_show(1002,"未找到商品数据");
  561. }
  562. $idinf['wsm_name'] ="";
  563. $idinf['wsm_supplier'] ="";
  564. $idinf['wsm_supplierNo'] ="";
  565. $idinf['wsm_contactor'] ="";
  566. $idinf['wsm_mobile'] ="";
  567. $idinf['addr_code'] ="";
  568. $idinf['wsm_addr'] ="";
  569. if($dn['wsm_code']!=""){
  570. $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code")
  571. ->leftJoin("warehouse_addr c","a.wsm_code=c.wsm_code and c.is_del=0")
  572. ->where(["a.wsm_code"=>$dn['wsm_code']])->field("a.name as wsm_name,b.name,b.code,c.wsm_name as wsm_contactor,c.wsm_mobile,c.wsm_addr,c.addr_code")->find();
  573. $idinf['wsm_name'] =isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
  574. $idinf['wsm_supplier'] =isset($wsmcode['name']) ? $wsmcode['name']:"";
  575. $idinf['wsm_supplierNo'] =isset($wsmcode['code']) ? $wsmcode['code']:"";
  576. $idinf['wsm_contactor'] =isset($wsmcode['wsm_contactor']) ? $wsmcode['wsm_contactor']:"";
  577. $idinf['wsm_mobile'] =isset($wsmcode['wsm_mobile']) ? $wsmcode['wsm_mobile']:"";
  578. $idinf['addr_code'] =isset($wsmcode['addr_code']) ? $wsmcode['addr_code']:"";
  579. $idinf['addr_cn'] =isset($wsmcode['addr_code']) ? GetAddr($wsmcode['addr_code']):"";
  580. $idinf['wsm_addr']=isset($wsmcode['wsm_addr']) ? $wsmcode['wsm_addr']:"";
  581. }
  582. $idinf['info'] =$dn;
  583. $int= isset($goon['cat_id']) && $goon['cat_id'] !=0 ? made($goon['cat_id']):[];
  584. $idinf['can']=$int;
  585. $idinf['order_type']=$dn['order_type'];
  586. //取出销售的工差单信息
  587. $diff = Db::name('sale_diff')->field('id,customer_remark,is_act,remark')->where('cgd_diffid',$id)->find();
  588. $idinf['diff_customer_remark']=$diff['customer_remark'];
  589. $idinf['diff_is_act']=$diff['is_act'];
  590. $idinf['diff_remark']=$diff['remark'];
  591. return app_show(0,"获取成功",$idinf);
  592. }
  593. public function diffstatu(){
  594. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
  595. if($id==""){
  596. return error_show(1002,"参数id不能为空");
  597. }
  598. $dio = Db::name('purchease_diff')->where(['id'=>$id,'is_del'=>0])->find();
  599. if(empty($dio)){
  600. return error_show(1002,"退货订单未找到");
  601. }
  602. $cgd = Db::name("purchease_order")->where(['cgdNo'=>$dio['cgdNo']])->find();
  603. if(empty($cgd)){
  604. return error_show(1002,"采购单未找到");
  605. }
  606. $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']) :"";
  607. if($status===""){
  608. return error_show(1002,"参数status不能为空");
  609. }
  610. $temp = $dio['status'];
  611. $dio['status']=$status;
  612. $dio['updatetime']=date("Y-m-d H:i:s");
  613. $item = Db::name("purchease_diff")->save($dio);
  614. if ($item){
  615. // $sto = ["order_code"=>$dio['cgdNo'],"status"=>$temp,"action_remark"=>'',"action_type"=>"status"];
  616. // ActionLog::logAdd($this->post['token'],$sto,"CGGCD",$dio['status'],$sto);
  617. // $process=["order_code"=>$dio['cgdNo'],"order_id"=>$dio['id'],"order_status"=>$status,"order_type"=>'CGGCD'];
  618. // ProcessOrder::AddProcess($this->post['token'],$process);
  619. return error_show(0,"更新成功");
  620. }else{
  621. return error_show(1002,"更新失败");
  622. }
  623. }
  624. //修改采购单的实时金价
  625. public function editGoldPrice()
  626. {
  627. $param = $this->request->only(['cgdNo', 'gold_price'], 'post', 'trim');
  628. $val = Validate::rule(['cgdNo|采购单号' => 'require', 'gold_price|实时金价' => 'require|float']);
  629. if (!$val->check($param)) return error_show(1004, $val->getError());
  630. //采购单
  631. $data = Db::name("purchease_order")
  632. ->field('id,status')
  633. ->where(["cgdNo" => $param['cgdNo'], "is_del" => 0])
  634. ->find();
  635. if (empty($data)) return error_show(1004, "未找到该采购单数据");
  636. if ($data['status'] != 0) return error_show(1005, '该状态下不允许修改实时金价');
  637. $rs = Db::name("purchease_order")
  638. ->where('id', $data['id'])
  639. ->update(['updatetime' => date('Y-m-d H:i:s'), 'gold_price' => $param['gold_price']]);
  640. return $rs ? app_show(0, '修改采购单实时金价成功') : error_show(1005, '修改采购单实时金价失败');
  641. }
  642. // public function create(){
  643. // $customer = isset($this->post['customer_code'])&&$this->post['customer_code']!="" ?trim($this->post['customer_code']):"";
  644. // if($customer==""){
  645. // return error_show(1004,"参数customer_code不能为空");
  646. // }
  647. // $supplier = isset($this->post['supplier_code'])&&$this->post['supplier_code']!="" ?trim($this->post['supplier_code']):"";
  648. // if($supplier==""){
  649. // return error_show(1004,"参数supplier_code不能为空");
  650. // }
  651. // $good_code = isset($this->post['good_code']) && $this->post['good_code']!=""?trim($this->post['good_code']):"";
  652. // if($good_code==""){
  653. // return error_show(1004,"参数good_code不能为空");
  654. // }
  655. // $good_num = isset($this->post['good_num'])&& $this->post['good_num']!==""? intval($this->post['good_num']):"";
  656. // if($good_num===""){
  657. // return error_show(1004,"参数good_code不能为空");
  658. // }
  659. // $file_url = isset($this->post['file_url'])&& $this->post['file_url']!==""? trim($this->post['file_url']):"";
  660. // if($file_url===""){
  661. // return error_show(1004,"参数file_url不能为空");
  662. // }
  663. // $mark =isset($this->post['remark'])&&$this->post['remark']!=""?trim($this->post['remark']):"";
  664. // if($mark==""){
  665. // return error_show(1004,"参数remark不能为空");
  666. // }
  667. //
  668. // $data=[
  669. // ""
  670. // ];
  671. // }
  672. }