SupplierClient.php 59 KB

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