TagGood.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\BaseController;
  4. use think\App;
  5. use think\facade\Db;
  6. class TagGood extends BaseController{
  7. public function __construct(App $app) {parent::__construct($app);}
  8. //新建标签
  9. public function create(){
  10. $post = $this->post;
  11. $type = isset($post['type'])&& $post['type']!="" ? intval($post['type']) :"";
  12. if($type==''){
  13. return error_show(1004,"参数 type 不能未空");
  14. }
  15. $tagName =isset($post['tag_name'])&&$post['tag_name']!='' ? trim($post['tag_name']):"";
  16. if($tagName==''){
  17. return error_show(1004,"参数 tag_name 不能未空");
  18. }
  19. $isT =Db::name("order_tag")->where(["type"=>$type,"tag_name"=>$tagName,"is_del"=>0])->findOrEmpty();
  20. if(!empty($isT)){
  21. return error_show(1004,"标签名称已存在");
  22. }
  23. $tagData=[
  24. "type"=>$type,
  25. "tag_name"=>$tagName,
  26. "status"=>1,
  27. "apply_id"=>$this->uid,
  28. "apply_name"=>$this->uname,
  29. "addtime"=>date("Y-m-d H:i:s"),
  30. "updatetime"=>date("Y-m-d H:i:s")
  31. ];
  32. $ins=Db::name("order_tag")->insert($tagData);
  33. return $ins?app_show(0,"标签新建成功"): error_show(1004,"标签新建失败");
  34. }
  35. //标签列表翻页
  36. public function list(){
  37. $page = isset($this->post['page'])&&$this->post['page']!=''?intval($this->post['page']):1;
  38. $size = isset($this->post['size'])&&$this->post['size']!=''?intval($this->post['size']):15;
  39. $type = isset($this->post['type'])&&$this->post['type']!=''?intval($this->post['type']):'';
  40. $status = isset($this->post['status'])&&$this->post['status']!==''?intval($this->post['status']):'';
  41. $condition =[["is_del","=",0]];
  42. if($type!=''){
  43. $condition[]=["type","=",$type];
  44. }
  45. if($status!==''){
  46. $condition[]=["status","=",$status];
  47. }
  48. $tagName =isset($this->post['tag_name'])&&$this->post['tag_name']!='' ? trim($this->post['tag_name']):"";
  49. if($tagName!=''){
  50. $condition[]=["tag_name","like","%$tagName%"];
  51. }
  52. $count =Db::name("order_tag")->where($condition)->count();
  53. $total=ceil($count/$size);
  54. $page = $page>=$total ? intval($total):$page;
  55. $list =Db::name("order_tag")->where($condition)->page($page,$size)->order("addtime desc")->select()->toArray();
  56. return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
  57. }
  58. //根据条件筛选合适的标签数据
  59. public function query(){
  60. $type = isset($this->post['type'])&&$this->post['type']!=''?intval($this->post['type']):'';
  61. $condition =[["is_del","=",0]];
  62. if($type!=''){
  63. $condition[]=["type","=",$type];
  64. }
  65. $tagName =isset($this->post['tag_name'])&&$this->post['tag_name']!='' ? trim($this->post['tag_name']):"";
  66. if($tagName!=''){
  67. $condition[]=["tag_name","like","%$tagName%"];
  68. }
  69. $status = isset($this->post['status'])&&$this->post['status']!==''?intval($this->post['status']):'';
  70. if($status!==''){
  71. $condition[]=["status","=",$status];
  72. }
  73. $list =Db::name("order_tag")->where($condition)->order("addtime desc")->select()->toArray();
  74. return app_show(0,"获取成功",$list);
  75. }
  76. //启禁用状态
  77. public function status(){
  78. $id =isset($this->post['id'])&&$this->post['id']!=''?intval($this->post['id']):'';
  79. if($id==''){
  80. return error_show(1004,"参数 id 不能为空");
  81. }
  82. $taginfo =Db::name("order_tag")->find(["id"=>$id]);
  83. if($taginfo==false){
  84. return error_show(1004,"标签数据不存在");
  85. }
  86. $status=isset($this->post['status'])&&$this->post['status']!==''?intval($this->post['status']):'';
  87. if($status===''){
  88. return error_show(1004,"参数 status 不能为空");
  89. }
  90. $update =["status"=>$status,"updatetime"=>date("Y-m-d H:i:s")];
  91. $up =Db::name("order_tag")->where($taginfo)->update($update);
  92. return $up?app_show(0,"标签更新成功"): error_show(1004,"标签更新失败");
  93. }
  94. //编辑标签名称类型数据
  95. public function save(){
  96. $id =isset($this->post['id'])&&$this->post['id']!=''?intval($this->post['id']):'';
  97. if($id==''){
  98. return error_show(1004,"参数 id 不能为空");
  99. }
  100. $taginfo =Db::name("order_tag")->where(["id"=>$id,"is_del"=>0])->find();
  101. if($taginfo==false){
  102. return error_show(1004,"标签数据不存在");
  103. }
  104. $tagName=isset($this->post['tag_name'])&&$this->post['tag_name']!=''?trim($this->post['tag_name']):'';
  105. if($tagName===''){
  106. return error_show(1004,"参数 tag_name 不能为空");
  107. }
  108. $type=isset($this->post['type'])&&$this->post['type']!=''?intval($this->post['type']):'';
  109. if($type==''){
  110. return error_show(1004,"参数 type 不能为空");
  111. }
  112. $tag =Db::name("order_tag")->where([['tag_name',"=",$tagName],['type',"=",$type],["id","<>",$id],["is_del","=",0]])->find();
  113. if($tag!=false){
  114. return error_show(1004,"标签名称已存在");
  115. }
  116. $update =["type"=>$type,"tag_name"=>$tagName,"updatetime"=>date("Y-m-d H:i:s")];
  117. $up =Db::name("order_tag")->where($taginfo)->update($update);
  118. return $up?app_show(0,"标签更新成功"): error_show(1004,"标签更新失败");
  119. }
  120. //删除标签
  121. public function delete(){
  122. $id =isset($this->post['id'])&&$this->post['id']!=''?intval($this->post['id']):'';
  123. if($id==''){
  124. return error_show(1004,"参数 id 不能为空");
  125. }
  126. $taginfo =Db::name("order_tag")->find(["id"=>$id]);
  127. if($taginfo==false){
  128. return error_show(1004,"标签数据不存在");
  129. }
  130. $update=["is_del"=>1,"updatetime"=>date("Y-m-d H:i:s")];
  131. $up =Db::name("order_tag")->where($taginfo)->update($update);
  132. return $up?app_show(0,"标签删除成功"): error_show(1004,"标签删除失败");
  133. }
  134. //单号添加标签
  135. public function AddTag(){
  136. $tagid =isset($this->post["tag_id"]) && $this->post["tag_id"]!=""?intval($this->post["tag_id"]) :"";
  137. if($tagid==""){
  138. return error_show(1004,"参数 tag_id 不能为空");
  139. }
  140. $taginfo =Db::name("order_tag")->where(["id"=>$tagid,"is_del"=>0])->find();
  141. if($taginfo==false){
  142. return error_show(1005,"标签数据不存在");
  143. }
  144. if($taginfo['status']==0){
  145. return error_show(1005,"标签已禁用");
  146. }
  147. $code =isset($this->post['code']) &&$this->post["code"]!="" ? trim($this->post["code"]):"";
  148. if($code==''){
  149. return error_show(1004,"参数 code 不能为空");
  150. }
  151. switch ($taginfo['type']){
  152. case 1:
  153. $model=Db::name("pay_payment")->where(["dzNo"=>$code,"is_del"=>0]);
  154. break;
  155. case 2:
  156. $model=Db::name("pay_invoice")->where(["hpNo"=>$code,"is_del"=>0]);
  157. break;
  158. case 3:
  159. $model=Db::name("trade_pool")->where(["logNo"=>$code,"is_del"=>0]);
  160. break;
  161. case 4:
  162. $model=Db::name("invoice_pool")->where(["invNo"=>$code,"is_del"=>0]);
  163. break;
  164. default:
  165. $model=False;
  166. break;
  167. }
  168. if($model==false){
  169. return error_show(1005,"未找到对应的单号数据");
  170. }
  171. $data=$model->findOrEmpty();
  172. if(empty($data)){
  173. return error_show(1005,"未找到对应的单号数据");
  174. }
  175. $update=["tag_id"=>$tagid,"updatetime"=>date("Y-m-d H:i:s")];
  176. $up =$model->update($update);
  177. return $up?app_show(0,"标签添加成功"):error_show(1005,"标签添加失败");
  178. }
  179. }