PartnerModel.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. <?php
  2. namespace App\Models;
  3. use App\Events\CompletedInfo;
  4. use App\Events\CreatedPartner;
  5. use App\Events\PartnerFeedPoolChange;
  6. use App\Events\UpdatedPartner;
  7. use App\Models\Partner\PartnerBeautyUser;
  8. use App\Models\User\UserModel;
  9. /**
  10. * App\Models\PartnerModel
  11. *
  12. * @property int $id 主键
  13. * @property int $uid 用户id
  14. * @property string $media_id 公众号id
  15. * @property string $home 故乡
  16. * @property string $address 常居城市
  17. * @property int $sex 性别[0未知;1男;2女]
  18. * @property string|null $photo_src 照片地址
  19. * @property int $check_photo 照片审核
  20. * @property string|null $photo_1 相册1
  21. * @property int|null $photo_1_check 相册1是否通过:-1未通过;0审核态;1通过
  22. * @property string|null $photo_2 相册2
  23. * @property int|null $photo_2_check 相册2是否通过:-1未通过;0审核态;1通过
  24. * @property string|null $photo_3 相册3
  25. * @property int|null $photo_3_check 相册3是否通过:-1未通过;0审核态;1通过
  26. * @property string|null $photo_4 相册4
  27. * @property int|null $photo_4_check 相册4是否通过:-1未通过;0审核态;1通过
  28. * @property string|null $voice 语音地址
  29. * @property string|null $school 学校
  30. * @property string $subject 专业
  31. * @property string $grade 年级
  32. * @property int $height 身高
  33. * @property string|null $age 生日
  34. * @property string $star 星座
  35. * @property int $check_contact 联系方式审核(弃用)
  36. * @property string|null $introduce 自我描述
  37. * @property string|null $expect 对另一半的期望
  38. * @property string|null $secret 暗号
  39. * @property int $times 被获取次数
  40. * @property int $praises 点赞数
  41. * @property int $feed_cnt 曝光次数
  42. * @property int $last_three_day_feed 近三天滑动次数
  43. * @property float $charm 魅力值
  44. * @property int $dechecks 审核失败次数
  45. * @property int $checks 审核成功次数
  46. * @property float $total_flower 已收获小fa
  47. * @property int $upload_at 最近上架时间
  48. * @property int $update_at 上次敏感信息修改时间
  49. * @property int $commited_at 提交审核时间
  50. * @property int $is_self 是否个人交友卡片(弃用)
  51. * @property int $feed_push_type feed流push类型
  52. * @property int $is_sell 1上架
  53. * 0下架
  54. * -1投诉下架
  55. * 2审核中
  56. * -2审核不通过
  57. * -3删除(或注销删除)
  58. * 3审核通过未上架
  59. * @property int $is_push_feed 是否推送到信息流
  60. * @property int $allow 是否推文
  61. * @property int $auto_sell 自动上架
  62. * @property int $is_hide 是否隐藏
  63. * @property string $qq QQ
  64. * @property string $weixin 微信
  65. * @property string $education 学历
  66. * @property int $base_score 基础分
  67. * @property int $score 热度
  68. * @property int $feedcheck_cnt 滑动审核次数
  69. * @property int $intro_check 描述是否通过:-1未通过;0审核态;1通过
  70. * @property int $voice_check 语音是否通过:-1未通过;0审核态;1通过
  71. * @property int $is_fpdx 是否是分配对象:0否;1是(弃用)
  72. * @property int $is_commit_check 是否提交审核:0否;1是
  73. * @property int $is_recommend 是否推荐卡片:0否;1是
  74. * @property int $is_voice_recommend 是否推荐语音:0否;1是
  75. * @property int $login_at 登录时间
  76. * @property int $long_no_login_tag 长时间未登录标记
  77. * @property int $black_at 拉黑时间
  78. * @property float $lat 纬度
  79. * @property float $lng 经度
  80. * @property int $feed_tag_cnt 更新后被滑动次数
  81. * @property int $feed_tag_like 更新后被喜欢次数
  82. * @property string $feed_pool_level 卡片池
  83. * @property int $wait_low_pool 待救活状态=0不待救活1待救活2操作过
  84. * @property int $wait_select 待精选状态=0不待精选1待精选2操作过
  85. * @property int $is_select 是否精选0否1是
  86. * @property int $select_at 精选时间
  87. * @property int $created_at 创建时间
  88. * @property int $updated_at 修改时间
  89. * @property-read \App\Models\User\UserModel $user
  90. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel newModelQuery()
  91. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel newQuery()
  92. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel query()
  93. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereAddress($value)
  94. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereAge($value)
  95. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereAllow($value)
  96. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereAutoSell($value)
  97. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereBaseScore($value)
  98. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereBlackAt($value)
  99. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereCharm($value)
  100. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereCheckContact($value)
  101. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereCheckPhoto($value)
  102. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereChecks($value)
  103. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereCommitedAt($value)
  104. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereCreatedAt($value)
  105. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereDechecks($value)
  106. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereEducation($value)
  107. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereExpect($value)
  108. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereFeedCnt($value)
  109. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereFeedPoolLevel($value)
  110. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereFeedPushType($value)
  111. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereFeedTagCnt($value)
  112. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereFeedTagLike($value)
  113. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereFeedcheckCnt($value)
  114. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereGrade($value)
  115. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereHeight($value)
  116. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereHome($value)
  117. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereId($value)
  118. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereIntroCheck($value)
  119. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereIntroduce($value)
  120. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereIsCommitCheck($value)
  121. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereIsFpdx($value)
  122. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereIsHide($value)
  123. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereIsPushFeed($value)
  124. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereIsRecommend($value)
  125. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereIsSelect($value)
  126. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereIsSelf($value)
  127. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereIsSell($value)
  128. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereIsVoiceRecommend($value)
  129. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereLastThreeDayFeed($value)
  130. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereLat($value)
  131. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereLng($value)
  132. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereLoginAt($value)
  133. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereLongNoLoginTag($value)
  134. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereMediaId($value)
  135. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel wherePhoto1($value)
  136. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel wherePhoto1Check($value)
  137. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel wherePhoto2($value)
  138. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel wherePhoto2Check($value)
  139. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel wherePhoto3($value)
  140. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel wherePhoto3Check($value)
  141. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel wherePhoto4($value)
  142. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel wherePhoto4Check($value)
  143. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel wherePhotoSrc($value)
  144. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel wherePraises($value)
  145. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereQq($value)
  146. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereSchool($value)
  147. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereScore($value)
  148. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereSecret($value)
  149. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereSelectAt($value)
  150. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereSex($value)
  151. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereStar($value)
  152. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereSubject($value)
  153. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereTimes($value)
  154. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereTotalFlower($value)
  155. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereUid($value)
  156. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereUpdateAt($value)
  157. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereUpdatedAt($value)
  158. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereUploadAt($value)
  159. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereVoice($value)
  160. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereVoiceCheck($value)
  161. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereWaitSelect($value)
  162. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PartnerModel whereWeixin($value)
  163. * @mixin \Eloquent
  164. */
  165. class PartnerModel extends Model
  166. {
  167. protected $table = 'kdgx_partner_charge_partner';
  168. protected $dateFormat = 'U';
  169. protected $fillable = [
  170. 'uid',
  171. 'media_id',
  172. 'home',
  173. 'address',
  174. 'sex',
  175. 'photo_src',
  176. 'check_photo',
  177. 'voice',
  178. 'school',
  179. 'subject',
  180. 'grade',
  181. 'height',
  182. 'age',
  183. 'star',
  184. 'check_contact',
  185. 'introduce',
  186. 'expect',
  187. 'intro_check',
  188. 'secret',
  189. 'login_at',
  190. 'upload_at',
  191. 'update_at',
  192. 'created_at',
  193. 'updated_at',
  194. 'black_at',
  195. 'is_self',
  196. 'is_sell',
  197. 'feed_push_type',
  198. 'allow',
  199. 'auto_sell',
  200. 'is_hide',
  201. 'qq',
  202. 'weixin',
  203. 'education',
  204. 'is_recommend',
  205. 'is_voice_recommend',
  206. 'feedcheck_cnt',
  207. 'photo_1',
  208. 'photo_1_check',
  209. 'photo_2',
  210. 'photo_2_check',
  211. 'photo_3',
  212. 'photo_3_check',
  213. 'photo_4',
  214. 'photo_4_check',
  215. 'base_score',
  216. 'is_push_feed',
  217. 'voice_check',
  218. 'is_commit_check',
  219. 'is_fpdx',
  220. 'is_sell',
  221. 'auto_sell',
  222. 'day_limit',
  223. 'long_no_login_tag',
  224. 'feed_tag_cnt',
  225. 'feed_tag_like',
  226. 'feed_pool_level',
  227. 'wait_select',
  228. 'is_select',
  229. 'wait_low_pool',
  230. ];
  231. protected $casts = [
  232. 'created_at' => 'integer',
  233. 'updated_at' => 'integer',
  234. 'login_at' => 'integer',
  235. 'upload_at' => 'integer',
  236. 'update_at' => 'integer',
  237. 'black_at' => 'integer',
  238. ];
  239. /**
  240. * @return \Illuminate\Database\Eloquent\Relations\HasOne
  241. */
  242. public function user()
  243. {
  244. return $this->hasOne(UserModel::class, 'uid', 'uid');
  245. }
  246. public static function boot()
  247. {
  248. parent::boot();
  249. self::created(function ($model) {
  250. event(new CreatedPartner($model));
  251. });
  252. self::saving(function ($model) {
  253. /** @var PartnerModel $model */
  254. $dirty = $model->getDirty();
  255. $updatekeys = array(
  256. 'check_photo',
  257. 'photo_1_check',
  258. 'photo_2_check',
  259. 'photo_3_check',
  260. 'photo_4_check',
  261. 'voice_check',
  262. 'weixin',
  263. 'qq'
  264. );
  265. $inter = array_intersect(array_keys($dirty), $updatekeys);
  266. if (!empty($inter)) {
  267. // 修正卡片类型
  268. if (
  269. 5 == $model->feed_push_type
  270. && (1 == $model->check_photo
  271. || 1 == $model->photo_1_check
  272. || 1 == $model->photo_2_check
  273. || 1 == $model->photo_3_check
  274. || 1 == $model->photo_4_check
  275. || 1 == $model->voice_check)
  276. ) {
  277. $model->feed_push_type = 3;
  278. // 提醒后补全信息回应事件
  279. event(new CompletedInfo($model->uid));
  280. } elseif (
  281. 3 == $model->feed_push_type
  282. && (1 != $model->photo_src
  283. && 1 != $model->photo_1_check
  284. && 1 != $model->photo_2_check
  285. && 1 != $model->photo_3_check
  286. && 1 != $model->photo_4_check
  287. && 1 != $model->voice_check)
  288. ) {
  289. $model->feed_push_type = 5;
  290. }
  291. foreach ($inter as $v) {
  292. if (1 != $model->getOriginal($v) && 1 == $model->$v) {
  293. $model->feed_tag_cnt = 0;
  294. $model->feed_tag_like = 0;
  295. $model->wait_select = 0;
  296. $model->is_select = 0;
  297. $model->feed_pool_level = "new";
  298. if (5 == $model->feed_push_type) {
  299. $model->feed_pool_level = "low";
  300. }
  301. break;
  302. } elseif (1 == $model->getOriginal($v) && 1 != $model->$v) {
  303. $model->feed_tag_cnt = 0;
  304. $model->feed_tag_like = 0;
  305. $model->wait_select = 0;
  306. $model->is_select = 0;
  307. $model->feed_pool_level = "new";
  308. if (5 == $model->feed_push_type) {
  309. $model->feed_pool_level = "low";
  310. }
  311. break;
  312. }
  313. }
  314. if (5 == $model->feed_push_type) {
  315. $model->feed_pool_level = "low";
  316. }
  317. }
  318. if ("low" == $model->feed_pool_level) {
  319. if (2 != $model->wait_low_pool) {
  320. $model->wait_low_pool = 1;
  321. }
  322. } else {
  323. $model->wait_low_pool = 0;
  324. }
  325. });
  326. self::saved(function ($model) {
  327. $fields = ['photo_src', 'photo_1', 'photo_2', 'photo_3', 'photo_4'];
  328. foreach ($fields as $field) {
  329. if ($model->isDirty($field)) {
  330. PartnerBeautyUser::updateOrCreate(
  331. ['partner_id' => $model->id, 'field' => $field],
  332. ['uid' => $model->uid, 'replaced_at' => 0, 'original_photo' => ($model->{$field} ?: '')]
  333. );
  334. }
  335. }
  336. });
  337. self::updated(function (/** @var PartnerModel $model */ $model) {
  338. event(new UpdatedPartner($model));
  339. if ($model->isDirty(['feed_pool_level'])) {
  340. // 卡片信息流层级池改变
  341. event(new PartnerFeedPoolChange($model));
  342. }
  343. });
  344. }
  345. }