AdminSignController.php 8.8 KB
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author:kane < chengjin005@163.com>
// +----------------------------------------------------------------------
namespace app\portal\controller;

use cmf\controller\AdminBaseController;
use think\Db;

/**
 * Class AdminSignController
 * @package app\portal\controller
 * @adminMenuRoot(
 *     'name'   =>'打卡管理',
 *     'action' =>'default',
 *     'parent' =>'',
 *     'display'=> true,
 *     'order'  => 30,
 *     'icon'   =>'th',
 *     'remark' =>'打卡管理'
 * )
 */
class AdminSignController extends AdminBaseController
{
    /**
     * 打卡列表
     * @adminMenu(
     *     'name'   => '打卡列表',
     *     'parent' => 'portal/AdminSign/default',
     *     'display'=> true,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '打卡列表',
     *     'param'  => ''
     * )
     */
    public function index()
    {
        $where   = ['user_type'=>2];
        $request = input('request.');

        if (!empty($request['user_nickname'])) {
            $nickname=$request['user_nickname'];
            $where['user_nickname']    = ['like', "%$nickname%"];
        }
        if (!empty($request['mobile'])) {
            $keyword = $request['mobile'];

            $where['mobile']    = ['like', "%$keyword%"];
        }
        $usersQuery = Db::name('user');

        $list = $usersQuery->where($where)->order("create_time DESC")->paginate(10);
        // 获取分页显示
        $page = $list->render();
        $this->assign('list', $list);
        $this->assign('page', $page);
        // 渲染模板输出
        return $this->fetch();
    }



    public function signTime(){
        $data=Db::name('config')->where('id',1)->find();
        $this->assign('list',$data);
        return $this->fetch();
    }
    public function signTimePost(){
        $param=$this->request->param();
        $param['morning_sign_time']=strtotime($param['morning_sign_time']);
        $param['morning_sign_end_time']=strtotime($param['morning_sign_end_time']);
        $param['noon_sign_time']=strtotime($param['noon_sign_time']);
        $param['noon_sign_end_time']=strtotime($param['noon_sign_end_time']);
        $param['night_sign_time']=strtotime($param['night_sign_time']);
        $param['night_sign_end_time']=strtotime($param['night_sign_end_time']);
        $param['sleep_sign_time']=strtotime($param['sleep_sign_time']);
        $param['sleep_sign_end_time']=strtotime($param['sleep_sign_end_time']);
        $param=array_filter($param);
        Db::name('config')->where('id',1)->update($param);
        $this->success('编辑成功');
    }




    public function sLogan(){
        $data=Db::name('config')->where('id',1)->find();
        $data['slogan']=cmf_replace_content_file_url(htmlspecialchars_decode($data['slogan']));
        $this->assign('list',$data);
        return $this->fetch();
    }

    public function sLoganPost(){
        $param=$this->request->param();
        $param['slogan']=htmlspecialchars(cmf_replace_content_file_url(htmlspecialchars_decode($param['slogan']),true));
        Db::name('config')->where('id',1)->update($param);
        $this->success('编辑成功');
    }




    public function score(){
        $data=Db::name('config')->where('id',1)->find();
        $this->assign('list',$data);
        return $this->fetch();
    }
    public function scorePost(){
        $param=$this->request->param();
        Db::name('config')->where('id',1)->update($param);
        $this->success('编辑成功');
    }


