Supplier.php 7.8 KB

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