ManagerController.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace addons\Purchase\api\modules\v1\controllers;
  3. use addons\Purchase\common\models\PurchaseManager;
  4. use common\enums\StatusEnum;
  5. use Yii;
  6. use api\controllers\OnAuthController;
  7. /**
  8. * 会员控制器
  9. *
  10. * Class ManagerController
  11. * @package addons\Purchase\api\modules\v1\controllers
  12. */
  13. class ManagerController extends OnAuthController
  14. {
  15. public $modelClass = '';
  16. /**
  17. * 不用进行登录验证的方法
  18. *
  19. * 例如: ['index', 'update', 'create', 'view', 'delete']
  20. * 默认全部需要验证
  21. *
  22. * @var array
  23. */
  24. protected $authOptional = ['index'];
  25. /**
  26. * 首页
  27. *
  28. * @return string
  29. */
  30. public function actionIndex()
  31. {
  32. return 'Hello world';
  33. }
  34. /**
  35. * @notes:资格申请
  36. * @return mixed|void|null
  37. * @author: lun
  38. * @Time: 2022/10/24 15:05
  39. */
  40. public function actionApply()
  41. {
  42. $request = Yii::$app->request;
  43. if ($request->isPost) {
  44. $post = Yii::$app->request->post();
  45. // 检查提交的参数
  46. $res = Yii::$app->services->validate->validate($post,[
  47. [['mobile','is_poss'], 'integer'],
  48. [['license','store_info','idcart_front','idcart_back','idcart_hands'], 'string'],
  49. ]);
  50. if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  51. // 检查是否曾经申请过
  52. $apply = PurchaseManager::find()->where(['user_id' => $this->user_id, 'status' => StatusEnum::ENABLED])->asArray()->one();
  53. if ($apply && $apply['is_poss'] == StatusEnum::ENABLED) return $this->error('您的申请已通过,无需再次申请');
  54. // 保存数据
  55. $post['user_id'] = $this->user_id;
  56. $res = PurchaseManager::setData($this->mall_id, $post);
  57. if ($res === false) return $this->error('提交失败:' . PurchaseManager::getStaticError());
  58. return $this->success('提交成功', $res);
  59. } else {
  60. // 查询申请记录
  61. $data = PurchaseManager::find()->where(['mall_id' => $this->mall_id, 'user_id' => $this->user_id, 'status' => StatusEnum::ENABLED])->asArray()->one();
  62. return $this->success('获取成功', $data);
  63. }
  64. }
  65. }