CommunityHeadApply.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. namespace addons\Community\common\models;
  3. use addons\Community\common\enums\ConfigEnum;
  4. use common\enums\StatusEnum;
  5. use common\models\common\Region;
  6. use common\models\user\User;
  7. use Yii;
  8. use yii\db\ActiveQuery;
  9. use yii\helpers\Json;
  10. /**
  11. * This is the model class for table "qimall_addons_community_head_apply".
  12. *
  13. * @property int $id 主键
  14. * @property int $status 状态[-1:删除;0:禁用;1启用]
  15. * @property int $created_at 创建时间
  16. * @property int $updated_at 修改时间
  17. * @property int $mall_id 所属商城
  18. * @property int $user_id 用户ID
  19. * @property string $name 自提点名称
  20. * @property string $intro 自提点简介
  21. * @property string $logo logo
  22. * @property string $license_pic 营业执照
  23. * @property string $id_card_pic 身份证照
  24. * @property string $contact_name 联系人姓名
  25. * @property string $contact_phone 联系人姓名
  26. * @property int $province_id 省份id
  27. * @property int $city_id 城市ID
  28. * @property int $district_id 地区id
  29. * @property string $street 详细地址
  30. * @property float $lng 经度
  31. * @property float $lat 纬度
  32. * @property string $area 省市区
  33. * @property int $submit_count 提交次数
  34. * @property int $check_count 审核次数
  35. * @property int $apply_status 审核次数
  36. * @property int $step 审核次数
  37. * @property int $is_home_delivery 是否提供送货上门服务
  38. */
  39. class CommunityHeadApply extends \common\models\base\BaseActiveRecord
  40. {
  41. /**
  42. * {@inheritdoc}
  43. */
  44. public static function tableName()
  45. {
  46. return 'qimall_addons_community_head_apply';
  47. }
  48. /**
  49. * {@inheritdoc}
  50. */
  51. public function rules()
  52. {
  53. return [
  54. [['status', 'created_at', 'updated_at', 'mall_id', 'user_id', 'province_id', 'city_id',
  55. 'district_id', 'submit_count', 'check_count', 'apply_status', 'step', 'is_home_delivery'], 'integer'],
  56. [['lng', 'lat'], 'number'],
  57. [['name', 'contact_name'], 'string', 'max' => 10],
  58. [['contact_phone'], 'string', 'max' => 11],
  59. [['intro', 'logo', 'license_pic', 'id_card_pic', 'street', 'area'], 'string', 'max' => 255],
  60. ];
  61. }
  62. /**
  63. * {@inheritdoc}
  64. */
  65. public function attributeLabels()
  66. {
  67. return [
  68. 'id' => 'ID',
  69. 'status' => 'Status',
  70. 'created_at' => 'Created At',
  71. 'updated_at' => 'Updated At',
  72. 'mall_id' => 'Mall ID',
  73. 'user_id' => 'User ID',
  74. 'name' => 'Name',
  75. 'intro' => 'Intro',
  76. 'logo' => 'Logo',
  77. 'license_pic' => 'License Pic',
  78. 'id_card_pic' => 'Id Card Pic',
  79. 'contact_name' => 'Contact Name',
  80. 'province_id' => 'Province ID',
  81. 'city_id' => 'City ID',
  82. 'district_id' => 'District ID',
  83. 'street' => 'Street',
  84. 'lng' => 'Lng',
  85. 'lat' => 'Lat',
  86. 'area' => 'Area',
  87. 'submit_count' => 'Submit Count',
  88. 'check_count' => 'Check Count',
  89. ];
  90. }
  91. /**
  92. * @return ActiveQuery
  93. */
  94. public function getUser(): ActiveQuery
  95. {
  96. return $this->hasOne(User::class, ['id' => 'user_id']);
  97. }
  98. /**
  99. * @return ActiveQuery
  100. */
  101. public function getCheck(): ActiveQuery
  102. {
  103. return $this->hasOne(CommunityHeadCheck::class, ['apply_id' => 'id']);
  104. }
  105. /**
  106. * @param CommunityHead $head
  107. * @param int $admin_id
  108. * @return void
  109. * @throws \Exception
  110. */
  111. public static function create(CommunityHead $head, int $admin_id)
  112. {
  113. $model = new CommunityHeadApply();
  114. $model->user_id = $head->user_id;
  115. $model->mall_id = $head->mall_id;
  116. $model->submit_count = 1;
  117. $district_name = Region::find()->where(['id' => $head->district_id])->select('name')->scalar();
  118. $area = $head->address;
  119. $street = $head->address;
  120. if (!empty($district_name)) {
  121. $index = strpos($head->address, $district_name);
  122. $d_len = strlen($district_name);
  123. $area = substr($area, 0, $index + $d_len);
  124. $street = substr($street, $index + $d_len);
  125. }
  126. $model->name = $head->name;
  127. $model->intro = $head->desc;
  128. $model->logo = $head->logo;
  129. $model->license_pic = $head->license_img;
  130. $model->id_card_pic = $head->idcard_img;
  131. $model->contact_name = $head->contacts;
  132. $model->contact_phone = $head->mobile;
  133. $model->province_id = $head->province_id;
  134. $model->city_id = $head->city_id;
  135. $model->district_id = $head->district_id;
  136. $model->street = $street; // 这里有问题
  137. $model->area = $area; // 这里有问题
  138. $model->lng = $head->longitude;
  139. $model->lat = $head->latitude;
  140. $model->is_home_delivery = $head->is_home_delivery;
  141. $model->apply_status = ConfigEnum::COMMUNITY_CHECK_STATUS_AGREE; // 修改为待审核
  142. if (!$model->save()) throw new \Exception($model->getErrorMessage());
  143. $checkModel = new CommunityHeadCheck();
  144. $checkModel->mall_id = $head->mall_id;
  145. $checkModel->apply_id = $model->id;
  146. $checkModel->admin_id = $admin_id;
  147. $checkModel->remark = "由后台管理员 [{$admin_id}] 直接创建";
  148. $checkModel->check_status = ConfigEnum::COMMUNITY_CHECK_STATUS_AGREE;
  149. if (!$checkModel->save()) throw new \Exception($checkModel->getErrorMessage());
  150. }
  151. }