Supplier.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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 = [];
  19. $name= isset($post['name'])&&$post['name']!="" ? trim($post['name']) :"";
  20. if($name!=""){
  21. $condition []=["name|contector","like","%{$name}%"];
  22. }
  23. $type=isset($post['type'])&&$post['type']!="" ? trim($post['type']) :"";
  24. if($type!=""){
  25. $condition []=["type","=",$type];
  26. }
  27. $page = isset($post['page'])&&$post['page']!="" ? intval($post['page']) :0;
  28. $size = isset($post['size'])&&$post['size']!="" ? intval($post['size']) :10;
  29. $count = Db::name("supplier_info")->where($condition)->count();
  30. $total = ceil($count/$size)>1 ? ceil($count/$size) : 1;
  31. $page = $page>=$total?intval($total):$page;
  32. $list = Db::name("supplier_info")->where($condition)->page($page,$size)->field("id,code,name,contector,nature,type,mobile,address,post,addtime")->select();
  33. return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
  34. }
  35. /**获取供应商列表
  36. * @return \think\response\Json|void
  37. * @throws \think\db\exception\DataNotFoundException
  38. * @throws \think\db\exception\DbException
  39. * @throws \think\db\exception\ModelNotFoundException
  40. */
  41. public function SupplierAll()
  42. {
  43. $post = $this->post;
  44. $condition = [];
  45. $name= isset($post['name'])&&$post['name']!="" ? trim($post['name']) :"";
  46. if($name!=""){
  47. $condition []=["name","like","%{$name}%"];
  48. }
  49. $type=isset($post['type'])&&$post['type']!="" ? trim($post['type']) :"";
  50. if($type!=""){
  51. $condition []=["type","=",$type];
  52. }
  53. $list = Db::name("supplier_info")->where($condition)->field("id,code,name,contector,nature,type,mobile,address,post,addtime,LENGTH(companyName) as weight")->limit(20)->order("weight asc")->select();
  54. return app_show(0,"获取成功",$list);
  55. }
  56. /**
  57. * 获取供应商信息
  58. *
  59. * @return \think\Response
  60. */
  61. public function SupplierInfo()
  62. {
  63. $post = $this->post;
  64. $sid = isset($post['id'])&& $post['id']!="" ? intval($post['id']) :"";
  65. if($sid==""){
  66. return error_show(1002,"参数d不能为空");
  67. }
  68. $supplier = Db::name("supplier_info")->where("id","=",$sid)->find();
  69. if($supplier==false){
  70. return error_show(1003,"供应商信息不存在");
  71. }
  72. $cgd = Db::name("pay")->where([["supplierNo","=",$supplier['code']],["status","<>",0]])
  73. ->field("id,payNo,pay_fee,wait_fee,status")->select();
  74. $list=["payment"=>["wait"=>["total"=>0,"num"=>0],"already"=>["total"=>0,"num"=>0]],"invoice"=>["wait"=>["total"=>0,"num"=>0],"already"=>["total"=>0,"num"=>0]]];
  75. foreach ($cgd as $key=>$value){
  76. $list['payment']['wait']['total']+= $value['wait_fee']*100;
  77. $list['payment']['already']['total']+= $value['pay_fee']*100;
  78. $paystage = Db::name("pay_stages")->where([["payNo","=",$value['payNo']],["is_del","=",0],['status',">","4"],['status',"<>","9"]])
  79. ->sum('pay_fee');
  80. $paywait = Db::name("pay_stages")->where([["payNo","=",$value['payNo']],["is_del","=",0],['status',"<","4"],
  81. ['status',"<>","9"]])
  82. ->sum('pay_fee');
  83. $list['invoice']['wait']['total']+= $paywait*100;
  84. $list['invoice']['already']['total']+= $paystage*100;
  85. if($value['status']==2){
  86. $list['payment']['already']["num"]++;
  87. }else{
  88. $list['payment']['wait']["num"]++;
  89. }
  90. }
  91. array_walk($list,function (&$v){
  92. $v['wait']['total'] = $v['wait']['total']/100;
  93. $v['already']['total'] = $v['already']['total']/100;
  94. });
  95. return app_show(0,"获取成功",$list);
  96. }
  97. /**
  98. * 修改供应商信息
  99. *
  100. * @param \think\Request $request
  101. * @return \think\Response
  102. */
  103. public function SupplierSave()
  104. {
  105. $post = $this->post;
  106. $sid = isset($post['id'])&& $post['id']!="" ? intval($post['id']) :"";
  107. if($sid==""){
  108. return error_show(1002,"参数d不能为空");
  109. }
  110. $supplier = Db::name("supplier_info")->where("id","=",$sid)->find();
  111. if($supplier==false){
  112. return error_show(1003,"供应商信息不存在");
  113. }
  114. $name= isset($post['name'])&& $post['name']!="" ? trim($post['name']) :"";
  115. if($name==""){
  116. return error_show(1002,"供货商名称不能为空");
  117. }
  118. $contector= isset($post['contector'])&& $post['contector']!="" ? trim($post['contector']) :"";
  119. if($contector==""){
  120. return error_show(1002,"联系人名称不能为空");
  121. }
  122. $mobile= isset($post['mobile'])&& $post['mobile']!="" ? trim($post['mobile']) :"";
  123. if($mobile==""){
  124. return error_show(1002,"联系人手机号不能为空");
  125. }
  126. if(!checkMobile($mobile)){
  127. return error_show(1002,"联系人手机号格式错误");
  128. }
  129. $pay_method= isset($post['pay_method'])&& $post['pay_method']!="" ? trim($post['pay_method']) :"";
  130. if($pay_method==""){
  131. return error_show(1002,"结账方式不能为空");
  132. }
  133. $paydays= isset($post['paydays'])&& $post['paydays']!="" ? trim($post['paydays']) :"";
  134. $return_ticket= isset($post['return_ticket'])&& $post['return_ticket']!="" ? trim($post['return_ticket']) :"";
  135. $data=[
  136. "id"=>$supplier['id'],
  137. "name"=>$name,
  138. "contector"=>$contector,
  139. "mobile"=>$mobile,
  140. "pay_method"=>$pay_method,
  141. "paydays"=>$paydays,
  142. "return_ticket"=>$return_ticket,
  143. "updatetime"=>date("Y-m-d H:i:s"),
  144. ];
  145. $save = Db::name("supplier_info")->save($data);
  146. return $save ? app_show(0,"修改成功") :error_show(1003,"修改失败");
  147. }
  148. /**
  149. * 供应商状态修改
  150. *
  151. * @param int $id
  152. * @return \think\Response
  153. */
  154. public function SupplierStatus()
  155. {
  156. $post = $this->post;
  157. $sid = isset($post['id'])&& $post['id']!="" ? intval($post['id']) :"";
  158. if($sid==""){
  159. return error_show(1002,"参数d不能为空");
  160. }
  161. $supplier = Db::name("supplier_info")->where("id","=",$sid)->find();
  162. if($supplier==false){
  163. return error_show(1003,"供应商信息不存在");
  164. }
  165. $status= isset($post['status'])&& $post['status']!="" ? intval($post['status']) :"";
  166. if($status==""){
  167. return error_show(1002,"参数status不能为空");
  168. }
  169. $data=[
  170. "id"=>$sid,
  171. "status"=>$status,
  172. "updatetime"=>date("Y-m-d H:i:s")
  173. ];
  174. $udap = DB::name("supplier_ifno")->save($data);
  175. return $udap ? app_show(0,"修改成功") :error_show(1003,"修改失败");
  176. }
  177. }