Supplier.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\admin\controller;
  4. use app\admin\BaseController;
  5. use think\App;
  6. use think\facade\Db;
  7. class Supplier extends BaseController
  8. {
  9. public function __construct(App $app) {parent::__construct($app);}
  10. /**
  11. * 显示资源列表
  12. *
  13. * @return \think\Response
  14. */
  15. public function SupplierList()
  16. {
  17. $post = $this->post;
  18. $condition = "1=1 ";
  19. $name= isset($post['name'])&&$post['name']!="" ? trim($post['name']) :"";
  20. if($name!=""){
  21. $condition .=" and (name like '%{$name}%' or contector like '%{$name}%')";
  22. }
  23. $page = isset($post['page'])&&$post['page']!="" ? intval($post['page']) :0;
  24. $size = isset($post['size'])&&$post['size']!="" ? intval($post['size']) :10;
  25. $count = Db::name("supplier_info")->where($condition)->count();
  26. $total = ceil($count/$size)>1 ? ceil($count/$size) : 1;
  27. $page = $page>=$total?intval($total):$page;
  28. $list = Db::name("supplier_info")->where($condition)->page($page,$size)->field("id,code,name,contector,nature,mobile,address,post,addtime")->select();
  29. return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
  30. }
  31. /**
  32. * 获取供应商信息
  33. *
  34. * @return \think\Response
  35. */
  36. public function SupplierInfo()
  37. {
  38. $post = $this->post;
  39. $sid = isset($post['id'])&& $post['id']!="" ? intval($post['id']) :"";
  40. if($sid==""){
  41. return error_show(1002,"参数d不能为空");
  42. }
  43. $supplier = Db::name("supplier_info")->where("id","=",$sid)->find();
  44. if($supplier==false){
  45. return error_show(1003,"供应商信息不存在");
  46. }
  47. $cgd = Db::name("pay")->where([["supplierNo","=",$supplier['code']],["status","<>",0]])
  48. ->field("id,payNo,pay_fee,wait_fee,status")->select();
  49. $list=["payment"=>["wait"=>["total"=>0,"num"=>0],"already"=>["total"=>0,"num"=>0]],"invoice"=>["wait"=>["total"=>0,"num"=>0],"already"=>["total"=>0,"num"=>0]]];
  50. foreach ($cgd as $key=>$value){
  51. $list['payment']['wait']['total']+= $value['wait_fee']*100;
  52. $list['payment']['already']['total']+= $value['pay_fee']*100;
  53. $paystage = Db::name("pay_stages")->where([["payNo","=",$value['payNo']],["is_del","=",0],['status',">","4"],['status',"<>","9"]])
  54. ->sum('pay_fee');
  55. $paywait = Db::name("pay_stages")->where([["payNo","=",$value['payNo']],["is_del","=",0],['status',"<","4"],
  56. ['status',"<>","9"]])
  57. ->sum('pay_fee');
  58. $list['invoice']['wait']['total']+= $paywait*100;
  59. $list['invoice']['already']['total']+= $paystage*100;
  60. if($value['status']==2){
  61. $list['payment']['already']["num"]++;
  62. }else{
  63. $list['payment']['wait']["num"]++;
  64. }
  65. }
  66. array_walk($list,function (&$v){
  67. $v['wait']['total'] = $v['wait']['total']/100;
  68. $v['already']['total'] = $v['already']['total']/100;
  69. });
  70. return app_show(0,"获取成功",$list);
  71. }
  72. /**
  73. * 修改供应商信息
  74. *
  75. * @param \think\Request $request
  76. * @return \think\Response
  77. */
  78. public function SupplierSave()
  79. {
  80. $post = $this->post;
  81. $sid = isset($post['id'])&& $post['id']!="" ? intval($post['id']) :"";
  82. if($sid==""){
  83. return error_show(1002,"参数d不能为空");
  84. }
  85. $supplier = Db::name("supplier_info")->where("id","=",$sid)->find();
  86. if($supplier==false){
  87. return error_show(1003,"供应商信息不存在");
  88. }
  89. $name= isset($post['name'])&& $post['name']!="" ? trim($post['name']) :"";
  90. if($name==""){
  91. return error_show(1002,"供货商名称不能为空");
  92. }
  93. $contector= isset($post['contector'])&& $post['contector']!="" ? trim($post['contector']) :"";
  94. if($contector==""){
  95. return error_show(1002,"联系人名称不能为空");
  96. }
  97. $mobile= isset($post['mobile'])&& $post['mobile']!="" ? trim($post['mobile']) :"";
  98. if($mobile==""){
  99. return error_show(1002,"联系人手机号不能为空");
  100. }
  101. if(!checkMobile($mobile)){
  102. return error_show(1002,"联系人手机号格式错误");
  103. }
  104. $pay_method= isset($post['pay_method'])&& $post['pay_method']!="" ? trim($post['pay_method']) :"";
  105. if($pay_method==""){
  106. return error_show(1002,"结账方式不能为空");
  107. }
  108. $paydays= isset($post['paydays'])&& $post['paydays']!="" ? trim($post['paydays']) :"";
  109. $return_ticket= isset($post['return_ticket'])&& $post['return_ticket']!="" ? trim($post['return_ticket']) :"";
  110. $data=[
  111. "id"=>$supplier['id'],
  112. "name"=>$name,
  113. "contector"=>$contector,
  114. "mobile"=>$mobile,
  115. "pay_method"=>$pay_method,
  116. "paydays"=>$paydays,
  117. "return_ticket"=>$return_ticket,
  118. "updatetime"=>date("Y-m-d H:i:s"),
  119. ];
  120. $save = Db::name("supplier_info")->save($data);
  121. return $save ? app_show(0,"修改成功") :error_show(1003,"修改失败");
  122. }
  123. /**
  124. * 供应商状态修改
  125. *
  126. * @param int $id
  127. * @return \think\Response
  128. */
  129. public function SupplierStatus()
  130. {
  131. $post = $this->post;
  132. $sid = isset($post['id'])&& $post['id']!="" ? intval($post['id']) :"";
  133. if($sid==""){
  134. return error_show(1002,"参数d不能为空");
  135. }
  136. $supplier = Db::name("supplier_info")->where("id","=",$sid)->find();
  137. if($supplier==false){
  138. return error_show(1003,"供应商信息不存在");
  139. }
  140. $status= isset($post['status'])&& $post['status']!="" ? intval($post['status']) :"";
  141. if($status==""){
  142. return error_show(1002,"参数status不能为空");
  143. }
  144. $data=[
  145. "id"=>$sid,
  146. "status"=>$status,
  147. "updatetime"=>date("Y-m-d H:i:s")
  148. ];
  149. $udap = DB::name("supplier_ifno")->save($data);
  150. return $udap ? app_show(0,"修改成功") :error_show(1003,"修改失败");
  151. }
  152. }