Supplier.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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,
  94. "source"=>$source,
  95. "code"=>$tr,
  96. "type"=>$type,
  97. "area"=>$area,
  98. "city"=>$city,
  99. "nature"=>$nature,
  100. "legaler"=>$legaler,
  101. "addr"=>$addr,
  102. "is_del"=>0,
  103. "ticket_type"=>$ticket_type,
  104. "addtime"=>date('Y-m-d H:i:s'),
  105. "updatetime"=>date("Y-m-d H:i:s"),
  106. "is_platform"=>$is_platform
  107. ];
  108. $join = Db::name('supplier')->insert($data);
  109. $st = ["order_code"=>"GYS","status"=>0,"action_remark"=>'',"action_type"=>"create"];
  110. ActionLog::logAdd($this->post['token'],$st,"role_share",0,$st);
  111. return $join? error_show(0,"添加成功") :error_show(1002,"添加失败");
  112. }
  113. /*编辑*/
  114. public function edit(){
  115. $id = isset($this->post['id']) && $this->post['id'] !==""? trim($this->post['id']):"";
  116. $ion = Db::name('supplier')->where(['id'=>$id,'is_del'=>0])->find();
  117. if(empty($ion)){
  118. return error_show(1004,"供应商不存在");
  119. }
  120. $name = isset($this->post['name']) && $this->post['name']!=="" ? $this->post['name']:"";
  121. if($name==""){
  122. return error_show(1002,'数据标题不能为空');
  123. }
  124. $rename =Db::name('supplier')->where(['name'=>$name,'is_del'=>0])->where('id','<>',$id)->find();
  125. if(!empty($rename)){
  126. return error_show(1004,"数据标题已存在");
  127. }
  128. $source = isset($this->post['source']) && $this->post['source'] !==""? $this->post['source']:"";
  129. if($source==""){
  130. return error_show(1002,"供应商来源不能为空");
  131. }
  132. $type = isset($this->post['type']) && $this->post['type']!==""? trim($this->post['type']) :"";
  133. if($type==""){
  134. return error_show(1002,"申请类型不能为空");
  135. }
  136. $area = isset($this->post['area']) && $this->post['area']!==""? trim($this->post['area']) :"";
  137. if($area==""){
  138. return error_show(1002,"大区不能为空");
  139. }
  140. $city = isset($this->post['city']) && $this->post['city']!==""? trim($this->post['city']) :"";
  141. if($city==""){
  142. return error_show(1002,"城市不能为空");
  143. }
  144. $nature = isset($this->post['nature']) && $this->post['nature']!==""? trim($this->post['nature']) :"";
  145. if($nature==""){
  146. return error_show(1002,"公司类型不能为空");
  147. }
  148. $legaler = isset($this->post['legaler']) && $this->post['legaler']!==""? trim($this->post['legaler']) :"";
  149. if($legaler==""){
  150. return error_show(1002,"法人不能为空");
  151. }
  152. $is_platform = isset($this->post['is_platform']) && $this->post['is_platform']!==""? intval($this->post['is_platform'])
  153. :"0";
  154. $addr = isset($this->post['addr']) && $this->post['addr']!==""? trim($this->post['addr']) :"";
  155. if($addr==""){
  156. return error_show(1002,"地址不能为空");
  157. }
  158. $vmp=[
  159. "id"=>$id,
  160. "legaler"=>$legaler,
  161. "name"=>$name,
  162. "source"=>$source,
  163. "type"=>$type,
  164. "area"=>$area,
  165. "city"=>$city,
  166. "nature"=>$nature,
  167. "addr"=>$addr,
  168. "is_del"=>0,
  169. "is_platform"=>$is_platform,
  170. "addtime"=>date('Y-m-d H:i:s'),
  171. "updatetime"=>date("Y-m-d H:i:s")
  172. ];
  173. $ed = Db::name('supplier')->where(['is_del'=>0,'id'=>$id])->save($vmp);
  174. $st = ["order_code"=>$id,"status"=>0,"action_remark"=>'',"action_type"=>"edit"];
  175. ActionLog::logAdd($this->post['token'],$st,"GYS",0,$vmp);
  176. return $ed ? error_show(0,"编辑成功") : error_show(1002,"编辑失败");
  177. }
  178. /*查询*/
  179. public function selec(){
  180. $id= isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']) :"";
  181. if($id==""){
  182. return error_show(1002,"供应商不存在");
  183. }
  184. $se = Db::name('supplier')->where(['id'=>$id,'is_del'=>0])->find();
  185. return app_show(0,"获取成功",$se);
  186. }
  187. /*删除*/
  188. public function del(){
  189. $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']) :"";
  190. $sup = Db::name('supplier')->where(["is_del"=>0,'id'=>$id])->find();
  191. if($sup==false){
  192. return error_show(1002,"供应商信息不存在");
  193. }
  194. $supp= Db::name('supplier')->update(['id'=>$id,'is_del'=>1,"updatetime"=>date("Y-m-d H:i:s")]);
  195. if($supp){
  196. // $st = ["order_code"=>$id,"status"=>0,"action_remark"=>'',"action_type"=>"del"];
  197. // ActionLog::logAdd($this->post['token'],$st,"GYS",0,$supp);
  198. return error_show(0,"供应商信息删除成功");
  199. }else{
  200. return error_show(1002,"供应商信息删除失败");
  201. }
  202. }
  203. }