Purch.php 33 KB

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