TuanFollow.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. namespace app\model;
  3. use think\Model;
  4. class TuanFollow extends Model
  5. {
  6. protected $connection = 'mysql';
  7. protected $pk = 'id';
  8. protected $name = 'tuan_follow';
  9. static public function add_follow($param)
  10. {
  11. $Membermob = new Member;
  12. $Member = $Membermob->getUserByWechat();
  13. $TuanFound = TuanFound::find($param['found_id']);
  14. $data['uid'] = $Member['id'];
  15. $data['nickname'] = $Member['nickname'];
  16. $data['avatar'] = $Member['userpic'];
  17. $data['join_time'] = time();
  18. $data['order_id'] = (int) $param['order_id'];
  19. $data['found_id'] = (int) $param['found_id'];
  20. $data['tuan_id'] = (int) $param['tuan_id'];
  21. $data['is_head'] = (int) $param['is_head'];
  22. $data['is_robot'] = (int) $param['is_robot'];
  23. $data['tuan_end_time'] = $TuanFound->tuan_end_time;
  24. $res = self::create($data);
  25. return $res->id;
  26. }
  27. static public function getTuanFollow($found_id)
  28. {
  29. $FollowList = self::where('found_id', $found_id)->select()->toArray();
  30. return $FollowList;
  31. }
  32. static public function getLuckyFollow($found_id, $luckydraw_num)
  33. {
  34. $Followlist = self::where('found_id', $found_id)->where('is_robot', '<>', 1)->where('pay_time', '>', 0)->select()->toArray();
  35. for ($i = 0; $i < $luckydraw_num; $i++) {
  36. $resList[$i] = $Followlist[mt_rand(0, count($Followlist) - 1)];
  37. }
  38. return $resList;
  39. }
  40. static public function setRefund()
  41. {
  42. $Followlist = self::where('is_refund', 0)->where('status', 2)->where('is_robot', '<>', 1)->where('pay_time', '>', 0)->select()->toArray();
  43. if (!empty($Followlist)) {
  44. foreach ($Followlist as $vo) {
  45. Order::refund_order($vo['order_id'], time());
  46. Order::update(['order_status_id' => 6, 'id' => $vo['order_id']]);
  47. self::setNotWinning($vo);
  48. self::where('id', $vo['id'])->update(['is_refund' => 1]);
  49. }
  50. }
  51. }
  52. static public function setNotWinning($Follow)
  53. {
  54. $TuanGoods = TuanGoods::find($Follow['tuan_id']);
  55. $orderInfo = Order::find($Follow['order_id']);
  56. if (!empty($TuanGoods) && !empty($orderInfo)) {
  57. $TuanGoods = $TuanGoods->toArray();
  58. $orderInfo = $orderInfo->toArray();
  59. if ($TuanGoods['not_winning_ptype'] == 2) {
  60. Member::where('id', $Follow['uid'])
  61. ->inc('balance', $TuanGoods['not_winning_redenvelope'])
  62. ->update();
  63. $cashlogsdata['uid'] = $Follow['uid'];
  64. $cashlogsdata['weid'] = weid();
  65. $cashlogsdata['order_id'] = $Follow['order_id'];
  66. $cashlogsdata['order_num_alias'] = $orderInfo['order_num_alias'];
  67. $cashlogsdata['remarks'] = '拼团没拼中,平台发红包';
  68. $cashlogsdata['prefix'] = 1;
  69. $cashlogsdata['amount'] = $TuanGoods['not_winning_redenvelope'];
  70. MemberCashlogs::create($cashlogsdata);
  71. } else if ($TuanGoods['not_winning_ptype'] == 3) {
  72. $coupon_id = $TuanGoods['not_winning_coupon_id'];
  73. $Coupondata = Coupon::where(['weid' => weid(), 'id' => $coupon_id])->find();
  74. if (!empty($Coupondata)) {
  75. $Coupondata = $Coupondata->toArray();
  76. if ($Coupondata['total_num'] == -1 || $Coupondata['total_num'] > $Coupondata['receive_num']) {
  77. unset($Coupondata['id']);
  78. $Coupondata['uid'] = $Follow['uid'];
  79. $Coupondata['coupon_id'] = $coupon_id;
  80. $r = CouponReceive::create($Coupondata);
  81. if ($r) {
  82. $receive_num = $Coupondata['receive_num'] + 1;
  83. Coupon::update(['id' => $coupon_id, 'receive_num' => $receive_num]);
  84. }
  85. }
  86. }
  87. } else if ($TuanGoods['not_winning_ptype'] == 4) {
  88. Points::create([
  89. 'weid' => weid(),
  90. 'uid' => $Follow['uid'],
  91. 'order_id' => $Follow['order_id'],
  92. 'order_num_alias' => $orderInfo['order_num_alias'],
  93. 'points' => $TuanGoods['not_winning_points'],
  94. 'description' => '拼团没拼中,平台送积分',
  95. 'prefix' => 1,
  96. 'creat_time' => time(),
  97. 'type' => 1
  98. ]);
  99. Member::where('id', $Follow['uid'])
  100. ->inc('points', (int) $TuanGoods['not_winning_points'])
  101. ->update();
  102. }
  103. }
  104. }
  105. }