Supplier.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\admin\controller;
  4. use think\App;
  5. use think\facade\Db;
  6. class Supplier extends Base
  7. {
  8. public function __construct(App $app) {parent::__construct($app);}
  9. /**
  10. * 显示资源列表
  11. *
  12. * @return \think\Response
  13. */
  14. public function SupplierList()
  15. {
  16. $post = $this->post;
  17. $condition = [];
  18. $companyNo = isset($post['companyNo']) && $post['companyNo'] != "" ? trim($post['companyNo']) : "";
  19. if ($companyNo != "") $condition [] = ["code", "=", $companyNo];
  20. $name = isset($post['name']) && $post['name'] != "" ? trim($post['name']) : "";
  21. if ($name != "") $condition [] = ["name|a.contector", "like", "%{$name}%"];
  22. $type = isset($post['type']) && $post['type'] != "" ? trim($post['type']) : "";
  23. if ($type != "") $condition [] = ["type", "=", $type];
  24. $supplierNo = isset($post['supplierNo']) && $post['supplierNo'] != "" ? trim($post['supplierNo']) : "";
  25. if ($supplierNo != "") $condition [] = ["a.code", "like", "%{$supplierNo}%"];
  26. $page = isset($post['page']) && $post['page'] != "" ? intval($post['page']) : 0;
  27. $size = isset($post['size']) && $post['size'] != "" ? intval($post['size']) : 10;
  28. $count = Db::name("supplier_info")
  29. ->alias("a")
  30. ->leftJoin("company_info b", "a.code=b.companyNo and b.is_del=0")
  31. ->where($condition)
  32. ->count('a.id');
  33. $total = ceil($count / $size) > 1 ? ceil($count / $size) : 1;
  34. $page = $page >= $total ? intval($total) : $page;
  35. $list = Db::name("supplier_info")
  36. ->alias("a")
  37. ->leftJoin("company_info b", "a.code=b.companyNo and b.is_del=0")
  38. ->where($condition)
  39. ->page($page, $size)
  40. ->order("a.id desc")
  41. ->field("a.*,b.company_name,company_address,company_license,bankNo,bank_name,b.contector as company_contector,b.mobile as company_mobile,company_img")
  42. ->select()
  43. ->toArray();
  44. return app_show(0, "获取成功", ["list" => $list, "count" => $count]);
  45. }
  46. /**获取供应商列表
  47. * @return \think\response\Json|void
  48. * @throws \think\db\exception\DataNotFoundException
  49. * @throws \think\db\exception\DbException
  50. * @throws \think\db\exception\ModelNotFoundException
  51. */
  52. public function SupplierAll()
  53. {
  54. $post = $this->post;
  55. $condition = [];
  56. $companyNo = isset($post['companyNo'])&& $post['companyNo']!="" ? trim($post['companyNo']) :"";
  57. if($companyNo!=""){
  58. $condition []=["code","=",$companyNo];
  59. }
  60. $name= isset($post['name'])&&$post['name']!="" ? trim($post['name']) :"";
  61. if($name!=""){
  62. $condition []=["name","like","%{$name}%"];
  63. }
  64. $type=isset($post['type'])&&$post['type']!="" ? trim($post['type']) :"";
  65. if($type!=""){
  66. $condition []=["type","=",$type];
  67. }
  68. $list = Db::name("supplier_info")->where($condition)->field("id,code,name,contector,nature,type,mobile,address,post,addtime,LENGTH(name) as weight")->limit(20)->order("weight asc")->select();
  69. return app_show(0,"获取成功",$list);
  70. }
  71. /**
  72. * 获取供应商信息
  73. *
  74. * @return \think\Response
  75. */
  76. public function SupplierInfo()
  77. {
  78. $post = $this->post;
  79. $sid = isset($post['id'])&& $post['id']!="" ? intval($post['id']) :"";
  80. if($sid==""){
  81. return error_show(1002,"参数d不能为空");
  82. }
  83. $supplier = Db::name("supplier_info")->where("id","=",$sid)->find();
  84. if($supplier==false){
  85. return error_show(1003,"供应商信息不存在");
  86. }
  87. $cgd = Db::name("pay")->where([["supplierNo","=",$supplier['code']],["status","<>",0]])
  88. ->field("id,payNo,pay_fee,wait_fee,status")->select();
  89. $list=["payment"=>["wait"=>["total"=>0,"num"=>0],"already"=>["total"=>0,"num"=>0]],"invoice"=>["wait"=>["total"=>0,"num"=>0],"already"=>["total"=>0,"num"=>0]]];
  90. foreach ($cgd as $key=>$value){
  91. $list['payment']['wait']['total']+= $value['wait_fee']*100;
  92. $list['payment']['already']['total']+= $value['pay_fee']*100;
  93. $paystage = Db::name("pay_stages")->where([["payNo","=",$value['payNo']],["is_del","=",0],['status',">","4"],['status',"<>","9"]])
  94. ->sum('pay_fee');
  95. $paywait = Db::name("pay_stages")->where([["payNo","=",$value['payNo']],["is_del","=",0],['status',"<","4"],
  96. ['status',"<>","9"]])
  97. ->sum('pay_fee');
  98. $list['invoice']['wait']['total']+= $paywait*100;
  99. $list['invoice']['already']['total']+= $paystage*100;
  100. if($value['status']==2){
  101. $list['payment']['already']["num"]++;
  102. }else{
  103. $list['payment']['wait']["num"]++;
  104. }
  105. }
  106. array_walk($list,function (&$v){
  107. $v['wait']['total'] = $v['wait']['total']/100;
  108. $v['already']['total'] = $v['already']['total']/100;
  109. });
  110. return app_show(0,"获取成功",$list);
  111. }
  112. /**
  113. * 修改供应商信息
  114. *
  115. * @param \think\Request $request
  116. * @return \think\Response
  117. */
  118. public function SupplierSave()
  119. {
  120. $post = $this->post;
  121. $sid = isset($post['id'])&& $post['id']!="" ? intval($post['id']) :"";
  122. if($sid==""){
  123. return error_show(1002,"参数d不能为空");
  124. }
  125. $supplier = Db::name("supplier_info")->where("id","=",$sid)->find();
  126. if($supplier==false){
  127. return error_show(1003,"供应商信息不存在");
  128. }
  129. $name= isset($post['name'])&& $post['name']!="" ? trim($post['name']) :"";
  130. if($name==""){
  131. return error_show(1002,"供货商名称不能为空");
  132. }
  133. $contector= isset($post['contector'])&& $post['contector']!="" ? trim($post['contector']) :"";
  134. if($contector==""){
  135. return error_show(1002,"联系人名称不能为空");
  136. }
  137. $mobile= isset($post['mobile'])&& $post['mobile']!="" ? trim($post['mobile']) :"";
  138. if($mobile==""){
  139. return error_show(1002,"联系人手机号不能为空");
  140. }
  141. if(!checkMobile($mobile)){
  142. return error_show(1002,"联系人手机号格式错误");
  143. }
  144. $pay_method= isset($post['pay_method'])&& $post['pay_method']!="" ? trim($post['pay_method']) :"";
  145. if($pay_method==""){
  146. return error_show(1002,"结账方式不能为空");
  147. }
  148. $paydays= isset($post['paydays'])&& $post['paydays']!="" ? trim($post['paydays']) :"";
  149. $return_ticket= isset($post['return_ticket'])&& $post['return_ticket']!="" ? trim($post['return_ticket']) :"";
  150. $data=[
  151. "id"=>$supplier['id'],
  152. "name"=>$name,
  153. "contector"=>$contector,
  154. "mobile"=>$mobile,
  155. "pay_method"=>$pay_method,
  156. "paydays"=>$paydays,
  157. "return_ticket"=>$return_ticket,
  158. "updatetime"=>date("Y-m-d H:i:s"),
  159. ];
  160. $save = Db::name("supplier_info")->save($data);
  161. return $save ? app_show(0,"修改成功") :error_show(1003,"修改失败");
  162. }
  163. /**
  164. * 供应商状态修改
  165. *
  166. * @param int $id
  167. * @return \think\Response
  168. */
  169. public function SupplierStatus()
  170. {
  171. $post = $this->post;
  172. $sid = isset($post['id'])&& $post['id']!="" ? intval($post['id']) :"";
  173. if($sid==""){
  174. return error_show(1002,"参数d不能为空");
  175. }
  176. $supplier = Db::name("supplier_info")->where("id","=",$sid)->find();
  177. if($supplier==false){
  178. return error_show(1003,"供应商信息不存在");
  179. }
  180. $status= isset($post['status'])&& $post['status']!="" ? intval($post['status']) :"";
  181. if($status==""){
  182. return error_show(1002,"参数status不能为空");
  183. }
  184. $data=[
  185. "id"=>$sid,
  186. "status"=>$status,
  187. "updatetime"=>date("Y-m-d H:i:s")
  188. ];
  189. $udap = DB::name("supplier_ifno")->save($data);
  190. return $udap ? app_show(0,"修改成功") :error_show(1003,"修改失败");
  191. }
  192. //获取所有供应商列表,为了超管账号切换到供应商模式时使用,展现在页面右上角
  193. public function supplierListBySuper(){
  194. $post = $this->request->only(['code'=>'','name'=>'','page'=>1,'size'=>10],'post','trim');
  195. $where = [['code', 'like', 'QS%']];
  196. if($post['code']!=='') $where[]=['code','like','%'.$post['code'].'%'];
  197. if($post['name']!=='') $where[]=['name','like','%'.$post['name'].'%'];
  198. $count = Db::name('supplier_info')
  199. ->where($where)
  200. ->count('id');
  201. $list =Db::name('supplier_info')
  202. ->field('id,code,name')
  203. ->where($where)
  204. ->page((int)$post['page'],(int)$post['size'])
  205. ->order(['id'=>'asc'])
  206. ->select()
  207. ->toArray();
  208. return app_show(0,'获取供应商列表成功',['count'=>$count,'list'=>$list]);
  209. }
  210. }