SupplierClient.php 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106
  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[] = ['c.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[] = ['c.supNo', "like", '%' . $param['supplierNo'] . '%'];
  733. if ($param['companyNo'] !== "") $where[] = ['c.supplierNo', "like", '%' . $param['companyNo'] . '%'];
  734. $condition = [];
  735. //只有level2的账号过滤数据权限
  736. if ($this->level == 2) {
  737. $hand = resign_hand_user($this->uid, 0);
  738. $role = $this->checkDataShare();
  739. if (!empty($role[DataGroupModel::$type_全部])) {
  740. $arr = array_unique(array_merge($hand, $role[DataGroupModel::$type_全部]));
  741. $condition[] = ["a.person_id", "in", $hand];
  742. $condition[] = ["a.apply_id", "in", $arr];
  743. $condition[] = ["a.cgderid", "in", $hand];
  744. }
  745. if ($param['relaComNo'] !== '') $where[] = ['c.supplierNo', "=", $param['relaComNo']];
  746. }
  747. //level3账号不允许看到库存品订单
  748. if ($this->level == 3){
  749. $where[] = ['c.supNo', '=', $param['relaComNo']];
  750. }
  751. // $condition .="a.cgderid in {$hand} or a.person_id in {$hand} or a.apply_id in ("
  752. // .implode(',',$role[DataGroupModel::$type_全部]).")";
  753. if ($param['company_name'] !== "") $where[] = ["a.apply_id", 'in', get_company_item_user_by_name($param['company_name'])];
  754. $count = Db::name("order_return")
  755. ->alias("a")
  756. ->leftJoin("order_returninfo b", "a.returnCode=b.returnCode")
  757. ->leftJoin("sale c", "c.orderCode=a.orderCode AND c.is_del=0")
  758. ->where($where)
  759. ->where(function ($query) use ($condition) {
  760. $query->whereOr($condition);
  761. })
  762. ->count('a.id');;
  763. $list = Db::name("order_return")
  764. ->alias("a")
  765. ->leftJoin("order_returninfo b", "a.returnCode=b.returnCode")
  766. ->leftJoin("sale c", "c.orderCode=a.orderCode AND c.is_del=0")
  767. ->where($where)
  768. ->where(function ($query) use ($condition) {
  769. $query->whereOr($condition);
  770. })
  771. ->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")
  772. ->page($param['page'], $param['size'])
  773. ->order("a.addtime desc")
  774. ->select()
  775. ->toArray();
  776. $all_createrid = array_column($list, 'apply_id');
  777. $item = get_company_name_by_uid($all_createrid);
  778. $data = [];
  779. foreach ($list as $value) {
  780. $value['company_name'] = $item[$value['apply_id']] ?? '';
  781. $data[] = $value;
  782. }
  783. return app_show(0, "获取成功", ['list' => $data, "count" => $count]);
  784. }
  785. /** 售后退货单
  786. * @return \think\response\Json|void
  787. * @throws \think\db\exception\DataNotFoundException
  788. * @throws \think\db\exception\DbException
  789. * @throws \think\db\exception\ModelNotFoundException
  790. */
  791. public function backlist()
  792. {
  793. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  794. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  795. $where = [['a.is_del', "=", 0]];
  796. $thNo = isset($this->post['thNo']) && $this->post['thNo'] != "" ? trim($this->post['thNo']) : "";
  797. if ($thNo != "") {
  798. $where[] = ['a.thNo', "like", "%{$thNo}%"];
  799. }
  800. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  801. if ($status !== "") {
  802. // $where['status'] = $status;
  803. $where[] = ['a.status', "=", $status];
  804. }
  805. $post_code = isset($this->post['post_code']) && $this->post['post_code'] != "" ? trim($this->post['post_code']) : "";
  806. if ($post_code != "") {
  807. $where[] = ['a.post_code', "like", "%{$post_code}%"];
  808. }
  809. $post_compay = isset($this->post['post_compay']) && $this->post['post_compay'] != "" ? trim($this->post['post_compay']) : "";
  810. if ($post_compay != "") {
  811. $where[] = ['a.post_company', "=", $post_compay];
  812. }
  813. $customer_code = isset($this->post['customer_code']) && $this->post['customer_code'] != "" ? trim($this->post['customer_code']) : "";
  814. if ($customer_code != "") {
  815. $where[] = ['b.customer_code', "like", "%{$customer_code}%"];
  816. }
  817. $order_code = isset($this->post['order_code']) && $this->post['order_code'] != "" ? trim($this->post['order_code']) : "";
  818. if ($order_code != "") {
  819. $where[] = ['a.orderCode', "like", "%{$order_code}%"];
  820. }
  821. $out_code = isset($this->post['out_code']) && $this->post['out_code'] != "" ? trim($this->post['out_code']) : "";
  822. if ($out_code != "") {
  823. $where[] = ['a.outCode', "like", "%{$out_code}%"];
  824. }
  825. $return_code = isset($this->post['return_code']) && $this->post['return_code'] != "" ? trim($this->post['return_code']) : "";
  826. if ($return_code != "") {
  827. $where[] = ['a.returnCode', "like", "%{$return_code}%"];
  828. }
  829. $start = isset($this->post['start']) && $this->post['start'] != '' ? $this->post['start'] : "";
  830. if ($start !== "") {
  831. $where[] = ['a.addtime', ">=", $start];
  832. }
  833. $end = isset($this->post['end']) && $this->post['end'] != '' ? $this->post['end'] : "";
  834. if ($end !== "") {
  835. $where[] = ['a.addtime', "<=", $end];
  836. }
  837. $order_source = isset($this->post['order_source']) && $this->post['order_source'] != "" ? trim($this->post['order_source']) : "";
  838. if ($order_source !== "") {
  839. $where[] = ['b.order_source', "=", $order_source];
  840. }
  841. $supplierNo = trim($this->post['supplierNo'] ?? '');
  842. if ($supplierNo !== '') $where[] = ['b.supNo', 'like', '%'.$supplierNo.'%'];
  843. $companyNo = trim($this->post['companyNo'] ?? '');
  844. if ($companyNo !== '') $where[] = ['b.supplierNo', 'like', '%'.$companyNo.'%'];
  845. $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo'] != "" ? trim($this->post['relaComNo']) : "";
  846. $condition = [];
  847. //只有level2的账号过滤数据权限
  848. if ($this->level == 2) {
  849. $role = $this->checkDataShare();
  850. $hand = resign_hand_user($this->uid, 0);
  851. if (!empty($role[DataGroupModel::$type_全部])) {
  852. $arr = array_unique(array_merge($hand, $role[DataGroupModel::$type_全部]));
  853. $condition[] = ['a.apply_id', 'in', $arr];
  854. $condition[] = ['a.cgderid', 'in', $hand];
  855. }
  856. if ($relaComNo != "") $where[] = ['b.supplierNo', '=', $relaComNo];
  857. }
  858. //供应商账号不允许看到库存品数据
  859. if ($this->level == 3) {
  860. $where[] = ['b.supNo', '=', $relaComNo];
  861. }
  862. $count = Db::name("order_back")
  863. ->alias('a')
  864. ->leftJoin('sale b', 'b.orderCode=a.orderCode AND b.is_del=0')
  865. ->where($where)
  866. ->where(function ($query) use ($condition) {
  867. $query->whereOr($condition);
  868. })
  869. ->count('a.id');
  870. $total = ceil($count / $size);
  871. $page = $page >= $total ? $total : $page;
  872. $list = Db::name("order_back")
  873. ->alias('a')
  874. ->leftJoin('sale b', 'b.orderCode=a.orderCode AND b.is_del=0')
  875. ->where($where)
  876. ->where(function ($query) use ($condition) {
  877. $query->whereOr($condition);
  878. })
  879. ->field('a.*,b.order_source')
  880. ->page($page, $size)
  881. ->order("a.addtime desc")
  882. ->select()
  883. ->toArray();
  884. $data = [];
  885. $all_wsm = Db::name("warehouse_info")
  886. ->alias("a")
  887. ->where(["a.wsm_code" => array_column($list, 'return_wsm')])
  888. ->column("a.name,a.supplierNo", 'a.wsm_code');//b.name,b.code
  889. $userCommon = new \app\admin\common\User();
  890. $names = $userCommon->handle('getCodeAndName', ['code' => array_unique(array_column($all_wsm, 'supplierNo'))]);
  891. foreach ($list as $value) {
  892. $value['wsm_name'] = "";
  893. $value['wsm_supplier'] = '';
  894. $value['wsm_supplierNo'] = '';
  895. if ($value['return_wsm'] != "") {
  896. $value['wsm_name'] = $all_wsm[$value['return_wsm']]['name'] ?? '';//isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
  897. $value['wsm_supplier'] = $names['data'][$all_wsm[$value['return_wsm']]['supplierNo']] ?? '';//isset($wsmcode['name']) ? $wsmcode['name']:"";
  898. $value['wsm_supplierNo'] = $all_wsm[$value['return_wsm']]['supplierNo'];//isset($wsmcode['code']) ? $wsmcode['code']:"";
  899. }
  900. $inorder = Db::name("order_backinfo")
  901. ->where(['thNo' => $value['thNo'], "is_del" => 0])
  902. ->select()
  903. ->toArray();
  904. $value['child'] = empty($inorder) ? [] : $inorder;
  905. $data[] = $value;
  906. }
  907. return app_show(0, "获取成功", ["list" => $data, "count" => $count]);
  908. }
  909. //退货单列表
  910. public function reorderlist(){
  911. $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']):"1";
  912. $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']):"10";
  913. $where =[['sr.is_del',"=",0]];
  914. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  915. if($bkcode!=""){
  916. $where[]=['sr.returnCode',"like", "%{$bkcode}%"];
  917. }
  918. $status = isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
  919. if($status!==""){
  920. $where[]=['sr.status',"=", $status];
  921. }
  922. $orderCode = isset($this->post['orderCode']) && $this->post['orderCode']!="" ? trim($this->post['orderCode']) :"";
  923. if($orderCode!=""){
  924. $where[]=['sr.orderCode',"like", "%{$orderCode}%"];
  925. }
  926. $apply_name = isset($this->post['apply_name']) && $this->post['apply_name']!="" ? trim($this->post['apply_name']) :"";
  927. if($apply_name!=""){
  928. $where[]=['sr.apply_name',"like", "%{$apply_name}%"];
  929. }
  930. $start =isset($this->post['start'])&&$this->post['start']!='' ? $this->post['start']:"";
  931. if($start!==""){
  932. $where[]=['sr.addtime',">=", $start.' 00:00:00'];
  933. }
  934. $end =isset($this->post['end'])&&$this->post['end']!='' ? $this->post['end']:"";
  935. if($end!==""){
  936. $where[]=['sr.addtime',"<=", $end.' 23:59:59'];
  937. }
  938. //商品成本编码搜索
  939. $good_code = isset($this->post['good_code']) && $this->post['good_code'] != "" ? trim($this->post['good_code']) : "";
  940. if ($good_code != "") {
  941. $where[] = ['sr.good_code', "like", "%{$good_code}%"];
  942. }
  943. //商品上线编码搜索
  944. $skuCode = isset($this->post['skuCode']) && $this->post['skuCode'] != "" ? trim($this->post['skuCode']) : "";
  945. if ($skuCode != "") {
  946. $where[] = ['b.skuCode', "like", "%{$skuCode}%"];
  947. }
  948. $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] != "" ? trim($this->post['supplierNo']) : "";
  949. if ($supplierNo !== "") $where[] = ['b.supNo', "like", '%' . $supplierNo . '%'];
  950. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] != "" ? trim($this->post['companyNo']) : "";
  951. if ($companyNo !== "") $where[] = ['b.supplierNo', "like", '%' . $companyNo . '%'];
  952. $customer_code = isset($this->post['customer_code']) && $this->post['customer_code'] != "" ? trim($this->post['customer_code']) : "";
  953. if ($customer_code !== "") $where[] = ['b.customer_code', "like", '%' . $customer_code . '%'];
  954. $order_source = $order_source = isset($this->post['order_source']) && $this->post['order_source'] != "" ? trim($this->post['order_source']) : "";
  955. if ($order_source !== "") $where[] = ['b.order_source', "=", $order_source];
  956. $condition=[];
  957. $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo'] != "" ? trim($this->post['relaComNo']) : "";
  958. //只有level2的账号过滤数据权限
  959. if ($this->level == 2) {
  960. $role = $this->checkDataShare();
  961. $hand = resign_hand_user($this->uid, 0);
  962. if (!empty($role[DataGroupModel::$type_全部])) {
  963. $arr = array_unique(array_merge($hand, $role[DataGroupModel::$type_全部]));
  964. // $uidim =implode(",",$hand);
  965. // $condition .= "sr.cgderid in ($uidim) or sr.person_id in ($uidim) or sr.apply_id in (" . implode(',',$arr) .
  966. // ")";
  967. $condition[] = ["sr.apply_id", "in", $arr];
  968. $condition[] = ["sr.cgderid", "in", $hand];
  969. $condition[] = ["sr.person_id", "in", $hand];
  970. }
  971. if ($relaComNo != "") $where[] = ['sr.companyNo', '=', $relaComNo];
  972. }
  973. //供应商账号不允许看到库存品数据
  974. if ($this->level == 3){
  975. $where[] = ['b.supNo', '=', $relaComNo];
  976. }
  977. if(in_array($this->roleid,config('app.wsm_cgder_role'))){
  978. $where[]=["b.order_type","=",1];
  979. }
  980. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  981. if ($company_name !== "") $where[] = ["sr.apply_id", 'in', get_company_item_user_by_name($company_name)];
  982. $count=Db::name("sale_return")
  983. ->alias('sr')
  984. ->leftJoin("sale b", "b.orderCode=sr.orderCode AND b.is_del=0")
  985. ->where($where)
  986. ->where(function ($query)use ($condition){$query->whereOr($condition);})
  987. ->count('sr.id');
  988. $total = ceil($count/$size);
  989. $page = $total>=$page ? $page :$total;
  990. $list = Db::name("sale_return")
  991. ->alias('sr')
  992. ->field('sr.*,b.skuCode,b.sale_price,b.good_num total_num,b.order_source')
  993. ->leftJoin("sale b", "b.orderCode=sr.orderCode AND b.is_del=0")
  994. ->where($where)
  995. ->where(function ($query)use ($condition){$query->whereOr($condition);})
  996. ->order("sr.addtime desc")
  997. ->page($page,$size)
  998. ->select()
  999. ->toArray();
  1000. $all_createrid = array_column($list,'apply_id');
  1001. $item = get_company_name_by_uid($all_createrid);
  1002. $data=[];
  1003. foreach ($list as $value){
  1004. $value['error_msg']='';
  1005. if($value['error_code']!=''){
  1006. $error = Db::name("result_info")->where(["result_code"=>$value['error_code']])->find();
  1007. $value['error_msg']= isset($error['result'])?$error['result']:"";
  1008. }
  1009. $value['return_total'] =$value['sale_price']*$value['num'] ;
  1010. $value['company_name'] = $item[$value['apply_id']]??'';
  1011. $data[]=$value ;
  1012. }
  1013. return app_show(0,"获取成功",["count"=>$count,'list'=>$data]);
  1014. }
  1015. }