| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- <?php
- class CommonController extends Controller
- {
- public function actionSendCode()
- {
- $phone = Helper::getPostString('phone', '');
- if (!Helper::isPhone($phone)) {
- Helper::error('手机号码格式错误');
- }
- // 验证码发送限制
- Helper::dealCommonResult(Helper::limitSmsSend(10, $phone, 5), false);
- if (!DB::getScalerWithCriteria('useradmin', DbCriteria::simpleCompare(['phone' => $phone])->setSelect('id'))) {
- Helper::error('该手机号用户不存在');
- }
- $code = (string)random_int(100000,999999);
- RedisInstance::getInstance()->set('user_code:'.$phone, $code, 600);
- // 发送短信
- Helper::dealCommonResult(SMS::getInstance()->send($phone, '2094847', [$code]));
- }
- public function actionSetPassword()
- {
- $phone = Helper::getPostString('phone');
- $code = Helper::getPostString('code');
- $password = Helper::getPostString('password');
- if (!Helper::isPhone($phone)) {
- Helper::error('手机号码格式错误');
- }
- if (!$code || !$password) {
- Helper::error('参数错误');
- }
- if (RedisInstance::getInstance()->get('user_code:'.$phone) != $code) {
- Helper::error('验证码错误');
- }
- $id = DB::getScalerWithCriteria('useradmin', DbCriteria::simpleCompare(['phone' => $phone])->setSelect('id'));
- if (!$id) {
- Helper::error('该手机号用户不存在');
- }
- DB::updateById('useradmin', ['password' => md5($password)], $id);
- Helper::ok();
- }
- /**
- * ajax提交图片temp临时存放
- */
- public function actionUploadtemp(){
- $type = strtolower($_FILES['surface']['type']);
- $size = $_FILES['surface']['size'];
- $maxsize = isset($_POST['imgmaxsize'])?$_POST['imgmaxsize']:'512000';
- $imagetype = isset($_POST['type'])?$_POST['type']:'all';
- if(stristr($type, 'png') || stristr($type, 'jpeg') || stristr($type, 'jpg')) {
- if($size > $maxsize){
- echo 'size';//图片容量超过200K
- }else{
- if(stristr($type, 'png')) {
- $extention = '.png';
- }else{
- $extention = '.jpg';
- }
- $temp_words = LewaimaiString::create_noncestr(32);//随机图片名
- $temp_url= 'public/temp/images/admin_'.Yii::app()->user->_id . '/';
- if(!is_dir($temp_url)){
- mkdir($temp_url,0755,true);
- }
- $temp_name = $temp_url.$temp_words.$extention;
- $time = LewaimaiString:: GetOutTradeNo();
- if(copy($_FILES['surface']['tmp_name'], $temp_name)){
- chmod($temp_name,0755);
- $cdn_url = getUpyunUploadPath();
- $fileName = $temp_words . $extention;
- $surfaceimg = $cdn_url.$fileName;
- LewaimaiImageUpload('./'.$temp_name,$surfaceimg);
- echo $surfaceimg;
- //清除本地文件
- LewaimaiUtility::clearTempimages();
- }else{
- echo 'error';//出错
- }
- }
- }else{
- echo 'suffix';//格式不对
- }
- exit;
- }
- public function actionCropImg()
- {
- $type = strtolower($_FILES['surface']['type']);
- $size = $_FILES['surface']['size'];
- $maxsize = isset($_POST['imgmaxsize'])?$_POST['imgmaxsize']:'512000';
- $imagetype = isset($_POST['type'])?$_POST['type']:'all';
- if(stristr($type, 'png') || stristr($type, 'jpeg') || stristr($type, 'jpg')) {
- if($size > $maxsize){
- echo 'size';//图片容量超过200K
- }else{
- if(stristr($type, 'png')) {
- $extention = '.png';
- }else{
- $extention = '.jpg';
- }
- $temp_words = LewaimaiString::create_noncestr(32);//随机图片名
- $temp_url= 'public/temp/images/admin_'.Yii::app()->user->_id . '/';
- if(!is_dir($temp_url)){
- mkdir($temp_url,0755,true);
- }
- $temp_name = $temp_url.$temp_words.$extention;
- $time = LewaimaiString:: GetOutTradeNo();
- $file = $_FILES['surface']['tmp_name'];
- if(isset($_POST['avatar_src']) && isset($_POST['avatar_data'])) {
- require_once 'CropImage.php';
- $crop = new CropImage($_POST['avatar_src'], $_POST['avatar_data'], $_FILES['surface']);
- $file = $crop->getResult();
- }
- if(copy($file, $temp_name)){
- chmod($temp_name,0755);
- $cdn_url = getUpyunUploadPath();
- $fileName = $temp_words . $extention;
- $surfaceimg = $cdn_url.$fileName;
- LewaimaiImageUpload('./'.$temp_name,$surfaceimg);
- echo $surfaceimg;
- //清除本地文件
- LewaimaiUtility::clearTempimages();
- }else{
- echo 'error';//出错
- }
- }
- }else{
- echo 'suffix';//格式不对
- }
- exit;
- }
- }
|