Supplier.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <?php
  2. namespace app\admin\controller;
  3. use app\BaseController;
  4. use think\App;
  5. use think\facade\Db;
  6. class Supplier extends BaseController
  7. {
  8. public $post = "";
  9. public function __construct(App $app){
  10. parent::__construct($app);
  11. $this->post = $this->request->post();
  12. }
  13. public function list(){
  14. $page = isset($this->post['page']) && $this->post['page'] != "" ? intval($this->post['page']) : 1;
  15. $size = isset($this->post['size']) && $this->post['size'] != "" ? intval($this->post['size']) : 10;
  16. $where = ['is_del'=>0];
  17. $name = isset($this->post['name']) && $this->post['name'] !== "" ? trim($this->post['name']) : "";
  18. if ($name !== "") {
  19. $where['name'] = ["like", "%{name}%"];
  20. }
  21. $code = isset($this->post['code']) && $this->post['code'] !== "" ? trim($this->post['code']) : "";
  22. if ($code !== "") {
  23. $where['code'] = ["like", "%{code}%"];
  24. }
  25. $source = isset($this->post['source']) && $this->post['source'] !== "" ? trim($this->post['source']) : "";
  26. if ($source !== "") {
  27. $where['source'] = ["like", "%{source}%"];
  28. }
  29. $area = isset($this->post['area']) && $this->post['area'] !== "" ? trim($this->post['area']) : "";
  30. if ($area !== "") {
  31. $where['area'] = ["like", "%{area}%"];
  32. }
  33. $city = isset($this->post['city']) && $this->post['city'] !== "" ? trim($this->post['city']) : "";
  34. if ($city !== "") {
  35. $where['city'] = ["like", "%{city}%"];
  36. }
  37. $nature = isset($this->post['nature']) && $this->post['nature'] !== "" ? trim($this->post['nature']) : "";
  38. if ($nature !== "") {
  39. $where['nature'] = ["like", "%{nature}%"];
  40. }
  41. $legaler = isset($this->post['legaler']) && $this->post['legaler'] !== "" ? trim($this->post['legaler']) : "";
  42. if ($legaler !== "") {
  43. $where['legaler'] = ["like", "%{legaler}%"];
  44. }
  45. $addr = isset($this->post['addr']) && $this->post['addr'] !== "" ? trim($this->post['addr']) : "";
  46. if ($addr !== "") {
  47. $where['addr'] = ["like", "%{addr}%"];
  48. }
  49. $count = Db::name("supplier")->where($where)->count();
  50. $total = ceil($count/$size);
  51. $page = $page >= $total ? $total : $page;
  52. $list = Db::name('supplier')->where($where)->page($page,$size)->select();
  53. return app_show(0,"获取成功",["list"=>$list,'count'=>$count]);
  54. }
  55. public function create(){
  56. $name = isset($this->post['name']) && $this->post['name'] !=="" ? trim($this->post['name']) :"";
  57. if($name==""){
  58. return error_show(1002,"数据标题不能为空");
  59. }
  60. $rename = Db::name('supplier')->where(['is_del' => 0, 'name' => $name])->find();
  61. if (!empty($rename)) {
  62. return error_show(1002, "公司名称已存在");
  63. }
  64. $code = rand(0000,9999);
  65. $str = sprintf("%04d",$code);
  66. $tr="GYS-".date("Ymd")."-".$str;
  67. $source= isset($this->post['source']) && $this->post['source']!==""? trim($this->post['source']) :"";
  68. if($source==""){
  69. return error_show(1002,"供应商来源不能为空");
  70. }
  71. $type = isset($this->post['type']) && $this->post['type']!==""? trim($this->post['type']) :"";
  72. if($type==""){
  73. return error_show(1002,"申请类型不能为空");
  74. }
  75. $area = isset($this->post['area']) && $this->post['area']!==""? trim($this->post['area']) :"";
  76. if($area==""){
  77. return error_show(1002,"大区不能为空");
  78. }
  79. $city = isset($this->post['city']) && $this->post['city']!==""? trim($this->post['city']) :"";
  80. if($city==""){
  81. return error_show(1002,"城市不能为空");
  82. }
  83. $nature = isset($this->post['nature']) && $this->post['nature']!==""? trim($this->post['nature']) :"";
  84. if($nature==""){
  85. return error_show(1002,"公司类型不能为空");
  86. }
  87. $ticket_type = isset($this->post['ticket_type']) && $this->post['ticket_type']!==""? trim($this->post['ticket_type']) :"";
  88. if($ticket_type==""){
  89. return error_show(1002,"回款方式不能为空");
  90. }
  91. $legaler = isset($this->post['legaler']) && $this->post['legaler']!==""? trim($this->post['legaler']) :"";
  92. if($legaler==""){
  93. return error_show(1002,"法人不能为空");
  94. }
  95. $addr = isset($this->post['addr']) && $this->post['addr']!==""? trim($this->post['addr']) :"";
  96. if($addr==""){
  97. return error_show(1002,"地址不能为空");
  98. }
  99. $data=[
  100. "name"=>$name,"source"=>$source,"code"=>$tr,
  101. "type"=>$type,"area"=>$area,"city"=>$city,
  102. "nature"=>$nature,"legaler"=>$legaler,"addr"=>$addr,
  103. "is_del"=>0,"ticket_type"=>$ticket_type,
  104. "addtime"=>date('Y-m-d H:i:s'),
  105. "updatetime"=>date("Y-m-d H:i:s"),
  106. ];
  107. $join = Db::name('supplier')->insert($data);
  108. return $join? error_show(0,"添加成功") :error_show(1002,"添加失败");
  109. }
  110. public function edit(){
  111. $id = isset($this->post['id']) && $this->post['id'] !==""? trim($this->post['id']):"";
  112. $ion = Db::name('supplier')->where(['id'=>$id,'is_del'=>0])->find();
  113. if(empty($ion)){
  114. return error_show(1004,"供应商不存在");
  115. }
  116. $name = isset($this->post['name']) && $this->post['name']!=="" ? $this->post['name']:"";
  117. if($name==""){
  118. return error_show(1002,'数据标题不能为空');
  119. }
  120. $rename =Db::name('supplier')->where(['name'=>$name,'is_del'=>0])->where('id','<>',$id)->find();
  121. if(!empty($rename)){
  122. return error_show(1004,"数据标题已存在");
  123. }
  124. $source = isset($this->post['source']) && $this->post['source'] !==""? $this->post['source']:"";
  125. if($source==""){
  126. return error_show(1002,"供应商来源不能为空");
  127. }
  128. $type = isset($this->post['type']) && $this->post['type']!==""? trim($this->post['type']) :"";
  129. if($type==""){
  130. return error_show(1002,"申请类型不能为空");
  131. }
  132. $area = isset($this->post['area']) && $this->post['area']!==""? trim($this->post['area']) :"";
  133. if($area==""){
  134. return error_show(1002,"大区不能为空");
  135. }
  136. $city = isset($this->post['city']) && $this->post['city']!==""? trim($this->post['city']) :"";
  137. if($city==""){
  138. return error_show(1002,"城市不能为空");
  139. }
  140. $nature = isset($this->post['nature']) && $this->post['nature']!==""? trim($this->post['nature']) :"";
  141. if($nature==""){
  142. return error_show(1002,"公司类型不能为空");
  143. }
  144. $legaler = isset($this->post['legaler']) && $this->post['legaler']!==""? trim($this->post['legaler']) :"";
  145. if($legaler==""){
  146. return error_show(1002,"法人不能为空");
  147. }
  148. $addr = isset($this->post['addr']) && $this->post['addr']!==""? trim($this->post['addr']) :"";
  149. if($addr==""){
  150. return error_show(1002,"地址不能为空");
  151. }
  152. $vmp=[
  153. "id"=>$id,"legaler"=>$legaler,
  154. "name"=>$name,"source"=>$source,
  155. "type"=>$type,"area"=>$area,"city"=>$city,
  156. "nature"=>$nature,"addr"=>$addr,
  157. "is_del"=>0,"addtime"=>date('Y-m-d H:i:s'),
  158. "updatetime"=>date("Y-m-d H:i:s")
  159. ];
  160. $ed = Db::name('supplier')->where(['is_del'=>0,'id'=>$id])->save($vmp);
  161. return $ed ? error_show(0,"编辑成功") : error_show(1002,"编辑失败");
  162. }
  163. public function selec(){
  164. $id= isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']) :"";
  165. if($id==""){
  166. return error_show(1002,"供应商不存在");
  167. }
  168. $se = Db::name('supplier')->where(['id'=>$id,'is_del'=>0])->find();
  169. return app_show(0,"获取成功",$se);
  170. }
  171. }