SupplierClient.php 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104
  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. $order_source = isset($this->post['order_source']) && $this->post['order_source'] != "" ? intval($this->post['order_source']) : "";
  391. if ($order_source != '') $where[] = ['b.order_source', '=', $order_source];
  392. $is_stock = isset($this->post['is_stock']) && $this->post['is_stock'] != "" ? intval($this->post['is_stock']) : "";
  393. if ($is_stock != '') $where[] = ['c.is_stock', '=', $is_stock];
  394. // $role = $this->checkDataShare();
  395. // if (!empty($role[DataGroupModel::$type_全部])) $where[] = ["a.apply_id", "in", $role[DataGroupModel::$type_全部]];
  396. //只有level2的账号过滤数据权限
  397. if ($this->level == 2) {
  398. $role = $this->checkDataShare();
  399. $hand = resign_hand_user($this->uid, 0);
  400. if (!empty($role[DataGroupModel::$type_全部])) {
  401. $arr = array_unique(array_merge($hand, $role[DataGroupModel::$type_全部]));
  402. $where[] = ['a.apply_id', 'in', $arr];
  403. }
  404. if($relaComNo!='') $where[]=['b.companyNo','=', $relaComNo];
  405. }
  406. if($this->level==3){
  407. if($relaComNo!='') $where[]=['b.supplierNo','=', $relaComNo];
  408. }
  409. $count = Db::name('purchease_return')
  410. ->alias('a')
  411. ->leftJoin("purchease_order b","b.cgdNo=a.cgdNo")
  412. ->leftJoin("good_basic c","c.spuCode=b.spuCode")
  413. ->where($where)
  414. ->count();
  415. $total = ceil($count / $size);
  416. $page = $page >= $total ? $total : $page;
  417. $list = Db::name('purchease_return')
  418. ->alias('a')
  419. ->leftJoin("purchease_order b","b.cgdNo=a.cgdNo")
  420. ->leftJoin("good_basic c","c.spuCode=b.spuCode")
  421. ->where($where)
  422. ->page($page,$size)
  423. ->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")
  424. ->order("a.addtime desc")
  425. ->select()
  426. ->toArray();
  427. $data=[];
  428. $userCommon = new \app\admin\common\User();
  429. $names = $userCommon->handle('getCodeAndName',['code'=>array_unique(array_column($list,'companyNo'))]);
  430. foreach ($list as $value){
  431. if($value['order_type']==3){
  432. $goon = Db::name("good_zixun")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->find();
  433. }else {
  434. $goon =Db::name('good_basic')->where(['spuCode'=>$value['spuCode']])->find();
  435. }
  436. $value['can']= isset($goon['cat_id']) && $goon['cat_id'] !=0 ? made($goon['cat_id']):[];
  437. $value['return_fee']= round($value['good_price']*$value['return_num'],2);
  438. $value['companyName'] = $names['data'][$value['companyNo']]??'';
  439. $data[]=$value;
  440. }
  441. return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
  442. }
  443. /**供应商端公差单列表
  444. * @return \think\response\Json|void
  445. * @throws \think\db\exception\DataNotFoundException
  446. * @throws \think\db\exception\DbException
  447. * @throws \think\db\exception\ModelNotFoundException
  448. */
  449. public function difflist(){
  450. $page = isset($this->post['page']) && $this->post['page'] !==""? intval($this->post['page']):"1";
  451. $size = isset($this->post['size']) && $this->post['size'] !==""? intval($this->post['size']):"10";
  452. $where = [['a.is_del',"=",0]];
  453. $cgdNo = isset($this->post['cgdNo']) && $this->post['cgdNo']!="" ? trim($this->post['cgdNo']):"";
  454. if($cgdNo!=""){
  455. $where[]=['a.cgdNo',"like", "%$cgdNo%"];
  456. }
  457. $status = isset($this->post['status']) && $this->post['status'] !==""? intval($this->post['status']):"";
  458. if($status!==""){
  459. $where[]=['a.status',"=",$status];
  460. }
  461. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  462. if ($start !="") {
  463. $where[]= ["a.addtime",'>=',$start];
  464. }
  465. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  466. if($end !=""){
  467. $where[]= ["a.addtime",'<=',$end];
  468. }
  469. $apply_name = isset($this->post['apply_name']) && $this->post['apply_name'] !==""? intval($this->post['apply_name']):"";
  470. if($apply_name!==""){
  471. $where[]=['a.apply_name',"like","%$apply_name%"];
  472. }
  473. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  474. if ($company_name !== "") $where[] = ["a.apply_id", 'in', get_company_item_user_by_name($company_name)];
  475. $order_source = $order_source = isset($this->post['order_source']) && $this->post['order_source'] != "" ? intval($this->post['order_source']) : "";
  476. if ($order_source !== "") $where[] = ['c.order_source', "=", $order_source];
  477. $is_stock = $order_source = isset($this->post['is_stock']) && $this->post['is_stock'] != "" ? intval($this->post['is_stock']) : "";
  478. if ($is_stock !== "") $where[] = ['b.is_stock', "=", $is_stock];
  479. $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo']!="" ? trim($this->post['relaComNo']):"";
  480. if ($this->level == 2) {
  481. $role = $this->checkDataShare();
  482. $hand = resign_hand_user($this->uid, 0);
  483. if (!empty($role[DataGroupModel::$type_全部])) {
  484. $arr = array_unique(array_merge($hand, $role[DataGroupModel::$type_全部]));
  485. $where[] = ['a.apply_id', 'in', $arr];
  486. }
  487. if($relaComNo!='') $where[]=['c.companyNo','=', $relaComNo];
  488. }
  489. if($this->level==3){
  490. if($relaComNo!='') $where[]=['c.supplierNo','=', $relaComNo];
  491. }
  492. $count = Db::name('purchease_diff')
  493. ->alias('a')
  494. ->leftJoin("good b","b.spuCode=a.good_code")
  495. ->leftJoin("purchease_order c","c.cgdNo=a.cgdNo")
  496. ->where($where)
  497. ->count();
  498. $total = ceil($count/$size);
  499. $page = $page >= $total ? $total : $page;
  500. $list = Db::name('purchease_diff')
  501. ->alias('a')
  502. ->leftJoin("good b","b.spuCode=a.good_code")
  503. ->leftJoin("purchease_order c","c.cgdNo=a.cgdNo")
  504. ->where($where)
  505. ->page($page,$size)
  506. ->order("a.addtime desc")
  507. ->field("a.*,b.cat_id,c.order_source,b.is_stock")
  508. ->select()
  509. ->toArray();
  510. $all_createrid = array_column($list,'apply_id');
  511. $item = get_company_name_by_uid($all_createrid);
  512. $data=[];
  513. foreach ($list as $value){
  514. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  515. $value['company_name'] = $item[$value['apply_id']]??'';
  516. //是否具有编辑权限
  517. $value['is_allow_update'] = 0;
  518. if (in_array($this->roleid, [1, 33]) || in_array($value['apply_id'], $role[DataGroupModel::$type_可编辑])) $value['is_allow_update'] = 1;
  519. $data[]=$value;
  520. }
  521. return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
  522. }
  523. //发货申请单列表
  524. public function orderOut()
  525. {
  526. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  527. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  528. $where = [["a.is_del", "=", 0]];
  529. $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !== "" ? trim($this->post['orderCode']) : "";
  530. if ($orderCode !== "") {
  531. $where[] = ['a.orderCode', "like", "%$orderCode%"];
  532. }
  533. $order_type = isset($this->post['order_type']) && $this->post['order_type'] !== "" ? trim($this->post['order_type']) : "";
  534. if ($order_type !== "") {
  535. $where[] = ['a.order_type', "=", $order_type];
  536. }
  537. $outCode = isset($this->post['outCode']) && $this->post['outCode'] !== "" ? trim($this->post['outCode']) : "";
  538. if ($outCode !== "") {
  539. $where[] = ['a.outCode', "like", "%$outCode%"];
  540. }
  541. $apply_name = isset($this->post['apply_name']) && $this->post['apply_name'] !== "" ? trim($this->post['apply_name']) : "";
  542. if ($apply_name !== "") {
  543. $where[] = ['a.apply_name', "like", "%$apply_name%"];
  544. }
  545. $good_code = isset($this->post['good_code']) && $this->post['good_code'] !== "" ? trim($this->post['good_code']) : "";
  546. if ($good_code !== "") {
  547. $where[] = ['b.good_code', "like", "%$good_code%"];
  548. }
  549. $good_name = isset($this->post['good_name']) && $this->post['good_name'] !== "" ? trim($this->post['good_name']) : "";
  550. if ($good_name !== "") {
  551. $where[] = ['b.good_name', "like", "%$good_name%"];
  552. }
  553. $supplier_name = isset($this->post['supplier_name']) && $this->post['supplier_name'] !== "" ? trim($this->post['supplier_name']) : "";
  554. if ($supplier_name !== "") {
  555. $where[] = ['wpo.supplier_name', "like", "%$supplier_name%"];
  556. }
  557. $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  558. if ($status !== "") {
  559. $where[] = ['a.status', "=", $status];
  560. }
  561. $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
  562. if ($start != "") {
  563. $where[] = ["a.addtime", '>=', $start . " 00:00:00"];
  564. }
  565. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
  566. if ($end != "") {
  567. $where[] = ["a.addtime", '<=', $end . " 23:59:59"];
  568. }
  569. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  570. if ($companyNo != "") {
  571. $where[] = ['b.supplierNo', "like", "%$companyNo%"];
  572. }
  573. $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo'] !== "" ? trim($this->post['relaComNo']) : "";
  574. $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !== "" ? trim($this->post['supplierNo']) : "";
  575. if ($supplierNo != '') {
  576. //sale b 表里存的supplierNo值是GS开头的,即业务公司编码
  577. //所以此处应该根据供应商编码筛选商品spuCode,然后筛选发货单
  578. $spuCode = Db::name('good_basic')
  579. ->where(['is_del' => 0, 'supplierNo' => $supplierNo])
  580. ->column('spuCode');
  581. $where[] = ['b.good_code', 'in', $spuCode];
  582. }
  583. $cgdNo = isset($this->post['cgdNo']) && $this->post['cgdNo'] !== "" ? $this->post['cgdNo'] : "";
  584. if ($cgdNo != "") {
  585. $where[] = ["os.cgdNo", 'like', '%' . $cgdNo . '%'];
  586. }
  587. $condition = '';
  588. //只有level2的账号过滤数据权限
  589. if ($this->level == 2) {
  590. $hand = resign_hand_user($this->uid, 0);
  591. $uidarr = implode(",", $hand);
  592. //库管只能看到库存品订单,供应商负责人只能看到非库存品订单
  593. if (!in_array($this->roleid, [1, 33])) {
  594. //库管看到所有的库存品发货申请单
  595. if (in_array($this->roleid, config('app.wsm_cgder_role'))) $condition .= " b.is_stock=1";
  596. else {
  597. $role = $this->checkDataShare();
  598. if (!empty($role[DataGroupModel::$type_全部])) {
  599. $arr = array_unique(array_merge($hand, $role[DataGroupModel::$type_全部]));
  600. if ($condition != '') $condition .= " or ";
  601. $condition .= " a.apply_id in (" . implode(',', $arr) . ")";
  602. }
  603. }
  604. if (!empty($hand)) {
  605. if ($condition != '') $condition .= " or ";
  606. $person_supplier = Db::connect('mysql_sys')
  607. ->name('supplier')
  608. ->where(['is_del'=>0,'personid'=>$uidarr])
  609. ->column('code');
  610. $condition .= "(b.is_stock=0 and wpo.supplierNo in ('" . implode('\',\'', $person_supplier) . "'))";
  611. }
  612. }
  613. if ($relaComNo != '') $where[] = ['b.supplierNo', '=', $relaComNo];
  614. }
  615. //供应商账号只能看到非库存品的订单
  616. if ($this->level == 3){
  617. $where[] = ['b.supNo', '=', $relaComNo];
  618. }
  619. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  620. if ($company_name !== "") $where[] = ["a.apply_id", 'in', get_company_item_user_by_name($company_name)];
  621. //发货时间筛选
  622. $start_sendtime = isset($this->post['start_sendtime']) && $this->post['start_sendtime'] !== "" ? $this->post['start_sendtime'] : "";
  623. $end_sendtime = isset($this->post['end_sendtime']) && $this->post['end_sendtime'] !== "" ? $this->post['end_sendtime'] : "";
  624. if ($start_sendtime != "" && $end_sendtime != "") {
  625. $where[] = ["a.sendtime", 'between', [$start_sendtime . " 00:00:00", $end_sendtime . " 23:59:59"]];
  626. $where[] = ["a.status", '>=', 2];//搜索发货时间时,要指定状态为已发货及之后的状态值(0待发货,1待库管发货,2已发货待收货,3已收货,4已全部退货',)
  627. }
  628. $order_source = isset($this->post['order_source']) && $this->post['order_source'] !== "" ? intval($this->post['order_source']) : "";
  629. if ($order_source !== "") $where[] = ["b.order_source", '=', $order_source];
  630. $count = Db::name('order_out')
  631. ->alias('a')
  632. ->join("sale b", "b.orderCode=a.orderCode", "left")
  633. ->join("warehouse_info n", "n.wsm_code=a.wsm_code", "left")
  634. ->leftJoin("order_send os", "os.outCode=a.outCode")
  635. ->leftJoin("purchease_order wpo", "wpo.cgdNo=os.cgdNo")
  636. ->where($where)
  637. ->where($condition)
  638. ->count();
  639. $total = ceil($count / $size);
  640. $page = $page >= $total ? $total : $page;
  641. $list = Db::name('order_out')
  642. ->alias('a')
  643. ->join("sale b", "b.orderCode=a.orderCode", "left")
  644. ->join("warehouse_info n", "n.wsm_code=a.wsm_code AND n.is_del=0", "left")
  645. ->leftJoin("order_send os", "os.outCode=a.outCode")
  646. ->leftJoin("purchease_order wpo", "wpo.cgdNo=os.cgdNo")
  647. ->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")
  648. ->where($where)
  649. ->where($condition)
  650. ->order("addtime desc")
  651. ->page($page, $size)
  652. ->select()
  653. ->toArray();
  654. $all_createrid = array_column($list, 'apply_id');
  655. $item = get_company_name_by_uid($all_createrid);
  656. $user = new \app\admin\common\User();
  657. $names = $user->handle("getCodeAndName", ["code" => array_merge(array_column($list, "supplierNo"), array_column($list, "customer_code"), array_column($list, "wsm_supplierNo"))]);
  658. $data = [];
  659. foreach ($list as $value) {
  660. $value['companyName'] = $names['data'][$value['customer_code']] ?? '';
  661. if ($value['order_type'] == 1 && $value['wsm_code'] == '') {
  662. $value['wsm_supplierNo'] = $value['supplierNo'];
  663. $value['wsm_supplier'] = $names['data'][$value['supplierNo']] ?? "";
  664. } else {
  665. $value['wsm_supplier'] = $names['data'][$value['wsm_supplierNo']] ?? "";
  666. }
  667. $addr = Db::name("order_addr")->where(["id" => $value['addrid']])->find();
  668. if ($addr) {
  669. $addinfo = $addr['addr_code'] != '' ? json_decode($addr['addr_code'], true) ?? $addr['addr_code'] : '';
  670. if (is_string($addinfo) && $addinfo != '') {
  671. $addinfo = ["provice_code" => '', "city_code" => '', "area_code" => ''];
  672. list($addinfo['provice_code'], $addinfo['city_code'], $addinfo['area_code']) = explode(",", $addr['addr_code']);
  673. }
  674. $addr['addr_cn'] = GetAddr(json_encode($addinfo));
  675. }
  676. if ($value['order_type'] == 3) {
  677. $goon = Db::name("good_zixun")->field('id,cat_id')->where(["spuCode" => $value['good_code'], "is_del" => 0])->find();
  678. } else {
  679. $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();
  680. }
  681. $value['wsm_has_account'] = 0;
  682. $value['addr'] = isset($addr['addr']) ? $addr['addr_cn'] . $addr['addr'] : "";
  683. $value['contactor'] = isset($addr['contactor']) ? $addr['contactor'] : "";
  684. $value['mobile'] = isset($addr['mobile']) ? $addr['mobile'] : "";
  685. $value['can'] = isset($goon['cat_id']) && $goon['cat_id'] != 0 ? made($goon['cat_id']) : [];
  686. $value['company_name'] = $item[$value['apply_id']] ?? '';
  687. $value['sendtime'] = $value['status'] < 2 ? '' : $value['sendtime'];
  688. $data[] = $value;
  689. }
  690. return app_show(0, "获取成功", ['list' => $data, 'count' => $count]);
  691. }
  692. //售后申请单列表
  693. public function afterList()
  694. {
  695. $param = $this->request->only([
  696. 'page' => 1,
  697. 'size' => 10,
  698. 'relaComNo' => '',
  699. 'returnCode' => '',
  700. 'outCode' => '',
  701. 'status' => '',
  702. 'order_type' => '',
  703. 'orderCode' => '',
  704. 'good_code' => '',
  705. 'good_name' => '',
  706. 'except_code' => '',
  707. 'apply_name' => '',
  708. 'start' => '',
  709. 'end' => '',
  710. 'company_name' => '',//部门名称
  711. 'supplierNo' => '',
  712. 'customer_code' => '',
  713. 'companyNo' => '',
  714. 'order_source' => '',
  715. ], 'post', 'trim');
  716. $where = [['a.is_del', "=", 0]];
  717. if ($param['returnCode'] !== '') $where[] = ['a.returnCode', "like", "%{$param['returnCode']}%"];
  718. if ($param['outCode'] !== '') $where[] = ['a.outCode', "like", "%{$param['outCode']}%"];
  719. if ($param['status'] !== '') $where[] = ['a.status', "=", $param['status']];
  720. if ($param['order_type'] !== "") $where[] = ['a.order_type', "=", $param['order_type']];
  721. if ($param['orderCode'] != "") $where[] = ['a.orderCode', "like", "%{$param['orderCode']}%"];
  722. if ($param['good_code'] != "") $where[] = ['a.good_code', "like", "%{$param['good_code']}%"];
  723. if ($param['good_name'] != "") $where[] = ['a.good_name', "like", "%{$param['good_name']}%"];
  724. if ($param['customer_code'] != "") $where[] = ['a.customer_code', "like", "%{$param['customer_code']}%"];
  725. if ($param['except_code'] != "") $where[] = ['a.except_code', "=", $param['except_code']];
  726. if ($param['apply_name'] != "") $where[] = ['a.apply_name', "like", "%{$param['apply_name']}%"];
  727. if ($param['start'] !== "") $where[] = ['a.addtime', ">=", $param['start']];
  728. if ($param['end'] !== "") $where[] = ['a.addtime', "<=", $param['end']];
  729. if ($param['order_source'] !== "") $where[] = ['c.order_source', "=", $param['order_source']];
  730. if ($param['supplierNo'] !== "") $where[] = ['a.supplierNo', "like", '%' . $param['supplierNo'] . '%'];
  731. if ($param['companyNo'] !== "") $where[] = ['a.companyNo', "like", '%' . $param['companyNo'] . '%'];
  732. $condition = [];
  733. //只有level2的账号过滤数据权限
  734. if ($this->level == 2) {
  735. $hand = resign_hand_user($this->uid, 0);
  736. $role = $this->checkDataShare();
  737. if (!empty($role[DataGroupModel::$type_全部])) {
  738. $arr = array_unique(array_merge($hand, $role[DataGroupModel::$type_全部]));
  739. $condition[] = ["a.person_id", "in", $hand];
  740. $condition[] = ["a.apply_id", "in", $arr];
  741. $condition[] = ["a.cgderid", "in", $hand];
  742. }
  743. if ($param['relaComNo'] !== '') $where[] = ['c.supplierNo', "=", $param['relaComNo']];
  744. }
  745. //level3账号不允许看到库存品订单
  746. if ($this->level == 3){
  747. $where[] = ['c.supNo', '=', $param['relaComNo']];
  748. }
  749. // $condition .="a.cgderid in {$hand} or a.person_id in {$hand} or a.apply_id in ("
  750. // .implode(',',$role[DataGroupModel::$type_全部]).")";
  751. if ($param['company_name'] !== "") $where[] = ["a.apply_id", 'in', get_company_item_user_by_name($param['company_name'])];
  752. $count = Db::name("order_return")
  753. ->alias("a")
  754. ->leftJoin("order_returninfo b", "a.returnCode=b.returnCode")
  755. ->leftJoin("sale c", "c.orderCode=a.orderCode AND c.is_del=0")
  756. ->where($where)
  757. ->where(function ($query) use ($condition) {
  758. $query->whereOr($condition);
  759. })
  760. ->count('a.id');;
  761. $list = Db::name("order_return")
  762. ->alias("a")
  763. ->leftJoin("order_returninfo b", "a.returnCode=b.returnCode")
  764. ->leftJoin("sale c", "c.orderCode=a.orderCode AND c.is_del=0")
  765. ->where($where)
  766. ->where(function ($query) use ($condition) {
  767. $query->whereOr($condition);
  768. })
  769. ->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")
  770. ->page($param['page'], $param['size'])
  771. ->order("a.addtime desc")
  772. ->select()
  773. ->toArray();
  774. $all_createrid = array_column($list, 'apply_id');
  775. $item = get_company_name_by_uid($all_createrid);
  776. $data = [];
  777. foreach ($list as $value) {
  778. $value['company_name'] = $item[$value['apply_id']] ?? '';
  779. $data[] = $value;
  780. }
  781. return app_show(0, "获取成功", ['list' => $data, "count" => $count]);
  782. }
  783. /** 售后退货单
  784. * @return \think\response\Json|void
  785. * @throws \think\db\exception\DataNotFoundException
  786. * @throws \think\db\exception\DbException
  787. * @throws \think\db\exception\ModelNotFoundException
  788. */
  789. public function backlist()
  790. {
  791. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  792. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  793. $where = [['a.is_del', "=", 0]];
  794. $thNo = isset($this->post['thNo']) && $this->post['thNo'] != "" ? trim($this->post['thNo']) : "";
  795. if ($thNo != "") {
  796. $where[] = ['a.thNo', "like", "%{$thNo}%"];
  797. }
  798. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  799. if ($status !== "") {
  800. // $where['status'] = $status;
  801. $where[] = ['a.status', "=", $status];
  802. }
  803. $post_code = isset($this->post['post_code']) && $this->post['post_code'] != "" ? trim($this->post['post_code']) : "";
  804. if ($post_code != "") {
  805. $where[] = ['a.post_code', "like", "%{$post_code}%"];
  806. }
  807. $post_compay = isset($this->post['post_compay']) && $this->post['post_compay'] != "" ? trim($this->post['post_compay']) : "";
  808. if ($post_compay != "") {
  809. $where[] = ['a.post_company', "=", $post_compay];
  810. }
  811. $customer_code = isset($this->post['customer_code']) && $this->post['customer_code'] != "" ? trim($this->post['customer_code']) : "";
  812. if ($customer_code != "") {
  813. $where[] = ['a.customer_code', "like", "%{$customer_code}%"];
  814. }
  815. $order_code = isset($this->post['order_code']) && $this->post['order_code'] != "" ? trim($this->post['order_code']) : "";
  816. if ($order_code != "") {
  817. $where[] = ['a.orderCode', "like", "%{$order_code}%"];
  818. }
  819. $out_code = isset($this->post['out_code']) && $this->post['out_code'] != "" ? trim($this->post['out_code']) : "";
  820. if ($out_code != "") {
  821. $where[] = ['a.outCode', "like", "%{$out_code}%"];
  822. }
  823. $return_code = isset($this->post['return_code']) && $this->post['return_code'] != "" ? trim($this->post['return_code']) : "";
  824. if ($return_code != "") {
  825. $where[] = ['a.returnCode', "like", "%{$return_code}%"];
  826. }
  827. $start = isset($this->post['start']) && $this->post['start'] != '' ? $this->post['start'] : "";
  828. if ($start !== "") {
  829. $where[] = ['a.addtime', ">=", $start];
  830. }
  831. $end = isset($this->post['end']) && $this->post['end'] != '' ? $this->post['end'] : "";
  832. if ($end !== "") {
  833. $where[] = ['a.addtime', "<=", $end];
  834. }
  835. $order_source = isset($this->post['order_source']) && $this->post['order_source'] != "" ? trim($this->post['order_source']) : "";
  836. if ($order_source !== "") {
  837. $where[] = ['b.order_source', "=", $order_source];
  838. }
  839. $supplierNo = trim($this->post['supplierNo'] ?? '');
  840. if ($supplierNo !== '') $where[] = ['a.supplierNo', 'like', '%'.$supplierNo.'%'];
  841. $companyNo = trim($this->post['companyNo'] ?? '');
  842. if ($companyNo !== '') $where[] = ['a.companyNo', 'like', '%'.$companyNo.'%'];
  843. $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo'] != "" ? trim($this->post['relaComNo']) : "";
  844. $condition = [];
  845. //只有level2的账号过滤数据权限
  846. if ($this->level == 2) {
  847. $role = $this->checkDataShare();
  848. $hand = resign_hand_user($this->uid, 0);
  849. if (!empty($role[DataGroupModel::$type_全部])) {
  850. $arr = array_unique(array_merge($hand, $role[DataGroupModel::$type_全部]));
  851. $condition[] = ['a.apply_id', 'in', $arr];
  852. $condition[] = ['a.cgderid', 'in', $hand];
  853. }
  854. if ($relaComNo != "") $where[] = ['b.supplierNo', '=', $relaComNo];
  855. }
  856. //供应商账号不允许看到库存品数据
  857. if ($this->level == 3) {
  858. $where[] = ['b.supNo', '=', $relaComNo];
  859. }
  860. $count = Db::name("order_back")
  861. ->alias('a')
  862. ->leftJoin('sale b', 'b.orderCode=a.orderCode AND b.is_del=0')
  863. ->where($where)
  864. ->where(function ($query) use ($condition) {
  865. $query->whereOr($condition);
  866. })
  867. ->count('a.id');
  868. $total = ceil($count / $size);
  869. $page = $page >= $total ? $total : $page;
  870. $list = Db::name("order_back")
  871. ->alias('a')
  872. ->leftJoin('sale b', 'b.orderCode=a.orderCode AND b.is_del=0')
  873. ->where($where)
  874. ->where(function ($query) use ($condition) {
  875. $query->whereOr($condition);
  876. })
  877. ->field('a.*,b.order_source')
  878. ->page($page, $size)
  879. ->order("a.addtime desc")
  880. ->select()
  881. ->toArray();
  882. $data = [];
  883. $all_wsm = Db::name("warehouse_info")
  884. ->alias("a")
  885. ->where(["a.wsm_code" => array_column($list, 'return_wsm')])
  886. ->column("a.name,a.supplierNo", 'a.wsm_code');//b.name,b.code
  887. $userCommon = new \app\admin\common\User();
  888. $names = $userCommon->handle('getCodeAndName', ['code' => array_unique(array_column($all_wsm, 'supplierNo'))]);
  889. foreach ($list as $value) {
  890. $value['wsm_name'] = "";
  891. $value['wsm_supplier'] = '';
  892. $value['wsm_supplierNo'] = '';
  893. if ($value['return_wsm'] != "") {
  894. $value['wsm_name'] = $all_wsm[$value['return_wsm']]['name'] ?? '';//isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
  895. $value['wsm_supplier'] = $names['data'][$all_wsm[$value['return_wsm']]['supplierNo']] ?? '';//isset($wsmcode['name']) ? $wsmcode['name']:"";
  896. $value['wsm_supplierNo'] = $all_wsm[$value['return_wsm']]['supplierNo'];//isset($wsmcode['code']) ? $wsmcode['code']:"";
  897. }
  898. $inorder = Db::name("order_backinfo")
  899. ->where(['thNo' => $value['thNo'], "is_del" => 0])
  900. ->select()
  901. ->toArray();
  902. $value['child'] = empty($inorder) ? [] : $inorder;
  903. $data[] = $value;
  904. }
  905. return app_show(0, "获取成功", ["list" => $data, "count" => $count]);
  906. }
  907. //退货单列表
  908. public function reorderlist(){
  909. $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']):"1";
  910. $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']):"10";
  911. $where =[['sr.is_del',"=",0]];
  912. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  913. if($bkcode!=""){
  914. $where[]=['sr.returnCode',"like", "%{$bkcode}%"];
  915. }
  916. $status = isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
  917. if($status!==""){
  918. $where[]=['sr.status',"=", $status];
  919. }
  920. $orderCode = isset($this->post['orderCode']) && $this->post['orderCode']!="" ? trim($this->post['orderCode']) :"";
  921. if($orderCode!=""){
  922. $where[]=['sr.orderCode',"like", "%{$orderCode}%"];
  923. }
  924. $apply_name = isset($this->post['apply_name']) && $this->post['apply_name']!="" ? trim($this->post['apply_name']) :"";
  925. if($apply_name!=""){
  926. $where[]=['sr.apply_name',"like", "%{$apply_name}%"];
  927. }
  928. $start =isset($this->post['start'])&&$this->post['start']!='' ? $this->post['start']:"";
  929. if($start!==""){
  930. $where[]=['sr.addtime',">=", $start.' 00:00:00'];
  931. }
  932. $end =isset($this->post['end'])&&$this->post['end']!='' ? $this->post['end']:"";
  933. if($end!==""){
  934. $where[]=['sr.addtime',"<=", $end.' 23:59:59'];
  935. }
  936. //商品成本编码搜索
  937. $good_code = isset($this->post['good_code']) && $this->post['good_code'] != "" ? trim($this->post['good_code']) : "";
  938. if ($good_code != "") {
  939. $where[] = ['sr.good_code', "like", "%{$good_code}%"];
  940. }
  941. //商品上线编码搜索
  942. $skuCode = isset($this->post['skuCode']) && $this->post['skuCode'] != "" ? trim($this->post['skuCode']) : "";
  943. if ($skuCode != "") {
  944. $where[] = ['b.skuCode', "like", "%{$skuCode}%"];
  945. }
  946. $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] != "" ? trim($this->post['supplierNo']) : "";
  947. if ($supplierNo !== "") $where[] = ['sr.supplierNo', "like", '%' . $supplierNo . '%'];
  948. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] != "" ? trim($this->post['companyNo']) : "";
  949. if ($companyNo !== "") $where[] = ['sr.companyNo', "like", '%' . $companyNo . '%'];
  950. $customer_code = isset($this->post['customer_code']) && $this->post['customer_code'] != "" ? trim($this->post['customer_code']) : "";
  951. if ($customer_code !== "") $where[] = ['sr.customer_code', "like", '%' . $customer_code . '%'];
  952. $order_source = $order_source = isset($this->post['order_source']) && $this->post['order_source'] != "" ? trim($this->post['order_source']) : "";
  953. if ($order_source !== "") $where[] = ['b.order_source', "=", $order_source];
  954. $condition=[];
  955. $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo'] != "" ? trim($this->post['relaComNo']) : "";
  956. //只有level2的账号过滤数据权限
  957. if ($this->level == 2) {
  958. $role = $this->checkDataShare();
  959. $hand = resign_hand_user($this->uid, 0);
  960. if (!empty($role[DataGroupModel::$type_全部])) {
  961. $arr = array_unique(array_merge($hand, $role[DataGroupModel::$type_全部]));
  962. // $uidim =implode(",",$hand);
  963. // $condition .= "sr.cgderid in ($uidim) or sr.person_id in ($uidim) or sr.apply_id in (" . implode(',',$arr) .
  964. // ")";
  965. $condition[] = ["sr.apply_id", "in", $arr];
  966. $condition[] = ["sr.cgderid", "in", $hand];
  967. $condition[] = ["sr.person_id", "in", $hand];
  968. }
  969. if ($relaComNo != "") $where[] = ['sr.companyNo', '=', $relaComNo];
  970. }
  971. //供应商账号不允许看到库存品数据
  972. if ($this->level == 3){
  973. $where[] = ['b.supNo', '=', $relaComNo];
  974. }
  975. if(in_array($this->roleid,config('app.wsm_cgder_role'))){
  976. $where[]=["b.order_type","=",1];
  977. }
  978. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  979. if ($company_name !== "") $where[] = ["sr.apply_id", 'in', get_company_item_user_by_name($company_name)];
  980. $count=Db::name("sale_return")
  981. ->alias('sr')
  982. ->leftJoin("sale b", "b.orderCode=sr.orderCode AND b.is_del=0")
  983. ->where($where)
  984. ->where(function ($query)use ($condition){$query->whereOr($condition);})
  985. ->count('sr.id');
  986. $total = ceil($count/$size);
  987. $page = $total>=$page ? $page :$total;
  988. $list = Db::name("sale_return")
  989. ->alias('sr')
  990. ->field('sr.*,b.skuCode,b.sale_price,b.good_num total_num,b.order_source')
  991. ->leftJoin("sale b", "b.orderCode=sr.orderCode AND b.is_del=0")
  992. ->where($where)
  993. ->where(function ($query)use ($condition){$query->whereOr($condition);})
  994. ->order("sr.addtime desc")
  995. ->page($page,$size)
  996. ->select()
  997. ->toArray();
  998. $all_createrid = array_column($list,'apply_id');
  999. $item = get_company_name_by_uid($all_createrid);
  1000. $data=[];
  1001. foreach ($list as $value){
  1002. $value['error_msg']='';
  1003. if($value['error_code']!=''){
  1004. $error = Db::name("result_info")->where(["result_code"=>$value['error_code']])->find();
  1005. $value['error_msg']= isset($error['result'])?$error['result']:"";
  1006. }
  1007. $value['return_total'] =$value['sale_price']*$value['num'] ;
  1008. $value['company_name'] = $item[$value['apply_id']]??'';
  1009. $data[]=$value ;
  1010. }
  1011. return app_show(0,"获取成功",["count"=>$count,'list'=>$data]);
  1012. }
  1013. }