SupplierClient.php 56 KB

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