UsersController.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: ring
  5. * Date: 2019/7/23
  6. * Time: 下午6:30
  7. */
  8. namespace App\Admin\Controllers;
  9. use App\Api\Util\IM;
  10. use App\Models\Users;
  11. use Encore\Admin\Controllers\AdminController;
  12. use Encore\Admin\Form;
  13. use Encore\Admin\Grid;
  14. use Encore\Admin\Layout\Content;
  15. use Encore\Admin\Show;
  16. use Illuminate\Support\Facades\Cache;
  17. class UsersController extends AdminController
  18. {
  19. use IM;
  20. protected $title = '用户管理';
  21. protected function grid()
  22. {
  23. $grid = new Grid(new Users());
  24. $grid->fixColumns(9,-3);
  25. $grid->lid('ID')->sortable();
  26. $grid->column('name', '名')->editable();
  27. $grid->column('tel', '电话');
  28. $grid->column('sex', '性别')->display(function ($x) {
  29. return $x == 1 ? '男':'女';
  30. });
  31. $grid->column('type', '类型')->display(function ($type) {
  32. $msg=$this->trump?'王牌':'';
  33. $s='普通';
  34. if($type==1){
  35. $s= $this->sex==2?$msg.'红娘':$msg.'月老';
  36. }
  37. return $s;
  38. })->sortable();
  39. // $grid->column('avatar', '头像')->image(config('love.QINIU_MY_DOMAINS'), 50, 50);
  40. $grid->column('vip', 'VIP')->display(function ($v) {
  41. return $v == 1 ? '是':'否';
  42. });
  43. $grid->column('rose', '余玫瑰');
  44. $grid->column('status', '状态')->display(function ($s) {
  45. return $s == 1 ? '在线':'离线';
  46. });
  47. $grid->column('openid', '微信绑定')->display(function ($o) {
  48. return $o ? '绑定':'未绑定';
  49. });
  50. $grid->column('realname', '姓名');
  51. $grid->column('age', '年龄');
  52. $grid->column('height', '身高');
  53. $grid->column('income', '收入');
  54. $grid->column('city', '城市');
  55. $grid->column('requirement', '交友条件');
  56. $grid->column('marriage', '婚姻')->display(function ($m) {
  57. return $m==1 ? '离遗':$m?'未婚':'丧偶';
  58. });
  59. $grid->column('think', '心声');
  60. $grid->column('wechat', '微信号');
  61. $grid->column('occupation', '职业');
  62. $grid->column('school', '毕业学校');
  63. $grid->column('km', '距离');
  64. $grid->column('wechat', '微信号');
  65. $grid->column('opt', '在')->display(function ($opt) {
  66. $s='浏览中';
  67. if($opt==1){
  68. $s='视频相亲';
  69. }
  70. if($opt==2){
  71. $s='专属相亲';
  72. }
  73. if($opt==4){
  74. $s='语音亲中';
  75. }
  76. if($opt==5){
  77. $s='交友';
  78. }
  79. return $s;
  80. });
  81. $grid->column('ban', '是否违规')->display(function ($b) {
  82. return $b>1 ? '有违规':'正常';
  83. });
  84. $grid->created_at('注册时间');
  85. $grid->updated_at('修改时间');
  86. $grid->disableExport();
  87. $grid->disableRowSelector();
  88. $grid->disableColumnSelector();
  89. $grid->disableCreateButton();
  90. $grid->expandFilter();
  91. $grid->model()->orderBy('id','desc');
  92. $grid->actions(function ($actions) {
  93. $actions->disableDelete();
  94. });
  95. $grid->filter(function ($filter) {
  96. $filter->disableIdFilter();
  97. $filter->equal('lid','用户ID')->placeholder('请输入用户ID');
  98. $filter->equal('realname','用户姓名')->placeholder('请输入用户姓名');
  99. $filter->equal('tel','用户电话')->placeholder('请输入用户电话');
  100. $filter->equal('type','类型')->select([0=> '普通',1=>'红娘/月老']);
  101. $filter->equal('vip','VIP')->select([1=> '是',0=>'否']);
  102. $filter->like('city','城市')->placeholder('请输入城市名');
  103. $filter->like('tuid','推荐人ID')->placeholder('查询某个用户推荐了几个人');
  104. });
  105. return $grid;
  106. }
  107. protected function form()
  108. {
  109. $form = new Form(new Users);
  110. $form->tab('基本信息', function ($form) {
  111. $form->display('lid', 'ID');
  112. $form->display('name', '名称');
  113. // $form->display('tel', '电话');
  114. $form->display('sex', '性别')->with(function ($value) {
  115. return $value==1?'男':'女';
  116. });
  117. $form->display('age', '年龄');
  118. $form->image('avatar', '头像');
  119. $form->display('realname', '姓名');
  120. $form->display('idcard', '身份证号');
  121. $form->display('opt', '在')->with(function ($x) {
  122. return $x==0 ? '浏览中':$x==1?'视频相亲':$x==2?'专属相亲':$x==4?'语音亲中':'交友';
  123. });
  124. $form->display('trump', '是否王牌')->with(function ($x) {
  125. return $x==1?'王牌':'非王牌';
  126. });
  127. $form->display('status', '状态')->with(function ($x) {
  128. return $x==1?'在线':'离线';
  129. });
  130. })->tab('编辑信息', function ($form) {
  131. $form->number('rose', '玫瑰')->rules('required|min:1');
  132. $form->select('vip', 'VIP')->options([0=>'不是VIP',1=>'是VIP']);
  133. $form->display('vip_time', 'VIP结束时间');//->format('YYYY-MM-DD HH:mm:ss');
  134. $form->select('type', '用户类型')->options([0=>'普通用户',1=>'月老/红娘']);
  135. $form->select('trump', '是否王牌')->options([0=>'普通用户',1=>'王牌']);
  136. $form->select('ban','禁止')->options([0=>'无',8=>'禁止登录',4=>'禁止开播',2=>'禁止发言',1=>'异常用户']);
  137. });
  138. $form->footer(function ($footer) {
  139. $footer->disableReset();
  140. $footer->disableViewCheck();
  141. $footer->disableEditingCheck();
  142. $footer->disableCreatingCheck();
  143. });
  144. $form->tools(function (Form\Tools $tools) {
  145. $tools->disableView();
  146. $tools->disableDelete();
  147. });
  148. $form->saved(function (Form $form) {
  149. if($form->vip!=$form->model()->vip){
  150. $this->portrait_set($form->model()->uid, ['Tag'=>'Tag_Profile_IM_Level','Value'=>1]);
  151. }
  152. if($form->trump!=$form->model()->trump){
  153. $this->portrait_set($form->model()->uid, ['Tag'=>'Tag_Profile_IM_Language','Value'=>$form->trump]);
  154. }
  155. if($form->type!=$form->model()->type){
  156. $this->portrait_set($form->model()->uid,['Tag'=>'Tag_Profile_IM_Role','Value'=>$form->type]);
  157. if($form->type){
  158. $this->imsendmassage('admin',$form->model()->uid,'你已经被开通为红娘/月老!');
  159. }
  160. }
  161. if($form->avatar!=$form->model()->avatar){
  162. $this->portrait_set($form->model()->uid,['Tag'=>'Tag_Profile_IM_Image','Value'=>$form->avatar]);
  163. }
  164. //$str=join(',', $form->ban);
  165. if($form->model()->ban>0){
  166. if($form->model()->ban==8){
  167. $str= $this->getUserSig($form->model()->uid);
  168. }
  169. $this->imsendmassage('admin',$form->model()->uid,'你有违规操作!');
  170. }
  171. });
  172. return $form;
  173. }
  174. public function detail($id){
  175. $d=Users::findOrFail($id);
  176. $show = new Show($d);
  177. $show->field('lid', '用户ID');
  178. // $show->field('tel', '用户电话');
  179. $show->field('sex', '性别')->as(function ($q)use($d){return $d->sex==1?'男-'.$d->age:'女-'.$d->age ;});
  180. $show->field('rose', '玫瑰数');
  181. $show->field('vip', '是否VIP')->as(function ($q)use($d){return $d->vip?'是'.date('Y-m-d',$d->vip_time):'否';});
  182. $show->field('type', '用户类型')->as(function ($q)use($d){return $q==0?'用户':$q==1&&$d->sex==1?'月老':'红娘';});
  183. // $show->field('ban', '是否违规');
  184. $show->field('created_at', '注册时间');
  185. $show->panel()->tools(function ($tools) {
  186. $tools->disableEdit();
  187. $tools->disableDelete();
  188. });
  189. $show->gifts('收的礼物', function ($comments) {
  190. $comments->id('ID')->sortable();
  191. $comments->column('user.lid', '送礼者ID');
  192. $comments->column('user.name', '送礼者名');
  193. $comments->column('user.avatar', '送礼者头像')->image(config('love.QINIU_MY_DOMAINS'), 50, 50);
  194. $comments->column('gift.name', '送礼名');
  195. $comments->column('gift.file', '送礼图')->image(config('love.QINIU_MY_DOMAINS'), 50, 50);
  196. $comments->column('rose', '送礼物时价')->help('单位玫瑰!');
  197. $comments->column('gift.rose', '礼物现价')->help('单位玫瑰!');
  198. $comments->created_at('送礼时间');
  199. $comments->disableExport();
  200. $comments->disableRowSelector();
  201. $comments->disableColumnSelector();
  202. $comments->disableCreateButton();
  203. $comments->disableactions();
  204. $comments->filter(function ($filter) {
  205. $filter->disableIdFilter();
  206. $filter->equal('user.lid', '客户ID')->placeholder('请输入送礼人ID');
  207. });
  208. });
  209. $show->userpays('消费明细', function ($comments) {
  210. $comments->id('ID')->sortable();
  211. $comments->column('rose', '玫瑰数');
  212. $comments->column('description', '描述');
  213. $comments->created_at('消费时间');
  214. $comments->disableExport();
  215. $comments->disableRowSelector();
  216. $comments->disableColumnSelector();
  217. $comments->disableCreateButton();
  218. $comments->disableactions();
  219. });
  220. $show->incomes('收入明细', function ($comments) {
  221. $comments->id('ID')->sortable();
  222. $comments->column('rose', '玫瑰数');
  223. $comments->column('money', '钱数');
  224. $comments->column('description', '描述');
  225. $comments->created_at('收入时间');
  226. $comments->disableExport();
  227. $comments->disableRowSelector();
  228. $comments->disableColumnSelector();
  229. $comments->disableCreateButton();
  230. $comments->disableactions();
  231. });
  232. $show->wallet('钱包明细', function ($comments) {
  233. $comments->id('ID')->sortable();
  234. $comments->column('money', '钱数');
  235. $comments->column('description', '描述');
  236. $comments->column('status', '状态')->display(function ($x) {
  237. $msg='';
  238. if($x==0){
  239. $msg='待进钱包';
  240. }
  241. if($x==1){
  242. $msg='到钱包';
  243. }
  244. if($x==5){
  245. $msg='申请提现';
  246. }
  247. if($x==6){
  248. $msg='异常';
  249. }
  250. return $msg;
  251. });
  252. $comments->created_at('收入时间');
  253. $comments->disableExport();
  254. $comments->disableRowSelector();
  255. $comments->disableColumnSelector();
  256. $comments->disableCreateButton();
  257. $comments->disableactions();
  258. });
  259. $show->reports('收到的举报', function ($comments) {
  260. $comments->id('ID')->sortable();
  261. $comments->column('answers', '回复内容');
  262. $comments->column('questions', '问题描述');
  263. $comments->created_at('举报时间');
  264. $comments->disableExport();
  265. $comments->disableRowSelector();
  266. $comments->disableColumnSelector();
  267. $comments->disableCreateButton();
  268. $comments->disableactions();
  269. });
  270. // $show->joinGroups('加了哪些群', function ($comments) {
  271. // // print_r($comments);
  272. // $comments->id('ID')->sortable();
  273. // $comments->created_at('加入时间');
  274. // $comments->disableExport();
  275. // $comments->disableRowSelector();
  276. // $comments->disableColumnSelector();
  277. // $comments->disableCreateButton();
  278. // $comments->disableactions();
  279. // });
  280. if($d->type){ //红娘有的功能
  281. $show->cashouts('提现明细', function ($comments) {
  282. $comments->id('ID')->sortable();
  283. $comments->column('rose', '玫瑰数');
  284. $comments->column('money', '钱数');
  285. $comments->column('description', '描述');
  286. $comments->created_at('收入时间');
  287. $comments->disableExport();
  288. $comments->disableRowSelector();
  289. $comments->disableColumnSelector();
  290. $comments->disableCreateButton();
  291. $comments->disableactions();
  292. });
  293. $show->gards('评价', function ($comments) {
  294. $comments->id('ID')->sortable();
  295. $comments->column('rose', '玫瑰数');
  296. $comments->column('start', '评价分数')->help('多多5分!');
  297. $comments->column('description', '描述');
  298. $comments->created_at('收入时间');
  299. $comments->disableExport();
  300. $comments->disableRowSelector();
  301. $comments->disableColumnSelector();
  302. $comments->disableCreateButton();
  303. $comments->disableactions();
  304. });
  305. }
  306. return $show;
  307. }
  308. public function update($id)
  309. {
  310. Cache::forget('user'.$id);
  311. Cache::forget('My'.$id);
  312. return $this->form()->update($id);
  313. }
  314. }