Purch.php 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\ActionLog;
  4. use app\admin\model\DataGroup as DataGroupModel;
  5. use app\admin\model\ProcessOrder;
  6. use think\App;
  7. use think\Exception;
  8. use think\facade\Db;
  9. use think\facade\Validate;
  10. //采购单相关功能
  11. class Purch extends Base
  12. {
  13. public $noble=[];
  14. public function __construct(App $app)
  15. {
  16. parent::__construct($app);
  17. $this->noble=\think\facade\Config::get("noble");
  18. }
  19. //采购单列表
  20. public function list(){
  21. $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']):"1";
  22. $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']):"10";
  23. $where = [['po.is_del', "=", 0]];
  24. $bkcode = isset($this->post['bk_code']) && $this->post['bk_code']!="" ? trim($this->post['bk_code']):"";
  25. if($bkcode!==""){
  26. $where[]=['po.bkcode',"like", "%{$bkcode}%"];
  27. }
  28. $status = isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
  29. if($status!==""){
  30. // $where['status'] = $status;
  31. $where[]=['po.status',"=", $status];
  32. }
  33. $cgdNo = isset($this->post['cgdNo']) && $this->post['cgdNo']!="" ? trim($this->post['cgdNo']) :"";
  34. if($cgdNo!==""){
  35. //$where['cgdNo'] = Db::Raw("like '%{$cgdNo}%'");
  36. $where[]=['po.cgdNo',"like", "%{$cgdNo}%"];
  37. }
  38. $apply_name = isset($this->post['apply_name']) && $this->post['apply_name']!="" ? trim($this->post['apply_name']):"";
  39. if($apply_name!==""){
  40. // $where['cgder'] =Db::Raw("like '%{$apply_name}%'");
  41. $where[]=['po.cgder',"like", "%{$apply_name}%"];
  42. }
  43. $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code']!="" ? trim($this->post['wsm_code']):"";
  44. if($wsm_code!==""){
  45. // $where['wsm_code'] = $wsm_code;
  46. $where[]=['po.wsm_code',"=", $wsm_code];
  47. }
  48. $wsm_in_code = isset($this->post['wsm_in_code']) && $this->post['wsm_in_code']!="" ? trim($this->post['wsm_in_code']):"";
  49. if($wsm_in_code!==""){
  50. $incode = Db::name("purchease_in")->where(["wsm_in_code"=>Db::raw(" like %{$wsm_in_code}%"),"is_del"=>0])->column("cgdNo");
  51. if(empty($incode)){
  52. return error_show(1004,"未找到有关入库单信息");
  53. }
  54. $where[]=['po.cgdNo',"in", $incode];
  55. }
  56. $good_name = isset($this->post['good_name']) && $this->post['good_name']!="" ? trim($this->post['good_name']):"";
  57. if($good_name!==""){
  58. //$where['good_name'] = Db::raw(" like %{$good_name}%");
  59. $where[]=['po.good_name',"like", "%{$good_name}%"];
  60. }
  61. $good_code = isset($this->post['good_code']) && $this->post['good_code']!="" ? trim($this->post['good_code']) :"";
  62. if($good_code!==""){
  63. // $where['good_code'] = Db::raw(" like %{$good_code}%");
  64. $where[]=['po.spuCode',"like", "%{$good_code}%"];
  65. }
  66. $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo']!="" ? trim($this->post['supplierNo']) :"";
  67. if($supplierNo!==""){
  68. // $where['good_code'] = Db::raw(" like %{$good_code}%");
  69. $where[]=['po.supplierNo',"=", $supplierNo];
  70. }
  71. $wsm_supplierNo = isset($this->post['wsm_supplierNo']) && $this->post['wsm_supplierNo']!="" ? trim($this->post['wsm_supplierNo']) :"";
  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[]=['po.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[]=['po.addtime',">=", $start." 00:00:00"];
  84. }
  85. $end = isset($this->post['end']) && $this->post['end']!="" ?$this->post['end']:"";
  86. if($end!==""){
  87. $where[]=['po.addtime',"<=", $end." 23:59:59"];
  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[]=['po.lasttime',">=", $last_start." 00:00:00"];
  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[]=['po.lasttime',"<=", $last_end." 23:59:59"];
  98. }
  99. $orderCode = isset($this->post['orderCode']) && $this->post['orderCode']!="" ?$this->post['orderCode']:"";
  100. if($orderCode!==""){
  101. //$where['lasttime'] = Db::raw(" <= '{$last_end}'");
  102. $where[]=['on.orderCode',"like", '%'.$orderCode.'%'];
  103. }
  104. //筛选供应商名称
  105. $supplier_name = isset($this->post['supplier_name']) && $this->post['supplier_name'] != "" ? $this->post['supplier_name'] : "";
  106. if ($supplier_name != '') $where[] = ['po.supplier_name', 'like', '%' . $supplier_name . '%'];
  107. $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo'] != "" ? trim($this->post['relaComNo']) : "";
  108. if ($relaComNo !== "") $where[] = ['po.companyNo', '=', $relaComNo];
  109. // $whereor=[];
  110. // if(!empty($role['write'])){
  111. //// $whereor[]=["po.cgder_id","in",$role['write']];
  112. //// $whereor[]=["sip.personid","=",$this->uid];
  113. // $whereor[]=["sip.personid","in",$role['write']];//最后的筛选条件
  114. //// $whereor[]=["po.cgder_id","=",$this->uid];
  115. // }
  116. // $role = $this->checkDataShare();
  117. // if (!empty($role[DataGroupModel::$type_全部])) $where[] = ["sip.personid", "in", $role[DataGroupModel::$type_全部]];
  118. $userCommon = new \app\admin\common\User();
  119. //只有level2的账号过滤数据权限
  120. if ($this->level == 2) {
  121. $role = $this->checkDataShare();
  122. $hand = resign_hand_user($this->uid, 0);
  123. if (!empty($role[DataGroupModel::$type_全部])) {
  124. $arr = array_unique(array_merge($hand, $role[DataGroupModel::$type_全部]));
  125. $sql = Db::connect('mysql_sys')
  126. ->name('supplier')
  127. ->field('code')
  128. ->where(['is_del'=>0,'personid'=>$arr])
  129. ->buildSql();
  130. $where[] = ['po.supplierNo', 'in', $sql];
  131. }
  132. }
  133. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  134. if ($company_name !== "") $where[] = ["po.cgder_id", 'in', get_company_item_user_by_name($company_name)];
  135. $order_type = isset($this->post['order_type']) && $this->post['order_type'] !== "" ? intval($this->post['order_type']) : "";
  136. if ($order_type !== "") $where[] = ["po.order_type", '=', $order_type];
  137. $order_source = isset($this->post['order_source']) && $this->post['order_source'] !== "" ? intval($this->post['order_source']) : "";
  138. if ($order_source !== "") $where[] = ["po.order_source", '=', $order_source];
  139. // if(!empty($role['platform']) ){
  140. // $where[]=["po.platform_id","in",$role['platform']];
  141. // }
  142. $count = Db::name("purchease_order")
  143. ->alias('po')
  144. ->leftJoin('order_num on', 'on.cgdNo=po.cgdNo')
  145. ->leftJoin("depart_user u", "u.uid=po.cgder_id AND u.is_del=0")
  146. // ->leftJoin('supplier sip', 'sip.code=po.supplierNo')
  147. ->where($where)
  148. ->where(function ($query) use ($where) {
  149. $query->whereOr([['po.order_type', '<>', 1], ['po.order_source', '=', 0]]);
  150. })->count();
  151. $total = ceil($count/$size);
  152. $page = $page >= $total ? $total : $page;
  153. $list = Db::name("purchease_order")
  154. ->alias('po')
  155. ->leftJoin('order_num on','on.cgdNo=po.cgdNo')
  156. // ->leftJoin('supplier sip', 'sip.code=po.supplierNo')
  157. ->field('po.*,on.orderCode,"" supplier_cgderid,"" supplier_cgder')
  158. ->where($where)
  159. ->where(function($query) use ($where){$query->whereOr([['po.order_type', '<>', 1],['po.order_source', '=', 0]]);})
  160. ->page($page,$size)
  161. ->order("po.addtime desc")
  162. ->select()
  163. ->toArray();
  164. $account = checkHasAccountBySupplierNos(array_column($list,'supplierNo'));
  165. $all_createrid = array_column($list,'cgder_id');
  166. $item = get_company_name_by_uid($all_createrid);
  167. $data=[];
  168. $wsmCodes = array_column($list, 'wsm_code');
  169. $wsmcode = Db::name("warehouse_info")
  170. ->alias("a")
  171. ->where(["a.wsm_code" => $wsmCodes])
  172. ->column("a.name as wsm_name,a.supplierNo as code", "wsm_code");
  173. $wsmsupplier=[];
  174. if(!empty($wsmcode)){
  175. $names = $userCommon->handle('getCodeAndName', ['code' => array_column($wsmcode,"code")]);
  176. $wsmsupplier = $names['data']??[];
  177. }
  178. //补充供应商负责人(sip.personid as supplier_cgderid,sip.person as supplier_cgder)
  179. $person_list = $userCommon->handle('sGetList', ['more_code' => array_unique(array_column($list, 'supplierNo')), 'size' => $size]);
  180. $person_list = array_column($person_list['data']['list'], null, 'code');
  181. foreach ($list as $value){
  182. $value['wsm_name'] = isset($wsmcode[$value['wsm_code']]['wsm_name']) ? $wsmcode[$value['wsm_code']]['wsm_name'] : "";
  183. $value['wsm_supplier'] = $wsmsupplier[$wsmcode[$value['wsm_code']]['code']] ?? "";
  184. $value['wsm_supplierNo'] = $wsmcode[$value['wsm_code']]['code'] ?? "";
  185. $value['supplier_cgderid'] = $person_list[$value['supplierNo']]['personid'] ?? '';
  186. $value['supplier_cgder'] = $person_list[$value['supplierNo']]['person'] ?? '';
  187. // $value['wsm_name']="";
  188. // if($value['wsm_code']!=""){
  189. //// $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code")
  190. //// ->where(["a.wsm_code"=>$value['wsm_code']])->field("a.name as wsm_name,b.name,b.code")->find();
  191. // $value['wsm_name'] =isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
  192. // $value['wsm_supplier'] =isset($wsmcode['name']) ? $wsmcode['name']:"";
  193. // $value['wsm_supplierNo'] =isset($wsmcode['code']) ? $wsmcode['code']:"";
  194. // }
  195. // $supplierCgder =Db::name("supplier")->where(["code"=>$value['supplierNo']])->findOrEmpty();
  196. // $value['supplier_cgderid'] = $supplierCgder['personid'] ??'';
  197. // $value['supplier_cgder'] = $supplierCgder['person'] ??'';
  198. if($value['order_type']==3){
  199. $goon = Db::name("good_zixun")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->find();
  200. $value["speclist"]=isset($goon['specinfo'])&&$goon['specinfo']!=""? json_decode($goon['specinfo'],true):"";
  201. //为了格式统一,缺了一个spec_value
  202. foreach ($value['speclist'] as &$v) {
  203. $v['spec_value'] = $v['spec_value_name'];
  204. }
  205. }else {
  206. $goon =Db::name('good_basic')->where(['spuCode'=>$value['spuCode']])->find();
  207. $spec = Db::name("good_spec")->where(["spuCode"=>$goon['spuCode'],"is_del"=>0])->select()->toArray();
  208. $speclist=[];
  209. if(!empty($spec)){
  210. foreach ($spec as $val){
  211. $temp=[];
  212. $temp['id']=$val['id'];
  213. $temp['spuCode']=$val['spuCode'];
  214. $temp['spec_id']=$val['spec_id'];
  215. $temp['spec_value_id']=$val['spec_value_id'];
  216. $sp = Db::name("specs")->where(["id"=>$val['spec_id']])->find();
  217. $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
  218. $spv = Db::name("spec_value")->where(["id"=>$val['spec_value_id']])->find();
  219. $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
  220. $speclist[]=$temp;
  221. }
  222. }
  223. $value["speclist"]=empty($speclist)?[]:$speclist;
  224. }
  225. //采购单详情字段order_type 为1或者2时,取线上商品库 商品创建人 order_type 为3或者4时 取采购反馈的商品库 商品反馈人
  226. // $value['cgder_id'] = $goon['createrid'];
  227. // $value['cgder'] = $goon['creater'];
  228. $inorder= Db::name("purchease_in")
  229. ->where(['cgdNo'=>$value['cgdNo'],"is_del"=>0])
  230. ->select()
  231. ->toArray();
  232. $value['child']=empty($inorder)? [] : $inorder;
  233. $value['send_num'] -=$value['th_num'];
  234. $value['total_fee'] =round($value['total_fee']-$value['th_fee'],2);
  235. //补充orderCode
  236. // $value['orderCode']=isset($all_orderCodes[$value['cgdNo']])?$all_orderCodes[$value['cgdNo']]:'';
  237. $value['company_name'] = $item[$value['cgder_id']]??'';
  238. $value['has_account'] = (int)isset($account[$value['supplierNo']]);
  239. //是否具有编辑权限
  240. // $value['is_allow_update'] = 0;
  241. // if (in_array($this->roleid, [1, 33]) || in_array($value['cgder_id'], $role[DataGroupModel::$type_可编辑])) $value['is_allow_update'] = 1;
  242. $data[]=$value;
  243. }
  244. return app_show(0,"获取成功",["list"=>$data ,"count"=>$count]);
  245. }
  246. public function info(){
  247. $cgdNo = isset($this->post['cgdNo']) && $this->post['cgdNo']!="" ?trim($this->post['cgdNo']):"";
  248. if($cgdNo==""){
  249. return error_show(1004,"参数cgdNo 不能为空");
  250. }
  251. //采购单
  252. $data = Db::name("purchease_order")->where(["cgdNo"=>$cgdNo,"is_del"=>0])->find();
  253. if(empty($data)){
  254. return error_show(1004,"未找到数据");
  255. }
  256. //采购退货单
  257. $im = Db::name('purchease_back')->where(['cgdNo'=>$data['cgdNo'],'is_del'=>0])->select();
  258. $var=[];
  259. foreach ($im as $value){
  260. if($data['order_type']==3){
  261. $goo = Db::name("good_zixun")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->find();
  262. }else {
  263. $goo =Db::name('good_basic')->where(['spuCode'=>$value['spuCode']])->find();
  264. }
  265. if($goo==false) {
  266. return error_show(1002, "未找到商品数据");
  267. }
  268. $cat= isset($goo['cat_id']) && $goo['cat_id'] !=0 ? made($goo['cat_id']):[];
  269. $value['cant']=$cat;
  270. $var[]=$value;
  271. }
  272. //采购工差单
  273. $dom = Db::name("purchease_diff")->where(['cgdNo'=>$data['cgdNo'],'is_del'=>0])->find();
  274. if($data['order_type']==3){
  275. $goon = Db::name("good_zixun")->where(["spuCode"=>$data['spuCode'],"is_del"=>0])->find();
  276. }else {
  277. $goon =Db::name('good_basic')->where(['spuCode'=>$data['spuCode']])->find();
  278. }
  279. if(empty($goon)){
  280. return error_show(1002,"未找到商品数据");
  281. }else{
  282. $goon['exclusive']=isset($goon['is_exclusive'])?makeExcluse($goon['is_exclusive']):"";
  283. $unit =Db::name("unit")->where(["id"=>$goon['good_unit']])->find();
  284. $goon['unit'] = isset($unit['unit'])?$unit['unit']:'';
  285. $spec = Db::name("good_spec")->where(["spuCode"=>$goon['spuCode'],"is_del"=>0])->select()->toArray();
  286. $speclist=[];
  287. if(!empty($spec)){
  288. foreach ($spec as $value){
  289. $temp=[];
  290. $temp['id']=$value['id'];
  291. $temp['spuCode']=$value['spuCode'];
  292. $temp['spec_id']=$value['spec_id'];
  293. $temp['spec_value_id']=$value['spec_value_id'];
  294. $temp['is_del']=$value['is_del'];
  295. $sp = Db::name("specs")->where(["id"=>$value['spec_id']])->find();
  296. $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
  297. $spv = Db::name("spec_value")->where(["id"=>$value['spec_value_id']])->find();
  298. $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
  299. $speclist[]=$temp;
  300. }
  301. }
  302. $goon["speclist"]=empty($speclist)?[]:$speclist;
  303. $proof =Db::name("good_proof")->where(["spuCode"=>$goon['spuCode'],"is_del"=>0])->order("updatetime desc")->field("id,proof_type,proof_url")->find();
  304. $goon['proof'] = isset($proof)&&$proof!=false? $proof:[];
  305. $goon['origin_place_cn']="";
  306. $goon['delivery_place_cn']="";
  307. if(isset($goon['delivery_place'])&&$goon['delivery_place']!==""){
  308. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  309. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$goon['delivery_place']);
  310. $goon['delivery_place_cn']=GetAddr(json_encode($place));
  311. }
  312. if(isset($goon['delivery_place'])&&$goon['origin_place']!==""){
  313. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  314. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$goon['origin_place']);
  315. $goon['origin_place_cn']=GetAddr(json_encode($place));
  316. }
  317. if($goon['brand_id']!=0){
  318. $brand=Db::name("brand")->where(["id"=>$goon['brand_id']])->find();
  319. $goon["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  320. }else{
  321. $goon["brand_name"]="";
  322. $goon["brand_id"]="";
  323. }
  324. $userCommon = new \app\admin\common\User();
  325. $supplier = $userCommon->handle('sInfo',['code'=>$goon['supplierNo']]);
  326. // $supplier = Db::name("supplier")->where(["code"=>$goon['supplierNo']])->find();
  327. $goon['supplier_cgderid'] = $supplier['data']['personid'] ??'';
  328. $goon['supplier_cgder'] = $supplier['data']['person'] ??'';
  329. $goon['supplierName'] = isset($supplier['data']['name'])?$supplier['data']['name']:"";
  330. $goon['noble_name']=isset($goon['noble_metal'])&&$goon['noble_metal']!=0?$this->noble[$goon['noble_metal']] :"";
  331. //补充客户名称
  332. if (empty($data['orderCode'])) $data['customer'] = [];
  333. else {
  334. $customer_code = Db::name('sale')
  335. ->alias('s')
  336. // ->field('c.companyNo,c.companyName')
  337. // ->leftJoin('customer_info c', 'c.companyNo=s.customer_code AND c.is_del=0')
  338. ->where(['s.orderCode' => $data['orderCode']])
  339. ->value('s.customer_code','');
  340. }
  341. $tmp = $userCommon->handle('getCodeAndName', ['code' => [
  342. $goon['companyNo'],
  343. $data['wsm_code'],
  344. $data['companyNo'],
  345. $customer_code
  346. ]]);
  347. if(!empty($data['orderCode'])){
  348. $data['customer']['companyNo'] = $customer_code;
  349. $data['customer']['companyName'] = $tmp['data'][$customer_code]??'';
  350. }
  351. if(isset($goon['companyNo'])&&$goon['companyNo']!=""){
  352. // $company = Db::name("business")->where(["companyNo"=>$goon['companyNo']])->find();
  353. }
  354. $goon['company'] = $tmp['data'][$goon['companyNo']] ?? '';
  355. }
  356. $int= isset($goon['cat_id']) && $goon['cat_id'] !=0 ? made($goon['cat_id']):[];
  357. $data['wsm_name']="";
  358. if($data['wsm_code']!=""){
  359. $wsmcode = Db::name("warehouse_info")
  360. ->alias("a")
  361. // ->leftJoin("supplier b","a.supplierNo=b.code")
  362. ->leftJoin("warehouse_addr c","a.wsm_code=c.wsm_code and c.is_del=0")
  363. ->where(["a.wsm_code"=>$data['wsm_code']])
  364. ->field("a.name as wsm_name,c.wsm_name as wsm_contactor,c.wsm_mobile,c.wsm_addr,c.addr_code")
  365. ->find();
  366. $data['wsm_name'] =isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
  367. $data['wsm_supplier'] =isset($wsmcode['data'][$data['wsm_code']]) ? $wsmcode['data'][$data['wsm_code']]:"";
  368. $data['wsm_supplierNo'] =isset($wsmcode['data'][$data['wsm_code']]) ? $wsmcode['data'][$data['wsm_code']]:"";
  369. $data['wsm_contactor'] =isset($wsmcode['wsm_contactor']) ? $wsmcode['wsm_contactor']:"";
  370. $data['wsm_mobile'] =isset($wsmcode['wsm_mobile']) ? $wsmcode['wsm_mobile']:"";
  371. // $data['wsm_addr'] =isset($wsmcode['wsm_addr']) ? $wsmcode['wsm_addr']:"";
  372. $data['addr_code'] =isset($wsmcode['addr_code']) ? $wsmcode['addr_code']:"";
  373. $data['wsm_addr'] =isset($wsmcode['addr_code']) ? GetAddr($wsmcode['addr_code']):"";
  374. $data['wsm_addr'].=isset($wsmcode['wsm_addr']) ? $wsmcode['wsm_addr']:"";
  375. $inorder= Db::name("purchease_in")->where(['cgdNo'=>$data['cgdNo'],"is_del"=>0])->select();
  376. $data['child']=empty($inorder)? [] : $inorder;
  377. }
  378. $data['can'] = $int;
  379. $data['goodinfo'] = $goon;
  380. $data['purcheasediff'] = $dom;
  381. $data['send_num'] -=$data['th_num'];
  382. $data['total_fee'] =round($data['total_fee']-$data['th_fee'],2);
  383. $data['company'] = '';
  384. if (isset($data['companyNo']) && $data['companyNo'] != "") {
  385. // $company = Db::name("business")->where(["companyNo"=>$data['companyNo']])->find();
  386. $data['company'] = $tmp['data'][$data['companyNo']] ?? '';
  387. }
  388. //$data['company'] = isset($company['company'])?$company['company']:"";
  389. //$data['info'] = $var;
  390. $data['purcheaseback'] = $var;
  391. //补充orderCode
  392. $data['orderCode'] = Db::name('order_num')
  393. ->where('cgdNo', $data['cgdNo'])
  394. ->value('orderCode', '');
  395. // //补充收货地址
  396. // $addr = Db::name('order_addr')
  397. // ->field('id,addr,addr_code,contactor,mobile,receipt_quantity')
  398. // ->where(['orderCode' => $data['orderCode'], 'is_del' => 0])
  399. // ->select()
  400. // ->toArray();
  401. // if (!empty($addr)) {
  402. // foreach ($addr as &$vv){
  403. // $temp = explode(',', $vv['addr_code']);
  404. // $temp_ = GetAddr(json_encode(['provice_code' => isset($temp[0]) ? $temp[0] : '', 'city_code' => isset($temp[1]) ? $temp[1] : '', 'area_code' => isset($temp[2]) ? $temp[2] : '']));
  405. // $vv['addr_code'] = $temp_ . $vv['addr'];
  406. // }
  407. // }else
  408. $addr=[];
  409. $data['addr_info'] = $addr;
  410. $data['has_account'] = (int)isset(checkHasAccountBySupplierNos([$data['supplierNo']])[$data['supplierNo']]);
  411. //补充商品创建人字段
  412. $data['good_createrid']=$goon['createrid']??'';
  413. $data['good_creater']=$goon['creater']??'';
  414. return app_show(0, "获取成功", $data);
  415. }
  416. public function edit(){
  417. $cgdNo = isset($this->post['cgdNo']) && $this->post['cgdNo']!="" ?trim($this->post['cgdNo']):"";
  418. if($cgdNo==""){
  419. return error_show(1004,"参数cgdNo 不能为空");
  420. }
  421. $data = Db::name("purchease_order")->where(["cgdNo"=>$cgdNo,"is_del"=>0])->find();
  422. if(empty($data)){
  423. return error_show(1004,"未找到数据");
  424. }
  425. $order = ["order_code"=>$cgdNo,"status"=> $data['status'] ,"action_remark"=>$this->post['remark'],"action_type"=>"edit"];
  426. $wsm_code = isset($this->post['wsm_code'])&&$this->post['wsm_code']!=""? trim($this->post['wsm_code']):"";
  427. if($wsm_code!=""){
  428. $ware = Db::name("warehouse_info")->where(["wsm_code"=>$wsm_code,"is_del"=>0])->find();
  429. if(empty($ware)){
  430. return error_show(1004,"未找到仓库信息");
  431. }
  432. // $good = Db::name("good_stock")->where(["wsm_code"=>$wsm_code,"good_type_code"=>$data['good_type_code'],"is_del"=>0])->find();
  433. // if(empty($good)){
  434. // return error_show(1004,"未找到仓库下商品信息");
  435. // }
  436. $data['wsm_code'] = $wsm_code;
  437. }
  438. $cgdid = isset($this->post['cgder_id'])&&$this->post['cgder_id']!=""?intval($this->post['cgder_id']):"";
  439. if($cgdid!=''){
  440. $cgduser = GetInfoById($this->post['token'],["id"=>$cgdid]);
  441. if((!empty($cgduser) && $cgduser['code']!=0) ||empty($cgduser) ){
  442. return error_show($cgduser['code'],$cgduser['message']);
  443. }
  444. $userinfo = $cgduser['data'];
  445. $data['cgder_id'] = $cgdid;
  446. $data['cgder'] = $userinfo['nickname'];
  447. }
  448. $good_num = isset($this->post['good_num'])&&$this->post['good_num']!=""?intval($this->post['good_num']):"";
  449. if($good_num!=""){
  450. $data['good_num'] = $good_num;
  451. }
  452. $good_price = isset($this->post['good_price'])&&$this->post['good_price']!=""?$this->post['good_price']:"";
  453. if($good_price!=""){
  454. $data['good_price'] = $good_price;
  455. }
  456. // $total_fee = isset($this->post['total_fee'])&&$this->post['total_fee']!=""?$this->post['total_fee']:"";
  457. // if($total_fee!=""){
  458. // $data['total_fee'] = $total_fee;
  459. // }
  460. $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!=""?$this->post['pakge_fee']:"";
  461. if($pakge_fee!=""){
  462. $data['pakge_fee'] = $pakge_fee;
  463. }
  464. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!=""?$this->post['cert_fee']:"";
  465. if($cert_fee!=""){
  466. $data['cert_fee'] = $cert_fee;
  467. }
  468. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!=""?$this->post['open_fee']:"";
  469. if($open_fee!=""){
  470. $data['open_fee'] = $open_fee;
  471. }
  472. $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!=""?$this->post['delivery_fee']:"";
  473. if($delivery_fee!=""){
  474. $data['delivery_fee'] = $delivery_fee;
  475. }
  476. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!=""?$this->post['mark_fee']:"";
  477. if($mark_fee!=""){
  478. $data['mark_fee'] = $mark_fee;
  479. }
  480. $teach_fee = isset($this->post['teach_fee'])&&$this->post['teach_fee']!=""?$this->post['teach_fee']:"";
  481. if($teach_fee!=""){
  482. $data['teach_fee'] = $teach_fee;
  483. }
  484. $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!=""?$this->post['nake_fee']:"";
  485. if($nake_fee!=""){
  486. $data['nake_fee'] = $nake_fee;
  487. }
  488. $weight = isset($this->post['weight'])&&$this->post['weight']!=""?$this->post['weight']:"";
  489. if($weight!=""){
  490. $data['weight'] = $weight;
  491. }
  492. $diff_weight = isset($this->post['diff_weight'])&&$this->post['diff_weight']!=""?$this->post['diff_weight']:"";
  493. if($diff_weight!=""){
  494. $data['diff_weight'] = $diff_weight;
  495. }
  496. $diff_fee = isset($this->post['diff_fee'])&&$this->post['diff_fee']!=""?$this->post['diff_fee']:"";
  497. if($diff_fee!=""){
  498. $data['diff_fee'] = $diff_fee;
  499. }
  500. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""?trim($this->post['supplierNo'])
  501. :"";
  502. if($supplierNo!=""){
  503. $userCommon = new \app\admin\common\User();
  504. $supplier_temp = $userCommon->handle('getCodeAndName', ['code' => $supplierNo]);
  505. // $supplier =Db::name("supplier")->where(['code'=>$supplierNo])->find();
  506. if($supplier_temp['code']!=0 || empty($supplier_temp['data']) ) return error_show(1004,"未找到供应商信息");
  507. // if(empty($supplier)){
  508. // return error_show(1004,"未找到供应商信息");
  509. // }
  510. $data['supplierNo'] = $supplierNo;
  511. $data['supplier_name'] = $supplier_temp['data'][$supplierNo]??"";
  512. }
  513. $remark = isset($this->post['remark'])&&$this->post['remark']!=""?trim($this->post['remark']):"";
  514. if($remark!=""){
  515. $data['remark'] = $remark;
  516. }
  517. $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);
  518. $data['total_fee'] = round($data['good_price']*$data['good_num'],2);
  519. $data['updatetime'] =date("Y-m-d H:i:s");
  520. $upd=Db::name("purchease_order")->save($data);
  521. if($upd){
  522. // ActionLog::logAdd($this->post['token'],$order,'cgd',$data['status'],$this->post);
  523. //修改状态,添加待办
  524. ActionLog::logAdd($this->post['token'], $order, "CGD", $data['status'], $this->post);
  525. // ProcessOrder::AddProcess($this->post['token'], [
  526. // "order_type" => 'CGD',
  527. // "order_code" => $cgdNo,//销售单code
  528. // "order_id" => $data['id'],
  529. // "order_status" => $data['status'],"before_status"=>1
  530. // ]);
  531. return app_show(0,"更新成功");
  532. }else{
  533. return error_show(1004,'更新失败');
  534. }
  535. }
  536. //修改采购单
  537. public function editNew()
  538. {
  539. $param = $this->request->only(['cgdNo', 'supplierNo', 'token', 'wsm_code' => ''], 'post', 'trim');
  540. $val = Validate::rule([
  541. 'cgdNo|采购单号' => 'require',
  542. 'supplierNo|供应商编号' => 'require',
  543. 'token' => 'require',
  544. ]);
  545. if (!$val->check($param)) return error_show(1004, $val->getError());
  546. Db::startTrans();
  547. try {
  548. $rs = Db::name('purchease_order')
  549. ->alias('po')
  550. ->field('po.id,po.order_type,po.order_source,po.status,po.cgder_id,po.cgder,po.supplierNo,po.supplier_name,po.wsm_code,wi.name wsm_name')
  551. ->leftJoin('warehouse_info wi', 'wi.wsm_code=po.wsm_code AND wi.is_del=0')
  552. ->where([
  553. 'po.cgdNo' => $param['cgdNo'],
  554. 'po.is_del' => 0,
  555. 'po.status' => 0
  556. ])->find();
  557. if (empty($rs)) throw new Exception('采购单不存在或不允许修改');
  558. $update = ['updatetime' => date('Y-m-d H:i:s')];
  559. //order_type==1备库
  560. if ($rs['order_type'] == 1 && $rs['order_source']==0) {
  561. if (empty($param['wsm_code'])) throw new Exception('备库单请传入仓库编码');
  562. else {
  563. $wsm_rs = Db::name('warehouse_info')
  564. ->field('id,wsm_code,name wsm_name')
  565. ->where([
  566. 'wsm_code' => $param['wsm_code'],
  567. 'is_del' => 0,
  568. ])->find();
  569. if (empty($wsm_rs)) throw new Exception('查不到该仓库的记录');
  570. else $update['wsm_code'] = $wsm_rs['wsm_code'];
  571. }
  572. }
  573. //供应商信息
  574. // $supplier_rs = Db::name('supplier')
  575. // ->field('id,name supplierName,code supplierNo,person,personid')
  576. // ->where(['is_del' => 0, 'code' => $param['supplierNo']])
  577. // ->find();
  578. $userCommon= new \app\admin\common\User();
  579. $supplier_temp =$userCommon->handle("sInfo",["code"=>$param['supplierNo']]);
  580. if ($supplier_temp['code']!=0 || empty($supplier_temp['data'])) throw new Exception('查不到该供应商的记录');
  581. else {
  582. $supplier_rs=$supplier_temp['data'];
  583. $update['cgder_id'] = $supplier_rs['personid'];
  584. $update['cgder'] = $supplier_rs['person'];
  585. $update['supplierNo'] = $supplier_rs['code'];
  586. $update['supplier_name'] = $supplier_rs['name'];
  587. }
  588. //是否修改内容确定
  589. if (isset($update['wsm_code'])) {
  590. if ($update['wsm_code'] == $rs['wsm_code'] && $update['supplierNo'] == $rs['supplierNo']) throw new Exception('没有修改的内容,不能提交');
  591. } elseif ($update['supplierNo'] == $rs['supplierNo']) throw new Exception('没有修改的内容,不能提交');
  592. if ($update['supplierNo'] == $rs['supplierNo'] && $param['wsm_code'] == $rs['wsm_code']) throw new Exception('没有修改的内容');
  593. //修改
  594. Db::name('purchease_order')
  595. ->where([
  596. 'id' => $rs['id'],
  597. 'is_del' => 0,
  598. 'status' => 0
  599. ])->update($update);
  600. $user = GetUserInfo($param['token']);
  601. $creater_id = isset($user['data']['id']) ? $user['data']['id'] : 0;
  602. $creater = isset($user['data']['nickname']) ? $user['data']['nickname'] : '';
  603. //添加修改记录
  604. Db::name('purchease_change_supplier_log')
  605. ->insert([
  606. 'cgdNo' => $param['cgdNo'],
  607. 'cgder_id_old' => $rs['cgder_id'],
  608. 'cgder_id' => $update['cgder_id'],
  609. 'cgder_old' => $rs['cgder'],
  610. 'cgder' => $update['cgder'],
  611. 'supplierNo_old' => $rs['supplierNo'],
  612. 'supplierNo' => $update['supplierNo'],
  613. 'supplier_name_old' => $rs['supplier_name'],
  614. 'supplier_name' => $update['supplier_name'],
  615. 'wsm_code_old' => $rs['wsm_code'],
  616. 'wsm_code' => isset($update['wsm_code']) ? $update['wsm_code'] : $rs['wsm_code'],
  617. 'wsm_name_old' => $rs['wsm_name'],
  618. 'wsm_name' => isset($wsm_rs['wsm_name']) ? $wsm_rs['wsm_name'] : $rs['wsm_name'],
  619. 'addtime' => date('Y-m-d H:i:s'),
  620. 'updatetime' => date('Y-m-d H:i:s'),
  621. 'creater_id' => $creater_id,
  622. 'creater' => $creater,
  623. ]);
  624. //记录日志
  625. ActionLog::logAdd(['id' => $creater_id, 'nickname' => $creater], $rs, "CGD", $rs['status'], $param);
  626. // ProcessOrder::AddProcess($this->post['token'], [
  627. // "order_type" => 'CGD',
  628. // "order_code" => $param['cgdNo'],//销售单code
  629. // "order_id" => $rs['id'],
  630. // "order_status" => $rs['status']
  631. // ]);
  632. //维护台账
  633. Db::name('standing_book')
  634. ->where('cgdNo', $param['cgdNo'])
  635. ->update(['supplierNo' => $param['supplierNo'], 'updatetime' => date('Y-m-d H:i:s')]);
  636. Db::commit();
  637. return app_show(0, '修改成功');
  638. } catch (Exception $exception) {
  639. Db::rollback();
  640. return error_show(1005, $exception->getMessage());
  641. }
  642. }
  643. public function status()
  644. {
  645. $cgdNo = isset($this->post['cgdNo']) && $this->post['cgdNo'] != "" ? $this->post['cgdNo'] : [];
  646. if (empty($cgdNo)) {
  647. return error_show(1004, "参数cgdNo 不能为空");
  648. }
  649. $remark = isset($this->post['remark']) && $this->post['remark'] != "" ? trim($this->post['remark']) : "";
  650. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  651. if ($status === "") {
  652. return error_show(1004, "参数status 不能为空");
  653. }
  654. Db::startTrans();
  655. try {
  656. if ($status == 0) {
  657. $data = Db::name("purchease_order")
  658. ->field('id,cgdNo,spuCode')
  659. ->whereIn('cgdNo', $cgdNo)
  660. ->where(["is_del" => 0])
  661. ->where('send_status', '>', 1)
  662. ->find();
  663. if (!empty($data)) throw new Exception($data['cgdNo'] . "采购单发货中无法取消");
  664. }
  665. // if($data['send_status']>1 && $status==0){
  666. // return error_show(1004,"采购单发货中无法取消");
  667. // }
  668. // $order = ["order_code"=>$cgdNo,"status"=> $data['status'] ,"action_remark"=>$remark,"action_type"=>"status"];
  669. // $data['status'] = $status;
  670. // $data['remark'] = $remark;
  671. // $data['updatetime'] =date("Y-m-d H:i:s");
  672. //原始数据
  673. $info = Db::name("purchease_order")
  674. ->whereIn('cgdNo', $cgdNo)
  675. ->column('id,cgdNo,status,supplierNo,spuCode,order_type', 'cgdNo');
  676. $upd = Db::name("purchease_order")
  677. ->whereIn('cgdNo', $cgdNo)
  678. ->save([
  679. 'status' => $status,
  680. 'remark' => $remark,
  681. 'updatetime' => date("Y-m-d H:i:s"),
  682. ]);
  683. if ($upd) {
  684. //获取供应商的负责人
  685. $userCommon = new \app\admin\common\User();
  686. $supplier = $userCommon->handle('sGetList',['more_code'=>array_column($info, 'supplierNo')]);
  687. $supplier_cgderid = array_column($supplier['data']['list'],'personid','code');
  688. // $supplier_cgderid = Db::name('supplier')
  689. // ->where('is_del', 0)
  690. // ->whereIn('code', array_column($info, 'supplierNo'))
  691. // ->column('personid', 'code');
  692. // ->leftJoin('supplier sip', 'sip.code=po.supplierNo')
  693. // ->field('po.*,on.orderCode,u.itemid,sip.personid as supplier_cgderid,sip.person as supplier_cgder')
  694. // $user=GetUserInfo($this->post['token']);
  695. $uid = $this->uid;
  696. $uname = $this->uname;
  697. foreach ($cgdNo as $vlue) {
  698. $isreturn = cgd_sale_return($vlue);
  699. if($isreturn){
  700. throw new Exception("{$vlue}关联销售单存在退货单正在进行");
  701. }
  702. if($status == 1){
  703. if($this->level == 2 && $uid != $supplier_cgderid[$info[$vlue]['supplierNo']]) throw new Exception('只能由供应商负责人来操作');//与供应商确认的这个操作,只能由供应商负责人来操作
  704. }
  705. if ($status == 1 || $status == 2) {
  706. // $orderinfo = Db::name('sale')
  707. // ->alias('a')
  708. // ->field('a.id,a.orderCode,a.is_stock,a.order_type,a.cgderid')
  709. // ->leftJoin('order_num b','b.orderCode=a.orderCode')
  710. // ->where([
  711. // 'a.is_del'=>0,
  712. // 'b.cgdNo'=>$vlue,
  713. // ])->findOrEmpty();
  714. // $is_stock = Db::name('good_basic')
  715. // ->where(['is_del' => 0, 'spuCode' => $info[$vlue]['spuCode']])
  716. // ->value('is_stock');
  717. // if ($is_stock == 1) {
  718. // //库存品,推给31库管人员、41库管-张凯旋
  719. // $uids = Db::name('user_role')
  720. // ->where([
  721. // ['is_del', '=', 0],
  722. // ['roleid', 'in', [31, 41]],
  723. // ['status', '=', 1]
  724. // ])->column('uid');
  725. //// if (!in_array($this->uid, $uids)) throw new Exception('库存品订单只能由库管人员操作');
  726. // $process = ["order_code" => $vlue, "order_id" => isset($info[$vlue]['id']) ? $info[$vlue]['id'] : 0, "order_status" => $status, "order_type" => 'CGD', "before_status" => isset($info[$vlue]['status']) ? $info[$vlue]['status'] : 0, 'holder_id' => isset($supplier_cgderid[$info[$vlue]['supplierNo']]) ? $supplier_cgderid[$info[$vlue]['supplierNo']] : 0, 'handle_user_list' => implode(',', $uids)];
  727. // } elseif ($is_stock == 0 || $info[$vlue]['order_type'] == 3) {
  728. //非库存品和采返商品,推给供应商负责人
  729. // if ($this->uid != $supplier_cgderid[$info[$vlue]['supplierNo']]) throw new Exception('非库存品和采返商品只能由供应商负责人操作');
  730. $process = ["order_code" => $vlue, "order_id" => isset($info[$vlue]['id']) ? $info[$vlue]['id'] : 0, "order_status" => $status, "order_type" => 'CGD', "before_status" => isset($info[$vlue]['status']) ? $info[$vlue]['status'] : 0, 'holder_id' => isset($supplier_cgderid[$info[$vlue]['supplierNo']]) ? $supplier_cgderid[$info[$vlue]['supplierNo']] : 0, 'handle_user_list' => isset($supplier_cgderid[$info[$vlue]['supplierNo']]) ? $supplier_cgderid[$info[$vlue]['supplierNo']] : 0];
  731. // }
  732. } else $process = ["order_code" => $vlue, "order_id" => isset($info[$vlue]['id']) ? $info[$vlue]['id'] : 0, "order_status" => $status, "order_type" => 'CGD', "before_status" => isset($info[$vlue]['status']) ? $info[$vlue]['status'] : 0, 'holder_id' => isset($supplier_cgderid[$info[$vlue]['supplierNo']]) ? $supplier_cgderid[$info[$vlue]['supplierNo']] : 0];
  733. ProcessOrder::AddProcess(['id' => $uid, 'nickname' => $uname], $process);
  734. $order = ["order_code" => $vlue, "status" => '', "action_remark" => $remark, "action_type" => "status"];
  735. ActionLog::logAdd(['id' => $uid, 'nickname' => $uname], $order, 'CGD', $status, $this->post);
  736. }
  737. // return app_show(0, "更新成功");
  738. } else throw new Exception('更新失败');
  739. // return error_show(1004, '更新失败');
  740. Db::commit();
  741. return app_show(0, "更新成功");
  742. } catch (Exception $exception) {
  743. Db::rollback();
  744. return error_show(1004, '更新失败,' . $exception->getMessage());
  745. }
  746. }
  747. //创建采购工差单
  748. public function diffcreat(){
  749. $token = isset($this->post['token']) && $this->post['token'] !=="" ?trim($this->post['token']):"";
  750. //$cgdNo=makeNo("CG");
  751. $cgdNo = $this->post['cgdNo'] && $this->post['cgdNo'] !=="" ? trim($this->post['cgdNo']) :"";
  752. if($cgdNo==""){
  753. return error_show(1002,"参数good_code不能为空");
  754. }
  755. $cg = Db::name('purchease_order')->where(['cgdNo'=>$cgdNo,'is_del'=>0])->find();
  756. if($cg==""){
  757. return error_show(1002,"未找到采购单数据");
  758. }
  759. if($cg['order_type']==3){
  760. $gd = Db::name("good_zixun")->where(["spuCode"=>$cg['spuCode']])->find();
  761. }else {
  762. $gd =Db::name('good_basic')->where(['spuCode'=>$cg['spuCode']])->find();
  763. }
  764. if($gd==""){
  765. return error_show(1002,"未找到商品数据");
  766. }
  767. $diff_weight = isset($this->post['diff_weight']) && $this->post['diff_weight'] !=="" ? floatval($this->post['diff_weight']) :"";
  768. if($diff_weight===""){
  769. return error_show(1002,"参数diff_weight不能为空");
  770. }
  771. // $apply_id =GetUserInfo($token);
  772. // if(empty($apply_id)||$apply_id['code']!=0){
  773. // return error_show(1002,"申请人数据不存在");
  774. // }
  775. $rid= $this->uid;
  776. $rname= $this->uname;
  777. $diff_price = round($diff_weight*$cg['gold_price']+$diff_weight*$cg['teach_fee'],2);
  778. //如果有未处理的工差单,不允许创建新的
  779. $wait_check = Db::name('purchease_diff')
  780. ->field('id')
  781. ->where(['apply_id'=>$rid,'status'=>1,'is_del'=>0,"cgdNo"=>$cgdNo])
  782. ->find();
  783. if(!empty($wait_check)) return error_show('1005','您还有未处理的工差单,请先处理');
  784. $data=[
  785. "cgdNo"=>$cgdNo,
  786. "good_code"=>$cg['spuCode'],
  787. "good_name"=>$cg['good_name'],
  788. "sale_price"=>$cg['good_price'],
  789. "good_weight"=>$cg['weight']*$cg['good_num'],
  790. "good_num"=>$cg['good_num'],
  791. "apply_id"=>$rid,
  792. "apply_name"=>$rname,
  793. "diff_weight"=>$diff_weight,
  794. "diff_price"=>$diff_price,
  795. "gold_price"=>$cg['good_price'],
  796. "status"=>1,
  797. "is_del"=>0,
  798. "addtime"=>date("Y-m-d H:i:s"),
  799. "updatetime"=>date("Y-m-d H:i:s")
  800. ];
  801. Db::startTrans();
  802. try{
  803. $item = Db::name("purchease_diff")->insert($data,true);
  804. if($item>0){
  805. $sto = ["order_code"=>$cgdNo,"status"=>1,"action_remark"=>'',"action_type"=>"create"];
  806. ActionLog::logAdd(['id'=>$rid,'nickname'=>$rname],$sto,"CGGCD",1,$data);
  807. $process=["order_code"=>$cgdNo,"order_id"=>$item,"order_status"=>1,"order_type"=>'CGGCD',"before_status"=>1,'holder_id'=>$rid];
  808. ProcessOrder::AddProcess(['id'=>$rid,'nickname'=>$rname],$process);
  809. $update_standing_book_data = [
  810. 'cgd_diff_id' => $item,//采购工差单id
  811. 'updatetime' => date("Y-m-d H:i:s")
  812. ];
  813. $orderCode = Db::name("order_num")->where([["cgdNo","=",$cg['cgdNo']],["status","=",1]])->find();
  814. if($orderCode!=false){
  815. $order = Db::name("sale")->where("orderCode", '=', $orderCode['orderCode'])->find();
  816. if($order==false){
  817. Db::rollback();
  818. return error_show(1002,"未找到确认单信息");
  819. }
  820. $data=[
  821. "cgd_diffid"=>$item,
  822. "orderCode"=>$orderCode['orderCode'],
  823. "good_code"=>$cg['spuCode'],
  824. "good_name"=>$cg['good_name'],
  825. "diff_weight"=>$diff_weight,
  826. "diff_price"=>round($diff_weight*$order['gold_price']+$diff_weight*$order['cost_price'],2),
  827. "gold_price"=>$order['sale_price'],
  828. "status"=>1,
  829. "addtime"=>date("Y-m-d H:i:s"),
  830. "updatetime"=>date("Y-m-d H:i:s")
  831. ];
  832. $cgd = Db::name('sale_diff')->insert($data,true);
  833. if($cgd==0){
  834. // $sto = ["order_code"=>$cg['bkcode'],"status"=>1,"action_remark"=>'',"action_type"=>"create"];
  835. // ActionLog::logAdd($this->post['token'],$sto,"ZXGCD",1,$sto);
  836. // $process=["order_code"=>$cg['bkcode'],"order_id"=>$cgd,"order_status"=>1,"order_type"=>'ZXGCD'];
  837. // ProcessOrder::AddProcess($this->post['token'],$process);
  838. // Db::commit();
  839. // return error_show(0,"新建成功");
  840. // }else{
  841. Db::rollback();
  842. return error_show(1002,"新建失败");
  843. }
  844. $sto = ["order_code"=>$orderCode['orderCode'],"status"=>1,"action_remark"=>'',"action_type"=>"create"];
  845. ActionLog::logAdd($this->post['token'],$sto,"XSGCD",1,$data);
  846. $process=["order_code"=>$orderCode['orderCode'],"order_id"=>$cgd,"order_status"=>1,"order_type"=>'XSGCD',"before_status"=>1,'holder_id'=>$order['apply_id']];
  847. ProcessOrder::AddProcess($this->post['token'],$process);
  848. $update_standing_book_data['sale_diff_id']=$cgd;//工差单id
  849. }
  850. //维护台账记录
  851. Db::name('standing_book')
  852. ->where('cgdNo', $cgdNo)
  853. ->update($update_standing_book_data);
  854. Db::commit();
  855. return error_show(0,"新建成功");
  856. }else{
  857. Db::rollback();
  858. return error_show(1002,"新建失败");
  859. }
  860. }catch (\Exception $e){
  861. Db::rollback();
  862. return error_show(1002,$e->getMessage());
  863. }
  864. }
  865. public function difflist(){
  866. $page = isset($this->post['page']) && $this->post['page'] !==""? intval($this->post['page']):"1";
  867. $size = isset($this->post['size']) && $this->post['size'] !==""? intval($this->post['size']):"10";
  868. $where = [['a.is_del',"=",0]];
  869. $cgdNo = isset($this->post['cgdNo']) && $this->post['cgdNo']!="" ? trim($this->post['cgdNo']):"";
  870. if($cgdNo!=""){
  871. $where[]=['a.cgdNo',"like", "%$cgdNo%"];
  872. }
  873. $status = isset($this->post['status']) && $this->post['status'] !==""? intval($this->post['status']):"";
  874. if($status!==""){
  875. $where[]=['a.status',"=",$status];
  876. }
  877. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  878. if ($start !="") {
  879. $where[]= ["a.addtime",'>=',$start];
  880. }
  881. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  882. if($end !=""){
  883. $where[]= ["a.addtime",'<=',$end];
  884. }
  885. $apply_name = isset($this->post['apply_name']) && $this->post['apply_name'] !==""? intval($this->post['apply_name']):"";
  886. if($apply_name!==""){
  887. $where[]=['a.apply_name',"like","%$apply_name%"];
  888. }
  889. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  890. if ($company_name !== "") $where[] = ["a.apply_id", 'in', get_company_item_user_by_name($company_name)];
  891. // $role = $this->checkDataShare();
  892. // if (!empty($role[DataGroupModel::$type_全部])) $where[] = ['a.apply_id', 'in', $role[DataGroupModel::$type_全部]];
  893. $role = $this->checkDataShare();
  894. $hand = resign_hand_user($this->uid,0);
  895. if (!empty($role[DataGroupModel::$type_全部])) {
  896. $arr= array_unique(array_merge($hand,$role[DataGroupModel::$type_全部]));
  897. $where[] = ['a.apply_id', 'in',$arr];
  898. }
  899. $count = Db::name('purchease_diff')
  900. ->alias('a')
  901. ->join("good b","b.spuCode=a.good_code","left")
  902. ->where($where)
  903. ->count();
  904. $total = ceil($count/$size);
  905. $page = $page >= $total ? $total : $page;
  906. $list = Db::name('purchease_diff')
  907. ->alias('a')
  908. ->join("good b","b.spuCode=a.good_code","left")
  909. ->where($where)
  910. ->page($page,$size)
  911. ->order("a.addtime desc")
  912. ->field("a.*,b.cat_id")
  913. ->select()
  914. ->toArray();
  915. $all_createrid = array_column($list,'apply_id');
  916. $item = get_company_name_by_uid($all_createrid);
  917. $data=[];
  918. foreach ($list as $value){
  919. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  920. $value['company_name'] = $item[$value['apply_id']]??'';
  921. //是否具有编辑权限
  922. $value['is_allow_update'] = 0;
  923. if (in_array($this->roleid, [1, 33]) || in_array($value['apply_id'], $role[DataGroupModel::$type_可编辑])) $value['is_allow_update'] = 1;
  924. $data[]=$value;
  925. }
  926. return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
  927. }
  928. public function diffinfo(){
  929. $id = isset($this->post['id']) && $this->post['id'] !=="" ? trim($this->post['id']) :"";
  930. if($id==""){
  931. return error_show(1002,"参数id 不能为空");
  932. }
  933. $idinf = Db::name('purchease_diff')->where(['id'=>$id,'is_del'=>0])->find();
  934. if($idinf==false){
  935. return error_show(1002,"未找到采购工差单数据");
  936. }
  937. $dn = Db::name('purchease_order')->where(['cgdNo'=>$idinf['cgdNo'],'is_del'=>0])->find();
  938. if($dn['order_type']==3){
  939. $goon = Db::name("good_zixun")->where(["spuCode"=>$dn['spuCode'],"is_del"=>0])->find();
  940. }else {
  941. $goon =Db::name('good_basic')->where(['spuCode'=>$dn['spuCode']])->find();
  942. }
  943. // $goon = Db::name('good')->where(['spuCode'=>$idinf['good_code']])->find();
  944. if(empty($goon)){
  945. return error_show(1002,"未找到商品数据");
  946. }
  947. $idinf['wsm_name'] ="";
  948. $idinf['wsm_supplier'] ="";
  949. $idinf['wsm_supplierNo'] ="";
  950. $idinf['wsm_contactor'] ="";
  951. $idinf['wsm_mobile'] ="";
  952. $idinf['addr_code'] ="";
  953. $idinf['wsm_addr'] ="";
  954. if($dn['wsm_code']!=""){
  955. $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code")
  956. ->leftJoin("warehouse_addr c","a.wsm_code=c.wsm_code and c.is_del=0")
  957. ->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();
  958. $idinf['wsm_name'] =isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
  959. $idinf['wsm_supplier'] =isset($wsmcode['name']) ? $wsmcode['name']:"";
  960. $idinf['wsm_supplierNo'] =isset($wsmcode['code']) ? $wsmcode['code']:"";
  961. $idinf['wsm_contactor'] =isset($wsmcode['wsm_contactor']) ? $wsmcode['wsm_contactor']:"";
  962. $idinf['wsm_mobile'] =isset($wsmcode['wsm_mobile']) ? $wsmcode['wsm_mobile']:"";
  963. $idinf['addr_code'] =isset($wsmcode['addr_code']) ? $wsmcode['addr_code']:"";
  964. $idinf['addr_cn'] =isset($wsmcode['addr_code']) ? GetAddr($wsmcode['addr_code']):"";
  965. $idinf['wsm_addr']=isset($wsmcode['wsm_addr']) ? $wsmcode['wsm_addr']:"";
  966. }
  967. $idinf['info'] =$dn;
  968. $int= isset($goon['cat_id']) && $goon['cat_id'] !=0 ? made($goon['cat_id']):[];
  969. $idinf['can']=$int;
  970. $idinf['order_type']=$dn['order_type'];
  971. $idinf['order_source']=$dn['order_source'];
  972. //取出销售的工差单信息
  973. $diff = Db::name('sale_diff')->field('id,customer_remark,is_act,remark')->where('cgd_diffid',$id)->find();
  974. $idinf['diff_customer_remark']=$diff['customer_remark'];
  975. $idinf['diff_is_act']=$diff['is_act'];
  976. $idinf['diff_remark']=$diff['remark'];
  977. return app_show(0,"获取成功",$idinf);
  978. }
  979. public function diffstatu(){
  980. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
  981. if($id==""){
  982. return error_show(1002,"参数id不能为空");
  983. }
  984. $dio = Db::name('purchease_diff')->where(['id'=>$id,'is_del'=>0])->find();
  985. if(empty($dio)){
  986. return error_show(1002,"工差订单未找到");
  987. }
  988. $cgd = Db::name("purchease_order")->where(['cgdNo'=>$dio['cgdNo']])->find();
  989. if(empty($cgd)){
  990. return error_show(1002,"采购单未找到");
  991. }
  992. $salediff=Db::name("sale_diff")->where(["cgd_diffid"=>$dio['id']])->find();
  993. if($salediff==false){
  994. return error_show(1002,"销售工差单未找到");
  995. }
  996. $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']) :"";
  997. if($status===""){
  998. return error_show(1002,"参数status不能为空");
  999. }
  1000. Db::startTrans();
  1001. try{
  1002. $temp = $dio['status'];
  1003. $dio['status']=$status;
  1004. $dio['updatetime']=date("Y-m-d H:i:s");
  1005. $item = Db::name("purchease_diff")->save($dio);
  1006. if ($item){
  1007. if($status==2){
  1008. $cgd['diff_fee'] =$dio['diff_price'];
  1009. $cgd['diff_weight'] =$dio['diff_weight'];
  1010. $cgd['updatetime'] =date("Y-m-d H:i:s");
  1011. $cgp=Db::name("purchease_order")->save($cgd);
  1012. if($cgp==false){
  1013. Db::rollback();
  1014. return error_show(1002,"采购单更新失败");
  1015. }
  1016. if($salediff['is_act']==1){
  1017. $saled=[
  1018. "diff_fee"=>$salediff['diff_price'],
  1019. "diff_weight"=>$salediff['diff_weight'],
  1020. "updatetime"=>date("Y-m-d H:i:s")
  1021. ];
  1022. $up =Db::name("sale")->where(["orderCode"=>$salediff['orderCode']])->save($saled);
  1023. if($up==false){
  1024. Db::rollback();
  1025. return error_show(1002,"销售单更新失败");
  1026. }
  1027. }
  1028. }
  1029. $sto = ["order_code" => $dio['cgdNo'], "status" => 1, "action_remark" => '', "action_type" => "create"];
  1030. ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], $sto, "CGGCD", $status, $this->post);
  1031. $process = ["order_code" => $dio['cgdNo'], "order_id" => $dio['id'], "order_status" => $status, "order_type" => 'CGGCD', "before_status" => 1, 'holder_id' => $dio['apply_id']];
  1032. ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], $process);
  1033. Db::commit();
  1034. return error_show(0,"更新成功");
  1035. }else{
  1036. Db::rollback();
  1037. return error_show(1002,"更新失败");
  1038. }
  1039. }catch (\Exception $e){
  1040. Db::rollback();
  1041. return error_show(1002,$e->getMessage()."|".$e->getLine());
  1042. }
  1043. }
  1044. //修改采购单的实时金价
  1045. public function editGoldPrice()
  1046. {
  1047. $param = $this->request->only(['cgdNo', 'gold_price'], 'post', 'trim');
  1048. $val = Validate::rule(['cgdNo|采购单号' => 'require', 'gold_price|实时金价' => 'require|float']);
  1049. if (!$val->check($param)) return error_show(1004, $val->getError());
  1050. //采购单
  1051. $data = Db::name("purchease_order")
  1052. ->field('id,demo_fee,good_num,weight,open_fee,teach_fee,pakge_fee,mark_fee,cert_fee,nake_fee,delivery_fee,status')
  1053. ->where(["cgdNo" => $param['cgdNo'], "is_del" => 0])
  1054. ->find();
  1055. if (empty($data)) return error_show(1004, "未找到该采购单数据");
  1056. if ($data['status'] != 0) return error_show(1005, '该状态下不允许修改实时金价');
  1057. $sale_price = round($data['demo_fee'] / $data['good_num'] + $data['open_fee'] / $data['good_num'] +$data['weight'] * $param["gold_price"] + $data['teach_fee'] * $data['weight'] +
  1058. $data['pakge_fee'] + $data['mark_fee'] + $data['cert_fee'] +$data['nake_fee'] + $data['delivery_fee'],2);
  1059. $total_price = round($data['good_num']*$sale_price,2);
  1060. $rs = Db::name("purchease_order")
  1061. ->where('id', $data['id'])
  1062. ->update(['updatetime' => date('Y-m-d H:i:s'), 'gold_price' => $param['gold_price'],"good_price"=>$sale_price,"total_fee"=>$total_price]);
  1063. return $rs ? app_show(0, '修改采购单实时金价成功') : error_show(1005, '修改采购单实时金价失败');
  1064. }
  1065. //采购单导出
  1066. public function exportCgdList()
  1067. {
  1068. $cgdNos = $this->request->post('cgdNos', [], 'trim');
  1069. if (empty($cgdNos)) return error_show(1004, '要导出的采购单编号不能为空');
  1070. $i = 1;
  1071. $send_type = [1 => '直接发货', 2 => '延时发货'];
  1072. $status = [0 => '待与供应商确认', 1 => '待入库', 2 => '部分入库', 3 => '入库完成', 4 => '已取消订单'];
  1073. $list = Db::name("purchease_order")
  1074. ->alias('po')
  1075. ->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 采购货款,"" as 购买方公司,s.arrive_time as 到货时间,"" 税率,oa.addr 收货地址,oa.mobile 电话,oa.contactor 联系人,s.platform_order 平台订单编号,oa.receipt_quantity 地址发货数量, oa.addr_code,po.order_type,s.supplierNo')
  1076. ->whereIn('po.cgdNo', $cgdNos)
  1077. ->leftJoin('order_num on', 'on.cgdNo=po.cgdNo')
  1078. ->leftJoin('sale s', 's.orderCode=on.orderCode AND s.is_del=0')
  1079. ->leftJoin('order_addr oa', 'oa.orderCode=on.orderCode AND oa.is_del=0')
  1080. // ->leftJoin('business b', 'b.companyNo=s.supplierNo AND b.is_del=0')
  1081. ->order("po.addtime desc")
  1082. ->withAttr('序号', function () use (&$i) {
  1083. return $i++;
  1084. })->withAttr('采购单状态', function ($val) use ($status) {
  1085. return isset($status[$val]) ? $status[$val] : '';
  1086. })->withAttr('发货方式', function ($val) use ($send_type) {
  1087. return isset($send_type[$val]) ? $send_type[$val] : '';
  1088. })->withAttr('发货方式', function ($val) use ($send_type) {
  1089. return isset($send_type[$val]) ? $send_type[$val] : '';
  1090. })
  1091. ->select()
  1092. ->toArray();
  1093. $all_supplierNo = array_column($list, 'supplierNo');
  1094. $userCommon = new \app\admin\common\User();
  1095. $tmp = $userCommon->handle('getCodeAndName', ['code' => $all_supplierNo]);
  1096. foreach ($list as &$value) {
  1097. if ($value['order_type'] == 3) {
  1098. $temp = Db::name("good_zixun")
  1099. ->where(["spuCode" => $value['产品编号'], "is_del" => 0])
  1100. ->field('id,specinfo,good_unit,tax')
  1101. ->find();
  1102. $good_unit = isset($temp['good_unit']) ? $temp['good_unit'] : 0;
  1103. $specinfo = isset($temp['specinfo']) ? json_decode($temp['specinfo'], true) : [];
  1104. $speclist = [];
  1105. foreach ($specinfo as $val) {
  1106. $speclist[] = $val['spec_name'] . ':' . $val['spec_value_name'];
  1107. }
  1108. $value['税率'] = $temp['tax'] . '%';
  1109. } else {
  1110. $good_unit = Db::name('good_basic')
  1111. ->field('id,good_unit,tax')
  1112. ->where(['spuCode' => $value['产品编号']])
  1113. ->find();
  1114. $spec = Db::name("good_spec")
  1115. ->field('id,spec_id,spec_value_id')
  1116. ->where(["spuCode" => $value['产品编号'], "is_del" => 0])
  1117. ->select()
  1118. ->toArray();
  1119. $speclist = [];
  1120. if (!empty($spec)) {
  1121. foreach ($spec as $val) {
  1122. $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', '');
  1123. }
  1124. }
  1125. $value['税率'] = isset($good_unit['tax']) ? $good_unit['tax'] . '%' : '';
  1126. }
  1127. $value['规格'] = empty($speclist) ? '' : implode(',', $speclist);;
  1128. $value['单位'] = isset($good_unit['good_unit']) ? Db::name('unit')->where(['id' => $good_unit['good_unit'], 'is_del' => 0])->value('unit', '') : '';
  1129. if (!empty($value['addr_code'])) {
  1130. $temp = explode(',', $value['addr_code']);
  1131. $temp_ = GetAddr(json_encode(['provice_code' => $temp[0], 'city_code' => $temp[1], 'area_code' => $temp[2]]));
  1132. $value['收货地址'] = $temp_ . $value['收货地址'];
  1133. }
  1134. $value['购买方公司'] = $tmp['data'][$value['supplierNo']] ?? '';
  1135. unset($value['addr_code']);
  1136. unset($value['order_type']);
  1137. unset($value['supplierNo']);
  1138. }
  1139. $headerArr = array_keys($list[0]);
  1140. excelSave('采购单导出' . date('YmdHis'), $headerArr, $list);
  1141. }
  1142. //获取采购单修改供应商的记录列表
  1143. public function getChangeSupplierList()
  1144. {
  1145. $param = $this->request->only(['cgdNo' => '', 'start' => '', 'end' => '', 'creater' => '', 'page' => 1, 'size' => 15, 'company_name' => ''], 'post', 'trim');
  1146. $where = [['a.is_del', '=', 0]];
  1147. if (!empty($param['cgdNo'])) $where[] = ['a.cgdNo', 'like', '%' . $param['cgdNo'] . '%'];
  1148. if (!empty($param['start'])) $where[] = ['a.addtime', '>=', $param['start']];
  1149. if (!empty($param['end'])) $where[] = ['a.addtime', '<=', $param['end'] . ' 23:59:59'];
  1150. if (!empty($param['creater'])) $where[] = ['a.creater', 'like', '%' . $param['creater'] . '%'];
  1151. if (!empty($param['company_name'])) $where[] = ["a.creater_id", 'in', get_company_item_user_by_name($param['company_name'])];
  1152. $count = Db::name('purchease_change_supplier_log')
  1153. ->alias('a')
  1154. ->where($where)
  1155. ->count('a.id');
  1156. $list = Db::name('purchease_change_supplier_log')
  1157. ->alias('a')
  1158. ->where($where)
  1159. ->order('a.id', 'desc')
  1160. ->page($param['page'], $param['size'])
  1161. ->select()
  1162. ->toArray();
  1163. $all_createrid = array_column($list,'createrid');
  1164. $item = get_company_name_by_uid($all_createrid);
  1165. foreach ($list as &$value){
  1166. $val['company_name']=$item[$value['createrid']]??'';
  1167. }
  1168. return app_show(0, '获取成功', ['list' => $list, 'count' => $count]);
  1169. }
  1170. // public function create(){
  1171. // $customer = isset($this->post['customer_code'])&&$this->post['customer_code']!="" ?trim($this->post['customer_code']):"";
  1172. // if($customer==""){
  1173. // return error_show(1004,"参数customer_code不能为空");
  1174. // }
  1175. // $supplier = isset($this->post['supplier_code'])&&$this->post['supplier_code']!="" ?trim($this->post['supplier_code']):"";
  1176. // if($supplier==""){
  1177. // return error_show(1004,"参数supplier_code不能为空");
  1178. // }
  1179. // $good_code = isset($this->post['good_code']) && $this->post['good_code']!=""?trim($this->post['good_code']):"";
  1180. // if($good_code==""){
  1181. // return error_show(1004,"参数good_code不能为空");
  1182. // }
  1183. // $good_num = isset($this->post['good_num'])&& $this->post['good_num']!==""? intval($this->post['good_num']):"";
  1184. // if($good_num===""){
  1185. // return error_show(1004,"参数good_code不能为空");
  1186. // }
  1187. // $file_url = isset($this->post['file_url'])&& $this->post['file_url']!==""? trim($this->post['file_url']):"";
  1188. // if($file_url===""){
  1189. // return error_show(1004,"参数file_url不能为空");
  1190. // }
  1191. // $mark =isset($this->post['remark'])&&$this->post['remark']!=""?trim($this->post['remark']):"";
  1192. // if($mark==""){
  1193. // return error_show(1004,"参数remark不能为空");
  1194. // }
  1195. //
  1196. // $data=[
  1197. // ""
  1198. // ];
  1199. // }
  1200. }