Purch.php 66 KB

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