TaskService.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <?php
  2. namespace App\Services\User;
  3. use App\Exceptions\AlertException;
  4. use App\Models\FlowerLogModel;
  5. use App\Models\User\UserModel;
  6. use App\Services\Service;
  7. use Exception;
  8. use Illuminate\Support\Facades\DB;
  9. /**
  10. * Class TaskService
  11. * @package App\Services\User
  12. * @deprecated
  13. */
  14. class TaskService extends Service
  15. {
  16. /**
  17. * @param int $uid
  18. * @return int|string
  19. * @throws AlertException
  20. * @deprecated vip领取每日小花任务
  21. */
  22. public function getVipFlowerEveryDay(int $uid)
  23. {
  24. $user = UserModel::findOrFail($uid);
  25. if ($user->be_vip_at == 0) {
  26. throw new AlertException("你还不是会员", 102);
  27. }
  28. if (FlowerLogModel::where([['uid', $uid], ['type', 15], ['create_at', '>', mktime(0, 0, 0)]])->exists()) {
  29. throw new AlertException("今天已经领取过了哦,明天再来吧。点此继续赚小fa", 101);
  30. }
  31. try {
  32. DB::beginTransaction();
  33. $flower = sprintf("%.2f", 0.5 + mt_rand() / mt_getrandmax() * (1.5 - 0.5));
  34. UserModel::where('uid', $uid)->increment('red_flower', $flower);
  35. $data = array(
  36. 'uid' => $uid,
  37. 'create_at' => time(),
  38. 'type' => 15,
  39. 'gold_flower' => 0,
  40. 'red_flower' => $flower,
  41. 'jsk' => 0,
  42. 'remark' => "会员每日小花礼包",
  43. );
  44. DB::table('kdgx_partner_charge_pay_logs')->insert($data);
  45. DB::commit();
  46. return $flower;
  47. } catch (Exception $exception) {
  48. DB::rollBack();
  49. return 0;
  50. }
  51. }
  52. /**
  53. * 领取新年任务
  54. * @param int $uid
  55. * @return int|string
  56. * @throws AlertException
  57. * @deprecated
  58. */
  59. public function getYearFlower(int $uid)
  60. {
  61. if (FlowerLogModel::where([['uid', $uid], ['type', 14], ['create_at', '>', mktime(0, 0, 0)]])->exists()) {
  62. throw new AlertException("今天已经领取过了哦,明天再来吧。点此继续赚小fa", 101);
  63. }
  64. try {
  65. DB::beginTransaction();
  66. $flower = sprintf("%.2f", 0.5 + mt_rand() / mt_getrandmax() * (1.5 - 0.5));
  67. UserModel::where('uid', $uid)->increment('red_flower', $flower);
  68. $data = array(
  69. 'uid' => $uid,
  70. 'create_at' => time(),
  71. 'type' => 14,
  72. 'gold_flower' => 0,
  73. 'red_flower' => $flower,
  74. 'jsk' => 0,
  75. 'remark' => "新年小花礼包",
  76. );
  77. DB::table('kdgx_partner_charge_pay_logs')->insert($data);
  78. DB::commit();
  79. return $flower;
  80. } catch (\Exception $exception) {
  81. DB::rollBack();
  82. return 0;
  83. }
  84. }
  85. /**
  86. * 完成某人的任务
  87. * @param int $uid
  88. * @param $task_type
  89. * @deprecated
  90. */
  91. public function task(int $uid, $task_type)
  92. {
  93. $Dtask = array(
  94. 1 => [
  95. 'red_flower' => 3,
  96. 'jsk' => 0,
  97. 'remark' => '完成任务[创建交友卡片]',
  98. ],
  99. 2 => [
  100. 'red_flower' => 2,
  101. 'jsk' => 0,
  102. 'remark' => '完成任务[首次卖室友]',
  103. ],
  104. 3 => [
  105. 'red_flower' => 3,
  106. 'jsk' => 0,
  107. 'remark' => '完成任务[首次上架自己]',
  108. ],
  109. 4 => [
  110. 'red_flower' => 3,
  111. 'jsk' => 0,
  112. 'remark' => '完成任务[首次上传语音]',
  113. ],
  114. 5 => [
  115. 'red_flower' => 1,
  116. 'jsk' => 0,
  117. 'remark' => '完成任务[首次表白]',
  118. ],
  119. 6 => [
  120. 'red_flower' => 5,
  121. 'jsk' => 0,
  122. 'remark' => '完成任务[关注官方微信]',
  123. ],
  124. 7 => [
  125. 'red_flower' => 5,
  126. 'jsk' => 0,
  127. 'remark' => '完成任务[添加到我到小程序]',
  128. ],
  129. );
  130. // 判断是否已完成
  131. $user = UserModel::find($uid);
  132. switch ($task_type) {
  133. case 1: # 设置个人信息
  134. if (substr($user->task, -1, 1) == 1) {
  135. return true;
  136. } else {
  137. $user->task = substr($user->task, 0, -1) . '1';
  138. }
  139. break;
  140. case 2: # 首次卖室友
  141. if (substr($user->task, -2, 1) == 1) {
  142. return true;
  143. } else {
  144. $user->task = substr($user->task, 0, -2) . '1' . substr($user->task, -1);
  145. }
  146. break;
  147. case 3: # 首次上架自己
  148. if (substr($user->task, -3, 1) == 1) {
  149. return true;
  150. } else {
  151. $user->task = substr($user->task, 0, -3) . '1' . substr($user->task, -2);
  152. }
  153. break;
  154. case 4: # 首次上传语音
  155. if (substr($user->task, -4, 1) == 1) {
  156. return true;
  157. } else {
  158. $user->task = substr($user->task, 0, -4) . '1' . substr($user->task, -3);
  159. }
  160. break;
  161. case 5: # 首次表白
  162. if (substr($user->task, -5, 1) == 1) {
  163. return true;
  164. } else {
  165. $user->task = substr($user->task, 0, -5) . '1' . substr($user->task, -4);
  166. }
  167. break;
  168. case 6: # 关注公众号
  169. if (substr($user->task, -6, 1) == 1) {
  170. return true;
  171. } else {
  172. $user->task = substr($user->task, 0, -6) . '1' . substr($user->task, -5);
  173. }
  174. break;
  175. case 7: # 添加到我到小程序
  176. if (substr($user->task, -7, 1) == 1) {
  177. return true;
  178. } else {
  179. $user->task = substr($user->task, 0, -7) . '1' . substr($user->task, -6);
  180. }
  181. break;
  182. default:
  183. return true;
  184. }
  185. // 记录任务
  186. $user->save();
  187. // 记录小fa明细
  188. DB::table('kdgx_partner_charge_pay_logs')->insert([
  189. 'uid' => $uid,
  190. 'create_at' => time(),
  191. 'type' => 2,
  192. 'red_flower' => $Dtask[$task_type]['red_flower'],
  193. 'jsk' => $Dtask[$task_type]['jsk'],
  194. 'remark' => $Dtask[$task_type]['remark'],
  195. ]);
  196. // 添加小fa数量
  197. $user->increment('red_flower', $Dtask[$task_type]['red_flower']);
  198. return true;
  199. }
  200. }