User.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\admin\controller\user;
  12. use app\admin\controller\AuthController;
  13. use app\admin\model\special\Grade;
  14. use app\admin\model\special\Special;
  15. use app\admin\model\special\SpecialSubject;
  16. use app\admin\model\special\SpecialSource;
  17. use app\wap\model\special\SpecialBuy;
  18. use service\FormBuilder as Form;
  19. use think\Db;
  20. use traits\CurdControllerTrait;
  21. use service\JsonService as Json;
  22. use think\Request;
  23. use think\Url;
  24. use app\admin\model\user\User as UserModel;
  25. use app\wap\model\user\UserBill;
  26. use app\admin\model\user\UserBill AS UserBillAdmin;
  27. use basic\ModelBasic;
  28. use service\HookService;
  29. use behavior\wap\UserBehavior;
  30. use app\admin\model\store\StoreVisit;
  31. use app\admin\model\wechat\WechatMessage;
  32. use app\admin\model\order\StoreOrder;
  33. use app\wap\model\store\StoreOrder as StoreOrderModel;
  34. use service\SystemConfigService;
  35. use app\admin\model\user\MemberRecord as MemberRecordModel;
  36. use app\wap\model\user\MemberShip;
  37. /**
  38. * 用户管理控制器
  39. * Class User
  40. * @package app\admin\controller\user
  41. */
  42. class User extends AuthController
  43. {
  44. use CurdControllerTrait;
  45. /**
  46. * 显示资源列表
  47. *
  48. * @return \think\Response
  49. */
  50. public function index()
  51. {
  52. $this->assign(['count_user'=>UserModel::count(),'count_vip'=>UserModel::where('level',1)->count()]);
  53. $this->assign('gold_name', SystemConfigService::get("gold_name"));
  54. return $this->fetch();
  55. }
  56. /**
  57. * 修改user表状态
  58. *
  59. * @return json
  60. */
  61. public function set_status($status = '', $uid = 0, $is_echo = 0)
  62. {
  63. if ($is_echo == 0) {
  64. if ($status == '' || $uid == 0) return Json::fail('参数错误');
  65. UserModel::where(['uid' => $uid])->update(['status' => $status]);
  66. } else {
  67. $uids = parent::postMore([
  68. ['uids', []]
  69. ]);
  70. UserModel::destrSyatus($uids['uids'], $status);
  71. }
  72. return Json::successful($status == 0 ? '禁用成功' : '解禁成功');
  73. }
  74. /**
  75. * 赠送会员
  76. */
  77. public function members($uid = 0)
  78. {
  79. if(!$uid)return Json::fail('参数错误');
  80. $user=UserModel::where(['uid' => $uid])->find();
  81. if(!$user) return Json::fail('用户不存在!');
  82. $form = Form::create(Url::build('gift_members', ['uid' => $uid]), [
  83. Form::select('member', '会员等级')->setOptions(function () {
  84. $list = MemberShip::where(['is_publish' => 1,'is_del'=>0])->field('title,id')->order('sort desc,add_time desc')->select();
  85. $list=count($list)>0 ? $list->toArray() : [];
  86. $menus = [];
  87. foreach ($list as $menu) {
  88. $menus[] = ['value' => $menu['id'], 'label' => $menu['title']];
  89. }
  90. return $menus;
  91. })->filterable(1),
  92. ]);
  93. $form->setMethod('post')->setTitle('赠送会员')->setSuccessScript('parent.$(".J_iframe:visible")[0].contentWindow.location.reload(); setTimeout(function(){parent.layer.close(parent.layer.getFrameIndex(window.name));},800);');
  94. $this->assign(compact('form'));
  95. return $this->fetch('public/form-builder');
  96. }
  97. /**赠送会员
  98. * @param int $uid
  99. */
  100. public function gift_members($uid = 0)
  101. {
  102. if(!$uid)return Json::fail('参数错误');
  103. $data = parent::postMore([
  104. ['member',0],
  105. ]);
  106. if (!$data['member']) return Json::fail('会员等级');
  107. $userInfo = UserModel::where('uid',$uid)->find();
  108. if (!$userInfo) return UserModel::setErrorInfo('用户不存在!');
  109. if($userInfo['level'] && $userInfo['is_permanent']) return UserModel::setErrorInfo('该用户是永久会员,无需续费!');
  110. $member=MemberShip::where('id',$data['member'])->where('is_publish',1)->where('is_del',0)->where('type',1)->find();
  111. $orderInfo = [
  112. 'uid' => $uid,
  113. 'order_id' => StoreOrderModel::getNewOrderId(),
  114. 'type'=>1,
  115. 'member_id' => $data['member'],
  116. 'total_num' => 1,
  117. 'total_price' => $member['original_price'],
  118. 'pay_price' => 0,
  119. 'pay_type' => 'yue',
  120. 'combination_id' => 0,
  121. 'is_gift' => 0,
  122. 'pink_time' => 0,
  123. 'paid' => 0,
  124. 'pink_id' => 0,
  125. 'unique' => md5(time() . '' . $uid . $data['member']),
  126. 'cost' => $member['original_price'],
  127. 'link_pay_uid' => 0,
  128. 'spread_uid' => $userInfo['spread_uid'] ? $userInfo['spread_uid'] : 0,
  129. 'is_del' => 0,
  130. ];
  131. $order = StoreOrderModel::set($orderInfo);
  132. if($order){
  133. $res1 = UserBill::expend('赠送会员', $uid, 'now_money', 'give_vip', $order['pay_price'], $order['id'], 0, '会员价值' . floatval($order['pay_price']) . '元');
  134. $res2 = StoreOrderModel::payMeSuccess($order['order_id']);
  135. if($res1 && $res2){
  136. return Json::successful('赠送成功');
  137. }else{
  138. return Json::fail('赠送失败');
  139. }
  140. }else{
  141. return Json::fail('赠送失败');
  142. }
  143. }
  144. /**
  145. * 清除会员等级
  146. */
  147. public function del_vip($uid = 0){
  148. if(!$uid) return Json::fail('参数错误!');
  149. $user=UserModel::where('uid',$uid)->where('level',1)->find();
  150. if(!$user) return Json::fail('用户不存在或不是会员!');
  151. $res=UserModel::edit(['level'=>0,'is_permanent'=>0,'overdue_time'=>0,'member_time'=>0],$uid,'uid');
  152. if($res){
  153. return Json::successful('清除会员成功');
  154. }else{
  155. return Json::fail('清除会员失败');
  156. }
  157. }
  158. public function user_data($uid = 0)
  159. {
  160. $spread = UserModel::where(['spread_uid' => $uid])->column('uid');
  161. $count['pay_count'] = Db::name('special_buy')->where('uid', $uid)->count();
  162. $count['bill_count'] = UserBill::where(['category' => 'now_money'])->where('uid', $uid)
  163. ->where('type', 'in', ['rake_back', 'rake_back_one', 'rake_back_two', 'extract'])
  164. ->count();
  165. $count['order_count'] = UserBill::where('u.uid', $uid)->alias('u')->join('__STORE_ORDER__ a', 'a.id=u.link_id')
  166. ->where('u.category', 'now_money')->where('u.type', 'in', ['rake_back', 'rake_back_one'])
  167. ->where(['a.paid' => 1, 'a.is_gift' => 0, 'a.is_receive_gift' => 0])->count();
  168. $count['spread_count'] = UserModel::where('uid', 'in', $spread)->count();
  169. $this->assign('gradeList', json_encode(Grade::getAll()));
  170. $this->assign('uid', $uid);
  171. $this->assign('count', json_encode($count));
  172. return $this->fetch();
  173. }
  174. public function member_record($uid = 0){
  175. if (!$uid) return Json::fail('缺少参数');
  176. $this->assign(MemberRecordModel::userOneRecord($uid));
  177. return $this->fetch();
  178. }
  179. public function get_subjec_list($grade_id = 0)
  180. {
  181. return Json::successful(SpecialSubject::where(['grade_id' => $grade_id, 'is_show' => 1,'is_del' => 0])->order('sort desc,add_time desc')->field('id,name')->select());
  182. }
  183. public function get_special_list($subjec_id = 0)
  184. {
  185. return Json::successful(Special::PreWhere()->where('subject_id', $subjec_id)->order('sort desc,add_time desc')->field('id,title')->select());
  186. }
  187. public function save_give()
  188. {
  189. $post = parent::postMore([
  190. ['uid', 0],
  191. ['special_id', 0],
  192. ]);
  193. if (!$post['uid'] || !$post['special_id']) return Json::fail('缺少参数无法赠送');
  194. $special = Special::get($post['special_id']);
  195. if (SpecialBuy::be(['uid' => $post['uid'], 'special_id' => $post['special_id'], 'is_del' => 0])) return Json::fail('此用户已经拥有此专题无需赠送');
  196. if ($special['type'] == SPECIAL_COLUMN) {
  197. $special_source = SpecialSource::getSpecialSource($special['id']);
  198. if ($special_source){
  199. foreach($special_source as $k => $v) {
  200. $task_special = Special::get($v['source_id']);
  201. if ($task_special['is_show'] == 1){
  202. SpecialBuy::setBuySpecial('', $post['uid'], $v['source_id'], 3,$post['special_id']);
  203. }
  204. }
  205. }
  206. $res=SpecialBuy::setBuySpecial('', $post['uid'], $post['special_id'], 3);
  207. }else{
  208. $res=SpecialBuy::setBuySpecial('', $post['uid'], $post['special_id'], 3);
  209. }
  210. if ($res)
  211. return Json::successful('赠送成功');
  212. else
  213. return Json::fail('赠送失败');
  214. }
  215. public function get_user_info($uid = 0)
  216. {
  217. if (!$uid) return Json::fail('缺少用户参数');
  218. return Json::successful(UserModel::getUserinfoV1($uid));
  219. }
  220. public function get_pay_list()
  221. {
  222. $where = parent::getMore([
  223. ['uid', 0],
  224. ['limit', 10],
  225. ['page', 1],
  226. ]);
  227. return Json::successful(SpecialBuy::getPayList($where));
  228. }
  229. public function get_spread_list()
  230. {
  231. $where = parent::getMore([
  232. ['uid', 0],
  233. ['limit', 10],
  234. ['page', 1],
  235. ]);
  236. return Json::successful(UserModel::getSpreadListV1($where));
  237. }
  238. public function get_order_list()
  239. {
  240. $where = parent::getMore([
  241. ['uid', 0],
  242. ['limit', 10],
  243. ['page', 1],
  244. ['excel', 0],
  245. ['start_date', ''],
  246. ['end_date', ''],
  247. ]);
  248. return Json::successful(StoreOrder::getOrderList($where));
  249. }
  250. public function get_bill_list()
  251. {
  252. $where = parent::getMore([
  253. ['limit', 10],
  254. ['page', 1],
  255. ['uid', 0],
  256. ['excel', 0],
  257. ['start_date', ''],
  258. ['end_date', ''],
  259. ]);
  260. return Json::successful(UserBillAdmin::getBillList($where, $where['uid']));
  261. }
  262. public function update_user_spread($uid = 0, $type = 0)
  263. {
  264. if (!$uid || !$type) return Json::fail('缺少参数');
  265. $user = UserModel::get($uid);
  266. switch ($type) {
  267. case '1':
  268. case "2":
  269. case "3":
  270. case '4':
  271. $user->is_promoter = (int)$type;
  272. break;
  273. case "5":
  274. $user->is_promoter = 1;
  275. $user->spread_uid = 0;
  276. break;
  277. }
  278. if ($user->save())
  279. return Json::successful('修改成功');
  280. else
  281. return Json::fail('修改失败');
  282. }
  283. /**
  284. * 获取user表
  285. *
  286. * @return json
  287. */
  288. public function get_user_list()
  289. {
  290. $where = parent::getMore([
  291. ['page', 1],
  292. ['limit', 20],
  293. ['nickname', ''],
  294. ['status', ''],
  295. ['pay_count', ''],
  296. ['is_promoter', ''],
  297. ['order', ''],
  298. ['data', ''],
  299. ['country', ''],
  300. ['province', ''],
  301. ['city', ''],
  302. ['user_time_type', ''],
  303. ['user_time', ''],
  304. ['sex', ''],
  305. ]);
  306. return Json::successlayui(UserModel::getUserList($where));
  307. }
  308. /**
  309. * 编辑模板消息
  310. * @param $id
  311. * @return mixed|\think\response\Json|void
  312. */
  313. public function edit($uid)
  314. {
  315. if (!$uid) return $this->failed('数据不存在');
  316. $user = UserModel::get($uid);
  317. if (!$user) return Json::fail('数据不存在!');
  318. $f = array();
  319. $f[] = Form::input('uid', '用户编号', $user->getData('uid'))->disabled(1);
  320. $f[] = Form::input('nickname', '用户姓名', $user->getData('nickname'));
  321. $f[] = Form::radio('money_status', '修改余额', 1)->options([['value' => 1, 'label' => '增加'], ['value' => 2, 'label' => '减少']]);
  322. $f[] = Form::number('money', '余额')->min(0);
  323. $f[] = Form::radio('status', '状态', $user->getData('status'))->options([['value' => 1, 'label' => '开启'], ['value' => 0, 'label' => '锁定']]);
  324. $f[] = Form::radio('is_promoter', '推广员', $user->getData('is_promoter'))->options([
  325. ['value' => 0, 'label' => '关闭'],
  326. ['value' => 1, 'label' => '推广员'],
  327. ]);
  328. $form = Form::make_post_form('添加用户通知', $f, Url::build('update', array('id' => $uid)));
  329. $this->assign(compact('form'));
  330. return $this->fetch('public/form-builder');
  331. }
  332. public function update(Request $request, $uid)
  333. {
  334. $data = parent::postMore([
  335. ['money_status', 0],
  336. ['is_promoter', 1],
  337. ['is_senior', 0],
  338. ['money', 0],
  339. ['nickname', ''],
  340. ['integration_status', 0],
  341. ['integration', 0],
  342. ['status', 0],
  343. ], $request);
  344. if (!$uid) return $this->failed('数据不存在');
  345. $user = UserModel::get($uid);
  346. if (!$user) return Json::fail('数据不存在!');
  347. ModelBasic::beginTrans();
  348. $res1 = false;
  349. $res2 = false;
  350. $edit = array();
  351. if ($data['money_status'] && $data['money']) {//余额增加或者减少
  352. if ($data['money_status'] == 1) {//增加
  353. $edit['now_money'] = bcadd($user['now_money'], $data['money'], 2);
  354. $res1 = UserBill::income('系统增加余额', $user['uid'], 'now_money', 'system_add', $data['money'], $this->adminId, $user['now_money'], '系统增加了' . floatval($data['money']) . '余额');
  355. try {
  356. HookService::listen('admin_add_money', $user, $data['money'], false, UserBehavior::class);
  357. } catch (\Exception $e) {
  358. ModelBasic::rollbackTrans();
  359. return Json::fail($e->getMessage());
  360. }
  361. } else if ($data['money_status'] == 2) {//减少
  362. $edit['now_money'] = bcsub($user['now_money'], $data['money'], 2);
  363. $res1 = UserBill::expend('系统减少余额', $user['uid'], 'now_money', 'system_sub', $data['money'], $this->adminId, $user['now_money'], '系统扣除了' . floatval($data['money']) . '余额');
  364. try {
  365. HookService::listen('admin_sub_money', $user, $data['money'], false, UserBehavior::class);
  366. } catch (\Exception $e) {
  367. ModelBasic::rollbackTrans();
  368. return Json::fail($e->getMessage());
  369. }
  370. }
  371. } else {
  372. $res1 = true;
  373. }
  374. if ($data['integration_status'] && $data['integration']) {//积分增加或者减少
  375. if ($data['integration_status'] == 1) {//增加
  376. $edit['integral'] = bcadd($user['integral'], $data['integration'], 2);
  377. $res2 = UserBill::income('系统增加积分', $user['uid'], 'integral', 'system_add', $data['integration'], $this->adminId, $user['integral'], '系统增加了' . floatval($data['integration']) . '积分');
  378. try {
  379. HookService::listen('admin_add_integral', $user, $data['integration'], false, UserBehavior::class);
  380. } catch (\Exception $e) {
  381. ModelBasic::rollbackTrans();
  382. return Json::fail($e->getMessage());
  383. }
  384. } else if ($data['integration_status'] == 2) {//减少
  385. $edit['integral'] = bcsub($user['integral'], $data['integration'], 2);
  386. $res2 = UserBill::expend('系统减少积分', $user['uid'], 'integral', 'system_sub', $data['integration'], $this->adminId, $user['integral'], '系统扣除了' . floatval($data['integration']) . '积分');
  387. try {
  388. HookService::listen('admin_sub_integral', $user, $data['integration'], false, UserBehavior::class);
  389. } catch (\Exception $e) {
  390. ModelBasic::rollbackTrans();
  391. return Json::fail($e->getMessage());
  392. }
  393. }
  394. } else {
  395. $res2 = true;
  396. }
  397. $edit['status'] = $data['status'];
  398. $edit['nickname'] = $data['nickname'];
  399. $edit['is_promoter'] = $data['is_promoter'];
  400. $edit['is_senior'] = $data['is_senior'];
  401. if ($edit) $res3 = UserModel::edit($edit, $uid);
  402. else $res3 = true;
  403. if ($res1 && $res2 && $res3) $res = true;
  404. else $res = false;
  405. ModelBasic::checkTrans($res);
  406. if ($res) return Json::successful('修改成功!');
  407. else return Json::fail('修改失败');
  408. }
  409. /**
  410. * 用户图表
  411. * @return mixed
  412. */
  413. public function user_analysis()
  414. {
  415. $where = parent::getMore([
  416. ['nickname', ''],
  417. ['status', ''],
  418. ['is_promoter', ''],
  419. ['date', ''],
  420. ['export', 0]
  421. ], $this->request);
  422. $user_count = UserModel::consume($where, '', true);
  423. //头部信息
  424. $header = [
  425. [
  426. 'name' => '新增用户',
  427. 'class' => 'fa-line-chart',
  428. 'value' => $user_count,
  429. 'color' => 'red'
  430. ],
  431. [
  432. 'name' => '用户留存',
  433. 'class' => 'fa-area-chart',
  434. 'value' => $this->gethreaderValue(UserModel::consume($where, '', true), $where) . '%',
  435. 'color' => 'lazur'
  436. ],
  437. [
  438. 'name' => '新增用户总消费',
  439. 'class' => 'fa-bar-chart',
  440. 'value' => '¥' . UserModel::consume($where),
  441. 'color' => 'navy'
  442. ],
  443. [
  444. 'name' => '用户活跃度',
  445. 'class' => 'fa-pie-chart',
  446. 'value' => $this->gethreaderValue(UserModel::consume($where, '', true)) . '%',
  447. 'color' => 'yellow'
  448. ],
  449. ];
  450. $name = ['新增用户', '用户消费'];
  451. $dates = $this->get_user_index($where, $name);
  452. $user_index = ['name' => json_encode($name), 'date' => json_encode($dates['time']), 'series' => json_encode($dates['series'])];
  453. //用户浏览分析
  454. $view = StoreVisit::getVisit($where['date'], ['', 'warning', 'info', 'danger']);
  455. $view_v1 = WechatMessage::getViweList($where['date'], ['', 'warning', 'info', 'danger']);
  456. $view = array_merge($view, $view_v1);
  457. $view_v2 = [];
  458. foreach ($view as $val) {
  459. $view_v2['color'][] = '#' . rand(100000, 339899);
  460. $view_v2['name'][] = $val['name'];
  461. $view_v2['value'][] = $val['value'];
  462. }
  463. $view = $view_v2;
  464. //消费会员排行用户分析
  465. $user_null = UserModel::getUserSpend($where['date']);
  466. //消费数据
  467. $now_number = UserModel::getUserSpend($where['date'], true);
  468. list($paren_number, $title) = UserModel::getPostNumber($where['date']);
  469. if ($paren_number == 0) {
  470. $rightTitle = [
  471. 'number' => $now_number > 0 ? $now_number : 0,
  472. 'icon' => 'fa-level-up',
  473. 'title' => $title
  474. ];
  475. } else {
  476. $number = (float)bcsub($now_number, $paren_number, 4);
  477. if ($now_number == 0) {
  478. $icon = 'fa-level-down';
  479. } else {
  480. $icon = $now_number > $paren_number ? 'fa-level-up' : 'fa-level-down';
  481. }
  482. $rightTitle = ['number' => $number, 'icon' => $icon, 'title' => $title];
  483. }
  484. unset($title, $paren_number, $now_number);
  485. list($paren_user_count, $title) = UserModel::getPostNumber($where['date'], true, 'add_time', '');
  486. if ($paren_user_count == 0) {
  487. $count = $user_count == 0 ? 0 : $user_count;
  488. $icon = $user_count == 0 ? 'fa-level-down' : 'fa-level-up';
  489. } else {
  490. $count = (float)bcsub($user_count, $paren_user_count, 4);
  491. $icon = $user_count < $paren_user_count ? 'fa-level-down' : 'fa-level-up';
  492. }
  493. $leftTitle = [
  494. 'count' => $count,
  495. 'icon' => $icon,
  496. 'title' => $title
  497. ];
  498. unset($count, $icon, $title);
  499. $consume = [
  500. 'title' => '消费金额为¥' . UserModel::consume($where),
  501. 'series' => UserModel::consume($where, 'xiaofei'),
  502. 'rightTitle' => $rightTitle,
  503. 'leftTitle' => $leftTitle,
  504. ];
  505. $form = UserModel::consume($where, 'form');
  506. $grouping = UserModel::consume($where, 'grouping');
  507. $this->assign(compact('header', 'user_index', 'view', 'user_null', 'consume', 'form', 'grouping', 'where'));
  508. return $this->fetch();
  509. }
  510. public function gethreaderValue($chart, $where = [])
  511. {
  512. if ($where) {
  513. switch ($where['date']) {
  514. case null:
  515. case 'today':
  516. case 'week':
  517. case 'year':
  518. if ($where['date'] == null) {
  519. $where['date'] = 'month';
  520. }
  521. $sum_user = UserModel::whereTime('add_time', $where['date'])->count();
  522. if ($sum_user == 0) return 0;
  523. $counts = bcdiv($chart, $sum_user, 4) * 100;
  524. return $counts;
  525. break;
  526. case 'quarter':
  527. $quarter = UserModel::getMonth('n');
  528. $quarter[0] = strtotime($quarter[0]);
  529. $quarter[1] = strtotime($quarter[1]);
  530. $sum_user = UserModel::where('add_time', 'between', $quarter)->count();
  531. if ($sum_user == 0) return 0;
  532. $counts = bcdiv($chart, $sum_user, 4) * 100;
  533. return $counts;
  534. default:
  535. //自定义时间
  536. $quarter = explode('-', $where['date']);
  537. $quarter[0] = strtotime($quarter[0]);
  538. $quarter[1] = strtotime($quarter[1]);
  539. $sum_user = UserModel::where('add_time', 'between', $quarter)->count();
  540. if ($sum_user == 0) return 0;
  541. $counts = bcdiv($chart, $sum_user, 4) * 100;
  542. return $counts;
  543. break;
  544. }
  545. } else {
  546. $num = UserModel::count();
  547. $chart = $num != 0 ? bcdiv($chart, $num, 5) * 100 : 0;
  548. return $chart;
  549. }
  550. }
  551. public function get_user_index($where, $name)
  552. {
  553. switch ($where['date']) {
  554. case null:
  555. $days = date("t", strtotime(date('Y-m', time())));
  556. $dates = [];
  557. $series = [];
  558. $times_list = [];
  559. foreach ($name as $key => $val) {
  560. for ($i = 1; $i <= $days; $i++) {
  561. if (!in_array($i . '号', $times_list)) {
  562. array_push($times_list, $i . '号');
  563. }
  564. $time = $this->gettime(date("Y-m", time()) . '-' . $i);
  565. if ($key == 0) {
  566. $dates['data'][] = UserModel::where('add_time', 'between', $time)->count();
  567. } else if ($key == 1) {
  568. $dates['data'][] = UserModel::consume(true, $time);
  569. }
  570. }
  571. $dates['name'] = $val;
  572. $dates['type'] = 'line';
  573. $series[] = $dates;
  574. unset($dates);
  575. }
  576. return ['time' => $times_list, 'series' => $series];
  577. case 'today':
  578. $dates = [];
  579. $series = [];
  580. $times_list = [];
  581. foreach ($name as $key => $val) {
  582. for ($i = 0; $i <= 24; $i++) {
  583. $strtitle = $i . '点';
  584. if (!in_array($strtitle, $times_list)) {
  585. array_push($times_list, $strtitle);
  586. }
  587. $time = $this->gettime(date("Y-m-d ", time()) . $i);
  588. if ($key == 0) {
  589. $dates['data'][] = UserModel::where('add_time', 'between', $time)->count();
  590. } else if ($key == 1) {
  591. $dates['data'][] = UserModel::consume(true, $time);
  592. }
  593. }
  594. $dates['name'] = $val;
  595. $dates['type'] = 'line';
  596. $series[] = $dates;
  597. unset($dates);
  598. }
  599. return ['time' => $times_list, 'series' => $series];
  600. case "week":
  601. $dates = [];
  602. $series = [];
  603. $times_list = [];
  604. foreach ($name as $key => $val) {
  605. for ($i = 0; $i <= 6; $i++) {
  606. if (!in_array('星期' . ($i + 1), $times_list)) {
  607. array_push($times_list, '星期' . ($i + 1));
  608. }
  609. $time = UserModel::getMonth('h', $i);
  610. if ($key == 0) {
  611. $dates['data'][] = UserModel::where('add_time', 'between', [strtotime($time[0]), strtotime($time[1])])->count();
  612. } else if ($key == 1) {
  613. $dates['data'][] = UserModel::consume(true, [strtotime($time[0]), strtotime($time[1])]);
  614. }
  615. }
  616. $dates['name'] = $val;
  617. $dates['type'] = 'line';
  618. $series[] = $dates;
  619. unset($dates);
  620. }
  621. return ['time' => $times_list, 'series' => $series];
  622. case 'year':
  623. $dates = [];
  624. $series = [];
  625. $times_list = [];
  626. $year = date('Y');
  627. foreach ($name as $key => $val) {
  628. for ($i = 1; $i <= 12; $i++) {
  629. if (!in_array($i . '月', $times_list)) {
  630. array_push($times_list, $i . '月');
  631. }
  632. $t = strtotime($year . '-' . $i . '-01');
  633. $arr = explode('/', date('Y-m-01', $t) . '/' . date('Y-m-', $t) . date('t', $t));
  634. if ($key == 0) {
  635. $dates['data'][] = UserModel::where('add_time', 'between', [strtotime($arr[0]), strtotime($arr[1])])->count();
  636. } else if ($key == 1) {
  637. $dates['data'][] = UserModel::consume(true, [strtotime($arr[0]), strtotime($arr[1])]);
  638. }
  639. }
  640. $dates['name'] = $val;
  641. $dates['type'] = 'line';
  642. $series[] = $dates;
  643. unset($dates);
  644. }
  645. return ['time' => $times_list, 'series' => $series];
  646. case 'quarter':
  647. $dates = [];
  648. $series = [];
  649. $times_list = [];
  650. foreach ($name as $key => $val) {
  651. for ($i = 1; $i <= 4; $i++) {
  652. $arr = $this->gettime('quarter', $i);
  653. if (!in_array(implode('--', $arr) . '季度', $times_list)) {
  654. array_push($times_list, implode('--', $arr) . '季度');
  655. }
  656. if ($key == 0) {
  657. $dates['data'][] = UserModel::where('add_time', 'between', [strtotime($arr[0]), strtotime($arr[1])])->count();
  658. } else if ($key == 1) {
  659. $dates['data'][] = UserModel::consume(true, [strtotime($arr[0]), strtotime($arr[1])]);
  660. }
  661. }
  662. $dates['name'] = $val;
  663. $dates['type'] = 'line';
  664. $series[] = $dates;
  665. unset($dates);
  666. }
  667. return ['time' => $times_list, 'series' => $series];
  668. default:
  669. $list = UserModel::consume($where, 'default');
  670. $dates = [];
  671. $series = [];
  672. $times_list = [];
  673. foreach ($name as $k => $v) {
  674. foreach ($list as $val) {
  675. $date = $val['add_time'];
  676. if (!in_array($date, $times_list)) {
  677. array_push($times_list, $date);
  678. }
  679. if ($k == 0) {
  680. $dates['data'][] = $val['num'];
  681. } else if ($k == 1) {
  682. $dates['data'][] = UserBill::where(['uid' => $val['uid'], 'type' => 'pay_product'])->sum('number');
  683. }
  684. }
  685. $dates['name'] = $v;
  686. $dates['type'] = 'line';
  687. $series[] = $dates;
  688. unset($dates);
  689. }
  690. return ['time' => $times_list, 'series' => $series];
  691. }
  692. }
  693. public function gettime($time = '', $season = '')
  694. {
  695. if (!empty($time) && empty($season)) {
  696. $timestamp0 = strtotime($time);
  697. $timestamp24 = strtotime($time) + 86400;
  698. return [$timestamp0, $timestamp24];
  699. } else if (!empty($time) && !empty($season)) {
  700. $firstday = date('Y-m-01', mktime(0, 0, 0, ($season - 1) * 3 + 1, 1, date('Y')));
  701. $lastday = date('Y-m-t', mktime(0, 0, 0, $season * 3, 1, date('Y')));
  702. return [$firstday, $lastday];
  703. }
  704. }
  705. /**
  706. * 会员等级首页
  707. */
  708. public function group()
  709. {
  710. return $this->fetch();
  711. }
  712. /**
  713. * 会员详情
  714. */
  715. public function see($uid = '')
  716. {
  717. $this->assign([
  718. 'uid' => $uid,
  719. 'userinfo' => UserModel::getUserDetailed($uid),
  720. 'is_layui' => true,
  721. 'headerList' => UserModel::getHeaderList($uid),
  722. 'count' => UserModel::getCountInfo($uid),
  723. 'gold_name'=>SystemConfigService::get("gold_name")
  724. ]);
  725. return $this->fetch();
  726. }
  727. public function getBuySpecilList($uid, $page = 1, $limit = 20)
  728. {
  729. $list = SpecialBuy::where(['a.uid' => $uid, 'a.is_del' => 0])
  730. ->join('__STORE_ORDER__ o', 'a.order_id=o.order_id', 'left')
  731. ->join("__SPECIAL__ s", 's.id=a.special_id')
  732. ->alias('a')->field(['a.*', 'o.total_num', 'o.pay_price', 's.title'])->page((int)$page, (int)$limit)->select();
  733. $list=count($list) ? $list->toArray() : [];
  734. foreach ($list as &$value){
  735. if($value['type']=='赠送获得') {
  736. $value['order_id']='赠送获得';
  737. $value['total_num']='1';
  738. $value['pay_price']='0';
  739. }
  740. }
  741. return Json::successful($list);
  742. }
  743. public function del_special_buy($id = 0)
  744. {
  745. if ($id == 0) return Json::fail('缺少参数');
  746. if (SpecialBuy::where('id', $id)->update(['is_del' => 1]))
  747. return Json::successful('删除成功');
  748. else
  749. return Json::fail('删除失败');
  750. }
  751. /*
  752. * 获取某个用户的推广下线
  753. * */
  754. public function getSpreadList($uid, $page = 1, $limit = 20)
  755. {
  756. return Json::successful(UserModel::getSpreadList($uid, (int)$page, (int)$limit));
  757. }
  758. /**
  759. * 获取某用户的订单列表
  760. */
  761. public function getOneorderList($uid, $page = 1, $limit = 20)
  762. {
  763. return Json::successful(StoreOrder::getOneorderList(compact('uid', 'page', 'limit')));
  764. }
  765. /**
  766. * 获取某用户的签到列表
  767. */
  768. public function getOneSignList($uid, $page = 1, $limit = 20)
  769. {
  770. return Json::successful(UserBillAdmin::getOneSignList(compact('uid', 'page', 'limit')));
  771. }
  772. /**
  773. * 获取某用户的余额变动记录
  774. */
  775. public function getOneBalanceChangList($uid, $page = 1, $limit = 20)
  776. {
  777. return Json::successful(UserBillAdmin::getOneBalanceChangList(compact('uid', 'page', 'limit')));
  778. }
  779. }