Supplier.php 8.1 KB

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