Vip.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <?php
  2. namespace app\user\controller;
  3. use app\common\library\PHPExcelService;
  4. use library\Controller;
  5. use think\cache\driver\Redis;
  6. use think\Db;
  7. /**
  8. * 会员等级
  9. * Class Vip
  10. * @package app\user\controller
  11. */
  12. class Vip extends Controller
  13. {
  14. /**
  15. * 绑定数据表
  16. * @var string
  17. */
  18. protected $table = 'store_vip';
  19. /**
  20. * 会员等级列表
  21. * @auth true
  22. * @menu true
  23. * @throws \think\Exception
  24. * @throws \think\db\exception\DataNotFoundException
  25. * @throws \think\db\exception\ModelNotFoundException
  26. * @throws \think\exception\DbException
  27. * @throws \think\exception\PDOException
  28. */
  29. public function index()
  30. {
  31. $this->title = 'Vip等级管理';
  32. $query = $this->_query($this->table)->where('is_del',0)->like('name');
  33. $query->dateBetween('create_at')->order('id desc')->page();
  34. }
  35. /**
  36. * 数据列表处理
  37. * @auth true
  38. * @menu true
  39. * @param array $data
  40. * @throws \think\db\exception\DataNotFoundException
  41. * @throws \think\db\exception\ModelNotFoundException
  42. * @throws \think\exception\DbException
  43. */
  44. protected function _index_page_filter(&$data)
  45. {
  46. //echo Db::getLastSql();die();
  47. }
  48. /**
  49. * 添加等级
  50. * @auth true
  51. * @menu true
  52. * @throws \think\Exception
  53. * @throws \think\db\exception\DataNotFoundException
  54. * @throws \think\db\exception\ModelNotFoundException
  55. * @throws \think\exception\DbException
  56. * @throws \think\exception\PDOException
  57. */
  58. public function add()
  59. {
  60. $this->title = '添加等级';
  61. $this->_form($this->table, 'add');
  62. }
  63. /**
  64. * 编辑等级
  65. * @auth true
  66. * @menu true
  67. * @throws \think\Exception
  68. * @throws \think\db\exception\DataNotFoundException
  69. * @throws \think\db\exception\ModelNotFoundException
  70. * @throws \think\exception\DbException
  71. * @throws \think\exception\PDOException
  72. */
  73. function edit()
  74. {
  75. $this->title = '编辑等级';
  76. $this->_form($this->table, 'add');
  77. }
  78. /**
  79. * 表单数据处理
  80. * @auth true
  81. * @menu true
  82. * @param array $data
  83. */
  84. protected function _form_filter(&$data)
  85. {
  86. if($this->request->post()){
  87. if ($data['discount'] == '') $this->error('请输入等级折扣');
  88. if ($data['discount'] < 1 || $data['discount'] > 10 ) $this->error('等级折扣错误');
  89. if(isset($data['id']) || !empty($data['id']) ){
  90. $data['update_at'] = date('Y-m-d H:i:s');
  91. }
  92. }
  93. }
  94. /**
  95. * 处理成功回调
  96. */
  97. public function _form_result($result){
  98. if($result){
  99. $this->uplog($result);
  100. $this->success('操作成功',url('/#/user/vip/index'));
  101. }
  102. }
  103. /**
  104. * @auth true
  105. * @menu true
  106. * 等级禁用
  107. */
  108. public function dis()
  109. {
  110. $data = $this->request->post();
  111. if (Db::name($this->table)->where('id',$data['id'])->update(['status'=>0])){
  112. $this->uplog($data['id']);
  113. $this->success('恭喜您,数据更新成功');
  114. }else{
  115. $this->error('数据更新失败');
  116. }
  117. }
  118. /**
  119. * @auth true
  120. * @menu true
  121. * 等级开启
  122. */
  123. public function open()
  124. {
  125. $data = $this->request->post();
  126. if (Db::name($this->table)->where('id',$data['id'])->update(['status'=>1])){
  127. $this->uplog($data['id']);
  128. $this->success('恭喜您,数据更新成功');
  129. }else{
  130. $this->error('数据更新失败');
  131. }
  132. }
  133. /**
  134. * @auth true
  135. * @menu true
  136. * 等级删除
  137. */
  138. public function del()
  139. {
  140. $data = $this->request->post();
  141. if (Db::name($this->table)->where('id',$data['id'])->update(['is_del'=>1])){
  142. $this->uplog($data['id']);
  143. $this->success('恭喜您,数据更新成功');
  144. }else{
  145. $this->error('数据更新失败');
  146. }
  147. }
  148. /**
  149. * @auth true
  150. * @menu true
  151. * 等级日志
  152. */
  153. public function uplog($id)
  154. {
  155. //插入修改日志 方便后期查问题
  156. $afterData = Db::name('store_vip')->where('id',$id)->find();
  157. $logdata = [
  158. 'uid' => $this->app->session->get('user.id'),
  159. 'vipid' => $id,
  160. 'after' => json_encode($afterData),
  161. ];
  162. Db::name('store_vip_log')->insert($logdata);
  163. }
  164. /**
  165. * @auth true
  166. * @menu true
  167. * 赠送会员等级
  168. */
  169. public function give()
  170. {
  171. if($this->request->post()){
  172. $data = $this->request->post();
  173. if (!isset($data['mid']) || $data['mid']==''){
  174. $this->error('请选择用户');
  175. }
  176. $otherData = [
  177. 'type' => 1,
  178. 'status' => 1,
  179. 'desc' => '后台人工赠送',
  180. 'order_table' => '',
  181. 'order_id' => '',
  182. ];
  183. $ret = memberVipChange($data['id'],$data['mid'],$otherData);
  184. if ($ret){
  185. $this->success('赠送成功');
  186. }else{
  187. $this->error('赠送失败');
  188. }
  189. }else{
  190. $id=$this->request->get('id');
  191. $this->assign('id',$id);
  192. $user = Db::name('store_member')
  193. ->field('id,name,phone,vip')
  194. ->where('is_deleted',0)
  195. ->select();
  196. foreach ($user as $k=>&$v){
  197. $v['vip_name'] = $v['vip'] > 0 ? Db::name('store_vip')->where('id',$v['vip'])->value('name') : '普通会员';
  198. }
  199. $this->assign('user',$user);
  200. $this->fetch();
  201. }
  202. }
  203. }