ApplyList.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. <?php
  2. namespace addons\OperationCenter\common\models;
  3. use Yii;
  4. /**
  5. * This is the model class for table "{{%addons_operation_center_apply_list}}".
  6. *
  7. * @property int $id
  8. * @property int $mall_id 商城ID
  9. * @property int $user_id 用户ID
  10. * @property int $level 申请等级
  11. * @property string|null $name 姓名
  12. * @property string|null $mobile 手机号
  13. * @property string|null $center_name 运营中心名称
  14. * @property string|null $idcard_front 身份证正面
  15. * @property string|null $idcard_reverse 身份证反面
  16. * @property string|null $operation_license 运营执照
  17. * @property string|null $logo logo
  18. * @property int|null $province_id 省份ID
  19. * @property string|null $province 省份
  20. * @property int|null $city_id 城市ID
  21. * @property string|null $city 城市
  22. * @property int|null $district_id 县区ID
  23. * @property string|null $district 县区
  24. * @property int|null $town_id 街镇ID
  25. * @property string|null $town 街镇
  26. * @property string|null $operation_address 详细地址
  27. * @property int $status 状态
  28. * @property string|null $reject_content 驳回理由
  29. * @property int $apply_at 审核时间
  30. * @property int $deleted_at
  31. * @property int $updated_at
  32. * @property int $created_at
  33. */
  34. class ApplyList extends BaseActiveRecord
  35. {
  36. /**
  37. * 申请中
  38. */
  39. const APPLYING = 1;
  40. /**
  41. * 已通过
  42. */
  43. const PASSED = 2;
  44. /**
  45. * 已驳回
  46. */
  47. const REJECTED = 3;
  48. /**
  49. * {@inheritdoc}
  50. */
  51. public static function tableName()
  52. {
  53. return '{{%addons_operation_center_apply_list}}';
  54. }
  55. /**
  56. * {@inheritdoc}
  57. */
  58. public function rules()
  59. {
  60. return [
  61. [['mall_id', 'user_id', 'level'], 'required'],
  62. [['mall_id', 'user_id', 'level', 'province_id', 'city_id', 'district_id', 'town_id', 'status', 'apply_at', 'deleted_at', 'updated_at', 'created_at'], 'integer'],
  63. [['name', 'mobile', 'center_name'], 'string', 'max' => 32],
  64. [['idcard_front', 'idcard_reverse', 'operation_license', 'logo', 'province', 'city', 'district', 'town', 'operation_address', 'reject_content'], 'string', 'max' => 255],
  65. ];
  66. }
  67. /**
  68. * {@inheritdoc}
  69. */
  70. public function attributeLabels()
  71. {
  72. return [
  73. 'id' => 'ID',
  74. 'mall_id' => 'Mall ID',
  75. 'user_id' => 'User ID',
  76. 'level' => 'Level',
  77. 'name' => 'Name',
  78. 'mobile' => 'Mobile',
  79. 'center_name' => 'Center Name',
  80. 'idcard_front' => 'Idcard Front',
  81. 'idcard_reverse' => 'Idcard Reverse',
  82. 'operation_license' => 'Operation License',
  83. 'logo' => 'Logo',
  84. 'province_id' => 'Province ID',
  85. 'province' => 'Province',
  86. 'city_id' => 'City ID',
  87. 'city' => 'City',
  88. 'district_id' => 'District ID',
  89. 'district' => 'District',
  90. 'town_id' => 'Town ID',
  91. 'town' => 'Town',
  92. 'operation_address' => 'Operation Address',
  93. 'status' => 'Status',
  94. 'reject_content' => 'Reject Content',
  95. 'apply_at' => 'Apply At',
  96. 'deleted_at' => 'Deleted At',
  97. 'updated_at' => 'Updated At',
  98. 'created_at' => 'Created At',
  99. ];
  100. }
  101. /**
  102. * @return ActiveQueryInterface the relational query object.
  103. */
  104. public function getUser()
  105. {
  106. return $this->hasOne(MallUser::class, ['id' => 'user_id']);
  107. }
  108. /**
  109. * @return ActiveQueryInterface the relational query object.
  110. */
  111. public function getCenter()
  112. {
  113. return $this->hasOne(UserCenter::class, ['user_id' => 'user_id']);
  114. }
  115. /**
  116. * 添加申请记录
  117. *
  118. * @param integer $user_id
  119. * @param integer $mall_id
  120. * @param array $array
  121. * @return true|static
  122. */
  123. public static function addApplyList(
  124. int $user_id,
  125. int $mall_id,
  126. array $data
  127. )
  128. {
  129. $model = new static;
  130. $data = array_merge($data, compact('user_id', 'mall_id'), [
  131. 'status' => static::APPLYING, 'level' => 0
  132. ]);
  133. $model->load($data, '');
  134. return $model->save();
  135. }
  136. /**
  137. * 是否已经申请或者已经通过
  138. *
  139. * @param integer $user_id
  140. * @return boolean|static
  141. */
  142. public static function hasApplyOrPassByUserId(int $user_id)
  143. {
  144. $one = static::find()
  145. ->andWhere(
  146. [
  147. 'user_id' => $user_id,
  148. 'status' => [
  149. static::APPLYING, static::PASSED
  150. ]
  151. ]
  152. )
  153. ->select(['id', 'status', 'user_id'])
  154. ->orderBy('id desc')
  155. ->one();
  156. return empty($one) ? false : $one;
  157. }
  158. /**
  159. * 获取申请状态
  160. *
  161. * @param integer $user_id
  162. * @return static|int
  163. */
  164. public static function getApplyStatus(int $user_id)
  165. {
  166. return static::find()
  167. ->select(['id', 'user_id', 'status', 'reject_content'])
  168. ->andWhere(['user_id' => $user_id])
  169. ->orderBy('id desc')
  170. ->one() ?? 0;
  171. }
  172. /**
  173. * 通过名称搜索ID
  174. *
  175. * @param integer $mall_id
  176. * @param string $name
  177. * @return array
  178. */
  179. public static function getUserIdByName(int $mall_id, string $name)
  180. {
  181. return static::find()
  182. ->andWhere(['mall_id' => $mall_id])
  183. ->andWhere(['like', 'name', $name])
  184. ->select(['user_id'])
  185. ->column();
  186. }
  187. /**
  188. * 通过名称搜索ID
  189. *
  190. * @param integer $mall_id
  191. * @param string $mobile
  192. * @return array
  193. */
  194. public static function getUserIdByMobile(int $mall_id, string $mobile)
  195. {
  196. return static::find()
  197. ->andWhere(['mall_id' => $mall_id])
  198. ->andWhere(['like', 'mobile', $mobile])
  199. ->select(['user_id'])
  200. ->column();
  201. }
  202. /**
  203. * 通过申请中详情
  204. *
  205. * @param integer $mall_id
  206. * @param integer $id
  207. * @return static|null
  208. */
  209. public static function getApplyingById(int $mall_id, int $id)
  210. {
  211. return static::find()
  212. ->andWhere(['mall_id' => $mall_id, 'id' => $id, 'status' => static::APPLYING])
  213. ->one();
  214. }
  215. /**
  216. * 通过
  217. *
  218. * @param Level $level
  219. * @return boolean
  220. */
  221. public function pass(Level $level)
  222. {
  223. $this->level = $level->id;
  224. $this->apply_at = time();
  225. $this->status = static::PASSED;
  226. return $this->save();
  227. }
  228. /**
  229. * 驳回
  230. *
  231. * @param string $content
  232. * @return boolean
  233. */
  234. public function reject(string $content = '')
  235. {
  236. $this->status = static::REJECTED;
  237. $this->reject_content = $content;
  238. return $this->save();
  239. }
  240. /**
  241. * 获取地址
  242. *
  243. * @return string
  244. */
  245. public function getOperationAddress()
  246. {
  247. return $this->province
  248. . $this->city
  249. . $this->district
  250. . $this->town
  251. . $this->operation_address;
  252. }
  253. /**
  254. * 是否通过后被删除运营中心
  255. *
  256. * @return boolean
  257. */
  258. public function isPassedButDelete()
  259. {
  260. return ($this->status == static::PASSED && empty($this->center));
  261. }
  262. }