Purch.php 66 KB

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