Supplier.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  13. if($token==""){
  14. return error_show(101,'token不能为空');
  15. }
  16. $effetc = VerifyTokens($token);
  17. if(!empty($effetc) && $effetc['code']!=0){
  18. return error_show($effetc['code'],$effetc['message']);
  19. }
  20. }
  21. /*列表*/
  22. public function list(){
  23. $page = isset($this->post['page']) && $this->post['page'] != "" ? intval($this->post['page']) : 1;
  24. $size = isset($this->post['size']) && $this->post['size'] != "" ? intval($this->post['size']) : 10;
  25. $where = ['is_del'=>0];
  26. $name = isset($this->post['name']) && $this->post['name'] !== "" ? trim($this->post['name']) : "";
  27. if ($name !== "") {
  28. $where['name'] = ["like", "%{name}%"];
  29. }
  30. $code = isset($this->post['code']) && $this->post['code'] !== "" ? trim($this->post['code']) : "";
  31. if ($code !== "") {
  32. $where['code'] = ["like", "%{code}%"];
  33. }
  34. $source = isset($this->post['source']) && $this->post['source'] !== "" ? trim($this->post['source']) : "";
  35. if ($source !== "") {
  36. $where['source'] = ["like", "%{source}%"];
  37. }
  38. $area = isset($this->post['area']) && $this->post['area'] !== "" ? trim($this->post['area']) : "";
  39. if ($area !== "") {
  40. $where['area'] = ["like", "%{area}%"];
  41. }
  42. $city = isset($this->post['city']) && $this->post['city'] !== "" ? trim($this->post['city']) : "";
  43. if ($city !== "") {
  44. $where['city'] = ["like", "%{city}%"];
  45. }
  46. $nature = isset($this->post['nature']) && $this->post['nature'] !== "" ? trim($this->post['nature']) : "";
  47. if ($nature !== "") {
  48. $where['nature'] = ["like", "%{nature}%"];
  49. }
  50. $legaler = isset($this->post['legaler']) && $this->post['legaler'] !== "" ? trim($this->post['legaler']) : "";
  51. if ($legaler !== "") {
  52. $where['legaler'] = ["like", "%{legaler}%"];
  53. }
  54. $addr = isset($this->post['addr']) && $this->post['addr'] !== "" ? trim($this->post['addr']) : "";
  55. if ($addr !== "") {
  56. $where['addr'] = ["like", "%{addr}%"];
  57. }
  58. $count = Db::name("supplier")->where($where)->count();
  59. $total = ceil($count/$size);
  60. $page = $page >= $total ? $total : $page;
  61. $list = Db::name('supplier')->where($where)->page($page,$size)->select();
  62. return app_show(0,"获取成功",["list"=>$list,'count'=>$count]);
  63. }
  64. /*新建*/
  65. public function create(){
  66. $name = isset($this->post['name']) && $this->post['name'] !=="" ? trim($this->post['name']) :"";
  67. if($name==""){
  68. return error_show(1002,"数据标题不能为空");
  69. }
  70. $rename = Db::name('supplier')->where(['is_del' => 0, 'name' => $name])->find();
  71. if (!empty($rename)) {
  72. return error_show(1002, "公司名称已存在");
  73. }
  74. $code = rand(0000,9999);
  75. $str = sprintf("%04d",$code);
  76. $tr="GYS-".date("Ymd")."-".$str;
  77. $source= isset($this->post['source']) && $this->post['source']!==""? trim($this->post['source']) :"";
  78. if($source==""){
  79. return error_show(1002,"供应商来源不能为空");
  80. }
  81. $type = isset($this->post['type']) && $this->post['type']!==""? trim($this->post['type']) :"";
  82. if($type==""){
  83. return error_show(1002,"申请类型不能为空");
  84. }
  85. $area = isset($this->post['area']) && $this->post['area']!==""? trim($this->post['area']) :"";
  86. if($area==""){
  87. return error_show(1002,"大区不能为空");
  88. }
  89. $city = isset($this->post['city']) && $this->post['city']!==""? trim($this->post['city']) :"";
  90. if($city==""){
  91. return error_show(1002,"城市不能为空");
  92. }
  93. $nature = isset($this->post['nature']) && $this->post['nature']!==""? trim($this->post['nature']) :"";
  94. if($nature==""){
  95. return error_show(1002,"公司类型不能为空");
  96. }
  97. $ticket_type = isset($this->post['ticket_type']) && $this->post['ticket_type']!==""? trim($this->post['ticket_type']) :"";
  98. if($ticket_type==""){
  99. return error_show(1002,"回款方式不能为空");
  100. }
  101. $legaler = isset($this->post['legaler']) && $this->post['legaler']!==""? trim($this->post['legaler']) :"";
  102. if($legaler==""){
  103. return error_show(1002,"法人不能为空");
  104. }
  105. $addr = isset($this->post['addr']) && $this->post['addr']!==""? trim($this->post['addr']) :"";
  106. if($addr==""){
  107. return error_show(1002,"地址不能为空");
  108. }
  109. $data=[
  110. "name"=>$name,"source"=>$source,"code"=>$tr,
  111. "type"=>$type,"area"=>$area,"city"=>$city,
  112. "nature"=>$nature,"legaler"=>$legaler,"addr"=>$addr,
  113. "is_del"=>0,"ticket_type"=>$ticket_type,
  114. "addtime"=>date('Y-m-d H:i:s'),
  115. "updatetime"=>date("Y-m-d H:i:s"),
  116. ];
  117. $join = Db::name('supplier')->insert($data);
  118. return $join? error_show(0,"添加成功") :error_show(1002,"添加失败");
  119. }
  120. /*编辑*/
  121. public function edit(){
  122. $id = isset($this->post['id']) && $this->post['id'] !==""? trim($this->post['id']):"";
  123. $ion = Db::name('supplier')->where(['id'=>$id,'is_del'=>0])->find();
  124. if(empty($ion)){
  125. return error_show(1004,"供应商不存在");
  126. }
  127. $name = isset($this->post['name']) && $this->post['name']!=="" ? $this->post['name']:"";
  128. if($name==""){
  129. return error_show(1002,'数据标题不能为空');
  130. }
  131. $rename =Db::name('supplier')->where(['name'=>$name,'is_del'=>0])->where('id','<>',$id)->find();
  132. if(!empty($rename)){
  133. return error_show(1004,"数据标题已存在");
  134. }
  135. $source = isset($this->post['source']) && $this->post['source'] !==""? $this->post['source']:"";
  136. if($source==""){
  137. return error_show(1002,"供应商来源不能为空");
  138. }
  139. $type = isset($this->post['type']) && $this->post['type']!==""? trim($this->post['type']) :"";
  140. if($type==""){
  141. return error_show(1002,"申请类型不能为空");
  142. }
  143. $area = isset($this->post['area']) && $this->post['area']!==""? trim($this->post['area']) :"";
  144. if($area==""){
  145. return error_show(1002,"大区不能为空");
  146. }
  147. $city = isset($this->post['city']) && $this->post['city']!==""? trim($this->post['city']) :"";
  148. if($city==""){
  149. return error_show(1002,"城市不能为空");
  150. }
  151. $nature = isset($this->post['nature']) && $this->post['nature']!==""? trim($this->post['nature']) :"";
  152. if($nature==""){
  153. return error_show(1002,"公司类型不能为空");
  154. }
  155. $legaler = isset($this->post['legaler']) && $this->post['legaler']!==""? trim($this->post['legaler']) :"";
  156. if($legaler==""){
  157. return error_show(1002,"法人不能为空");
  158. }
  159. $addr = isset($this->post['addr']) && $this->post['addr']!==""? trim($this->post['addr']) :"";
  160. if($addr==""){
  161. return error_show(1002,"地址不能为空");
  162. }
  163. $vmp=[
  164. "id"=>$id,"legaler"=>$legaler,
  165. "name"=>$name,"source"=>$source,
  166. "type"=>$type,"area"=>$area,"city"=>$city,
  167. "nature"=>$nature,"addr"=>$addr,
  168. "is_del"=>0,"addtime"=>date('Y-m-d H:i:s'),
  169. "updatetime"=>date("Y-m-d H:i:s")
  170. ];
  171. $ed = Db::name('supplier')->where(['is_del'=>0,'id'=>$id])->save($vmp);
  172. return $ed ? error_show(0,"编辑成功") : error_show(1002,"编辑失败");
  173. }
  174. /*查询*/
  175. public function selec(){
  176. $id= isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']) :"";
  177. if($id==""){
  178. return error_show(1002,"供应商不存在");
  179. }
  180. $se = Db::name('supplier')->where(['id'=>$id,'is_del'=>0])->find();
  181. return app_show(0,"获取成功",$se);
  182. }
  183. /*删除*/
  184. public function del(){
  185. $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']) :"";
  186. $sup = Db::name('supplier')->where(["is_del"=>0,'id'=>$id])->find();
  187. if($sup==false){
  188. return error_show(1002,"供应商信息不存在");
  189. }
  190. $supp= Db::name('supplier')->update(['id'=>$id,'is_del'=>1,"updatetime"=>date("Y-m-d H:i:s")]);
  191. if($supp){
  192. return error_show(0,"供应商信息删除成功");
  193. }else{
  194. return error_show(1002,"供应商信息删除失败");
  195. }
  196. }
  197. }