SupplierClient.php 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108
  1. <?php
  2. namespace app\admin\controller;
  3. use think\App;
  4. use think\facade\Db;
  5. class SupplierClient extends Base {
  6. public function __construct(App $app) {parent::__construct($app);}
  7. /**供应商销售单列表
  8. * @return \think\response\Json|void
  9. * @throws \think\db\exception\DataNotFoundException
  10. * @throws \think\db\exception\DbException
  11. * @throws \think\db\exception\ModelNotFoundException
  12. */
  13. public function cgdlist(){
  14. $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']):"1";
  15. $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']):"10";
  16. $where = [['po.is_del', "=", 0]];
  17. $bkcode = isset($this->post['bk_code']) && $this->post['bk_code']!="" ? trim($this->post['bk_code']):"";
  18. if($bkcode!==""){
  19. $where[]=['po.bkcode',"like", "%{$bkcode}%"];
  20. }
  21. $status = isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
  22. if($status!==""){
  23. $where[]=['po.status',"=", $status];
  24. }
  25. $cgdNo = isset($this->post['cgdNo']) && $this->post['cgdNo']!="" ? trim($this->post['cgdNo']) :"";
  26. if($cgdNo!==""){
  27. $where[]=['po.cgdNo',"like", "%{$cgdNo}%"];
  28. }
  29. $apply_name = isset($this->post['apply_name']) && $this->post['apply_name']!="" ? trim($this->post['apply_name']):"";
  30. if($apply_name!==""){
  31. $where[]=['po.cgder',"like", "%{$apply_name}%"];
  32. }
  33. $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code']!="" ? trim($this->post['wsm_code']):"";
  34. if($wsm_code!==""){
  35. $where[]=['po.wsm_code',"=", $wsm_code];
  36. }
  37. $wsm_in_code = isset($this->post['wsm_in_code']) && $this->post['wsm_in_code']!="" ? trim($this->post['wsm_in_code']):"";
  38. if($wsm_in_code!==""){
  39. $incode = Db::name("purchease_in")->where(["wsm_in_code"=>Db::raw(" like %{$wsm_in_code}%"),"is_del"=>0])->column("cgdNo");
  40. if(empty($incode)){
  41. return error_show(1004,"未找到有关入库单信息");
  42. }
  43. $where[]=['po.cgdNo',"in", $incode];
  44. }
  45. $good_name = isset($this->post['good_name']) && $this->post['good_name']!="" ? trim($this->post['good_name']):"";
  46. if($good_name!==""){
  47. $where[]=['po.good_name',"like", "%{$good_name}%"];
  48. }
  49. $good_code = isset($this->post['good_code']) && $this->post['good_code']!="" ? trim($this->post['good_code']) :"";
  50. if($good_code!==""){
  51. $where[]=['po.spuCode',"like", "%{$good_code}%"];
  52. }
  53. $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo']!="" ? trim($this->post['supplierNo']) :"";
  54. if($supplierNo!==""){
  55. $where[]=['po.supplierNo',"=", $supplierNo];
  56. }
  57. $wsm_supplierNo = isset($this->post['wsm_supplierNo']) && $this->post['wsm_supplierNo']!="" ? trim($this->post['wsm_supplierNo']) :"";
  58. if($wsm_supplierNo!==""){
  59. $wsmcode = Db::name("warehouse_info")->where(["is_del"=>0,"supplierNo"=>$wsm_supplierNo])->column("wsm_code");
  60. $where[]=['po.wsm_code',"in", $wsmcode];
  61. }
  62. $start = isset($this->post['start']) && $this->post['start']!="" ?$this->post['start']:"";
  63. if($start!==""){
  64. $where[]=['po.addtime',">=", $start." 00:00:00"];
  65. }
  66. $end = isset($this->post['end']) && $this->post['end']!="" ?$this->post['end']:"";
  67. if($end!==""){
  68. $where[]=['po.addtime',"<=", $end." 23:59:59"];
  69. }
  70. $last_start = isset($this->post['last_start']) && $this->post['last_start']!="" ?$this->post['last_start']:"";
  71. if($last_start!==""){
  72. $where[]=['po.lasttime',">=", $last_start." 00:00:00"];
  73. }
  74. $last_end = isset($this->post['last_end']) && $this->post['last_end']!="" ?$this->post['last_end']:"";
  75. if($last_end!==""){
  76. $where[]=['po.lasttime',"<=", $last_end." 23:59:59"];
  77. }
  78. $orderCode = isset($this->post['orderCode']) && $this->post['orderCode']!="" ?$this->post['orderCode']:"";
  79. if($orderCode!==""){
  80. $where[]=['on.orderCode',"like", '%'.$orderCode.'%'];
  81. }
  82. //筛选供应商名称
  83. $supplier_name = isset($this->post['supplier_name']) && $this->post['supplier_name'] != "" ? $this->post['supplier_name'] : "";
  84. if ($supplier_name != '') $where[] = ['po.supplier_name', 'like', '%' . $supplier_name . '%'];
  85. $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo'] != "" ? trim($this->post['relaComNo']) : "";
  86. if ($relaComNo !== "") $where[] = ['po.companyNo', '=', $relaComNo];
  87. $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo'] != "" ? trim($this->post['relaComNo']) : "";
  88. $userCommon = new \app\admin\common\User();
  89. // //只有level2的账号过滤数据权限
  90. if ($this->level == 2) {
  91. $role = $this->checkDataShare();
  92. $hand = resign_hand_user($this->uid, 0);
  93. if (!empty($role[DataGroupModel::$type_全部])) {
  94. $arr = array_unique(array_merge($hand, $role[DataGroupModel::$type_全部]));
  95. $supplierNos = Db::connect('mysql_sys')
  96. ->name('supplier')
  97. ->where(['is_del' => 0, 'personid' => $arr])
  98. ->column('code');
  99. $where[] = ['po.supplierNo', 'in', $supplierNos];
  100. }
  101. if ($relaComNo !== "") $where[] = ['po.companyNo', '=', $relaComNo];
  102. }
  103. if ($this->level == 3) {
  104. if ($relaComNo !== "") $where[] = ['po.supplierNo', '=', $relaComNo];
  105. }
  106. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  107. if ($company_name !== "") $where[] = ["po.cgder_id", 'in', get_company_item_user_by_name($company_name)];
  108. $order_type = isset($this->post['order_type']) && $this->post['order_type'] !== "" ? intval($this->post['order_type']) : "";
  109. if ($order_type !== "") $where[] = ["po.order_type", '=', $order_type];
  110. $order_source = isset($this->post['order_source']) && $this->post['order_source'] !== "" ? intval($this->post['order_source']) : "";
  111. if ($order_source !== "") $where[] = ["po.order_source", '=', $order_source];
  112. $count = Db::name("purchease_order")
  113. ->alias('po')
  114. ->leftJoin('order_num on', 'on.cgdNo=po.cgdNo')
  115. ->leftJoin("depart_user u", "u.uid=po.cgder_id AND u.is_del=0")
  116. ->where($where)
  117. ->where(function ($query) use ($where) {
  118. $query->whereOr([['po.order_type', '<>', 1], ['po.order_source', '=', 0]]);
  119. })->count();
  120. $total = ceil($count/$size);
  121. $page = $page >= $total ? $total : $page;
  122. $list = Db::name("purchease_order")
  123. ->alias('po')
  124. ->leftJoin('order_num on','on.cgdNo=po.cgdNo')
  125. ->field('po.*,on.orderCode,"" supplier_cgderid,"" supplier_cgder')
  126. ->where($where)
  127. ->where(function($query) use ($where){$query->whereOr([['po.order_type', '<>', 1],['po.order_source', '=', 0]]);})
  128. ->page($page,$size)
  129. ->order("po.addtime desc")
  130. ->select()
  131. ->toArray();
  132. $account = checkHasAccountBySupplierNos(array_column($list,'supplierNo'));
  133. $all_createrid = array_column($list,'cgder_id');
  134. $item = get_company_name_by_uid($all_createrid);
  135. $data=[];
  136. $wsmCodes = array_column($list, 'wsm_code');
  137. $wsmcode = Db::name("warehouse_info")
  138. ->alias("a")
  139. ->where(["a.wsm_code" => $wsmCodes])
  140. ->column("a.name as wsm_name,a.supplierNo as code", "wsm_code");
  141. $names = $userCommon->handle('getCodeAndName', ['code' => array_unique(array_merge(array_column($wsmcode,"code"),array_column($list,"companyNo")))]);
  142. $person_list = $userCommon->handle('sGetList', ['more_code' => array_unique(array_column($list, 'supplierNo')), 'size' => $size]);
  143. $person_list = array_column($person_list['data']['list'], null, 'code');
  144. foreach ($list as $value){
  145. $value['wsm_name'] = $value['wsm_code'] != '' ? $wsmcode[$value['wsm_code']]['wsm_name'] ?? '' : "";
  146. $value['wsm_supplier'] = $value['wsm_code'] != '' ? $person_list[$wsmcode[$value['wsm_code']]['code']]['name'] ?? "" : '';
  147. $value['wsm_supplierNo'] = $value['wsm_code'] != '' ? $wsmcode[$value['wsm_code']]['code'] ?? "" : '';
  148. $value['supplier_cgderid'] = $person_list[$value['supplierNo']]['personid'] ?? '';
  149. $value['supplier_cgder'] = $person_list[$value['supplierNo']]['person'] ?? '';
  150. $value['companyName'] = $names['data'][$value['companyNo']] ?? '';
  151. if($value['order_type']==3){
  152. $goon = Db::name("good_zixun")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->find();
  153. $value["speclist"]=isset($goon['specinfo'])&&$goon['specinfo']!=""? json_decode($goon['specinfo'],true):"";
  154. //为了格式统一,缺了一个spec_value
  155. if ($value['speclist'] != '') {
  156. foreach ($value['speclist'] as &$v) {
  157. $v['spec_value'] = $v['spec_value_name'];
  158. }
  159. }
  160. }else {
  161. $goon =Db::name('good_basic')->where(['spuCode'=>$value['spuCode']])->find();
  162. $spec = Db::name("good_spec")->where(["spuCode"=>$goon['spuCode'],"is_del"=>0])->select()->toArray();
  163. $speclist=[];
  164. if(!empty($spec)){
  165. foreach ($spec as $val){
  166. $temp=[];
  167. $temp['id']=$val['id'];
  168. $temp['spuCode']=$val['spuCode'];
  169. $temp['spec_id']=$val['spec_id'];
  170. $temp['spec_value_id']=$val['spec_value_id'];
  171. $sp = Db::name("specs")->where(["id"=>$val['spec_id']])->find();
  172. $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
  173. $spv = Db::name("spec_value")->where(["id"=>$val['spec_value_id']])->find();
  174. $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
  175. $speclist[]=$temp;
  176. }
  177. }
  178. $value["speclist"]=empty($speclist)?[]:$speclist;
  179. }
  180. $inorder= Db::name("purchease_in")
  181. ->where(['cgdNo'=>$value['cgdNo'],"is_del"=>0])
  182. ->select()
  183. ->toArray();
  184. $value['child']=empty($inorder)? [] : $inorder;
  185. $value['send_num'] -=$value['th_num'];
  186. $value['total_fee'] =round($value['total_fee']-$value['th_fee'],2);
  187. $value['company_name'] = $item[$value['cgder_id']]??'';
  188. $value['has_account'] = (int)isset($account[$value['supplierNo']]);
  189. $data[]=$value;
  190. }
  191. return app_show(0,"获取成功",["list"=>$data ,"count"=>$count]);
  192. }
  193. /**供应商入库单
  194. * @return \think\response\Json|void
  195. * @throws \think\db\exception\DataNotFoundException
  196. * @throws \think\db\exception\DbException
  197. * @throws \think\db\exception\ModelNotFoundException
  198. */
  199. public function cgdInList(){
  200. $page = isset($this->post['page']) && $this->post['page'] !==""? intval($this->post['page']):"1";
  201. $size = isset($this->post['size']) && $this->post['size'] !==""? intval($this->post['size']):"10";
  202. $where =[['a.is_del',"=",0],['b.is_del',"=",0]];
  203. $wsm_in_code=isset($this->post['wsm_in_code']) && $this->post['wsm_in_code']!==""? trim($this->post['wsm_in_code']) :"";
  204. if($wsm_in_code!==""){
  205. $where[]=["a.wsm_in_code",'like',"%$wsm_in_code%"];
  206. }
  207. $cgdNo= isset($this->post['cgdNo']) && $this->post['cgdNo'] !==""? trim($this->post['cgdNo']) :"";
  208. if($cgdNo!==""){
  209. $where[]=['a.cgdNo','like',"%$cgdNo%"];
  210. }
  211. $apply_name = isset($this->post['apply_name']) && $this->post['apply_name'] !==""? trim($this->post['apply_name']):"";
  212. if($apply_name!==""){
  213. $where[]=['a.apply_name','like',"%$apply_name%"];
  214. }
  215. $apply_id= isset($this->post['apply_id']) && $this->post['apply_id'] !==""? trim($this->post['apply_id']):"";
  216. if($apply_id!==""){
  217. $where[]=['a.apply_id','=',$apply_id];
  218. }
  219. $status= isset($this->post['status']) && $this->post['status'] !==""? trim($this->post['status']):"";
  220. if($status!==""){
  221. $where[]=['a.status','=',$status];
  222. }
  223. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  224. if ($start !=="") {
  225. $where[]= ["a.sendtime",'>=',$start];
  226. }
  227. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  228. if($end !==""){
  229. $where[]= ["a.sendtime",'<=',$end];
  230. }
  231. $order_type=isset($this->post['order_type']) && $this->post['order_type']!==""? intval($this->post['order_type']):"";
  232. if($order_type !==""){
  233. $where[]= ["b.order_type",'=',$order_type];
  234. }
  235. $order_source=isset($this->post['order_source']) && $this->post['order_source']!==""? intval($this->post['order_source']):"";
  236. if($order_source !=="") $where[]= ["b.order_source",'=',$order_source];
  237. $good_type_code=isset($this->post['good_type_code']) && $this->post['good_type_code']!==""? trim($this->post['good_type_code']):"";
  238. if($good_type_code !==""){
  239. $where[]= ["b.spuCode",'like',"%$good_type_code%"];
  240. }
  241. $good_name=isset($this->post['good_name']) && $this->post['good_name']!==""? trim($this->post['good_name']):"";
  242. if($good_name !==""){
  243. $where[]= ["b.good_name",'like',"%$good_name%"];
  244. }
  245. $supplie=isset($this->post['supplier']) && $this->post['supplier']!==""? trim($this->post['supplier']):"";
  246. if($supplie !==""){
  247. $where[]= ["b.supplier_name",'like',"%$supplie%"];
  248. }
  249. $wsm_code=isset($this->post['wsm_code']) && $this->post['wsm_code']!==""? trim($this->post['wsm_code']):"";
  250. if($wsm_code !==""){
  251. $where[]= ["a.wsm_code",'=',$wsm_code];
  252. }
  253. $supplierNo =isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']):"";
  254. if($supplierNo!==""){
  255. $where[]= ["b.supplierNo",'=',$supplierNo];
  256. }
  257. $condition=[];
  258. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  259. if ($company_name !== "") $where[] = ["a.apply_id", 'in', get_company_item_user_by_name($company_name)];
  260. $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo']!="" ? trim($this->post['relaComNo']):"";
  261. if($this->level==2){
  262. if($relaComNo!=='') $where[]=['b.companyNo','=', $relaComNo];
  263. $role = $this->checkDataShare();
  264. $hand = resign_hand_user($this->uid, 0);
  265. if (!empty($role[DataGroupModel::$type_全部])) {
  266. $arr = array_unique(array_merge($hand, $role[DataGroupModel::$type_全部]));
  267. if($arr){
  268. $sys_supplier = Db::connect('mysql_sys')
  269. ->name('supplier')
  270. ->field('code')
  271. ->where(['is_del'=>0,'personid'=>$arr])
  272. ->buildSql();
  273. $condition[] = ["b.supplierNo", "in", $sys_supplier];
  274. }
  275. $condition[] = ["a.apply_id", "in", $hand];
  276. $condition[] = ["c.contactor", "in", $hand];
  277. }
  278. }
  279. if($this->level==3){
  280. if($relaComNo!=='') $where[]=['b.supplierNo','=', $relaComNo];
  281. }
  282. $count = Db::name('purchease_in')
  283. ->alias('a')
  284. ->join("purchease_order b","b.cgdNo=a.cgdNo","left")
  285. ->leftJoin("warehouse_info c","a.wsm_code=c.wsm_code")
  286. ->where($where)
  287. ->where(function ($query)use ($condition){$query->whereOr($condition);})
  288. ->count();
  289. $total = ceil($count/$size);
  290. $page = $page >= $total ? $total : $page;
  291. $list = Db::name('purchease_in')
  292. ->alias('a')
  293. ->join("purchease_order b","b.cgdNo=a.cgdNo","left")
  294. ->leftJoin("warehouse_info c","a.wsm_code=c.wsm_code")
  295. ->where($where)
  296. ->where(function ($query)use ($condition){$query->whereOr($condition);})
  297. ->page($page,$size)
  298. ->field("a.apply_name,a.sendtime,b.order_type,b.order_source,a.status,a.cgdNo,a.wsm_in_code,a.send_num,a.wsm_code,b.good_name,b.spuCode,a.post_company,a.post_code,a.post_fee,a.apply_id,a.wsm_num,a.error_num,a.wait_num,a.status,a.check_name,a.checkid,b.bkcode,b.supplierNo,'' cgder_id,'' cgder,b.good_createrid,b.good_creater,c.name wsm_name,b.supplierNo,b.supplier_name,c.supplierNo wsm_supplierNo,b.companyNo")
  299. ->order("a.addtime desc")
  300. ->select()
  301. ->toArray();
  302. $all_createrid = array_column($list,'apply_id');
  303. $item = get_company_name_by_uid($all_createrid);
  304. //获取采购单供应商和仓库供应商的名称
  305. $userCommon = new \app\admin\common\User();
  306. $names = $userCommon->handle('getCodeAndName',['code'=>array_unique(array_merge(array_column($list,'companyNo'),array_column($list,'wsm_supplierNo')))]);
  307. $all_supplier = $userCommon->handle('sGetList',['more_code'=>array_column($list,'supplierNo'),'page'=>1,'size'=>$size]);
  308. $all_supplier_list = array_column($all_supplier['data']['list'],null,'code');
  309. $data=[];
  310. foreach ($list as $value){
  311. $value['cgder_id'] = $all_supplier_list[$value['supplierNo']]['personid']??'';
  312. $value['cgder'] = $all_supplier_list[$value['supplierNo']]['person']??'';
  313. //获取规格、品牌信息
  314. if ($value['order_type'] == 3) {
  315. $temp = Db::name('good_zixun')
  316. ->alias('gz')
  317. ->field('gz.specinfo,b.brand_name')
  318. ->join('brand b', 'b.id=gz.brand_id')
  319. ->where(['gz.spuCode' => $value['spuCode'], 'gz.is_del' => 0])
  320. ->find();
  321. $value["brand_name"] = $temp['brand_name'];
  322. $value["speclist"] = json_decode($temp['specinfo'], true);
  323. } else {
  324. $value['brand_name'] = Db::name('good_basic')
  325. ->alias('gb')
  326. ->join('brand b', 'b.id=gb.brand_id')
  327. ->where(['gb.spuCode' => $value['spuCode']])
  328. ->value('b.brand_name');
  329. $spec = Db::name("good_spec")
  330. ->where(["spuCode" => $value['spuCode'], "is_del" => 0])
  331. ->select()
  332. ->toArray();
  333. $speclist = [];
  334. if (!empty($spec)) {
  335. foreach ($spec as $val) {
  336. $temp = [];
  337. $temp['id'] = $val['id'];
  338. $temp['spuCode'] = $val['spuCode'];
  339. $temp['spec_id'] = $val['spec_id'];
  340. $temp['spec_value_id'] = $val['spec_value_id'];
  341. $sp = Db::name("specs")->where(["id" => $val['spec_id']])->find();
  342. $temp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
  343. $spv = Db::name("spec_value")->where(["id" => $val['spec_value_id']])->find();
  344. $temp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
  345. $speclist[] = $temp;
  346. }
  347. }
  348. $value["speclist"] = empty($speclist) ? [] : $speclist;
  349. }
  350. $value['wsm_supplier'] = $names['data'][$value['wsm_supplierNo']]??'';
  351. $value['companyName'] = $names['data'][$value['companyNo']]??'';
  352. $value['company_name'] = $item[$value['apply_id']]??'';
  353. $data[]=$value;
  354. }
  355. return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
  356. }
  357. /** 采购端退货列表
  358. * @return \think\response\Json|void
  359. * @throws \think\db\exception\DataNotFoundException
  360. * @throws \think\db\exception\DbException
  361. * @throws \think\db\exception\ModelNotFoundException
  362. */
  363. public function returnList(){
  364. $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']):"1";
  365. $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']):"10";
  366. $where = [['a.is_del',"=",0],['b.is_del',"=",0]];
  367. $cgdNo = isset($this->post['cgdNo']) && $this->post['cgdNo']!="" ? trim($this->post['cgdNo']):"";
  368. if($cgdNo!=""){
  369. $where[]=['a.cgdNo',"like", "%$cgdNo%"];
  370. }
  371. $returnCode= isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  372. if($returnCode!=""){
  373. $where[]=['a.returnCode',"like", "%$returnCode%"];
  374. }
  375. $good_type_code=isset($this->post['good_type_code']) && $this->post['good_type_code']!==""? trim($this->post['good_type_code']):"";
  376. if($good_type_code !=""){
  377. $where[]= ["b.spuCode",'like',"%$good_type_code%"];
  378. }
  379. $good_name=isset($this->post['good_name']) && $this->post['good_name']!==""? trim($this->post['good_name']):"";
  380. if($good_name !=""){
  381. $where[]= ["b.good_name",'like',"%$good_name%"];
  382. }
  383. $status=isset($this->post['status']) && $this->post['status']!==""? trim($this->post['status']):"";
  384. if($status!=""){
  385. $where[]= ["a.status",'=',$status];
  386. }
  387. $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo']!="" ? trim($this->post['relaComNo']):"";
  388. $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] != "" ? trim($this->post['supplierNo']) : "";
  389. if ($supplierNo != '') $where[] = ['b.supplierNo', '=', $supplierNo];
  390. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] != "" ? trim($this->post['companyNo']) : "";
  391. if ($companyNo != '') $where[] = ['b.companyNo', '=', $companyNo];
  392. $order_source = isset($this->post['order_source']) && $this->post['order_source'] != "" ? intval($this->post['order_source']) : "";
  393. if ($order_source != '') $where[] = ['b.order_source', '=', $order_source];
  394. $is_stock = isset($this->post['is_stock']) && $this->post['is_stock'] != "" ? intval($this->post['is_stock']) : "";
  395. if ($is_stock != '') $where[] = ['c.is_stock', '=', $is_stock];
  396. // $role = $this->checkDataShare();
  397. // if (!empty($role[DataGroupModel::$type_全部])) $where[] = ["a.apply_id", "in", $role[DataGroupModel::$type_全部]];
  398. //只有level2的账号过滤数据权限
  399. if ($this->level == 2) {
  400. $role = $this->checkDataShare();
  401. $hand = resign_hand_user($this->uid, 0);
  402. if (!empty($role[DataGroupModel::$type_全部])) {
  403. $arr = array_unique(array_merge($hand, $role[DataGroupModel::$type_全部]));
  404. $where[] = ['a.apply_id', 'in', $arr];
  405. }
  406. if($relaComNo!='') $where[]=['b.companyNo','=', $relaComNo];
  407. }
  408. if($this->level==3){
  409. if($relaComNo!='') $where[]=['b.supplierNo','=', $relaComNo];
  410. }
  411. $count = Db::name('purchease_return')
  412. ->alias('a')
  413. ->leftJoin("purchease_order b","b.cgdNo=a.cgdNo")
  414. ->leftJoin("good_basic c","c.spuCode=b.spuCode")
  415. ->where($where)
  416. ->count();
  417. $total = ceil($count / $size);
  418. $page = $page >= $total ? $total : $page;
  419. $list = Db::name('purchease_return')
  420. ->alias('a')
  421. ->leftJoin("purchease_order b","b.cgdNo=a.cgdNo")
  422. ->leftJoin("good_basic c","c.spuCode=b.spuCode")
  423. ->where($where)
  424. ->page($page,$size)
  425. ->field("a.*,b.spuCode,b.good_price,b.order_type,b.good_price,b.total_fee,b.good_name,b.order_source,c.is_stock,b.supplierNo,b.supplier_name,b.companyNo")
  426. ->order("a.addtime desc")
  427. ->select()
  428. ->toArray();
  429. $data=[];
  430. $userCommon = new \app\admin\common\User();
  431. $names = $userCommon->handle('getCodeAndName',['code'=>array_unique(array_column($list,'companyNo'))]);
  432. foreach ($list as $value){
  433. if($value['order_type']==3){
  434. $goon = Db::name("good_zixun")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->find();
  435. }else {
  436. $goon =Db::name('good_basic')->where(['spuCode'=>$value['spuCode']])->find();
  437. }
  438. $value['can']= isset($goon['cat_id']) && $goon['cat_id'] !=0 ? made($goon['cat_id']):[];
  439. $value['return_fee']= round($value['good_price']*$value['return_num'],2);
  440. $value['companyName'] = $names['data'][$value['companyNo']]??'';
  441. $data[]=$value;
  442. }
  443. return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
  444. }
  445. /**供应商端公差单列表
  446. * @return \think\response\Json|void
  447. * @throws \think\db\exception\DataNotFoundException
  448. * @throws \think\db\exception\DbException
  449. * @throws \think\db\exception\ModelNotFoundException
  450. */
  451. public function difflist(){
  452. $page = isset($this->post['page']) && $this->post['page'] !==""? intval($this->post['page']):"1";
  453. $size = isset($this->post['size']) && $this->post['size'] !==""? intval($this->post['size']):"10";
  454. $where = [['a.is_del',"=",0]];
  455. $cgdNo = isset($this->post['cgdNo']) && $this->post['cgdNo']!="" ? trim($this->post['cgdNo']):"";
  456. if($cgdNo!=""){
  457. $where[]=['a.cgdNo',"like", "%$cgdNo%"];
  458. }
  459. $status = isset($this->post['status']) && $this->post['status'] !==""? intval($this->post['status']):"";
  460. if($status!==""){
  461. $where[]=['a.status',"=",$status];
  462. }
  463. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  464. if ($start !="") {
  465. $where[]= ["a.addtime",'>=',$start];
  466. }
  467. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  468. if($end !=""){
  469. $where[]= ["a.addtime",'<=',$end];
  470. }
  471. $apply_name = isset($this->post['apply_name']) && $this->post['apply_name'] !==""? intval($this->post['apply_name']):"";
  472. if($apply_name!==""){
  473. $where[]=['a.apply_name',"like","%$apply_name%"];
  474. }
  475. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  476. if ($company_name !== "") $where[] = ["a.apply_id", 'in', get_company_item_user_by_name($company_name)];
  477. $order_source = $order_source = isset($this->post['order_source']) && $this->post['order_source'] != "" ? intval($this->post['order_source']) : "";
  478. if ($order_source !== "") $where[] = ['c.order_source', "=", $order_source];
  479. $is_stock = $order_source = isset($this->post['is_stock']) && $this->post['is_stock'] != "" ? intval($this->post['is_stock']) : "";
  480. if ($is_stock !== "") $where[] = ['b.is_stock', "=", $is_stock];
  481. $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo']!="" ? trim($this->post['relaComNo']):"";
  482. if ($this->level == 2) {
  483. $role = $this->checkDataShare();
  484. $hand = resign_hand_user($this->uid, 0);
  485. if (!empty($role[DataGroupModel::$type_全部])) {
  486. $arr = array_unique(array_merge($hand, $role[DataGroupModel::$type_全部]));
  487. $where[] = ['a.apply_id', 'in', $arr];
  488. }
  489. if($relaComNo!='') $where[]=['c.companyNo','=', $relaComNo];
  490. }
  491. if($this->level==3){
  492. if($relaComNo!='') $where[]=['c.supplierNo','=', $relaComNo];
  493. }
  494. $count = Db::name('purchease_diff')
  495. ->alias('a')
  496. ->leftJoin("good b","b.spuCode=a.good_code")
  497. ->leftJoin("purchease_order c","c.cgdNo=a.cgdNo")
  498. ->where($where)
  499. ->count();
  500. $total = ceil($count/$size);
  501. $page = $page >= $total ? $total : $page;
  502. $list = Db::name('purchease_diff')
  503. ->alias('a')
  504. ->leftJoin("good b","b.spuCode=a.good_code")
  505. ->leftJoin("purchease_order c","c.cgdNo=a.cgdNo")
  506. ->where($where)
  507. ->page($page,$size)
  508. ->order("a.addtime desc")
  509. ->field("a.*,b.cat_id,c.order_source,b.is_stock")
  510. ->select()
  511. ->toArray();
  512. $all_createrid = array_column($list,'apply_id');
  513. $item = get_company_name_by_uid($all_createrid);
  514. $data=[];
  515. foreach ($list as $value){
  516. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  517. $value['company_name'] = $item[$value['apply_id']]??'';
  518. //是否具有编辑权限
  519. $value['is_allow_update'] = 0;
  520. if (in_array($this->roleid, [1, 33]) || in_array($value['apply_id'], $role[DataGroupModel::$type_可编辑])) $value['is_allow_update'] = 1;
  521. $data[]=$value;
  522. }
  523. return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
  524. }
  525. //发货申请单列表
  526. public function orderOut()
  527. {
  528. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  529. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  530. $where = [["a.is_del", "=", 0]];
  531. $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !== "" ? trim($this->post['orderCode']) : "";
  532. if ($orderCode !== "") {
  533. $where[] = ['a.orderCode', "like", "%$orderCode%"];
  534. }
  535. $order_type = isset($this->post['order_type']) && $this->post['order_type'] !== "" ? trim($this->post['order_type']) : "";
  536. if ($order_type !== "") {
  537. $where[] = ['a.order_type', "=", $order_type];
  538. }
  539. $outCode = isset($this->post['outCode']) && $this->post['outCode'] !== "" ? trim($this->post['outCode']) : "";
  540. if ($outCode !== "") {
  541. $where[] = ['a.outCode', "like", "%$outCode%"];
  542. }
  543. $apply_name = isset($this->post['apply_name']) && $this->post['apply_name'] !== "" ? trim($this->post['apply_name']) : "";
  544. if ($apply_name !== "") {
  545. $where[] = ['a.apply_name', "like", "%$apply_name%"];
  546. }
  547. $good_code = isset($this->post['good_code']) && $this->post['good_code'] !== "" ? trim($this->post['good_code']) : "";
  548. if ($good_code !== "") {
  549. $where[] = ['b.good_code', "like", "%$good_code%"];
  550. }
  551. $good_name = isset($this->post['good_name']) && $this->post['good_name'] !== "" ? trim($this->post['good_name']) : "";
  552. if ($good_name !== "") {
  553. $where[] = ['b.good_name', "like", "%$good_name%"];
  554. }
  555. $supplier_name = isset($this->post['supplier_name']) && $this->post['supplier_name'] !== "" ? trim($this->post['supplier_name']) : "";
  556. if ($supplier_name !== "") {
  557. $where[] = ['wpo.supplier_name', "like", "%$supplier_name%"];
  558. }
  559. $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  560. if ($status !== "") {
  561. $where[] = ['a.status', "=", $status];
  562. }
  563. $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
  564. if ($start != "") {
  565. $where[] = ["a.addtime", '>=', $start . " 00:00:00"];
  566. }
  567. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
  568. if ($end != "") {
  569. $where[] = ["a.addtime", '<=', $end . " 23:59:59"];
  570. }
  571. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  572. if ($companyNo != "") {
  573. $where[] = ['b.supplierNo', "like", "%$companyNo%"];
  574. }
  575. $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo'] !== "" ? trim($this->post['relaComNo']) : "";
  576. $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !== "" ? trim($this->post['supplierNo']) : "";
  577. if ($supplierNo != '') {
  578. //sale b 表里存的supplierNo值是GS开头的,即业务公司编码
  579. //所以此处应该根据供应商编码筛选商品spuCode,然后筛选发货单
  580. // $spuCode = Db::name('good_basic')
  581. // ->where(['is_del' => 0, 'supplierNo' => $supplierNo])
  582. // ->column('spuCode');
  583. $where[] = ['b.supNo', 'like', "%$supplierNo%"];
  584. }
  585. $cgdNo = isset($this->post['cgdNo']) && $this->post['cgdNo'] !== "" ? $this->post['cgdNo'] : "";
  586. if ($cgdNo != "") {
  587. $where[] = ["os.cgdNo", 'like', '%' . $cgdNo . '%'];
  588. }
  589. $condition = '';
  590. //只有level2的账号过滤数据权限
  591. if ($this->level == 2) {
  592. $hand = resign_hand_user($this->uid, 0);
  593. $uidarr = implode(",", $hand);
  594. //库管只能看到库存品订单,供应商负责人只能看到非库存品订单
  595. if (!in_array($this->roleid, [1, 33])) {
  596. //库管看到所有的库存品发货申请单
  597. if (in_array($this->roleid, config('app.wsm_cgder_role'))) $condition .= " b.is_stock=1";
  598. else {
  599. $role = $this->checkDataShare();
  600. if (!empty($role[DataGroupModel::$type_全部])) {
  601. $arr = array_unique(array_merge($hand, $role[DataGroupModel::$type_全部]));
  602. if ($condition != '') $condition .= " or ";
  603. $condition .= " a.apply_id in (" . implode(',', $arr) . ")";
  604. }
  605. }
  606. if (!empty($hand)) {
  607. if ($condition != '') $condition .= " or ";
  608. $person_supplier = Db::connect('mysql_sys')
  609. ->name('supplier')
  610. ->where(['is_del'=>0,'personid'=>$uidarr])
  611. ->column('code');
  612. $condition .= "(b.is_stock=0 and wpo.supplierNo in ('" . implode('\',\'', $person_supplier) . "'))";
  613. }
  614. }
  615. if ($relaComNo != '') $where[] = ['b.supplierNo', '=', $relaComNo];
  616. }
  617. //供应商账号只能看到非库存品的订单
  618. if ($this->level == 3){
  619. $where[] = ['b.supNo', '=', $relaComNo];
  620. }
  621. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  622. if ($company_name !== "") $where[] = ["a.apply_id", 'in', get_company_item_user_by_name($company_name)];
  623. //发货时间筛选
  624. $start_sendtime = isset($this->post['start_sendtime']) && $this->post['start_sendtime'] !== "" ? $this->post['start_sendtime'] : "";
  625. $end_sendtime = isset($this->post['end_sendtime']) && $this->post['end_sendtime'] !== "" ? $this->post['end_sendtime'] : "";
  626. if ($start_sendtime != "" && $end_sendtime != "") {
  627. $where[] = ["a.sendtime", 'between', [$start_sendtime . " 00:00:00", $end_sendtime . " 23:59:59"]];
  628. $where[] = ["a.status", '>=', 2];//搜索发货时间时,要指定状态为已发货及之后的状态值(0待发货,1待库管发货,2已发货待收货,3已收货,4已全部退货',)
  629. }
  630. $order_source = isset($this->post['order_source']) && $this->post['order_source'] !== "" ? intval($this->post['order_source']) : "";
  631. if ($order_source !== "") $where[] = ["b.order_source", '=', $order_source];
  632. $count = Db::name('order_out')
  633. ->alias('a')
  634. ->join("sale b", "b.orderCode=a.orderCode", "left")
  635. ->join("warehouse_info n", "n.wsm_code=a.wsm_code", "left")
  636. ->leftJoin("order_send os", "os.outCode=a.outCode")
  637. ->leftJoin("purchease_order wpo", "wpo.cgdNo=os.cgdNo")
  638. ->where($where)
  639. ->where($condition)
  640. ->count();
  641. $total = ceil($count / $size);
  642. $page = $page >= $total ? $total : $page;
  643. $list = Db::name('order_out')
  644. ->alias('a')
  645. ->join("sale b", "b.orderCode=a.orderCode", "left")
  646. ->join("warehouse_info n", "n.wsm_code=a.wsm_code AND n.is_del=0", "left")
  647. ->leftJoin("order_send os", "os.outCode=a.outCode")
  648. ->leftJoin("purchease_order wpo", "wpo.cgdNo=os.cgdNo")
  649. ->field("a.*,b.order_type,b.order_source,b.good_name,b.good_code,b.skuCode,b.customer_code,'' companyName,b.origin_price,b.sale_price,b.total_price,os.cgdNo,wpo.supplierNo,n.supplierNo wsm_supplierNo")
  650. ->where($where)
  651. ->where($condition)
  652. ->order("addtime desc")
  653. ->page($page, $size)
  654. ->select()
  655. ->toArray();
  656. $all_createrid = array_column($list, 'apply_id');
  657. $item = get_company_name_by_uid($all_createrid);
  658. $user = new \app\admin\common\User();
  659. $names = $user->handle("getCodeAndName", ["code" => array_merge(array_column($list, "supplierNo"), array_column($list, "customer_code"), array_column($list, "wsm_supplierNo"))]);
  660. $data = [];
  661. foreach ($list as $value) {
  662. $value['companyName'] = $names['data'][$value['customer_code']] ?? '';
  663. if ($value['order_type'] == 1 && $value['wsm_code'] == '') {
  664. $value['wsm_supplierNo'] = $value['supplierNo'];
  665. $value['wsm_supplier'] = $names['data'][$value['supplierNo']] ?? "";
  666. } else {
  667. $value['wsm_supplier'] = $names['data'][$value['wsm_supplierNo']] ?? "";
  668. }
  669. $addr = Db::name("order_addr")->where(["id" => $value['addrid']])->find();
  670. if ($addr) {
  671. $addinfo = $addr['addr_code'] != '' ? json_decode($addr['addr_code'], true) ?? $addr['addr_code'] : '';
  672. if (is_string($addinfo) && $addinfo != '') {
  673. $addinfo = ["provice_code" => '', "city_code" => '', "area_code" => ''];
  674. list($addinfo['provice_code'], $addinfo['city_code'], $addinfo['area_code']) = explode(",", $addr['addr_code']);
  675. }
  676. $addr['addr_cn'] = GetAddr(json_encode($addinfo));
  677. }
  678. if ($value['order_type'] == 3) {
  679. $goon = Db::name("good_zixun")->field('id,cat_id')->where(["spuCode" => $value['good_code'], "is_del" => 0])->find();
  680. } else {
  681. $goon = Db::name('good_platform')->field('a.id,b.cat_id')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')->where(['a.skuCode' => $value['skuCode']])->find();
  682. }
  683. $value['wsm_has_account'] = 0;
  684. $value['addr'] = isset($addr['addr']) ? $addr['addr_cn'] . $addr['addr'] : "";
  685. $value['contactor'] = isset($addr['contactor']) ? $addr['contactor'] : "";
  686. $value['mobile'] = isset($addr['mobile']) ? $addr['mobile'] : "";
  687. $value['can'] = isset($goon['cat_id']) && $goon['cat_id'] != 0 ? made($goon['cat_id']) : [];
  688. $value['company_name'] = $item[$value['apply_id']] ?? '';
  689. $value['sendtime'] = $value['status'] < 2 ? '' : $value['sendtime'];
  690. $data[] = $value;
  691. }
  692. return app_show(0, "获取成功", ['list' => $data, 'count' => $count]);
  693. }
  694. //售后申请单列表
  695. public function afterList()
  696. {
  697. $param = $this->request->only([
  698. 'page' => 1,
  699. 'size' => 10,
  700. 'relaComNo' => '',
  701. 'returnCode' => '',
  702. 'outCode' => '',
  703. 'status' => '',
  704. 'order_type' => '',
  705. 'orderCode' => '',
  706. 'good_code' => '',
  707. 'good_name' => '',
  708. 'except_code' => '',
  709. 'apply_name' => '',
  710. 'start' => '',
  711. 'end' => '',
  712. 'company_name' => '',//部门名称
  713. 'supplierNo' => '',
  714. 'customer_code' => '',
  715. 'companyNo' => '',
  716. 'order_source' => '',
  717. ], 'post', 'trim');
  718. $where = [['a.is_del', "=", 0]];
  719. if ($param['returnCode'] !== '') $where[] = ['a.returnCode', "like", "%{$param['returnCode']}%"];
  720. if ($param['outCode'] !== '') $where[] = ['a.outCode', "like", "%{$param['outCode']}%"];
  721. if ($param['status'] !== '') $where[] = ['a.status', "=", $param['status']];
  722. if ($param['order_type'] !== "") $where[] = ['a.order_type', "=", $param['order_type']];
  723. if ($param['orderCode'] != "") $where[] = ['a.orderCode', "like", "%{$param['orderCode']}%"];
  724. if ($param['good_code'] != "") $where[] = ['a.good_code', "like", "%{$param['good_code']}%"];
  725. if ($param['good_name'] != "") $where[] = ['a.good_name', "like", "%{$param['good_name']}%"];
  726. if ($param['customer_code'] != "") $where[] = ['a.customer_code', "like", "%{$param['customer_code']}%"];
  727. if ($param['except_code'] != "") $where[] = ['a.except_code', "=", $param['except_code']];
  728. if ($param['apply_name'] != "") $where[] = ['a.apply_name', "like", "%{$param['apply_name']}%"];
  729. if ($param['start'] !== "") $where[] = ['a.addtime', ">=", $param['start']];
  730. if ($param['end'] !== "") $where[] = ['a.addtime', "<=", $param['end']];
  731. if ($param['order_source'] !== "") $where[] = ['c.order_source', "=", $param['order_source']];
  732. if ($param['supplierNo'] !== "") $where[] = ['a.supplierNo', "like", '%' . $param['supplierNo'] . '%'];
  733. if ($param['companyNo'] !== "") $where[] = ['a.companyNo', "like", '%' . $param['companyNo'] . '%'];
  734. if ($param['relaComNo'] !== "") $where[] = ['a.companyNo', "like", '%' . $param['companyNo'] . '%'];
  735. $condition = [];
  736. //只有level2的账号过滤数据权限
  737. if ($this->level == 2) {
  738. $hand = resign_hand_user($this->uid, 0);
  739. $role = $this->checkDataShare();
  740. if (!empty($role[DataGroupModel::$type_全部])) {
  741. $arr = array_unique(array_merge($hand, $role[DataGroupModel::$type_全部]));
  742. $condition[] = ["a.person_id", "in", $hand];
  743. $condition[] = ["a.apply_id", "in", $arr];
  744. $condition[] = ["a.cgderid", "in", $hand];
  745. }
  746. // if ($param['relaComNo'] !== '') $where[] = ['c.supplierNo', "=", $param['relaComNo']];
  747. }
  748. //level3账号不允许看到库存品订单,暂时该过滤条件废弃
  749. if ($this->level == 3){
  750. // $where[] = ['c.supNo', '=', $param['relaComNo']];
  751. }
  752. // $condition .="a.cgderid in {$hand} or a.person_id in {$hand} or a.apply_id in ("
  753. // .implode(',',$role[DataGroupModel::$type_全部]).")";
  754. if ($param['company_name'] !== "") $where[] = ["a.apply_id", 'in', get_company_item_user_by_name($param['company_name'])];
  755. $count = Db::name("order_return")
  756. ->alias("a")
  757. ->leftJoin("order_returninfo b", "a.returnCode=b.returnCode")
  758. ->leftJoin("sale c", "c.orderCode=a.orderCode AND c.is_del=0")
  759. ->where($where)
  760. ->where(function ($query) use ($condition) {
  761. $query->whereOr($condition);
  762. })
  763. ->count('a.id');;
  764. $list = Db::name("order_return")
  765. ->alias("a")
  766. ->leftJoin("order_returninfo b", "a.returnCode=b.returnCode")
  767. ->leftJoin("sale c", "c.orderCode=a.orderCode AND c.is_del=0")
  768. ->where($where)
  769. ->where(function ($query) use ($condition) {
  770. $query->whereOr($condition);
  771. })
  772. ->field("a.*,b.return_wsm,b.contactor,b.mobile,b.addr,b.addr_code,b.post_code,b.post_company,b.post_fee,b.gys_remark,c.order_source")
  773. ->page($param['page'], $param['size'])
  774. ->order("a.addtime desc")
  775. ->select()
  776. ->toArray();
  777. $all_createrid = array_column($list, 'apply_id');
  778. $item = get_company_name_by_uid($all_createrid);
  779. $data = [];
  780. foreach ($list as $value) {
  781. $value['company_name'] = $item[$value['apply_id']] ?? '';
  782. $data[] = $value;
  783. }
  784. return app_show(0, "获取成功", ['list' => $data, "count" => $count]);
  785. }
  786. /** 售后退货单
  787. * @return \think\response\Json|void
  788. * @throws \think\db\exception\DataNotFoundException
  789. * @throws \think\db\exception\DbException
  790. * @throws \think\db\exception\ModelNotFoundException
  791. */
  792. public function backlist()
  793. {
  794. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  795. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  796. $where = [['a.is_del', "=", 0]];
  797. $thNo = isset($this->post['thNo']) && $this->post['thNo'] != "" ? trim($this->post['thNo']) : "";
  798. if ($thNo != "") {
  799. $where[] = ['a.thNo', "like", "%{$thNo}%"];
  800. }
  801. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  802. if ($status !== "") {
  803. // $where['status'] = $status;
  804. $where[] = ['a.status', "=", $status];
  805. }
  806. $post_code = isset($this->post['post_code']) && $this->post['post_code'] != "" ? trim($this->post['post_code']) : "";
  807. if ($post_code != "") {
  808. $where[] = ['a.post_code', "like", "%{$post_code}%"];
  809. }
  810. $post_compay = isset($this->post['post_compay']) && $this->post['post_compay'] != "" ? trim($this->post['post_compay']) : "";
  811. if ($post_compay != "") {
  812. $where[] = ['a.post_company', "=", $post_compay];
  813. }
  814. $customer_code = isset($this->post['customer_code']) && $this->post['customer_code'] != "" ? trim($this->post['customer_code']) : "";
  815. if ($customer_code != "") {
  816. $where[] = ['a.customer_code', "like", "%{$customer_code}%"];
  817. }
  818. $order_code = isset($this->post['order_code']) && $this->post['order_code'] != "" ? trim($this->post['order_code']) : "";
  819. if ($order_code != "") {
  820. $where[] = ['a.orderCode', "like", "%{$order_code}%"];
  821. }
  822. $out_code = isset($this->post['out_code']) && $this->post['out_code'] != "" ? trim($this->post['out_code']) : "";
  823. if ($out_code != "") {
  824. $where[] = ['a.outCode', "like", "%{$out_code}%"];
  825. }
  826. $return_code = isset($this->post['return_code']) && $this->post['return_code'] != "" ? trim($this->post['return_code']) : "";
  827. if ($return_code != "") {
  828. $where[] = ['a.returnCode', "like", "%{$return_code}%"];
  829. }
  830. $start = isset($this->post['start']) && $this->post['start'] != '' ? $this->post['start'] : "";
  831. if ($start !== "") {
  832. $where[] = ['a.addtime', ">=", $start];
  833. }
  834. $end = isset($this->post['end']) && $this->post['end'] != '' ? $this->post['end'] : "";
  835. if ($end !== "") {
  836. $where[] = ['a.addtime', "<=", $end];
  837. }
  838. $order_source = isset($this->post['order_source']) && $this->post['order_source'] != "" ? trim($this->post['order_source']) : "";
  839. if ($order_source !== "") {
  840. $where[] = ['b.order_source', "=", $order_source];
  841. }
  842. $supplierNo = trim($this->post['supplierNo'] ?? '');
  843. if ($supplierNo !== '') $where[] = ['a.supplierNo', 'like', '%'.$supplierNo.'%'];
  844. $companyNo = trim($this->post['companyNo'] ?? '');
  845. if ($companyNo !== '') $where[] = ['a.companyNo', 'like', '%'.$companyNo.'%'];
  846. $relaComNo = trim($this->post['relaComNo'] ?? '');
  847. if ($relaComNo !== '') $where[] = ['a.companyNo', 'like', '%'.$relaComNo.'%'];
  848. $condition = [];
  849. //只有level2的账号过滤数据权限
  850. if ($this->level == 2) {
  851. $role = $this->checkDataShare();
  852. $hand = resign_hand_user($this->uid, 0);
  853. if (!empty($role[DataGroupModel::$type_全部])) {
  854. $arr = array_unique(array_merge($hand, $role[DataGroupModel::$type_全部]));
  855. $condition[] = ['a.apply_id', 'in', $arr];
  856. $condition[] = ['a.cgderid', 'in', $hand];
  857. }
  858. // if ($relaComNo != "") $where[] = ['b.supplierNo', '=', $relaComNo];
  859. }
  860. //供应商账号不允许看到库存品数据
  861. // if ($this->level == 3) {
  862. // $where[] = ['b.supNo', '=', $relaComNo];
  863. // }
  864. $count = Db::name("order_back")
  865. ->alias('a')
  866. ->leftJoin('sale b', 'b.orderCode=a.orderCode AND b.is_del=0')
  867. ->where($where)
  868. ->where(function ($query) use ($condition) {
  869. $query->whereOr($condition);
  870. })
  871. ->count('a.id');
  872. $total = ceil($count / $size);
  873. $page = $page >= $total ? $total : $page;
  874. $list = Db::name("order_back")
  875. ->alias('a')
  876. ->leftJoin('sale b', 'b.orderCode=a.orderCode AND b.is_del=0')
  877. ->where($where)
  878. ->where(function ($query) use ($condition) {
  879. $query->whereOr($condition);
  880. })
  881. ->field('a.*,b.order_source')
  882. ->page($page, $size)
  883. ->order("a.addtime desc")
  884. ->select()
  885. ->toArray();
  886. $data = [];
  887. $all_wsm = Db::name("warehouse_info")
  888. ->alias("a")
  889. ->where(["a.wsm_code" => array_column($list, 'return_wsm')])
  890. ->column("a.name,a.supplierNo", 'a.wsm_code');//b.name,b.code
  891. $userCommon = new \app\admin\common\User();
  892. $names = $userCommon->handle('getCodeAndName', ['code' => array_unique(array_column($all_wsm, 'supplierNo'))]);
  893. foreach ($list as $value) {
  894. $value['wsm_name'] = "";
  895. $value['wsm_supplier'] = '';
  896. $value['wsm_supplierNo'] = '';
  897. if ($value['return_wsm'] != "") {
  898. $value['wsm_name'] = $all_wsm[$value['return_wsm']]['name'] ?? '';//isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
  899. $value['wsm_supplier'] = $names['data'][$all_wsm[$value['return_wsm']]['supplierNo']] ?? '';//isset($wsmcode['name']) ? $wsmcode['name']:"";
  900. $value['wsm_supplierNo'] = $all_wsm[$value['return_wsm']]['supplierNo'];//isset($wsmcode['code']) ? $wsmcode['code']:"";
  901. }
  902. $inorder = Db::name("order_backinfo")
  903. ->where(['thNo' => $value['thNo'], "is_del" => 0])
  904. ->select()
  905. ->toArray();
  906. $value['child'] = empty($inorder) ? [] : $inorder;
  907. $data[] = $value;
  908. }
  909. return app_show(0, "获取成功", ["list" => $data, "count" => $count]);
  910. }
  911. //退货单列表
  912. public function reorderlist(){
  913. $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']):"1";
  914. $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']):"10";
  915. $where =[['sr.is_del',"=",0]];
  916. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  917. if($bkcode!=""){
  918. $where[]=['sr.returnCode',"like", "%{$bkcode}%"];
  919. }
  920. $status = isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
  921. if($status!==""){
  922. $where[]=['sr.status',"=", $status];
  923. }
  924. $orderCode = isset($this->post['orderCode']) && $this->post['orderCode']!="" ? trim($this->post['orderCode']) :"";
  925. if($orderCode!=""){
  926. $where[]=['sr.orderCode',"like", "%{$orderCode}%"];
  927. }
  928. $apply_name = isset($this->post['apply_name']) && $this->post['apply_name']!="" ? trim($this->post['apply_name']) :"";
  929. if($apply_name!=""){
  930. $where[]=['sr.apply_name',"like", "%{$apply_name}%"];
  931. }
  932. $start =isset($this->post['start'])&&$this->post['start']!='' ? $this->post['start']:"";
  933. if($start!==""){
  934. $where[]=['sr.addtime',">=", $start.' 00:00:00'];
  935. }
  936. $end =isset($this->post['end'])&&$this->post['end']!='' ? $this->post['end']:"";
  937. if($end!==""){
  938. $where[]=['sr.addtime',"<=", $end.' 23:59:59'];
  939. }
  940. //商品成本编码搜索
  941. $good_code = isset($this->post['good_code']) && $this->post['good_code'] != "" ? trim($this->post['good_code']) : "";
  942. if ($good_code != "") {
  943. $where[] = ['sr.good_code', "like", "%{$good_code}%"];
  944. }
  945. //商品上线编码搜索
  946. $skuCode = isset($this->post['skuCode']) && $this->post['skuCode'] != "" ? trim($this->post['skuCode']) : "";
  947. if ($skuCode != "") {
  948. $where[] = ['b.skuCode', "like", "%{$skuCode}%"];
  949. }
  950. $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] != "" ? trim($this->post['supplierNo']) : "";
  951. if ($supplierNo !== "") $where[] = ['b.supNo', "like", '%' . $supplierNo . '%'];
  952. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] != "" ? trim($this->post['companyNo']) : "";
  953. if ($companyNo !== "") $where[] = ['sr.companyNo', "like", '%' . $companyNo . '%'];
  954. $customer_code = isset($this->post['customer_code']) && $this->post['customer_code'] != "" ? trim($this->post['customer_code']) : "";
  955. if ($customer_code !== "") $where[] = ['sr.customer_code', "like", '%' . $customer_code . '%'];
  956. $order_source = $order_source = isset($this->post['order_source']) && $this->post['order_source'] != "" ? trim($this->post['order_source']) : "";
  957. if ($order_source !== "") $where[] = ['b.order_source', "=", $order_source];
  958. $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo'] != "" ? trim($this->post['relaComNo']) : "";
  959. if ($relaComNo != "") $where[] = ['sr.companyNo', '=', $relaComNo];
  960. $condition=[];
  961. //只有level2的账号过滤数据权限
  962. if ($this->level == 2) {
  963. $role = $this->checkDataShare();
  964. $hand = resign_hand_user($this->uid, 0);
  965. if (!empty($role[DataGroupModel::$type_全部])) {
  966. $arr = array_unique(array_merge($hand, $role[DataGroupModel::$type_全部]));
  967. // $uidim =implode(",",$hand);
  968. // $condition .= "sr.cgderid in ($uidim) or sr.person_id in ($uidim) or sr.apply_id in (" . implode(',',$arr) .
  969. // ")";
  970. $condition[] = ["sr.apply_id", "in", $arr];
  971. $condition[] = ["sr.cgderid", "in", $hand];
  972. $condition[] = ["sr.person_id", "in", $hand];
  973. }
  974. // if ($relaComNo != "") $where[] = ['sr.companyNo', '=', $relaComNo];
  975. }
  976. //供应商账号不允许看到库存品数据
  977. // if ($this->level == 3){
  978. // $where[] = ['b.supNo', '=', $relaComNo];
  979. // }
  980. if(in_array($this->roleid,config('app.wsm_cgder_role'))){
  981. $where[]=["b.order_type","=",1];
  982. }
  983. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  984. if ($company_name !== "") $where[] = ["sr.apply_id", 'in', get_company_item_user_by_name($company_name)];
  985. $count=Db::name("sale_return")
  986. ->alias('sr')
  987. ->leftJoin("sale b", "b.orderCode=sr.orderCode AND b.is_del=0")
  988. ->where($where)
  989. ->where(function ($query)use ($condition){$query->whereOr($condition);})
  990. ->count('sr.id');
  991. $total = ceil($count/$size);
  992. $page = $total>=$page ? $page :$total;
  993. $list = Db::name("sale_return")
  994. ->alias('sr')
  995. ->field('sr.*,b.skuCode,b.sale_price,b.good_num total_num,b.order_source')
  996. ->leftJoin("sale b", "b.orderCode=sr.orderCode AND b.is_del=0")
  997. ->where($where)
  998. ->where(function ($query)use ($condition){$query->whereOr($condition);})
  999. ->order("sr.addtime desc")
  1000. ->page($page,$size)
  1001. ->select()
  1002. ->toArray();
  1003. $all_createrid = array_column($list,'apply_id');
  1004. $item = get_company_name_by_uid($all_createrid);
  1005. $data=[];
  1006. foreach ($list as $value){
  1007. $value['error_msg']='';
  1008. if($value['error_code']!=''){
  1009. $error = Db::name("result_info")->where(["result_code"=>$value['error_code']])->find();
  1010. $value['error_msg']= isset($error['result'])?$error['result']:"";
  1011. }
  1012. $value['return_total'] =$value['sale_price']*$value['num'] ;
  1013. $value['company_name'] = $item[$value['apply_id']]??'';
  1014. $data[]=$value ;
  1015. }
  1016. return app_show(0,"获取成功",["count"=>$count,'list'=>$data]);
  1017. }
  1018. }