SupplierClient.php 59 KB

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