Purch.php 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005
  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\Exception;
  7. use think\facade\Db;
  8. use think\facade\Validate;
  9. //采购单相关功能
  10. class Purch extends Base
  11. {
  12. public $noble=[];
  13. public function __construct(App $app)
  14. {
  15. parent::__construct($app);
  16. $this->noble=\think\facade\Config::get("noble");
  17. }
  18. public function list(){
  19. $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']):"1";
  20. $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']):"10";
  21. $where = [['is_del', "=", 0], ['order_type', '<>', 5]];//不显示类型为5即订单导入生成的采购单
  22. $bkcode = isset($this->post['bk_code']) && $this->post['bk_code']!="" ? trim($this->post['bk_code']):"";
  23. if($bkcode!=""){
  24. $where[]=['bkcode',"like", "%{$bkcode}%"];
  25. }
  26. $status = isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
  27. if($status!==""){
  28. // $where['status'] = $status;
  29. $where[]=['status',"=", $status];
  30. }
  31. $cgdNo = isset($this->post['cgdNo']) && $this->post['cgdNo']!="" ? trim($this->post['cgdNo'])
  32. :"";
  33. if($cgdNo!=""){
  34. //$where['cgdNo'] = Db::Raw("like '%{$cgdNo}%'");
  35. $where[]=['cgdNo',"like", "%{$cgdNo}%"];
  36. }
  37. $apply_name = isset($this->post['apply_name']) && $this->post['apply_name']!="" ? trim($this->post['apply_name']):"";
  38. if($apply_name!=""){
  39. // $where['cgder'] =Db::Raw("like '%{$apply_name}%'");
  40. $where[]=['cgder',"like", "%{$apply_name}%"];
  41. }
  42. $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code']!="" ? trim($this->post['wsm_code']):"";
  43. if($wsm_code!=""){
  44. // $where['wsm_code'] = $wsm_code;
  45. $where[]=['wsm_code',"=", $wsm_code];
  46. }
  47. $wsm_in_code = isset($this->post['wsm_in_code']) && $this->post['wsm_in_code']!="" ? trim($this->post['wsm_in_code']):"";
  48. if($wsm_in_code!=""){
  49. $incode = Db::name("purchease_in")->where(["wsm_in_code"=>Db::raw(" like %{$wsm_in_code}%"),"is_del"=>0])->column("cgdNo");
  50. if(empty($incode)){
  51. return error_show(1004,"未找到有关入库单信息");
  52. }
  53. $where[]=['cgdNo',"in", $incode];
  54. }
  55. $good_name = isset($this->post['good_name']) && $this->post['good_name']!="" ? trim($this->post['good_name']):"";
  56. if($good_name!=""){
  57. //$where['good_name'] = Db::raw(" like %{$good_name}%");
  58. $where[]=['good_name',"like", "%{$good_name}%"];
  59. }
  60. $good_code = isset($this->post['good_code']) && $this->post['good_code']!="" ? trim($this->post['good_code'])
  61. :"";
  62. if($good_code!=""){
  63. // $where['good_code'] = Db::raw(" like %{$good_code}%");
  64. $where[]=['spuCode',"like", "%{$good_code}%"];
  65. }
  66. $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo']!="" ? trim($this->post['supplierNo'])
  67. :"";
  68. if($supplierNo!=""){
  69. // $where['good_code'] = Db::raw(" like %{$good_code}%");
  70. $where[]=['supplierNo',"like", "%{$supplierNo}%"];
  71. }
  72. $wsm_supplierNo = isset($this->post['wsm_supplierNo']) && $this->post['wsm_supplierNo']!="" ? trim($this->post['wsm_supplierNo'])
  73. :"";
  74. if($wsm_supplierNo!=""){
  75. $supplier = Db::name("supplier")->where(["code"=>$wsm_supplierNo])->find();
  76. if(empty($supplier)){
  77. return error_show(1004,"未找到供应商信息");
  78. }
  79. $wsmcode = Db::name("warehouse_info")->where(["is_del"=>0,"supplierNo"=>$wsm_supplierNo])->column("wsm_code");
  80. $where[]=['wsm_code',"in", $wsmcode];
  81. }
  82. $start = isset($this->post['start']) && $this->post['start']!="" ?$this->post['start']:"";
  83. if($start!=""){
  84. // $where['addtime'] = Db::raw(" >= '{$start}'");
  85. $where[]=['addtime',">=", $start];
  86. }
  87. $end = isset($this->post['end']) && $this->post['end']!="" ?$this->post['end']:"";
  88. if($end!=""){
  89. $where[]=['addtime',"<=", $end];
  90. }
  91. $last_start = isset($this->post['last_start']) && $this->post['last_start']!="" ?$this->post['last_start']:"";
  92. if($last_start!=""){
  93. //$where['lasttime'] = Db::raw(" >= '{$last_start}'");
  94. $where[]=['lasttime',">=", $last_start];
  95. }
  96. $last_end = isset($this->post['last_end']) && $this->post['last_end']!="" ?$this->post['last_end']:"";
  97. if($last_end!=""){
  98. //$where['lasttime'] = Db::raw(" <= '{$last_end}'");
  99. $where[]=['lasttime',"<=", $last_end];
  100. }
  101. $role=$this->checkRole();
  102. if(!empty($role['write'])){
  103. $where[]=["cgder_id","in",$role['write']];
  104. }
  105. $count=Db::name("purchease_order")->where($where)->count();
  106. $total = ceil($count/$size);
  107. $page = $page >= $total ? $total : $page;
  108. $list = Db::name("purchease_order")->where($where)->page($page,$size)->order("addtime desc")->select();
  109. $data=[];
  110. foreach ($list as $value){
  111. $value['wsm_name']="";
  112. if($value['wsm_code']!=""){
  113. $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code")
  114. ->where(["a.wsm_code"=>$value['wsm_code']])->field("a.name as wsm_name,b.name,b.code")->find();
  115. $value['wsm_name'] =isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
  116. $value['wsm_supplier'] =isset($wsmcode['name']) ? $wsmcode['name']:"";
  117. $value['wsm_supplierNo'] =isset($wsmcode['code']) ? $wsmcode['code']:"";
  118. }
  119. if($value['order_type']==3|| $value['order_type']==4){
  120. $goon = Db::name("good_zixun")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->find();
  121. $value["speclist"]=isset($goon['specinfo'])&&$goon['specinfo']!=""? json_decode($goon['specinfo'],true):"";
  122. }else {
  123. $goon =Db::name('good_basic')->where(['spuCode'=>$value['spuCode']])->find();
  124. $spec = Db::name("good_spec")->where(["spuCode"=>$goon['spuCode'],"is_del"=>0])->select()->toArray();
  125. $speclist=[];
  126. if(!empty($spec)){
  127. foreach ($spec as $val){
  128. $temp=[];
  129. $temp['id']=$val['id'];
  130. $temp['spuCode']=$val['spuCode'];
  131. $temp['spec_id']=$val['spec_id'];
  132. $temp['spec_value_id']=$val['spec_value_id'];
  133. $sp = Db::name("specs")->where(["id"=>$val['spec_id']])->find();
  134. $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
  135. $spv = Db::name("spec_value")->where(["id"=>$val['spec_value_id']])->find();
  136. $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
  137. $speclist[]=$temp;
  138. }
  139. }
  140. $value["speclist"]=empty($speclist)?[]:$speclist;
  141. }
  142. //采购单详情字段order_type 为1或者2时,取线上商品库 商品创建人 order_type 为3或者4时 取采购反馈的商品库 商品反馈人
  143. // $value['cgder_id'] = $goon['createrid'];
  144. // $value['cgder'] = $goon['creater'];
  145. $inorder= Db::name("purchease_in")->where(['cgdNo'=>$value['cgdNo'],"is_del"=>0])->select();
  146. $value['child']=empty($inorder)? [] : $inorder;
  147. $data[]=$value;
  148. }
  149. return app_show(0,"获取成功",["list"=>$data ,"count"=>$count]);
  150. }
  151. public function info(){
  152. $cgdNo = isset($this->post['cgdNo']) && $this->post['cgdNo']!="" ?trim($this->post['cgdNo']):"";
  153. if($cgdNo==""){
  154. return error_show(1004,"参数cgdNo 不能为空");
  155. }
  156. //采购单
  157. $data = Db::name("purchease_order")->where(["cgdNo"=>$cgdNo,"is_del"=>0])->find();
  158. if(empty($data)){
  159. return error_show(1004,"未找到数据");
  160. }
  161. //采购退货单
  162. $im = Db::name('purchease_back')->where(['cgdNo'=>$data['cgdNo'],'is_del'=>0])->select();
  163. $var=[];
  164. foreach ($im as $value){
  165. if($data['order_type']==3|| $data['order_type']==4){
  166. $goo = Db::name("good_zixun")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->find();
  167. }else {
  168. $goo =Db::name('good_basic')->where(['spuCode'=>$value['spuCode']])->find();
  169. }
  170. if($goo==false) {
  171. return error_show(1002, "未找到商品数据");
  172. }
  173. $cat= isset($goo['cat_id']) && $goo['cat_id'] !=0 ? made($goo['cat_id']):[];
  174. $value['cant']=$cat;
  175. $var[]=$value;
  176. }
  177. //采购工差单
  178. $dom = Db::name("purchease_diff")->where(['cgdNo'=>$data['cgdNo'],'is_del'=>0])->find();
  179. if($data['order_type']==3|| $data['order_type']==4){
  180. $goon = Db::name("good_zixun")->where(["spuCode"=>$data['spuCode'],"is_del"=>0])->find();
  181. }else {
  182. $goon =Db::name('good_basic')->where(['spuCode'=>$data['spuCode']])->find();
  183. }
  184. if(empty($goon)){
  185. return error_show(1002,"未找到商品数据");
  186. }else{
  187. $goon['exclusive']=isset($goon['is_exclusive'])?makeExcluse($goon['is_exclusive']):"";
  188. $unit =Db::name("unit")->where(["id"=>$goon['good_unit']])->find();
  189. $goon['unit'] = isset($unit['unit'])?$unit['unit']:'';
  190. $spec = Db::name("good_spec")->where(["spuCode"=>$goon['spuCode'],"is_del"=>0])->select()->toArray();
  191. $speclist=[];
  192. if(!empty($spec)){
  193. foreach ($spec as $value){
  194. $temp=[];
  195. $temp['id']=$value['id'];
  196. $temp['spuCode']=$value['spuCode'];
  197. $temp['spec_id']=$value['spec_id'];
  198. $temp['spec_value_id']=$value['spec_value_id'];
  199. $temp['is_del']=$value['is_del'];
  200. $sp = Db::name("specs")->where(["id"=>$value['spec_id']])->find();
  201. $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
  202. $spv = Db::name("spec_value")->where(["id"=>$value['spec_value_id']])->find();
  203. $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
  204. $speclist[]=$temp;
  205. }
  206. }
  207. $goon["speclist"]=empty($speclist)?[]:$speclist;
  208. $proof =Db::name("good_proof")->where(["spuCode"=>$goon['spuCode'],"is_del"=>0])->order("updatetime desc")->field("id,proof_type,proof_url")->find();
  209. $goon['proof'] = isset($proof)&&$proof!=false? $proof:[];
  210. $goon['origin_place_cn']="";
  211. $goon['delivery_place_cn']="";
  212. if(isset($goon['delivery_place'])&&$goon['delivery_place']!==""){
  213. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  214. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$goon['delivery_place']);
  215. $goon['delivery_place_cn']=GetAddr(json_encode($place));
  216. }
  217. if(isset($goon['delivery_place'])&&$goon['origin_place']!==""){
  218. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  219. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$goon['origin_place']);
  220. $goon['origin_place_cn']=GetAddr(json_encode($place));
  221. }
  222. if($goon['brand_id']!=0){
  223. $brand=Db::name("brand")->where(["id"=>$goon['brand_id']])->find();
  224. $goon["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  225. }else{
  226. $goon["brand_name"]="";
  227. $goon["brand_id"]="";
  228. }
  229. $supplier = Db::name("supplier")->where(["code"=>$goon['supplierNo']])->find();
  230. $goon['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  231. $goon['noble_name']=isset($goon['noble_metal'])&&$goon['noble_metal']!=0?$this->noble[$goon['noble_metal']] :"";
  232. if(isset($goon['companyNo'])&&$goon['companyNo']!=""){
  233. $company = Db::name("business")->where(["companyNo"=>$goon['companyNo']])->find();
  234. }
  235. $goon['company'] = isset($company['company'])?$company['company']:"";
  236. }
  237. $int= isset($goon['cat_id']) && $goon['cat_id'] !=0 ? made($goon['cat_id']):[];
  238. $data['wsm_name']="";
  239. if($data['wsm_code']!=""){
  240. $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code")
  241. ->leftJoin("warehouse_addr c","a.wsm_code=c.wsm_code and c.is_del=0")
  242. ->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();
  243. $data['wsm_name'] =isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
  244. $data['wsm_supplier'] =isset($wsmcode['name']) ? $wsmcode['name']:"";
  245. $data['wsm_supplierNo'] =isset($wsmcode['code']) ? $wsmcode['code']:"";
  246. $data['wsm_contactor'] =isset($wsmcode['wsm_contactor']) ? $wsmcode['wsm_contactor']:"";
  247. $data['wsm_mobile'] =isset($wsmcode['wsm_mobile']) ? $wsmcode['wsm_mobile']:"";
  248. // $data['wsm_addr'] =isset($wsmcode['wsm_addr']) ? $wsmcode['wsm_addr']:"";
  249. $data['addr_code'] =isset($wsmcode['addr_code']) ? $wsmcode['addr_code']:"";
  250. $data['wsm_addr'] =isset($wsmcode['addr_code']) ? GetAddr($wsmcode['addr_code']):"";
  251. $data['wsm_addr'].=isset($wsmcode['wsm_addr']) ? $wsmcode['wsm_addr']:"";
  252. $inorder= Db::name("purchease_in")->where(['cgdNo'=>$data['cgdNo'],"is_del"=>0])->select();
  253. $data['child']=empty($inorder)? [] : $inorder;
  254. }
  255. $data['can'] = $int;
  256. $data['goodinfo'] = $goon;
  257. $data['purcheasediff'] = $dom;
  258. if(isset($data['companyNo'])&&$data['companyNo']!=""){
  259. $company = Db::name("business")->where(["companyNo"=>$data['companyNo']])->find();
  260. }
  261. $data['company'] = isset($company['company'])?$company['company']:"";
  262. //$data['info'] = $var;
  263. $data['purcheaseback'] = $var;
  264. return app_show(0,"获取成功",$data);
  265. }
  266. public function edit(){
  267. $cgdNo = isset($this->post['cgdNo']) && $this->post['cgdNo']!="" ?trim($this->post['cgdNo']):"";
  268. if($cgdNo==""){
  269. return error_show(1004,"参数cgdNo 不能为空");
  270. }
  271. $data = Db::name("purchease_order")->where(["cgdNo"=>$cgdNo,"is_del"=>0])->find();
  272. if(empty($data)){
  273. return error_show(1004,"未找到数据");
  274. }
  275. $order = ["order_code"=>$cgdNo,"status"=> $data['status'] ,"action_remark"=>$this->post['remark'],"action_type"=>"edit"];
  276. $wsm_code = isset($this->post['wsm_code'])&&$this->post['wsm_code']!=""? trim($this->post['wsm_code']):"";
  277. if($wsm_code!=""){
  278. $ware = Db::name("warehouse_info")->where(["wsm_code"=>$wsm_code,"is_del"=>0])->find();
  279. if(empty($ware)){
  280. return error_show(1004,"未找到仓库信息");
  281. }
  282. // $good = Db::name("good_stock")->where(["wsm_code"=>$wsm_code,"good_type_code"=>$data['good_type_code'],"is_del"=>0])->find();
  283. // if(empty($good)){
  284. // return error_show(1004,"未找到仓库下商品信息");
  285. // }
  286. $data['wsm_code'] = $wsm_code;
  287. }
  288. $cgdid = isset($this->post['cgder_id'])&&$this->post['cgder_id']!=""?intval($this->post['cgder_id']):"";
  289. if($cgdid!=''){
  290. $cgduser = GetInfoById($this->post['token'],["id"=>$cgdid]);
  291. if((!empty($cgduser) && $cgduser['code']!=0) ||empty($cgduser) ){
  292. return error_show($cgduser['code'],$cgduser['message']);
  293. }
  294. $userinfo = $cgduser['data'];
  295. $data['cgder_id'] = $cgdid;
  296. $data['cgder'] = $userinfo['nickname'];
  297. }
  298. $good_num = isset($this->post['good_num'])&&$this->post['good_num']!=""?intval($this->post['good_num']):"";
  299. if($good_num!=""){
  300. $data['good_num'] = $good_num;
  301. }
  302. $good_price = isset($this->post['good_price'])&&$this->post['good_price']!=""?$this->post['good_price']:"";
  303. if($good_price!=""){
  304. $data['good_price'] = $good_price;
  305. }
  306. // $total_fee = isset($this->post['total_fee'])&&$this->post['total_fee']!=""?$this->post['total_fee']:"";
  307. // if($total_fee!=""){
  308. // $data['total_fee'] = $total_fee;
  309. // }
  310. $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!=""?$this->post['pakge_fee']:"";
  311. if($pakge_fee!=""){
  312. $data['pakge_fee'] = $pakge_fee;
  313. }
  314. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!=""?$this->post['cert_fee']:"";
  315. if($cert_fee!=""){
  316. $data['cert_fee'] = $cert_fee;
  317. }
  318. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!=""?$this->post['open_fee']:"";
  319. if($open_fee!=""){
  320. $data['open_fee'] = $open_fee;
  321. }
  322. $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!=""?$this->post['delivery_fee']:"";
  323. if($delivery_fee!=""){
  324. $data['delivery_fee'] = $delivery_fee;
  325. }
  326. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!=""?$this->post['mark_fee']:"";
  327. if($mark_fee!=""){
  328. $data['mark_fee'] = $mark_fee;
  329. }
  330. $teach_fee = isset($this->post['teach_fee'])&&$this->post['teach_fee']!=""?$this->post['teach_fee']:"";
  331. if($teach_fee!=""){
  332. $data['teach_fee'] = $teach_fee;
  333. }
  334. $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!=""?$this->post['nake_fee']:"";
  335. if($nake_fee!=""){
  336. $data['nake_fee'] = $nake_fee;
  337. }
  338. $weight = isset($this->post['weight'])&&$this->post['weight']!=""?$this->post['weight']:"";
  339. if($weight!=""){
  340. $data['weight'] = $weight;
  341. }
  342. $diff_weight = isset($this->post['diff_weight'])&&$this->post['diff_weight']!=""?$this->post['diff_weight']:"";
  343. if($diff_weight!=""){
  344. $data['diff_weight'] = $diff_weight;
  345. }
  346. $diff_fee = isset($this->post['diff_fee'])&&$this->post['diff_fee']!=""?$this->post['diff_fee']:"";
  347. if($diff_fee!=""){
  348. $data['diff_fee'] = $diff_fee;
  349. }
  350. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""?trim($this->post['supplierNo'])
  351. :"";
  352. if($supplierNo!=""){
  353. $supplier =Db::name("supplier")->where(['code'=>$supplierNo])->find();
  354. if(empty($supplier)){
  355. return error_show(1004,"未找到供应商信息");
  356. }
  357. $data['supplierNo'] = $supplierNo;
  358. $data['supplier_name'] = $supplier['name'];
  359. }
  360. $remark = isset($this->post['remark'])&&$this->post['remark']!=""?trim($this->post['remark']):"";
  361. if($remark!=""){
  362. $data['remark'] = $remark;
  363. }
  364. $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']+$data['teach_fee']*$data['weight']+$data['delivery_fee']),2);
  365. $data['total_fee'] = round($data['good_price']*$data['good_num'],2);
  366. $data['updatetime'] =date("Y-m-d H:i:s");
  367. $upd=Db::name("purchease_order")->save($data);
  368. if($upd){
  369. // ActionLog::logAdd($this->post['token'],$order,'cgd',$data['status'],$this->post);
  370. //修改状态,添加待办
  371. ActionLog::logAdd($this->post['token'], $order, "CGD", $data['status'], $this->post);
  372. // ProcessOrder::AddProcess($this->post['token'], [
  373. // "order_type" => 'CGD',
  374. // "order_code" => $cgdNo,//销售单code
  375. // "order_id" => $data['id'],
  376. // "order_status" => $data['status'],"before_status"=>1
  377. // ]);
  378. return app_show(0,"更新成功");
  379. }else{
  380. return error_show(1004,'更新失败');
  381. }
  382. }
  383. //修改采购单
  384. public function editNew()
  385. {
  386. $param = $this->request->only(['cgdNo', 'supplierNo', 'token', 'wsm_code' => ''], 'post', 'trim');
  387. $val = Validate::rule([
  388. 'cgdNo|采购单号' => 'require',
  389. 'supplierNo|供应商编号' => 'require',
  390. 'token' => 'require',
  391. ]);
  392. if (!$val->check($param)) return error_show(1004, $val->getError());
  393. Db::startTrans();
  394. try {
  395. $rs = Db::name('purchease_order')
  396. ->alias('po')
  397. ->field('po.id,po.order_type,po.status,po.cgder_id,po.cgder,po.supplierNo,po.supplier_name,po.wsm_code,wi.name wsm_name')
  398. ->leftJoin('warehouse_info wi', 'wi.wsm_code=po.wsm_code AND wi.is_del=0')
  399. ->where([
  400. 'po.cgdNo' => $param['cgdNo'],
  401. 'po.is_del' => 0,
  402. 'po.status' => 0
  403. ])->find();
  404. if (empty($rs)) throw new Exception('采购单不存在或不允许修改');
  405. $update = ['updatetime' => date('Y-m-d H:i:s')];
  406. //order_type==1备库
  407. if ($rs['order_type'] == 1) {
  408. if (empty($param['wsm_code'])) throw new Exception('备库单请传入仓库编码');
  409. else {
  410. $wsm_rs = Db::name('warehouse_info')
  411. ->field('id,wsm_code,name wsm_name')
  412. ->where([
  413. 'wsm_code' => $param['wsm_code'],
  414. 'is_del' => 0,
  415. ])->find();
  416. if (empty($wsm_rs)) throw new Exception('查不到该仓库的记录');
  417. else $update['wsm_code'] = $wsm_rs['wsm_code'];
  418. }
  419. }
  420. //供应商信息
  421. $supplier_rs = Db::name('supplier')
  422. ->field('id,name supplierName,code supplierNo,person,personid')
  423. ->where(['is_del' => 0, 'code' => $param['supplierNo']])
  424. ->find();
  425. if (empty($supplier_rs)) throw new Exception('查不到该供应商的记录');
  426. else {
  427. $update['cgder_id'] = $supplier_rs['personid'];
  428. $update['cgder'] = $supplier_rs['person'];
  429. $update['supplierNo'] = $supplier_rs['supplierNo'];
  430. $update['supplier_name'] = $supplier_rs['supplierName'];
  431. }
  432. //修改
  433. Db::name('purchease_order')
  434. ->where([
  435. 'id' => $rs['id'],
  436. 'is_del' => 0,
  437. 'status' => 0
  438. ])->update($update);
  439. $user = GetUserInfo($param['token']);
  440. $creater_id = isset($user['data']['id']) ? $user['data']['id'] : 0;
  441. $creater = isset($user['data']['nickname']) ? $user['data']['nickname'] : '';
  442. //添加修改记录
  443. Db::name('purchease_change_supplier_log')
  444. ->insert([
  445. 'cgdNo' => $param['cgdNo'],
  446. 'cgder_id_old' => $rs['cgder_id'],
  447. 'cgder_id' => $update['cgder_id'],
  448. 'cgder_old' => $rs['cgder'],
  449. 'cgder' => $update['cgder'],
  450. 'supplierNo_old' => $rs['supplierNo'],
  451. 'supplierNo' => $update['supplierNo'],
  452. 'supplier_name_old' => $rs['supplier_name'],
  453. 'supplier_name' => $update['supplier_name'],
  454. 'wsm_code_old' => $rs['wsm_code'],
  455. 'wsm_code' => isset($update['wsm_code']) ? $update['wsm_code'] : $rs['wsm_code'],
  456. 'wsm_name_old' => $rs['wsm_name'],
  457. 'wsm_name' => isset($wsm_rs['wsm_name']) ? $wsm_rs['wsm_name'] : $rs['wsm_name'],
  458. 'addtime' => date('Y-m-d H:i:s'),
  459. 'updatetime' => date('Y-m-d H:i:s'),
  460. 'creater_id' => $creater_id,
  461. 'creater' => $creater,
  462. ]);
  463. //记录日志
  464. ActionLog::logAdd(['id' => $creater_id, 'nickname' => $creater], $rs, "CGD", $rs['status'], $param);
  465. // ProcessOrder::AddProcess($this->post['token'], [
  466. // "order_type" => 'CGD',
  467. // "order_code" => $param['cgdNo'],//销售单code
  468. // "order_id" => $rs['id'],
  469. // "order_status" => $rs['status']
  470. // ]);
  471. Db::commit();
  472. return app_show(0, '修改成功');
  473. } catch (Exception $exception) {
  474. Db::rollback();
  475. return error_show(1005, $exception->getMessage());
  476. }
  477. }
  478. public function status()
  479. {
  480. $cgdNo = isset($this->post['cgdNo']) && $this->post['cgdNo'] != "" ? $this->post['cgdNo'] : [];
  481. if (empty($cgdNo)) {
  482. return error_show(1004, "参数cgdNo 不能为空");
  483. }
  484. $remark = isset($this->post['remark']) && $this->post['remark'] != "" ? trim($this->post['remark']) : "";
  485. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  486. if ($status === "") {
  487. return error_show(1004, "参数status 不能为空");
  488. }
  489. if ($status == 0) {
  490. $data = Db::name("purchease_order")
  491. ->field('id,cgdNo')
  492. ->whereIn('cgdNo', $cgdNo)
  493. ->where(["is_del" => 0])
  494. ->where('send_status', '>', 1)
  495. ->find();
  496. if (!empty($data)) {
  497. return error_show(1004, $data['cgdNo'] . "采购单发货中无法取消");
  498. }
  499. }
  500. // if($data['send_status']>1 && $status==0){
  501. // return error_show(1004,"采购单发货中无法取消");
  502. // }
  503. // $order = ["order_code"=>$cgdNo,"status"=> $data['status'] ,"action_remark"=>$remark,"action_type"=>"status"];
  504. // $data['status'] = $status;
  505. // $data['remark'] = $remark;
  506. // $data['updatetime'] =date("Y-m-d H:i:s");
  507. $upd = Db::name("purchease_order")
  508. ->whereIn('cgdNo', $cgdNo)
  509. ->save([
  510. 'status' => $status,
  511. 'remark' => $remark,
  512. 'updatetime' => date("Y-m-d H:i:s"),
  513. ]);
  514. if ($upd) {
  515. $process = ["order_code" => implode(',', $cgdNo), "order_id" => 0, "order_status" => $status, "order_type" => 'CGD',"before_status"=>0];
  516. ProcessOrder::AddProcess($this->post['token'], $process);
  517. $order = ["order_code" => implode(',', $cgdNo), "status" => '', "action_remark" => $remark, "action_type" => "status"];
  518. ActionLog::logAdd($this->post['token'], $order, 'CGD', $status, $this->post);
  519. return app_show(0, "更新成功");
  520. } else {
  521. return error_show(1004, '更新失败');
  522. }
  523. }
  524. public function diffcreat(){
  525. $token = isset($this->post['token']) && $this->post['token'] !=="" ?trim($this->post['token']):"";
  526. //$cgdNo=makeNo("CG");
  527. $cgdNo = $this->post['cgdNo'] && $this->post['cgdNo'] !=="" ? trim($this->post['cgdNo']) :"";
  528. if($cgdNo==""){
  529. return error_show(1002,"参数good_code不能为空");
  530. }
  531. $cg = Db::name('purchease_order')->where(['cgdNo'=>$cgdNo,'is_del'=>0])->find();
  532. if($cg==""){
  533. return error_show(1002,"未找到采购单数据");
  534. }
  535. if($cg['order_type']==3|| $cg['order_type']==4){
  536. $gd = Db::name("good_zixun")->where(["spuCode"=>$cg['spuCode']])->find();
  537. }else {
  538. $gd =Db::name('good_basic')->where(['spuCode'=>$cg['spuCode']])->find();
  539. }
  540. if($gd==""){
  541. return error_show(1002,"未找到商品数据");
  542. }
  543. $diff_weight = isset($this->post['diff_weight']) && $this->post['diff_weight'] !=="" ? floatval($this->post['diff_weight']) :"";
  544. if($diff_weight===""){
  545. return error_show(1002,"参数diff_weight不能为空");
  546. }
  547. $apply_id =GetUserInfo($token);
  548. if(empty($apply_id)||$apply_id['code']!=0){
  549. return error_show(1002,"申请人数据不存在");
  550. }
  551. $rid= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  552. $rname= isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  553. $diff_price = round($diff_weight*$cg['gold_price']+$diff_weight*$cg['teach_fee'],2);
  554. $data=[
  555. "cgdNo"=>$cgdNo,
  556. "good_code"=>$cg['spuCode'],
  557. "good_name"=>$cg['good_name'],
  558. "sale_price"=>$cg['good_price'],
  559. "good_weight"=>$cg['weight']*$cg['good_num'],
  560. "good_num"=>$cg['good_num'],
  561. "apply_id"=>$rid,
  562. "apply_name"=>$rname,
  563. "diff_weight"=>$diff_weight,
  564. "diff_price"=>$diff_price,
  565. "gold_price"=>$cg['good_price'],
  566. "status"=>1,
  567. "is_del"=>0,
  568. "addtime"=>date("Y-m-d H:i:s"),
  569. "updatetime"=>date("Y-m-d H:i:s")
  570. ];
  571. Db::startTrans();
  572. try{
  573. $item = Db::name("purchease_diff")->insert($data,true);
  574. if($item>0){
  575. $sto = ["order_code"=>$cgdNo,"status"=>1,"action_remark"=>'',"action_type"=>"create"];
  576. ActionLog::logAdd($this->post['token'],$sto,"CGGCD",1,$data);
  577. $process=["order_code"=>$cgdNo,"order_id"=>$item,"order_status"=>1,"order_type"=>'CGGCD',"before_status"=>1];
  578. ProcessOrder::AddProcess($this->post['token'],$process);
  579. $orderCode = Db::name("order_num")->where([["cgdNo","=",$cg['cgdNo']],["status","=",1]])->find();
  580. if($orderCode!=false){
  581. $order = Db::name("sale")->where("orderCode", '=', $orderCode['orderCode'])->find();
  582. if($order==false){
  583. Db::rollback();
  584. return error_show(1002,"未找到确认单信息");
  585. }
  586. $data=[
  587. "cgd_diffid"=>$item,
  588. "orderCode"=>$orderCode['orderCode'],
  589. "good_code"=>$cg['spuCode'],
  590. "good_name"=>$cg['good_name'],
  591. "diff_weight"=>$diff_weight,
  592. "diff_price"=>round($diff_weight*$order['gold_price']+$diff_weight*$order['cost_price'],2),
  593. "gold_price"=>$order['sale_price'],
  594. "status"=>1,
  595. "addtime"=>date("Y-m-d H:i:s"),
  596. "updatetime"=>date("Y-m-d H:i:s")
  597. ];
  598. $cgd = Db::name('sale_diff')->insert($data,true);
  599. if($cgd==0){
  600. // $sto = ["order_code"=>$cg['bkcode'],"status"=>1,"action_remark"=>'',"action_type"=>"create"];
  601. // ActionLog::logAdd($this->post['token'],$sto,"ZXGCD",1,$sto);
  602. // $process=["order_code"=>$cg['bkcode'],"order_id"=>$cgd,"order_status"=>1,"order_type"=>'ZXGCD'];
  603. // ProcessOrder::AddProcess($this->post['token'],$process);
  604. // Db::commit();
  605. // return error_show(0,"新建成功");
  606. // }else{
  607. Db::rollback();
  608. return error_show(1002,"新建失败");
  609. }
  610. $sto = ["order_code"=>$orderCode['orderCode'],"status"=>1,"action_remark"=>'',"action_type"=>"create"];
  611. ActionLog::logAdd($this->post['token'],$sto,"XSGCD",1,$data);
  612. $process=["order_code"=>$orderCode['orderCode'],"order_id"=>$cgd,"order_status"=>1,"order_type"=>'XSGCD',"before_status"=>1];
  613. ProcessOrder::AddProcess($this->post['token'],$process);
  614. }
  615. Db::commit();
  616. return error_show(0,"新建成功");
  617. }else{
  618. Db::rollback();
  619. return error_show(1002,"新建失败");
  620. }
  621. }catch (\Exception $e){
  622. Db::rollback();
  623. return error_show(1002,$e->getMessage());
  624. }
  625. }
  626. public function difflist(){
  627. $page = isset($this->post['page']) && $this->post['page'] !==""? intval($this->post['page']):"1";
  628. $size = isset($this->post['size']) && $this->post['size'] !==""? intval($this->post['size']):"10";
  629. $where = [['a.is_del',"=",0]];
  630. $cgdNo = isset($this->post['cgdNo']) && $this->post['cgdNo']!="" ? trim($this->post['cgdNo']):"";
  631. if($cgdNo!=""){
  632. $where[]=['a.cgdNo',"like", "%$cgdNo%"];
  633. }
  634. $status = isset($this->post['status']) && $this->post['status'] !==""? intval($this->post['status']):"";
  635. if($status!==""){
  636. $where[]=['a.status',"=",$status];
  637. }
  638. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  639. if ($start !="") {
  640. $where[]= ["a.addtime",'>=',$start];
  641. }
  642. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  643. if($end !=""){
  644. $where[]= ["a.addtime",'<=',$end];
  645. }
  646. $apply_name = isset($this->post['apply_name']) && $this->post['apply_name'] !==""? intval($this->post['apply_name']):"";
  647. if($apply_name!==""){
  648. $where[]=['a.apply_name',"like","%$apply_name%"];
  649. }
  650. $count = Db::name('purchease_diff')->alias('a')->join("good b","b.spuCode=a.good_code","left")
  651. ->where($where)->count();
  652. $total = ceil($count/$size);
  653. $page = $page >= $total ? $total : $page;
  654. $list = Db::name('purchease_diff')->alias('a')->join("good b","b.spuCode=a.good_code","left")
  655. ->where($where)->page($page,$size)->order("a.addtime desc")->field("a.*,b.cat_id")->select();
  656. $data=[];
  657. foreach ($list as $value){
  658. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  659. $data[]=$value;
  660. }
  661. return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
  662. }
  663. public function diffinfo(){
  664. $id = isset($this->post['id']) && $this->post['id'] !=="" ? trim($this->post['id']) :"";
  665. if($id==""){
  666. return error_show(1002,"参数id 不能为空");
  667. }
  668. $idinf = Db::name('purchease_diff')->where(['id'=>$id,'is_del'=>0])->find();
  669. if($idinf==false){
  670. return error_show(1002,"未找到采购工差单数据");
  671. }
  672. $dn = Db::name('purchease_order')->where(['cgdNo'=>$idinf['cgdNo'],'is_del'=>0])->find();
  673. if($dn['order_type']==3|| $dn['order_type']==4){
  674. $goon = Db::name("good_zixun")->where(["spuCode"=>$dn['spuCode'],"is_del"=>0])->find();
  675. }else {
  676. $goon =Db::name('good_basic')->where(['spuCode'=>$dn['spuCode']])->find();
  677. }
  678. // $goon = Db::name('good')->where(['spuCode'=>$idinf['good_code']])->find();
  679. if(empty($goon)){
  680. return error_show(1002,"未找到商品数据");
  681. }
  682. $idinf['wsm_name'] ="";
  683. $idinf['wsm_supplier'] ="";
  684. $idinf['wsm_supplierNo'] ="";
  685. $idinf['wsm_contactor'] ="";
  686. $idinf['wsm_mobile'] ="";
  687. $idinf['addr_code'] ="";
  688. $idinf['wsm_addr'] ="";
  689. if($dn['wsm_code']!=""){
  690. $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code")
  691. ->leftJoin("warehouse_addr c","a.wsm_code=c.wsm_code and c.is_del=0")
  692. ->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();
  693. $idinf['wsm_name'] =isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
  694. $idinf['wsm_supplier'] =isset($wsmcode['name']) ? $wsmcode['name']:"";
  695. $idinf['wsm_supplierNo'] =isset($wsmcode['code']) ? $wsmcode['code']:"";
  696. $idinf['wsm_contactor'] =isset($wsmcode['wsm_contactor']) ? $wsmcode['wsm_contactor']:"";
  697. $idinf['wsm_mobile'] =isset($wsmcode['wsm_mobile']) ? $wsmcode['wsm_mobile']:"";
  698. $idinf['addr_code'] =isset($wsmcode['addr_code']) ? $wsmcode['addr_code']:"";
  699. $idinf['addr_cn'] =isset($wsmcode['addr_code']) ? GetAddr($wsmcode['addr_code']):"";
  700. $idinf['wsm_addr']=isset($wsmcode['wsm_addr']) ? $wsmcode['wsm_addr']:"";
  701. }
  702. $idinf['info'] =$dn;
  703. $int= isset($goon['cat_id']) && $goon['cat_id'] !=0 ? made($goon['cat_id']):[];
  704. $idinf['can']=$int;
  705. $idinf['order_type']=$dn['order_type'];
  706. //取出销售的工差单信息
  707. $diff = Db::name('sale_diff')->field('id,customer_remark,is_act,remark')->where('cgd_diffid',$id)->find();
  708. $idinf['diff_customer_remark']=$diff['customer_remark'];
  709. $idinf['diff_is_act']=$diff['is_act'];
  710. $idinf['diff_remark']=$diff['remark'];
  711. return app_show(0,"获取成功",$idinf);
  712. }
  713. public function diffstatu(){
  714. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
  715. if($id==""){
  716. return error_show(1002,"参数id不能为空");
  717. }
  718. $dio = Db::name('purchease_diff')->where(['id'=>$id,'is_del'=>0])->find();
  719. if(empty($dio)){
  720. return error_show(1002,"工差订单未找到");
  721. }
  722. $cgd = Db::name("purchease_order")->where(['cgdNo'=>$dio['cgdNo']])->find();
  723. if(empty($cgd)){
  724. return error_show(1002,"采购单未找到");
  725. }
  726. $salediff=Db::name("sale_diff")->where(["cgd_diffid"=>$dio['id']])->find();
  727. if($salediff==false){
  728. return error_show(1002,"销售工差单未找到");
  729. }
  730. $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']) :"";
  731. if($status===""){
  732. return error_show(1002,"参数status不能为空");
  733. }
  734. Db::startTrans();
  735. try{
  736. $temp = $dio['status'];
  737. $dio['status']=$status;
  738. $dio['updatetime']=date("Y-m-d H:i:s");
  739. $item = Db::name("purchease_diff")->save($dio);
  740. if ($item){
  741. if($status==2){
  742. $cgd['diff_fee'] =$dio['diff_price'];
  743. $cgd['diff_weight'] =$dio['diff_weight'];
  744. $cgd['updatetime'] =date("Y-m-d H:i:s");
  745. $cgp=Db::name("purchease_order")->save($cgd);
  746. if($cgp==false){
  747. Db::rollback();
  748. return error_show(1002,"采购单更新失败");
  749. }
  750. if($salediff['is_act']==1){
  751. $saled=[
  752. "diff_fee"=>$salediff['diff_price'],
  753. "diff_weight"=>$salediff['diff_weight'],
  754. "updatetime"=>date("Y-m-d H:i:s")
  755. ];
  756. $up =Db::name("sale")->where(["orderCode"=>$salediff['orderCode']])->save($saled);
  757. if($up==false){
  758. Db::rollback();
  759. return error_show(1002,"销售单更新失败");
  760. }
  761. }
  762. }
  763. $sto = ["order_code"=>$dio['cgdNo'],"status"=>1,"action_remark"=>'',"action_type"=>"create"];
  764. ActionLog::logAdd($this->post['token'],$sto,"CGGCD",$status,$this->post);
  765. $process=["order_code"=>$dio['cgdNo'],"order_id"=>$dio['id'],"order_status"=>$status,"order_type"=>'CGGCD',"before_status"=>1];
  766. ProcessOrder::AddProcess($this->post['token'],$process);
  767. Db::commit();
  768. return error_show(0,"更新成功");
  769. }else{
  770. Db::rollback();
  771. return error_show(1002,"更新失败");
  772. }
  773. }catch (\Exception $e){
  774. Db::rollback();
  775. return error_show(1002,$e->getMessage()."|".$e->getLine());
  776. }
  777. }
  778. //修改采购单的实时金价
  779. public function editGoldPrice()
  780. {
  781. $param = $this->request->only(['cgdNo', 'gold_price'], 'post', 'trim');
  782. $val = Validate::rule(['cgdNo|采购单号' => 'require', 'gold_price|实时金价' => 'require|float']);
  783. if (!$val->check($param)) return error_show(1004, $val->getError());
  784. //采购单
  785. $data = Db::name("purchease_order")
  786. ->field('id,demo_fee,good_num,weight,open_fee,teach_fee,pakge_fee,mark_fee,cert_fee,nake_fee,delivery_fee,status')
  787. ->where(["cgdNo" => $param['cgdNo'], "is_del" => 0])
  788. ->find();
  789. if (empty($data)) return error_show(1004, "未找到该采购单数据");
  790. if ($data['status'] != 0) return error_show(1005, '该状态下不允许修改实时金价');
  791. $sale_price = round($data['demo_fee'] / $data['good_num'] + $data['open_fee'] / $data['good_num'] +
  792. $data['weight'] * $param["gold_price"] + $data['teach_fee'] * $data['weight'] +
  793. $data['pakge_fee'] + $data['mark_fee'] + $data['cert_fee'] +$data['nake_fee'] + $data['delivery_fee'],2);
  794. $total_price = round($data['good_num']*$sale_price,2);
  795. $rs = Db::name("purchease_order")
  796. ->where('id', $data['id'])
  797. ->update(['updatetime' => date('Y-m-d H:i:s'), 'gold_price' => $param['gold_price'],"good_price"=>$sale_price,"total_fee"=>$total_price]);
  798. return $rs ? app_show(0, '修改采购单实时金价成功') : error_show(1005, '修改采购单实时金价失败');
  799. }
  800. //采购单导出
  801. public function exportCgdList()
  802. {
  803. $cgdNos = $this->request->post('cgdNos', [], 'trim');
  804. if (empty($cgdNos)) return error_show(1004, '要导出的采购单编号不能为空');
  805. $i = 1;
  806. $send_type = [1 => '直接发货', 2 => '延时发货'];
  807. $status = [0 => '待与供应商确认', 1 => '待入库', 2 => '部分入库', 3 => '入库完成', 4 => '已取消订单'];
  808. $list = Db::name("purchease_order")
  809. ->alias('po')
  810. ->field('"" as 序号,po.addtime as 创建时间,po.cgdNo as 采购单编号,po.status as 采购单状态,po.cgder as 采购员,s.orderCode as 确认单号,s.addtime as 确认单时间,po.spuCode as 产品编号,po.good_name as 产品名称,"" as 规格,"" as 单位,po.supplier_name as 供应商名称,po.supplierNo as 供应商编号,po.nake_fee as 裸价,po.delivery_fee as 物流费,s.send_type as 发货方式,po.good_price as 采购单价,s.remark as 确认单备注,po.good_num as 采购数量,po.total_fee as 采购货款,b.company as 购买方公司,s.arrive_time as 到货时间,po.order_type')
  811. ->whereIn('po.cgdNo', $cgdNos)
  812. ->leftJoin('order_num on', 'on.cgdNo=po.cgdNo')
  813. ->leftJoin('sale s', 's.orderCode=on.orderCode')
  814. ->leftJoin('business b', 'b.companyNo=s.supplierNo')
  815. ->order("po.addtime desc")
  816. ->withAttr('序号', function () use (&$i) {
  817. return $i++;
  818. })->withAttr('采购单状态', function ($val) use ($status) {
  819. return isset($status[$val]) ? $status[$val] : '';
  820. })->withAttr('发货方式', function ($val) use ($send_type) {
  821. return isset($send_type[$val]) ? $send_type[$val] : '';
  822. })
  823. ->select()
  824. ->toArray();
  825. foreach ($list as &$value) {
  826. if ($value['order_type'] == 3 || $value['order_type'] == 4) {
  827. $temp = Db::name("good_zixun")
  828. ->where(["spuCode" => $value['产品编号'], "is_del" => 0])
  829. ->field('id,specinfo,good_unit')
  830. ->find();
  831. $good_unit = isset($temp['good_unit']) ? $temp['good_unit'] : 0;
  832. $specinfo = isset($temp['specinfo']) ? json_decode($temp['specinfo'], true) : [];
  833. $speclist = [];
  834. foreach ($specinfo as $val) {
  835. $speclist[] = $val['spec_name'] . ':' . $val['spec_value_name'];
  836. }
  837. } else {
  838. $good_unit = Db::name('good_basic')
  839. ->where(['spuCode' => $value['产品编号']])
  840. ->value('good_unit', 0);
  841. $spec = Db::name("good_spec")
  842. ->field('id,spec_id,spec_value_id')
  843. ->where(["spuCode" => $value['产品编号'], "is_del" => 0])
  844. ->select()
  845. ->toArray();
  846. $speclist = [];
  847. if (!empty($spec)) {
  848. foreach ($spec as $val) {
  849. $speclist[] = Db::name("specs")->where(["id" => $val['spec_id']])->value('spec_name', '') . ':' . Db::name("spec_value")->where(["id" => $val['spec_value_id']])->value('spec_value', '');
  850. }
  851. }
  852. }
  853. $value['规格'] = empty($speclist) ? '' : implode(',', $speclist);;
  854. $value['单位'] = $good_unit ? Db::name('unit')->where(['id' => $good_unit, 'is_del' => 0])->value('unit', '') : '';
  855. unset($value['order_type']);
  856. }
  857. $headerArr = array_keys($list[0]);
  858. excelSave('采购单导出' . date('YmdHis'), $headerArr, $list);
  859. }
  860. //获取采购单修改供应商的记录列表
  861. public function getChangeSupplierList(){
  862. $param = $this->request->only(['cgdNo'=>'','start'=>'','end'=>'','creater'=>'','page'=>1,'size'=>15],'post','trim');
  863. $where=[['is_del','=',0]];
  864. if(!empty($param['cgdNo'])) $where[]=['cgdNo','like','%'.$param['cgdNo'].'%'];
  865. if(!empty($param['start'])) $where[]=['addtime','>=',$param['start']];
  866. if(!empty($param['end'])) $where[]=['addtime','<=',$param['end'].' 23:59:59'];
  867. if(!empty($param['creater'])) $where[]=['creater','like','%'.$param['creater'].'%'];
  868. $total = Db::name('purchease_change_supplier_log')
  869. ->where($where)
  870. ->count('id');
  871. $list =Db::name('purchease_change_supplier_log')
  872. ->withoutField('status,remark')
  873. ->where($where)
  874. ->order('id','desc')
  875. ->page($param['page'],$param['size'])
  876. ->select()
  877. ->toArray();
  878. return app_show(0,'获取成功',['list'=>$list,'count'=>$total]);
  879. }
  880. // public function create(){
  881. // $customer = isset($this->post['customer_code'])&&$this->post['customer_code']!="" ?trim($this->post['customer_code']):"";
  882. // if($customer==""){
  883. // return error_show(1004,"参数customer_code不能为空");
  884. // }
  885. // $supplier = isset($this->post['supplier_code'])&&$this->post['supplier_code']!="" ?trim($this->post['supplier_code']):"";
  886. // if($supplier==""){
  887. // return error_show(1004,"参数supplier_code不能为空");
  888. // }
  889. // $good_code = isset($this->post['good_code']) && $this->post['good_code']!=""?trim($this->post['good_code']):"";
  890. // if($good_code==""){
  891. // return error_show(1004,"参数good_code不能为空");
  892. // }
  893. // $good_num = isset($this->post['good_num'])&& $this->post['good_num']!==""? intval($this->post['good_num']):"";
  894. // if($good_num===""){
  895. // return error_show(1004,"参数good_code不能为空");
  896. // }
  897. // $file_url = isset($this->post['file_url'])&& $this->post['file_url']!==""? trim($this->post['file_url']):"";
  898. // if($file_url===""){
  899. // return error_show(1004,"参数file_url不能为空");
  900. // }
  901. // $mark =isset($this->post['remark'])&&$this->post['remark']!=""?trim($this->post['remark']):"";
  902. // if($mark==""){
  903. // return error_show(1004,"参数remark不能为空");
  904. // }
  905. //
  906. // $data=[
  907. // ""
  908. // ];
  909. // }
  910. }