FlowerLogModel.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. namespace App\Models;
  3. use App\Jobs\GrowingIO\SignFlowerReportJob;
  4. use App\Models\User\UserModel;
  5. use DB;
  6. use Exception;
  7. use Illuminate\Support\Facades\Redis;
  8. /**
  9. * App\Models\FlowerLogModel
  10. *
  11. * @property int $id 主键
  12. * @property int $uid 用户id
  13. * @property int $type 记录类型[1:消费卡片;2:任务;3:充值;4:系统扣除;5:系统补偿;6:收获;7:签到;8:赠送;9:获赠;10:分享奖励;11:消费退回一张;12:红包]
  14. * @property float $gold_flower 金fa增减情况
  15. * @property float $red_flower 红fa增减情况
  16. * @property int $jsk 解锁卡
  17. * @property string $type_id 记录外链id[消费时:partner_id;任务:任务号;充值:充值金额;系统退还:partner_id;收获小fa:partner_id;赠送:接收者uid;获赠:赠送者uid]
  18. * @property string $remark 备注
  19. * @property int $fixed_at 记录处理时间
  20. * @property \Illuminate\Support\Carbon $create_at 操作时间
  21. * @property int $update_at 修改时间
  22. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\FlowerLogModel newModelQuery()
  23. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\FlowerLogModel newQuery()
  24. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\FlowerLogModel query()
  25. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\FlowerLogModel whereCreateAt($value)
  26. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\FlowerLogModel whereFixedAt($value)
  27. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\FlowerLogModel whereGoldFlower($value)
  28. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\FlowerLogModel whereId($value)
  29. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\FlowerLogModel whereJsk($value)
  30. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\FlowerLogModel whereRedFlower($value)
  31. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\FlowerLogModel whereRemark($value)
  32. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\FlowerLogModel whereType($value)
  33. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\FlowerLogModel whereTypeId($value)
  34. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\FlowerLogModel whereUid($value)
  35. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\FlowerLogModel whereUpdateAt($value)
  36. * @mixin \Eloquent
  37. */
  38. class FlowerLogModel extends Model
  39. {
  40. protected $table = "kdgx_partner_charge_pay_logs";
  41. protected $dateFormat = 'U';
  42. public const CREATED_AT = 'create_at';
  43. public const UPDATED_AT = null;
  44. protected $fillable = ['uid', 'type', 'gold_flower', 'red_flower', 'jsk', 'type_id', 'remark', 'fixed_at'];
  45. private $type = array(
  46. 1 => [
  47. 'type' => 1,
  48. 'desc' => '消费卡片',
  49. ],
  50. 2 => [
  51. 'type' => 2,
  52. 'desc' => '任务',
  53. ],
  54. 3 => [
  55. 'type' => 3,
  56. 'desc' => '充值',
  57. ],
  58. 4 => [
  59. 'type' => 4,
  60. 'desc' => '系统扣除',
  61. ],
  62. 5 => [
  63. 'type' => 5,
  64. 'desc' => '系统补偿',
  65. ],
  66. 6 => [
  67. 'type' => 6,
  68. 'desc' => '收获',
  69. ],
  70. 7 => [
  71. 'type' => 7,
  72. 'desc' => '签到',
  73. ],
  74. 8 => [
  75. 'type' => 8,
  76. 'desc' => '赠送',
  77. ],
  78. 9 => [
  79. 'type' => 9,
  80. 'desc' => '获赠',
  81. ],
  82. 10 => [
  83. 'type' => 10,
  84. 'desc' => '分享奖励',
  85. ],
  86. 11 => [
  87. 'type' => 11,
  88. 'desc' => '消费退回一张',
  89. ],
  90. 12 => [
  91. 'type' => 12,
  92. 'desc' => '红包',
  93. ],
  94. 13 => [
  95. 'type' => 13,
  96. 'desc' => '72小时提升匹配成功率'
  97. ],
  98. 14 => [
  99. 'type' => 14,
  100. 'desc' => '心动邀请'
  101. ],
  102. 15 => [
  103. 'type' => 15,
  104. 'desc' => '会员每日小花礼包'
  105. ]
  106. );
  107. /**
  108. * 获取奖励红包 1.小花|2.小花红包|3.现金红包
  109. * @param int $uid
  110. * @return bool|string
  111. * @throws Exception
  112. */
  113. public function redpack(int $uid)
  114. {
  115. $feed_limit = Redis::hget("session_msy_{$uid}", "feed_limit") ?? 1;
  116. switch ($feed_limit) {
  117. case 5: // 小花红包
  118. case 15: // 小花
  119. $red_flower = sprintf("%.2f", 0.5 + mt_rand() / mt_getrandmax() * (0.8 - 0.5));
  120. break;
  121. case 30:
  122. case 50:
  123. case 70:
  124. case 90:
  125. $red_flower = sprintf("%.2f", 0.3 + mt_rand() / mt_getrandmax() * (0.5 - 0.3));
  126. break;
  127. default:
  128. return false;
  129. }
  130. DB::beginTransaction();
  131. try {
  132. DB::table('kdgx_partner_charge_user')->where('uid', $uid)->increment('red_flower', $red_flower);
  133. $data = array(
  134. 'uid' => $uid,
  135. 'create_at' => time(),
  136. 'type' => 12,
  137. 'gold_flower' => 0,
  138. 'red_flower' => $red_flower,
  139. 'jsk' => 0,
  140. 'remark' => "划卡片红包"
  141. );
  142. $flowerLog = self::create($data);
  143. dispatch_now(new SignFlowerReportJob($flowerLog, UserModel::find($uid)));
  144. DB::commit();
  145. return array(
  146. 'fee' => $red_flower,
  147. 'type' => 1
  148. );
  149. } catch (Exception $e) {
  150. DB::rollBack();
  151. return false;
  152. }
  153. }
  154. }