You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
222 lines
6.8 KiB
222 lines
6.8 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | Niucloud-admin 企业快速开发的多应用管理平台
|
|
// +----------------------------------------------------------------------
|
|
// | 官方网址:https://www.niucloud.com
|
|
// +----------------------------------------------------------------------
|
|
// | niucloud团队 版权所有 开源版本可自由商用
|
|
// +----------------------------------------------------------------------
|
|
// | Author: Niucloud Team
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app\api\controller\login;
|
|
|
|
use addon\zhjw\app\model\follow_up_reminders\FollowUpReminders;
|
|
use addon\zhjw\app\model\schedules\Schedules;
|
|
use addon\zhjw\app\model\staff\Staff;
|
|
use app\dict\member\MemberLoginTypeDict;
|
|
use app\model\member\Contact;
|
|
use app\model\member\StaffMessage;
|
|
use app\service\api\captcha\CaptchaService;
|
|
use app\service\api\login\ConfigService;
|
|
use app\service\api\login\LoginService;
|
|
use core\base\BaseController;
|
|
use Exception;
|
|
use think\facade\Db;
|
|
use think\Response;
|
|
|
|
class Login extends BaseController
|
|
{
|
|
/**
|
|
* 登录
|
|
* @return Response
|
|
*/
|
|
public function login()
|
|
{
|
|
$data = $this->request->params([
|
|
[ 'username', '' ],
|
|
[ 'password', '' ],
|
|
]);
|
|
|
|
$result = ( new LoginService() )->account($data[ 'username' ], $data[ 'password' ]);
|
|
if (!$result) {
|
|
//账号密码错误, 重置验证码
|
|
return fail('ACCOUNT_OR_PASSWORD_ERROR');
|
|
}
|
|
return success($result);
|
|
}
|
|
|
|
/**
|
|
* 登出
|
|
* @return Response
|
|
*/
|
|
public function logout()
|
|
{
|
|
( new LoginService )->logout();
|
|
return success('MEMBER_LOGOUT');
|
|
}
|
|
|
|
/**
|
|
* 创建验证码
|
|
* @return Response
|
|
*/
|
|
public function captcha()
|
|
{
|
|
return success(( new CaptchaService() )->create());
|
|
}
|
|
|
|
/**
|
|
* 发送手机验证码
|
|
* @param $type
|
|
* @return Response
|
|
* @throws Exception
|
|
*/
|
|
public function sendMobileCode($type)
|
|
{
|
|
$data = $this->request->params([
|
|
[ 'mobile', '' ],
|
|
]);
|
|
return success(( new LoginService() )->sendMobileCode($data[ 'mobile' ], $type));
|
|
}
|
|
|
|
/**
|
|
* 手机号登录
|
|
* @return Response
|
|
*/
|
|
public function mobile()
|
|
{
|
|
$data = $this->request->params([
|
|
[ 'mobile', '' ],
|
|
[ 'nickname', '' ],
|
|
[ 'headimg', '' ],
|
|
[ 'mobile', '' ]
|
|
]);
|
|
//校验登录注册配置
|
|
( new ConfigService() )->checkLoginConfig(MemberLoginTypeDict::MOBILE);
|
|
return success(( new LoginService() )->mobile($data));
|
|
}
|
|
|
|
/**
|
|
* 重置密码
|
|
* @return Response
|
|
*/
|
|
public function resetPassword()
|
|
{
|
|
$data = $this->request->params([
|
|
[ 'mobile', '' ],
|
|
[ 'password', '' ]
|
|
]);
|
|
//参数验证
|
|
$this->validate($data, 'app\validate\member\Member.reset_password');
|
|
( new LoginService() )->resetPassword($data[ 'mobile' ], $data[ 'password' ]);
|
|
return success('PASSWORD_RESET_SUCCESS');
|
|
}
|
|
|
|
public function checkMobileCode(){
|
|
$data = $this->request->params([
|
|
[ 'mobile', '' ]
|
|
]);
|
|
return success( ( new LoginService() )->checkMobileCode($data['mobile']));
|
|
}
|
|
|
|
|
|
//定时任务
|
|
|
|
public function follow_warn(){
|
|
$reminders = new FollowUpReminders();
|
|
$staffMessage = new StaffMessage();
|
|
$contact = new Contact();
|
|
$list = $reminders->where([
|
|
['reminder_time','<',date("Y-m-d H:i:s",time())],
|
|
['task_status','=',1]
|
|
])->select();
|
|
|
|
if($list){
|
|
$list = $list->toArray();
|
|
foreach ($list as $k=>$v){
|
|
$is_friends = $contact->where(['hair_staff_id' => 0,'closed_staff_id' => $v['follow_staff_id']])->find();
|
|
if(!$is_friends){
|
|
$contact->insert([
|
|
'hair_staff_id' => 0,
|
|
'closed_staff_id' => $v['follow_staff_id'],
|
|
'create_time' => date('Y-m-d H:i:s')
|
|
]);
|
|
}
|
|
|
|
$staffMessage->insert([
|
|
'hair_staff_id' => 0,
|
|
'closed_staff_id' => $v['follow_staff_id'],
|
|
'content' => $v['follow_content'],
|
|
'create_time' => date("Y-m-d H:i:s")
|
|
]);
|
|
|
|
$reminders->where(['id' => $v['id']])->update(['task_status' => 2]);
|
|
}
|
|
}
|
|
}
|
|
|
|
//定时任务 每日考勤
|
|
public function clocking(){
|
|
$staff = new Staff();
|
|
$schedules = new Schedules();
|
|
$list = $staff->where([
|
|
['type','in','1,2']
|
|
])->select();
|
|
|
|
foreach ($list as $k=>$v){
|
|
|
|
$is_clocking = Db::name("staff_clocking")->where(['staff_id' => $v['id'],'create_time' => date("Y-m-d")])->find();
|
|
if($v['type'] == 1){
|
|
//教练
|
|
if(!$is_clocking){
|
|
$schedules_list = $schedules->where(['date_time' => date("Y-m-d"),'staff_id' => $v['id']])->select();
|
|
foreach ($schedules_list as $k1=>$v1){
|
|
$time_slot = explode(",",$v1['time_slot']);
|
|
|
|
Db::name("staff_clocking")->insert([
|
|
'staff_id' => $v['id'],
|
|
'status' => 1,
|
|
'create_time' => date("Y-m-d"),
|
|
'add_time' => date("Y-m-d").' '.$time_slot[0].':00',
|
|
'end_time' => date("Y-m-d").' '.$time_slot[1].':00',
|
|
'courses_id' => $v1['courses_id'],
|
|
'type' => 2
|
|
]);
|
|
}
|
|
}
|
|
|
|
}else{
|
|
//销售
|
|
if(!$is_clocking){
|
|
Db::name("staff_clocking")->insert([
|
|
'staff_id' => $v['id'],
|
|
'status' => 1,
|
|
'create_time' => date("Y-m-d"),
|
|
'add_time' => date("Y-m-d").' 00:00:00',
|
|
'end_time' => date("Y-m-d").' 23:59:59',
|
|
'type' => 1
|
|
]);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
public function schedules_tast(){
|
|
$schedules = new Schedules();
|
|
$where = [];
|
|
$where[] = ['date_time','=',date("Y-m-d")];
|
|
//判断 是未开始 - 进行中的 - 已结束
|
|
$list = $schedules->where($where)->select();
|
|
if($list){
|
|
foreach ($list as $k=>$v){
|
|
$status = getTimeSlotStatus($v['time_slot']);
|
|
$schedules->where(['id' => $v['id']])->update(['status' => $status]);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|