123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- <?php
- /**
- *
- * @author: xaboy<365615158@qq.com>
- * @day: 2017/11/11
- */
- namespace app\admin\controller\user;
- use app\admin\controller\AuthController;
- use crmeb\repositories\OrderRepository;
- use crmeb\repositories\ShortLetterRepositories;
- use crmeb\services\{ExpressService,
- JsonService,
- JsonService as Json,
- MiniProgramService,
- WechatService,
- FormBuilder as Form,
- CacheService,
- UtilService as Util};
- use app\admin\model\ump\StorePink;
- use crmeb\basic\BaseModel;
- use think\cache\driver\Redis;
- use think\facade\Route as Url;
- use crmeb\services\YLYService;
- use think\facade\Log;
- use think\facade\Validate;
- /**
- * 订单管理控制器 同一个订单表放在一个控制器
- * Class StoreOrder
- * @package app\admin\controller\store
- */
- class PullNew extends AuthController
- {
- /**
- * @return mixed
- */
- public function index()
- {
- return $this->fetch();
- }
- public function list()
- {
- $where = Util::getMore([
- ['page', 1],
- ['limit', 20],
- ]);
- return Json::successlayui(\app\admin\model\user\PullNew::list($where));
- }
- /**
- * 显示创建资源表单页.
- *
- * @return \think\Response
- */
- public function create($id = 0)
- {
- $f = [];
- $f[] = Form::input('title', '标题')->col(12);
- $f[] = Form::dateTime('add_time' ,'开始时间');
- $f[] = Form::dateTime('end_time', '结束时间');
- if ($id) $f[] = Form::hidden('id', $id);
- $form = Form::make_post_form('添加', $f, Url::buildUrl('save'));
- $this->assign(compact('form'));
- return $this->fetch('public/form-builder');
- }
- public function save()
- {
- $model = new \app\admin\model\user\PullNew();
- $data = Util::postMore([
- 'title',
- 'add_time',
- 'end_time',
- ]);
- $validate = Validate::rule([
- 'title' => 'require',
- 'add_time' => 'require',
- 'end_time' => 'require',
- ]);
- $validate->message([
- 'title.require' => '标题不能为空',
- 'add_time.require' => '请选择进场时间',
- 'end_time.require' => '请选择结束时间',
- ]);
- if (!$validate->check($data)) {
- return Json::fail($validate->getError());
- }
- $data['add_time'] = strtotime($data['add_time']);
- $data['end_time'] = strtotime($data['end_time']);
- $res = $model->save($data);
- if ($res) return Json::successful('添加成功');
- return Json::fail('添加失败');
- }
- public function ranking($id)
- {
- $this->assign('new_id', $id);
- return $this->fetch();
- }
- /**
- * 拉新排行
- * @param $new_id
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function ranking_list($new_id)
- {
- $where = Util::getMore([
- ['page', 1],
- ['limit', 20],
- ]);
- $redis = new Redis();
- $redis->connect('127.0.0.1','6379', 3600);
- if (!$redis->get('Ranking_'.$new_id)){
- $new = \app\admin\model\user\PullNew::where('id', $new_id)->find();
- $user = \app\admin\model\user\User::select();
- $user_count = [];
- foreach ($user as $item){
- $uids = get_downline_dow_time($user, $item['uid'], $new['add_time'], $new['end_time']);
- if (count($uids) > 0){
- $user_count[] = ['uid' => $item['uid'],'nickname' => $item['nickname'], 'count' => count($uids), 'push' => \app\admin\model\user\User::where('spread_uid', $item['uid'])->whereBetweenTime('add_time', $new['add_time'], $new['end_time'])->count()];
- }
- }
- }else{
- $user_count = $redis->get('Ranking');
- }
- $count = array_column($user_count, 'count');
- array_multisort($count, SORT_DESC, $user_count);
- $redis->set('Ranking_'.$new_id, $user_count);
- $data['count'] = count($user_count);
- $start=($where['page']-1)*$where['limit'];//偏移量,当前页-1乘以每页显示条数
- $data['data'] = array_slice($user_count,$start,$where['limit']);
- return Json::successlayui($data);
- }
- /**
- * 删除
- * @param $id
- * @return void
- * @throws \Exception
- */
- public function delete($id)
- {
- if (!$id) Json::fail('删除失败');
- $model = new \app\admin\model\user\PullNew();
- $res = \app\admin\model\user\PullNew::destroy($id);
- if ($res){
- return Json::success('删除成功!');
- }else{
- return Json::fail($model->getErrorInfo());
- }
- }
- }
|