Purch.php 68 KB

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