Purch.php 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  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. return app_show(0,"更新成功");
  363. }else{
  364. return error_show(1004,'更新失败');
  365. }
  366. }
  367. public function status(){
  368. $cgdNo = isset($this->post['cgdNo']) && $this->post['cgdNo']!="" ?trim($this->post['cgdNo']):"";
  369. if($cgdNo==""){
  370. return error_show(1004,"参数cgdNo 不能为空");
  371. }
  372. $data = Db::name("purchease_order")->where(["cgdNo"=>$cgdNo,"is_del"=>0])->find();
  373. if(empty($data)){
  374. return error_show(1004,"未找到数据");
  375. }
  376. $remark= isset($this->post['remark']) && $this->post['remark']!="" ?trim($this->post['remark']):"";
  377. $status = isset($this->post['status'])&&$this->post['status']!==""? intval($this->post['status']):"";
  378. if($status===""){
  379. return error_show(1004,"参数status 不能为空");
  380. }
  381. if($data['send_status']>1 && $status==0){
  382. return error_show(1004,"采购单发货中无法取消");
  383. }
  384. $order = ["order_code"=>$cgdNo,"status"=> $data['status'] ,"action_remark"=>$remark,"action_type"=>"status"];
  385. $data['status'] = $status;
  386. $data['remark'] = $remark;
  387. $data['updatetime'] =date("Y-m-d H:i:s");
  388. $upd=Db::name("purchease_order")->save($data);
  389. if($upd){
  390. $process=["order_code"=>$cgdNo,"order_id"=>$data['id'],"order_status"=>$status,"order_type"=>'CGD'];
  391. ProcessOrder::AddProcess($this->post['token'],$process);
  392. ActionLog::logAdd($this->post['token'],$order,'cgd',$status,$this->post);
  393. return app_show(0,"更新成功");
  394. }else{
  395. return error_show(1004,'更新失败');
  396. }
  397. }
  398. public function diffcreat(){
  399. $token = isset($this->post['token']) && $this->post['token'] !=="" ?trim($this->post['token']):"";
  400. //$cgdNo=makeNo("CG");
  401. $cgdNo = $this->post['cgdNo'] && $this->post['cgdNo'] !=="" ? trim($this->post['cgdNo']) :"";
  402. if($cgdNo==""){
  403. return error_show(1002,"参数good_code不能为空");
  404. }
  405. $cg = Db::name('purchease_order')->where(['cgdNo'=>$cgdNo,'is_del'=>0])->find();
  406. if($cg==""){
  407. return error_show(1002,"未找到采购单数据");
  408. }
  409. $gd= Db::name('good')->where(['spuCode'=>$cg['spuCode']])->find();
  410. if($gd==""){
  411. return error_show(1002,"未找到商品数据");
  412. }
  413. $diff_weight = isset($this->post['diff_weight']) && $this->post['diff_weight'] !=="" ? floatval($this->post['diff_weight']) :"";
  414. if($diff_weight===""){
  415. return error_show(1002,"参数diff_weight不能为空");
  416. }
  417. $apply_id =GetUserInfo($token);
  418. if(empty($apply_id)||$apply_id['code']!=0){
  419. return error_show(1002,"申请人数据不存在");
  420. }
  421. $rid= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  422. $rname= isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  423. $diff_price = $diff_weight*$cg['gold_price'];
  424. $data=[
  425. "cgdNo"=>$cgdNo,
  426. "good_code"=>$cg['spuCode'],
  427. "good_name"=>$cg['good_name'],
  428. "sale_price"=>$cg['good_price'],
  429. "good_weight"=>$cg['weight'],
  430. "good_num"=>$cg['good_num'],
  431. "apply_id"=>$rid,
  432. "apply_name"=>$rname,
  433. "diff_weight"=>$diff_weight,
  434. "diff_price"=>$diff_price,
  435. "gold_price"=>$cg['good_price'],
  436. "status"=>1,
  437. "is_del"=>0,
  438. "addtime"=>date("Y-m-d H:i:s"),
  439. "updatetime"=>date("Y-m-d H:i:s")
  440. ];
  441. Db::startTrans();
  442. try{
  443. $item = Db::name("purchease_diff")->insert($data,true);
  444. if($item>0){
  445. // $stm = ["order_code"=>$cgdNo,"status"=>1,"action_remark"=>'',"action_type"=>"create"];
  446. // ActionLog::logAdd($this->post['token'],$stm,"CGGCD",1,$stm);
  447. // $process=["order_code"=>$cgdNo,"order_id"=>$item,"order_status"=>1,"order_type"=>'CGGCD'];
  448. // ProcessOrder::AddProcess($this->post['token'],$process);
  449. $orderCode = Db::name("order_num")->where([["cgdNo","=",$cg['cgdNo']],["status","=",1]])->column("orderCode");
  450. if(!empty($orderCode)){
  451. $order = Db::name("sale")->where("orderCode", 'in', $orderCode)->select()->toArray();
  452. if(empty($order)){
  453. Db::rollback();
  454. return error_show(1002,"未找到确认单信息");
  455. }
  456. foreach ($orderCode as $value){
  457. $data=[
  458. "cgd_diffid"=>$item,
  459. "orderCode"=>$value,
  460. "good_code"=>$cg['spuCode'],
  461. "good_name"=>$cg['good_name'],
  462. "diff_weight"=>$diff_weight,
  463. "diff_price"=>$diff_weight*$cg['good_price'],
  464. "gold_price"=>$cg['good_price'],
  465. "status"=>1,
  466. "addtime"=>date("Y-m-d H:i:s"),
  467. "updatetime"=>date("Y-m-d H:i:s")
  468. ];
  469. $cgd = Db::name('sale_diff')->insert($data,true);
  470. if($cgd==0){
  471. // $sto = ["order_code"=>$cg['bkcode'],"status"=>1,"action_remark"=>'',"action_type"=>"create"];
  472. // ActionLog::logAdd($this->post['token'],$sto,"ZXGCD",1,$sto);
  473. // $process=["order_code"=>$cg['bkcode'],"order_id"=>$cgd,"order_status"=>1,"order_type"=>'ZXGCD'];
  474. // ProcessOrder::AddProcess($this->post['token'],$process);
  475. // Db::commit();
  476. // return error_show(0,"新建成功");
  477. // }else{
  478. Db::rollback();
  479. return error_show(1002,"新建失败");
  480. }
  481. }
  482. }
  483. Db::commit();
  484. return error_show(0,"新建成功");
  485. }else{
  486. Db::rollback();
  487. return error_show(1002,"新建失败");
  488. }
  489. }catch (\Exception $e){
  490. Db::rollback();
  491. return error_show(1002,$e->getMessage());
  492. }
  493. }
  494. public function difflist(){
  495. $page = isset($this->post['page']) && $this->post['page'] !==""? intval($this->post['page']):"1";
  496. $size = isset($this->post['size']) && $this->post['size'] !==""? intval($this->post['size']):"10";
  497. $where = [['a.is_del',"=",0]];
  498. $cgdNo = isset($this->post['cgdNo']) && $this->post['cgdNo']!="" ? trim($this->post['cgdNo']):"";
  499. if($cgdNo!=""){
  500. $where[]=['a.cgdNo',"like", "%$cgdNo%"];
  501. }
  502. $status = isset($this->post['status']) && $this->post['status'] !==""? intval($this->post['status']):"";
  503. if($status!==""){
  504. $where[]=['a.status',"=",$status];
  505. }
  506. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  507. if ($start !="") {
  508. $where[]= ["a.addtime",'>=',$start];
  509. }
  510. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  511. if($end !=""){
  512. $where[]= ["a.addtime",'<=',$end];
  513. }
  514. $apply_name = isset($this->post['apply_name']) && $this->post['apply_name'] !==""? intval($this->post['apply_name']):"";
  515. if($apply_name!==""){
  516. $where[]=['a.apply_name',"like","%$apply_name%"];
  517. }
  518. $count = Db::name('purchease_diff')->alias('a')->join("good b","b.spuCode=a.good_code","left")
  519. ->where($where)->count();
  520. $total = ceil($count/$size);
  521. $page = $page >= $total ? $total : $page;
  522. $list = Db::name('purchease_diff')->alias('a')->join("good b","b.spuCode=a.good_code","left")
  523. ->where($where)->page($page,$size)->order("a.addtime desc")->field("a.*,b.cat_id")->select();
  524. $data=[];
  525. foreach ($list as $value){
  526. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  527. $data[]=$value;
  528. }
  529. return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
  530. }
  531. public function diffinfo(){
  532. $id = isset($this->post['id']) && $this->post['id'] !=="" ? trim($this->post['id']) :"";
  533. if($id==""){
  534. return error_show(1002,"参数id 不能为空");
  535. }
  536. $idinf = Db::name('purchease_diff')->where(['id'=>$id,'is_del'=>0])->find();
  537. if($idinf==false){
  538. return error_show(1002,"未找到采购工差单数据");
  539. }
  540. $dn = Db::name('purchease_order')->where(['cgdNo'=>$idinf['cgdNo'],'is_del'=>0])->find();
  541. if($dn['order_type']==3|| $dn['order_type']==4){
  542. $goon = Db::name("good_zixun")->where(["spuCode"=>$dn['spuCode'],"is_del"=>0])->find();
  543. }else {
  544. $goon =Db::name('good_basic')->where(['spuCode'=>$dn['spuCode']])->find();
  545. }
  546. // $goon = Db::name('good')->where(['spuCode'=>$idinf['good_code']])->find();
  547. if(empty($goon)){
  548. return error_show(1002,"未找到商品数据");
  549. }
  550. $idinf['wsm_name'] ="";
  551. $idinf['wsm_supplier'] ="";
  552. $idinf['wsm_supplierNo'] ="";
  553. $idinf['wsm_contactor'] ="";
  554. $idinf['wsm_mobile'] ="";
  555. $idinf['addr_code'] ="";
  556. $idinf['wsm_addr'] ="";
  557. if($dn['wsm_code']!=""){
  558. $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code")
  559. ->leftJoin("warehouse_addr c","a.wsm_code=c.wsm_code and c.is_del=0")
  560. ->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();
  561. $idinf['wsm_name'] =isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
  562. $idinf['wsm_supplier'] =isset($wsmcode['name']) ? $wsmcode['name']:"";
  563. $idinf['wsm_supplierNo'] =isset($wsmcode['code']) ? $wsmcode['code']:"";
  564. $idinf['wsm_contactor'] =isset($wsmcode['wsm_contactor']) ? $wsmcode['wsm_contactor']:"";
  565. $idinf['wsm_mobile'] =isset($wsmcode['wsm_mobile']) ? $wsmcode['wsm_mobile']:"";
  566. $idinf['addr_code'] =isset($wsmcode['addr_code']) ? $wsmcode['addr_code']:"";
  567. $idinf['addr_cn'] =isset($wsmcode['addr_code']) ? GetAddr($wsmcode['addr_code']):"";
  568. $idinf['wsm_addr']=isset($wsmcode['wsm_addr']) ? $wsmcode['wsm_addr']:"";
  569. }
  570. $idinf['info'] =$dn;
  571. $int= isset($goon['cat_id']) && $goon['cat_id'] !=0 ? made($goon['cat_id']):[];
  572. $idinf['can']=$int;
  573. $idinf['order_type']=$dn['order_type'];
  574. //取出销售的工差单信息
  575. $diff = Db::name('sale_diff')->field('id,customer_remark,is_act,remark')->where('cgd_diffid',$id)->find();
  576. $idinf['diff_customer_remark']=$diff['customer_remark'];
  577. $idinf['diff_is_act']=$diff['is_act'];
  578. $idinf['diff_remark']=$diff['remark'];
  579. return app_show(0,"获取成功",$idinf);
  580. }
  581. public function diffstatu(){
  582. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
  583. if($id==""){
  584. return error_show(1002,"参数id不能为空");
  585. }
  586. $dio = Db::name('purchease_diff')->where(['id'=>$id,'is_del'=>0])->find();
  587. if(empty($dio)){
  588. return error_show(1002,"退货订单未找到");
  589. }
  590. $cgd = Db::name("purchease_order")->where(['cgdNo'=>$dio['cgdNo']])->find();
  591. if(empty($cgd)){
  592. return error_show(1002,"采购单未找到");
  593. }
  594. $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']) :"";
  595. if($status===""){
  596. return error_show(1002,"参数status不能为空");
  597. }
  598. $temp = $dio['status'];
  599. $dio['status']=$status;
  600. $dio['updatetime']=date("Y-m-d H:i:s");
  601. $item = Db::name("purchease_diff")->save($dio);
  602. if ($item){
  603. // $sto = ["order_code"=>$dio['cgdNo'],"status"=>$temp,"action_remark"=>'',"action_type"=>"status"];
  604. // ActionLog::logAdd($this->post['token'],$sto,"CGGCD",$dio['status'],$sto);
  605. // $process=["order_code"=>$dio['cgdNo'],"order_id"=>$dio['id'],"order_status"=>$status,"order_type"=>'CGGCD'];
  606. // ProcessOrder::AddProcess($this->post['token'],$process);
  607. return error_show(0,"更新成功");
  608. }else{
  609. return error_show(1002,"更新失败");
  610. }
  611. }
  612. // public function create(){
  613. // $customer = isset($this->post['customer_code'])&&$this->post['customer_code']!="" ?trim($this->post['customer_code']):"";
  614. // if($customer==""){
  615. // return error_show(1004,"参数customer_code不能为空");
  616. // }
  617. // $supplier = isset($this->post['supplier_code'])&&$this->post['supplier_code']!="" ?trim($this->post['supplier_code']):"";
  618. // if($supplier==""){
  619. // return error_show(1004,"参数supplier_code不能为空");
  620. // }
  621. // $good_code = isset($this->post['good_code']) && $this->post['good_code']!=""?trim($this->post['good_code']):"";
  622. // if($good_code==""){
  623. // return error_show(1004,"参数good_code不能为空");
  624. // }
  625. // $good_num = isset($this->post['good_num'])&& $this->post['good_num']!==""? intval($this->post['good_num']):"";
  626. // if($good_num===""){
  627. // return error_show(1004,"参数good_code不能为空");
  628. // }
  629. // $file_url = isset($this->post['file_url'])&& $this->post['file_url']!==""? trim($this->post['file_url']):"";
  630. // if($file_url===""){
  631. // return error_show(1004,"参数file_url不能为空");
  632. // }
  633. // $mark =isset($this->post['remark'])&&$this->post['remark']!=""?trim($this->post['remark']):"";
  634. // if($mark==""){
  635. // return error_show(1004,"参数remark不能为空");
  636. // }
  637. //
  638. // $data=[
  639. // ""
  640. // ];
  641. // }
  642. }