    public function signImage(){
        $param=$this->request->param();
        if (empty($param)){
            $param['id']=1;
        }
        $data=Db::name('sign_image')->where('id',$param['id'])->find();
        $data['music']=json_decode($data['music'],true);
        $this->assign('list',$data);
        return $this->fetch();
    }
    public function signImagePost(){
        $param=$this->request->param();
//        var_dump($param);
//        $param['music']=\GuzzleHttp\json_encode()
        if (!empty($param['video_names']) && !empty($param['video_urls'])) {
            $param['music'] = [];
            foreach ($param['video_urls'] as $key => $url) {
                $fileUrl = cmf_asset_relative_url($url);
                array_push( $param['music'] , ["url" => $fileUrl, "name" => $param['video_names'][$key]]);
            }
        $param['music']=json_encode($param['music']);
        }
        unset($param['video_names']);
        unset($param['video_urls']);
        Db::name('sign_image')->where('id',$param['id'])->update($param);
        $this->success('编辑成功');
    }
    public function daySign(){
        $param=$this->request->param();

        $where['us.user_id']=$param['id'];


        if (!empty($param['user_nickname'])) {
            $nickname=$param['user_nickname'];
            $where['u.user_nickname']    = ['like', "%$nickname%"];
        }
        if (!empty($param['mobile'])) {
            $keyword = $param['mobile'];
            $where['u.mobile']    = ['like', "%$keyword%"];
        }
        if (!empty($param['status'])) {
            $status = $param['status'];
            $where['us.status']    = $status;
        }
        $data=Db::name('user_sign')->alias('us')->join('user u','us.user_id=u.id')->where($where)->order('us.create_time','desc')->field('*,us.id as usid')->paginate(10);
        $this->assign('list',$data);
        $this->assign('id',$param['id']);
        $this->assign('keyword', isset($keyword) ? $keyword : '');
        $this->assign('nickname', isset($nickname) ? $nickname : '');
        $this->assign('status', isset($status) ? $status : '');
        return $this->fetch();
    }

    public function daySignDelete(){
        $param=$this->request->param();
        if (!empty($param['ids'])){
            Db::name('user_sign')->where(['id' => ['in', $param['ids']]])->delete();
            $this->success('删除成功');
        }
        Db::name('user_sign')->where('id', $param['id'])->delete();
        $this->success('删除成功');
    }


    public function weekSign(){
        $param=$this->request->param();

        $where['uw.user_id']=$param['id'];


        if (!empty($param['user_nickname'])) {
            $nickname=$param['user_nickname'];
            $where['u.user_nickname']    = ['like', "%$nickname%"];
        }
        if (!empty($param['mobile'])) {
            $keyword = $param['mobile'];
            $where['u.mobile']    = ['like', "%$keyword%"];
        }
        $data=Db::name('user_week_sign')->alias('uw')->join('user u','uw.user_id=u.id')->where($where)->order('uw.create_time','desc')->field('*,uw.id as uwid')->paginate(10);
        $this->assign('list',$data);
        $this->assign('id',$param['id']);
        $this->assign('keyword', isset($keyword) ? $keyword : '');
        $this->assign('nickname', isset($nickname) ? $nickname : '');
        return $this->fetch();
    }

    public function weekSignDelete(){
        $param=$this->request->param();
        if (!empty($param['ids'])){
            Db::name('user_week_sign')->where(['id' => ['in', $param['ids']]])->delete();
            $this->success('删除成功');
        }
        Db::name('user_week_sign')->where('id', $param['id'])->delete();
        $this->success('删除成功');
    }


    /**
     * 删除打卡记录
     * @adminMenu(
     *     'name'   => '删除打卡记录',
     *     'parent' => 'index',
     *     'display'=> false,
     *     'hasView'=> false,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '删除打卡记录',
     *     'param'  => ''
     * )
     */
    public function delete()
    {
        $param=$this->request->param();
        if (!empty($param['ids'])){
            Db::name('user_sign')->where(['user_id' => ['in', $param['ids']]])->delete();
            Db::name('user_week_sign')->where(['user_id' => ['in', $param['ids']]])->delete();
            Db::name('user')->where(['user_id' => ['in', $param['ids']]])->update(['all_sign_day'=>0,'stay_sign_day'=>0,'longest_sign_day'=>0]);
            $this->success('删除成功');
        }
        Db::name('user_sign')->where('user_id', $param['id'])->delete();
        Db::name('user_week_sign')->where('user_id', $param['id'])->delete();
        Db::name('user')->where('user_id', $param['id'])->update(['all_sign_day'=>0,'stay_sign_day'=>0,'longest_sign_day'=>0]);
        $this->success('删除成功');
    }

}