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.
246 lines
8.8 KiB
246 lines
8.8 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | Niucloud-admin 企业快速开发的多应用管理平台
|
|
// +----------------------------------------------------------------------
|
|
// | 官方网址:https://www.niucloud.com
|
|
// +----------------------------------------------------------------------
|
|
// | niucloud团队 版权所有 开源版本可自由商用
|
|
// +----------------------------------------------------------------------
|
|
// | Author: Niucloud Team
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app\service\api\member;
|
|
|
|
use app\model\assignment\Assignment;
|
|
use app\model\campus\Campus;
|
|
use app\model\communication_records\CommunicationRecords;
|
|
use app\model\course_schedule\CourseSchedule;
|
|
use app\model\member\Member;
|
|
use app\model\person_course_schedule\PersonCourseSchedule;
|
|
use app\model\service_logs\ServiceLogs;
|
|
use app\service\core\member\CoreMemberService;
|
|
use core\base\BaseApiService;
|
|
use core\exception\ApiException;
|
|
use core\util\Barcode;
|
|
use think\facade\Db;
|
|
use think\Model;
|
|
|
|
/**
|
|
* 会员服务层
|
|
* Class MemberService
|
|
* @package app\service\api\member
|
|
*/
|
|
class MemberService extends BaseApiService
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->model = new Member();
|
|
}
|
|
|
|
/**
|
|
* 新增会员
|
|
*/
|
|
public function add(array $data)
|
|
{
|
|
return $this->model->create($data)?->member_id ?? 0;
|
|
}
|
|
|
|
/**
|
|
* 更新会员
|
|
* @param array $data
|
|
* @return true
|
|
*/
|
|
public function edit(array $data)
|
|
{
|
|
$member = $this->findMemberInfo(['member_id' => $this->member_id]);
|
|
|
|
if ($member->isEmpty()) throw new ApiException('MEMBER_NOT_EXIST');
|
|
$member->allowField(['nickname', 'headimg', 'birthday', 'sex', 'last_visit_time'])->save($data);
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* 获取会员信息
|
|
* @return array
|
|
*/
|
|
public function getInfo()
|
|
{
|
|
$field = 'member_id, username, member_no, mobile, register_channel, nickname, headimg, member_level, member_label, login_ip, login_type, login_time, create_time, last_visit_time, last_consum_time, sex, status, birthday, point, balance, growth, is_member, member_time, is_del, province_id, city_id, district_id, address, location, money, money_get, wx_openid, weapp_openid, commission, commission_get, commission_cash_outing';
|
|
return $this->model->where([['member_id', '=', $this->member_id]])->with(['member_level_name_bind'])->field($field)->append(['sex_name'])->findOrEmpty()->toArray();
|
|
}
|
|
|
|
/**
|
|
* 检测会员信息是否存在
|
|
* @return int
|
|
*/
|
|
public function getCount($condition)
|
|
{
|
|
return $this->model->where($condition)->count();
|
|
}
|
|
|
|
/**
|
|
* 会员中心信息
|
|
*/
|
|
public function center()
|
|
{
|
|
$field = 'member_id, username, member_no, mobile, register_channel, nickname, headimg, member_level, member_label, login_ip, login_type, login_time, create_time, last_visit_time, last_consum_time, sex, status, birthday, point, balance, growth, is_member, member_time, is_del, province_id, city_id, district_id, address, location, money, money_get, commission, commission_get, commission_cash_outing';
|
|
return $this->model->where([['member_id', '=', $this->member_id]])->field($field)->append(['sex_name'])->findOrEmpty()->toArray();
|
|
}
|
|
|
|
/**
|
|
* 获取会员的模型对象(todo 慎用!!! 现主要用于登录)
|
|
* @param array $data
|
|
* @return Member|array|mixed|Model !!! 仔细看,返回值是模型对象 如果想要判断是否为空 请用 $member->isEmpty()
|
|
*/
|
|
public function findMemberInfo(array $data)
|
|
{
|
|
//会员账号
|
|
if (!empty($data['username']))
|
|
$where[] = ['username', '=', $data['username']];
|
|
//会员手机号
|
|
if (!empty($data['mobile']))
|
|
$where[] = ['mobile', '=', $data['mobile']];
|
|
//会员id
|
|
if (!empty($data['member_id']))
|
|
$where[] = ['member_id', '=', $data['member_id']];
|
|
//微信公众号openid
|
|
if (!empty($data['wx_openid']))
|
|
$where[] = ['wx_openid', '=', $data['wx_openid']];
|
|
//微信小程序openid
|
|
if (!empty($data['weapp_openid']))
|
|
$where[] = ['weapp_openid', '=', $data['weapp_openid']];
|
|
// 微信unionid
|
|
if (!empty($data['wx_unionid']))
|
|
$where[] = ['wx_unionid', '=', $data['wx_unionid']];
|
|
if (!empty($data['username|mobile']))
|
|
$where[] = ['username|mobile', '=', $data['username|mobile']];
|
|
if (empty($where)) {
|
|
$where[] = ['member_id', '=', -1];
|
|
}
|
|
return $this->model->where($where)->findOrEmpty();
|
|
}
|
|
|
|
/**
|
|
* 通过对象修改会员信息
|
|
* @param $member
|
|
* @param $data
|
|
* @return void
|
|
*/
|
|
public function editByFind($member, $data)
|
|
{
|
|
return $member->save($data);
|
|
}
|
|
|
|
/**
|
|
* 修改字段
|
|
* @param string $field
|
|
* @param $data
|
|
* @return null
|
|
*/
|
|
public function modify(string $field, $data)
|
|
{
|
|
return (new CoreMemberService())->modify($this->member_id, $field, $data);
|
|
}
|
|
|
|
public function getQrcode()
|
|
{
|
|
// 生成会员二维码
|
|
$qrcode_dir = 'upload/member/temp';
|
|
if (!is_dir($qrcode_dir)) mkdir($qrcode_dir, intval('0755', 8), true);
|
|
$id = "member-" . $this->member_id;
|
|
$qrcode_path = "{$qrcode_dir}/order_qrcode_{$this->member_id}.png";
|
|
\core\util\QRcode::png($id, $qrcode_path, 'L', 16, 1);
|
|
|
|
// 生成会员条形码
|
|
$barcode_path = (new Barcode(14, $id))->generateBarcode($qrcode_dir, 2);
|
|
$detail = [];
|
|
$detail['verify_code_qrcode'] = image_to_base64($qrcode_path, true);
|
|
$detail['verify_code_barcode'] = image_to_base64($barcode_path);
|
|
return $detail;
|
|
}
|
|
|
|
/**
|
|
* 初始化会员数据
|
|
*/
|
|
public function initMemberData()
|
|
{
|
|
if ($this->member_id) {
|
|
event("MemberLoginAfter", ['member_id' => $this->member_id]);
|
|
}
|
|
}
|
|
|
|
public function get_campuses_list()
|
|
{
|
|
$campus = new Campus();
|
|
$list = $campus->select()->toArray();
|
|
return $list;
|
|
|
|
}
|
|
|
|
public function list_call_up($resource_id)
|
|
{
|
|
$campus = new CommunicationRecords();
|
|
return $campus->where('resource_id', $resource_id)->select()->toArray();
|
|
}
|
|
|
|
public function update_call_up($resource_id, $remarks)
|
|
{
|
|
$campus = new CommunicationRecords();
|
|
return $campus->where('resource_id', $resource_id)->update(['remarks' => $remarks]);
|
|
}
|
|
|
|
public function jl_index(){
|
|
|
|
$schedules = new CourseSchedule();
|
|
$person_course_schedule = new PersonCourseSchedule();
|
|
$Assignment = new Assignment();
|
|
$service_logs = new ServiceLogs();
|
|
$course_list = $schedules
|
|
->alias("a")
|
|
->join(['school_venue' => 'b'],'a.venue_id = b.id','left')
|
|
->join(['school_course' => 'c'],'a.course_id = c.id','left')
|
|
->where([
|
|
['a.status','<>','completed'],
|
|
['a.course_date', 'between', [date('Y-m-d', strtotime('-6 days')), date('Y-m-d')]],
|
|
])
|
|
->where("a.coach_id = {$this->member_id} OR education_id = {$this->member_id} OR find_in_set('{$this->member_id}', a.assistant_ids) ")
|
|
->field("a.id,a.status,c.course_name,a.course_date,a.time_slot,b.venue_name as address,a.student_ids")
|
|
->order("time_slot desc")
|
|
->limit(3)
|
|
->select();
|
|
|
|
if($course_list){
|
|
$course_list = $course_list->toArray();
|
|
foreach ($course_list as $k=>$v){
|
|
$course_list[$k]['students_count'] = $person_course_schedule->where(['schedule_id' => $v['id']])->count();
|
|
$course_list[$k]['sign_count'] = $person_course_schedule->where(['schedule_id' => $v['id'],'status' => 2])->count();
|
|
}
|
|
}
|
|
|
|
//作业列表
|
|
$task_list = $Assignment
|
|
->alias("a")
|
|
->join(['school_class' => 'b'],"a.class_id = b.id","left")
|
|
->join(['school_course' => 'c'],"a.course_id = c.id","left")
|
|
->field("a.id,a.create_time,b.class_name,c.course_name")
|
|
->where([
|
|
'a.personnel_id' => $this->member_id,
|
|
'a.status' => 3
|
|
])
|
|
->limit("5")
|
|
->select();
|
|
|
|
|
|
$service_list = $service_logs
|
|
->alias("a")
|
|
->join(['school_service' => 'b'],"a.service_id = b.id","left")
|
|
->field("a.id,b.service_name,b.description,a.created_at,a.status")
|
|
->where(['staff_id' => $this->member_id])
|
|
->order("a.created_at desc")
|
|
->limit("5")
|
|
->select();
|
|
|
|
return ['course_list' => $course_list,'task_list' => $task_list,'service_list' => $service_list];
|
|
}
|
|
}
|
|
|