CommonController.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. class CommonController extends Controller
  3. {
  4. public function actionSendCode()
  5. {
  6. $phone = Helper::getPostString('phone', '');
  7. if (!Helper::isPhone($phone)) {
  8. Helper::error('手机号码格式错误');
  9. }
  10. // 验证码发送限制
  11. Helper::dealCommonResult(Helper::limitSmsSend(10, $phone, 5), false);
  12. if (!DB::getScalerWithCriteria('useradmin', DbCriteria::simpleCompare(['phone' => $phone])->setSelect('id'))) {
  13. Helper::error('该手机号用户不存在');
  14. }
  15. $code = (string)random_int(100000,999999);
  16. RedisInstance::getInstance()->set('user_code:'.$phone, $code, 600);
  17. // 发送短信
  18. Helper::dealCommonResult(SMS::getInstance()->send($phone, '2094847', [$code]));
  19. }
  20. public function actionSetPassword()
  21. {
  22. $phone = Helper::getPostString('phone');
  23. $code = Helper::getPostString('code');
  24. $password = Helper::getPostString('password');
  25. if (!Helper::isPhone($phone)) {
  26. Helper::error('手机号码格式错误');
  27. }
  28. if (!$code || !$password) {
  29. Helper::error('参数错误');
  30. }
  31. if (RedisInstance::getInstance()->get('user_code:'.$phone) != $code) {
  32. Helper::error('验证码错误');
  33. }
  34. $id = DB::getScalerWithCriteria('useradmin', DbCriteria::simpleCompare(['phone' => $phone])->setSelect('id'));
  35. if (!$id) {
  36. Helper::error('该手机号用户不存在');
  37. }
  38. DB::updateById('useradmin', ['password' => md5($password)], $id);
  39. Helper::ok();
  40. }
  41. /**
  42. * ajax提交图片temp临时存放
  43. */
  44. public function actionUploadtemp(){
  45. $type = strtolower($_FILES['surface']['type']);
  46. $size = $_FILES['surface']['size'];
  47. $maxsize = isset($_POST['imgmaxsize'])?$_POST['imgmaxsize']:'512000';
  48. $imagetype = isset($_POST['type'])?$_POST['type']:'all';
  49. if(stristr($type, 'png') || stristr($type, 'jpeg') || stristr($type, 'jpg')) {
  50. if($size > $maxsize){
  51. echo 'size';//图片容量超过200K
  52. }else{
  53. if(stristr($type, 'png')) {
  54. $extention = '.png';
  55. }else{
  56. $extention = '.jpg';
  57. }
  58. $temp_words = LewaimaiString::create_noncestr(32);//随机图片名
  59. $temp_url= 'public/temp/images/admin_'.Yii::app()->user->_id . '/';
  60. if(!is_dir($temp_url)){
  61. mkdir($temp_url,0755,true);
  62. }
  63. $temp_name = $temp_url.$temp_words.$extention;
  64. $time = LewaimaiString:: GetOutTradeNo();
  65. if(copy($_FILES['surface']['tmp_name'], $temp_name)){
  66. chmod($temp_name,0755);
  67. $cdn_url = getUpyunUploadPath();
  68. $fileName = $temp_words . $extention;
  69. $surfaceimg = $cdn_url.$fileName;
  70. LewaimaiImageUpload('./'.$temp_name,$surfaceimg);
  71. echo $surfaceimg;
  72. //清除本地文件
  73. LewaimaiUtility::clearTempimages();
  74. }else{
  75. echo 'error';//出错
  76. }
  77. }
  78. }else{
  79. echo 'suffix';//格式不对
  80. }
  81. exit;
  82. }
  83. public function actionCropImg()
  84. {
  85. $type = strtolower($_FILES['surface']['type']);
  86. $size = $_FILES['surface']['size'];
  87. $maxsize = isset($_POST['imgmaxsize'])?$_POST['imgmaxsize']:'512000';
  88. $imagetype = isset($_POST['type'])?$_POST['type']:'all';
  89. if(stristr($type, 'png') || stristr($type, 'jpeg') || stristr($type, 'jpg')) {
  90. if($size > $maxsize){
  91. echo 'size';//图片容量超过200K
  92. }else{
  93. if(stristr($type, 'png')) {
  94. $extention = '.png';
  95. }else{
  96. $extention = '.jpg';
  97. }
  98. $temp_words = LewaimaiString::create_noncestr(32);//随机图片名
  99. $temp_url= 'public/temp/images/admin_'.Yii::app()->user->_id . '/';
  100. if(!is_dir($temp_url)){
  101. mkdir($temp_url,0755,true);
  102. }
  103. $temp_name = $temp_url.$temp_words.$extention;
  104. $time = LewaimaiString:: GetOutTradeNo();
  105. $file = $_FILES['surface']['tmp_name'];
  106. if(isset($_POST['avatar_src']) && isset($_POST['avatar_data'])) {
  107. require_once 'CropImage.php';
  108. $crop = new CropImage($_POST['avatar_src'], $_POST['avatar_data'], $_FILES['surface']);
  109. $file = $crop->getResult();
  110. }
  111. if(copy($file, $temp_name)){
  112. chmod($temp_name,0755);
  113. $cdn_url = getUpyunUploadPath();
  114. $fileName = $temp_words . $extention;
  115. $surfaceimg = $cdn_url.$fileName;
  116. LewaimaiImageUpload('./'.$temp_name,$surfaceimg);
  117. echo $surfaceimg;
  118. //清除本地文件
  119. LewaimaiUtility::clearTempimages();
  120. }else{
  121. echo 'error';//出错
  122. }
  123. }
  124. }else{
  125. echo 'suffix';//格式不对
  126. }
  127. exit;
  128. }
  129. }