合规国际互联网加速 OSASE为企业客户提供高速稳定SD-WAN国际加速解决方案。 广告
>[info] >## TrainerspicController ```` <?php /** * Created by PhpStorm. * User: Administrator * Date: 2018/9/8 * Time: 15:12 */ namespace app\adminapi\controller\trainers; use app\admin\model\Nintyuser; use app\admin\model\ParklinesmsInfo; use app\admin\model\Trainer; use app\admin\model\Trainerpic; use app\adminapi\controller\AdminApi; use app\adminapi\exception\ParameterException; use IanZhi\Parkline\Exception\ParklineException; use IanZhi\Parkline\ParklineApi; use think\Request; class TrainerspicController extends AdminApi { public function __construct() { parent::__construct(); } /** * 搜索-获取指定条件的信息 * @param Request $request * @return string * @throws \think\exception\DbException */ public function index(Request $request) { //获取参数 $params = $request->param(); //筛选私教 $trainer_id = @$params['trainer_id']; //筛选图片类型 $pic_type = @$params['pic_type']; //搜索条件 $condition = ' 1=1 '; if($trainer_id != '') $condition .= " AND trainer_id =".$trainer_id; if($pic_type != '') $condition .= " AND pic_type =".$pic_type; //查询数据 if(empty($params['list_rows'])){ $params['list_rows'] = 10; } if(@$params['isdel'] == ''){ //未删除 $isdel = 0; }else{ $isdel = $params['isdel']; } $result = Trainerpic::where($condition)->where('isdel',$isdel)->order('pic_order desc')->paginate($params['list_rows']); $page = $result->render(); $this->success($result,$page); } /** * @param Request $request * @throws ParameterException * @throws \think\exception\DbException */ public function add(Request $request) { //获取参数 $params = $request->param(); //判断是否上传了图片 if(empty($params['pic_image'])){ throw new ParameterException('图片不能为空'); } //查看之前是否已存在刷脸照片 if($params['pic_type'] == 1){ $data_status = Trainerpic::where('trainer_id',$params['trainer_id'])->where('pic_type',1)->delete(); } $result = Trainerpic::createData($params); if($result){ if($params['pic_type'] == 1){ //刷脸设备更新 TODO 需要更新刷脸设备图片 //通过当前教练id,获取手机号 $user_info = Trainer::where('id',$params['trainer_id'])->find(); //手机号 // $mobile_user = $user_info['mobile']; //微信昵称 // $name_user = base64_decode($user_info['name']); //用户名称real_name // $real_name = $user_info['real_name']; //获取用户名 // $name_name = empty($real_name)?$name_user:$real_name; if(empty($user_info['mobile'])){ $this->success('当前手机号为空,查找指定手机号失败'); } //1:查找指定成员mobile // $status_park = ParklineApi::queryUser($mobile_user); // if($status_park['code'] == '100101'){ // //查询当前健身房旗下所有devid // $parklines_all = ParklinesmsInfo::where('fitness_id',1)->select(); // foreach ($parklines_all as $value){ // //获取设备 // $deviceId = $value['devid']; // $status_face = ParklineApi::setUserFace($user_info['mobile'],$deviceId,$params['pic_image']); // $test[] = $status_face; // } // $this->success($test); // } //2:为空时:TODO 为空时 } $this->success($result); }else{ throw new ParameterException('参数错误'); } } /** * @param Request $request * @return void * @throws ParameterException * @throws ParklineException * @throws \think\exception\DbException */ public function update(Request $request) { //获取参数 $pic_id = $request->param('id'); $pic_type = $request->param('pic_type'); $pic_image = $request->param('pic_image'); $trainer_id = $request->param('trainer_id'); // 参数验证 if (!$pic_id || !$trainer_id) { throw new ParameterException('缺少参数!'); } $pic = Trainerpic::get($pic_id); if (!$pic) { throw new ParameterException('id对应的图片不存在'); } $pic->pic_type = $pic_type; $pic->pic_image = $pic_image; // $pic->pic_image = 'https://199fit.com/uploads/20180927/78c7e6d304ace7ada372607178f2fe46.jpg'; $pic->save(); if ($pic->pic_type == 1) { //判断健身房下是否有设备 $locks = $pic->getFitnessLocks(); if(empty($locks)){ throw new ParklineException('当前健身房下暂无设备!'); } // 判断用户是否创建 // $equipment_bind_info = ParklineApi::queryUser($pic->trainer->mobile); // if($equipment_bind_info['code'] != '100101'){ // $this->addParklineUser(); // } // 判断用户是否绑定 $mobile = $pic->trainer->mobile; $result = ParklineApi::queryUserBinds($mobile, 0, 1000); if ($result['code'] != '100101') { throw new ParklineException('获取用户绑定信息失败!'); } $binds = $result['data']; // foreach ($binds as $bind) { // $add_bind_flag = true; // foreach ($locks as $lock) { // if ($bind['devid'] == $lock['devid']) { // $add_bind_flag = false; // } // } // if ($add_bind_flag) { // ParklineApi::bindUserToEquipment( // $pic->trainer->mobile, // $bind['devid'], // '01', // date('Y-m-d', time()), // date('Y-m-d', time() + 365 * 24 * 3600), // '00:00', // '23:59'); // } // } // $file_size = fileSize('.'.$pic->pic_image); // var_dump($file_size);exit; // $file1=file_get_contents($info->getPathname()); // return strlen($file1); // if(strlen($file1)>999999) // 更改用户刷脸信息 foreach ($binds as $bind) { $face_file = fileToBase64('.'.$pic->pic_image); $update_picstatus[] = ParklineApi::setUserFace($pic->trainer->mobile,$bind['devid'],$face_file); } } $this->success($update_picstatus); // $this->success($pic); } /** * @param Request $request * @throws ParameterException * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function del(Request $request) { //获取参数 $params = $request->param(); //循环 删除 foreach ($params['ids'] as $v){ //校验数据 $status_id = Trainerpic::get($v); if( empty($status_id) ){ throw new ParameterException('该参数不存在:id'); } //软删除数据 isdel是否删除:0=否,1=是 $result = Trainerpic::where('id',$v)->update(['isdel'=>1]); } $this->success($result); } }