BuyInviteModel.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace App\Models;
  3. /**
  4. * App\Models\BuyInviteModel
  5. *
  6. * @property int $id
  7. * @property int $invite_id 邀请id
  8. * @property int $invite_uid 被邀请用户
  9. * @property \Illuminate\Support\Carbon $created_at 时间
  10. * @property int $state 邀请状态【0有效助力|1因被邀请者限制成无效助力|2因助力id完成成无效助力】
  11. * @property int $dis_score 折扣金额
  12. * @property string|null $comment 留言
  13. * @property \Illuminate\Support\Carbon|null $updated_at 更新时间
  14. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BuyInviteModel newModelQuery()
  15. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BuyInviteModel newQuery()
  16. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BuyInviteModel query()
  17. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BuyInviteModel whereComment($value)
  18. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BuyInviteModel whereCreatedAt($value)
  19. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BuyInviteModel whereDisScore($value)
  20. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BuyInviteModel whereId($value)
  21. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BuyInviteModel whereInviteId($value)
  22. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BuyInviteModel whereInviteUid($value)
  23. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BuyInviteModel whereState($value)
  24. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BuyInviteModel whereUpdatedAt($value)
  25. * @mixin \Eloquent
  26. */
  27. class BuyInviteModel extends Model
  28. {
  29. protected $table = "kdgx_partner_charge_buy_invite";
  30. protected $dateFormat = 'U';
  31. public $fillable = ['id', 'invite_id', 'invite_uid', 'state', 'comment', 'dis_score'];
  32. /**
  33. * 获取折扣百分比
  34. * @param int $uid 发起用户uid
  35. * @param int $partner_id 折扣卡片id
  36. * @return int
  37. */
  38. public function effectiveInvite(int $uid, int $partner_id)
  39. {
  40. $recod = new RecodeModel();
  41. if (
  42. $recod->where([
  43. ['partner_id', $partner_id],
  44. ['uid', $uid]
  45. ])->exists()
  46. ) {
  47. return 100;
  48. }
  49. $listModel = new BuyInviteListModel();
  50. $list = $listModel->where([
  51. ['uid', $uid],
  52. ['partner_id', $partner_id]
  53. ])->first();
  54. if (collect($list)->isEmpty()) {
  55. return 0;
  56. } else {
  57. $cnt = $this->where([
  58. ['invite_id', $list->id],
  59. ['state', 0]
  60. ])->sum('dis_score');
  61. return $cnt;
  62. }
  63. }
  64. }