Purch.php 34 KB

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