PartnerApplyForm.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: chenkuan
  5. * Date: 2017/12/26
  6. * Time: 下午1:49
  7. */
  8. namespace wechat\models\forms;
  9. use wechat\models\IndexApi;
  10. use yii\base\Model;
  11. class PartnerApplyForm extends Model
  12. {
  13. public $name;
  14. public $mobile;
  15. public $email;
  16. public $memo;
  17. public $type;
  18. /**
  19. * @return array
  20. */
  21. public function rules()
  22. {
  23. return [
  24. [['type'], 'integer'],
  25. [['create_time'], 'safe'],
  26. [['name', 'email'], 'string', 'max' => 255],
  27. [['mobile'], 'string', 'max' => 30],
  28. [['memo'], 'string', 'max' => 1000],
  29. ];
  30. }
  31. public function savePartnerApply()
  32. {
  33. if ($this->validate()) {
  34. $api = new IndexApi();
  35. $data = [];
  36. $data['type'] = $this->type;
  37. $data['name'] = $this->name;
  38. $data['mobile'] = $this->mobile;
  39. $data['email'] = $this->email;
  40. $data['memo'] = $this->memo;
  41. $result = $api->savePartnerApply($data);
  42. if ($result['code'] == 1) {
  43. return true;
  44. } else {
  45. if (is_array($result['message'])) {
  46. $this->addErrors($result['message']);
  47. } else {
  48. $this->addError('name', $result['message']);
  49. }
  50. }
  51. }
  52. return !$this->hasErrors();
  53. }
  54. }