TaskBusiness.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <?php
  2. namespace app\business;
  3. use support\Db;
  4. use support\Log;
  5. use support\Redis;
  6. class TaskBusiness
  7. {
  8. /**产品的每日分红
  9. * @param int $taskId 任务ID
  10. * @return void
  11. */
  12. static public function taskOne(int $taskId)
  13. {
  14. Db::beginTransaction();
  15. try {
  16. $cronTask = Db::table('wa_cron_task')->where('id', $taskId)->lockForUpdate()->first();
  17. if (empty($cronTask)) {
  18. throw new \Exception('没有查询当任务!');
  19. }
  20. $proder = Db::table('wa_payorder')->where('id', $cronTask->order_id)->first();
  21. if (empty($proder)) {
  22. Db::table('wa_cron_task')->where('id', $taskId)->update([
  23. 'is_finish' => 2
  24. ]);
  25. }
  26. if ($cronTask->goods_type == 1) {
  27. /** @var $has 查询今天是否已经发奖 */
  28. $has = Db::table('wa_stream')
  29. ->where('user_id', $cronTask->user_id)
  30. ->where('type', streamType9)
  31. ->where('mold', moldType7)
  32. ->whereBetween('add_time', [strtotime(date('Y-m-d') . ' 00:00:00'), strtotime(date('Y-m-d') . ' 23:59:59')])
  33. ->where('source_id', $taskId)
  34. ->exists();
  35. /** @var $usersData 查询会员信息 */
  36. $usersData = Db::table('wa_users')->where('id', $cronTask->user_id)->first();
  37. if (empty($has) && !empty($usersData)) {
  38. $goodslist = Db::table('wa_goods')->where('id', $cronTask->goods_id)->first();
  39. if (!empty($goodslist->original_bonus)) {
  40. StreamBusiness::addStream($usersData->id, $goodslist->original_bonus, streamType9, moldType7, moldTypefild7, $taskId);
  41. } else {
  42. StreamBusiness::addStream($usersData->id, $goodslist->bonus, streamType9, moldType7, moldTypefild7, $taskId);
  43. }
  44. if (!empty($usersData->pid) && !empty($cronTask->rebate)) {
  45. StreamBusiness::addStream($usersData->pid, $cronTask->rebate, streamType9, moldType9, moldTypefild9, $taskId);
  46. }
  47. if (!empty($usersData->ppid) && !empty($cronTask->rebate_one)) {
  48. StreamBusiness::addStream($usersData->ppid, $cronTask->rebate_one, streamType9, moldType9, moldTypefild9, $taskId);
  49. }
  50. if (!empty($usersData->toppid) && !empty($cronTask->rebate_two)) {
  51. StreamBusiness::addStream($usersData->toppid, $cronTask->rebate_two, streamType9, moldType9, moldTypefild9, $taskId);
  52. }
  53. }
  54. } elseif ($cronTask->goods_type == 2) {
  55. /** @var $has 查询今天是否已经发奖 */
  56. $has = Db::table('wa_stream')
  57. ->where('user_id', $cronTask->user_id)
  58. ->where('type', streamType26)
  59. ->where('mold', moldType11)
  60. ->whereBetween('add_time', [strtotime(date('Y-m-d') . ' 00:00:00'), strtotime(date('Y-m-d') . ' 23:59:59')])
  61. ->where('source_id', $taskId)
  62. ->exists();
  63. /** @var $usersData 查询会员信息 */
  64. $usersData = Db::table('wa_users')->where('id', $cronTask->user_id)->first();
  65. if (empty($has) && !empty($usersData)) {
  66. if ($cronTask->is_activity > 0 && $cronTask->event_time < time() && $cronTask->event_time > 0) {
  67. $bonus = bcdiv($cronTask->bonus, $cronTask->is_activity, 2);
  68. if (!empty($cronTask->balance)) {
  69. $balance = bcdiv($cronTask->balance, $cronTask->is_activity, 2);
  70. } else {
  71. $balance = 0;
  72. }
  73. } else {
  74. $bonus = $cronTask->bonus;
  75. $balance = $cronTask->balance;
  76. }
  77. StreamBusiness::addStream($usersData->id, $bonus, streamType26, moldType11, moldTypefild11, $taskId);
  78. if (!empty($balance)) {
  79. StreamBusiness::addStream($usersData->id, $balance, streamType30, moldType10, moldTypefild10, $taskId);
  80. StreamBusiness::delStream($usersData->id, $balance, streamType27, moldType3, moldTypefild3, $taskId);
  81. }
  82. }
  83. }
  84. Db::table('wa_cron_task')->where('id', $taskId)->update([
  85. 'day_dividend_time' => strtotime(date('Y-m-d', strtotime('+1 days')) . ' 00:10:00'),
  86. 'is_day' => 2
  87. ]);
  88. Db::commit();
  89. } catch (\Throwable $exception) {
  90. Db::rollBack();
  91. Log::channel('task')->error($exception->getMessage(), [$taskId]);
  92. }
  93. }
  94. static public function taskFj(int $taskId)
  95. {
  96. Db::beginTransaction();
  97. try {
  98. StreamBusiness::addStream($taskId, 88888, streamType13, moldType4, moldTypefild4, $taskId);
  99. Db::table('wa_users')->where('id', $taskId)->update([
  100. 'is_f' => 2,
  101. ]);
  102. Db::commit();
  103. } catch (\Throwable $exception) {
  104. Db::rollBack();
  105. Log::channel('task_jr')->error($exception->getMessage(), $taskId);
  106. }
  107. }
  108. /** 申请通过
  109. * @param $taskId
  110. * @return void
  111. */
  112. static public function TaskRefund($taskId)
  113. {
  114. Db::beginTransaction();
  115. try {
  116. $cronTask = Db::table('wa_cron_task_four')->where('id', $taskId)->lockForUpdate()->first();
  117. if (empty($cronTask)) {
  118. throw new \Exception('没有查询当任务!');
  119. }
  120. $proder = Db::table('wa_payorder')->where('id', $cronTask->order_id)->first();
  121. if (empty($proder)) {
  122. Db::table('wa_cron_task')->where('id', $taskId)->update([
  123. 'is_finish' => 2
  124. ]);
  125. }
  126. /** @var $has 查询今天是否已经发奖 */
  127. $has = Db::table('wa_stream')
  128. ->where('user_id', $cronTask->user_id)
  129. ->where('type', streamType37)
  130. ->where('mold', moldType12)
  131. ->whereBetween('add_time', [strtotime(date('Y-m-d') . ' 00:00:00'), strtotime(date('Y-m-d') . ' 23:59:59')])
  132. ->where('source_id', $taskId)
  133. ->exists();
  134. /** @var $usersData 查询会员信息 */
  135. $usersData = Db::table('wa_users')->where('id', $cronTask->user_id)->first();
  136. if (empty($has) && !empty($usersData)) {
  137. $goodslist = Db::table('wa_goods')->where('id', $cronTask->goods_id)->first();
  138. if(!empty($goodslist->bonus)){
  139. StreamBusiness::addStream($usersData->id, $goodslist->bonus, streamType37, moldType12, moldTypefild12, $taskId);
  140. }
  141. if($usersData->money_thirteen<$usersData->accumulate_thirteen){
  142. Db::table('wa_users')->where('id', $usersData->id)->update(['money_thirteen'=>$usersData->accumulate_thirteen]);
  143. }
  144. if($usersData->money_fourteen<$usersData->accumulate_fourteen){
  145. Db::table('wa_users')->where('id', $usersData->id)->update(['money_fourteen'=>$usersData->accumulate_fourteen]);
  146. }
  147. }
  148. Db::table('wa_cron_task_sign_two')->where('id', $taskId)->update([
  149. 'day_dividend_time' => strtotime(date('Y-m-d', strtotime('+1 days')) . ' 00:00:00'),
  150. 'is_day' => 2
  151. ]);
  152. Db::commit();
  153. } catch (\Throwable $exception) {
  154. Db::rollBack();
  155. Log::channel('task')->error($exception->getMessage(), []);
  156. }
  157. }
  158. /**基金每日分红
  159. * @param int $taskId 任务ID
  160. * @return void
  161. */
  162. static public function taskSign(int $taskId)
  163. {
  164. Db::beginTransaction();
  165. try {
  166. $cronTask = Db::table('wa_cron_task_sign')->where('id', $taskId)->lockForUpdate()->first();
  167. if (empty($cronTask)) {
  168. throw new \Exception('没有查询当任务!');
  169. }
  170. if ($cronTask->dividend_time >= time()) {
  171. /** @var $has 查询今天是否已经发奖 */
  172. $has = Db::table('wa_stream')
  173. ->where('user_id', $cronTask->user_id)
  174. ->where('type', streamType13)
  175. ->where('mold', moldType2)
  176. ->whereBetween('add_time', [strtotime(date('Y-m-d') . ' 00:00:00'), strtotime(date('Y-m-d') . ' 23:59:59')])
  177. ->where('source_id', $taskId)
  178. ->exists();
  179. /** @var $usersData 查询会员信息 */
  180. $usersData = Db::table('wa_users')->where('id', $cronTask->user_id)->first();
  181. if (empty($has) && !empty($usersData)) {
  182. StreamBusiness::addStream($usersData->id, $cronTask->bonus, streamType13, moldType2, moldTypefild2, $taskId);
  183. }
  184. Db::table('wa_cron_task_sign')->where('id', $taskId)->update([
  185. 'day_dividend_time' => strtotime(date('Y-m-d', strtotime('+1 days')) . ' 00:30:00'),
  186. 'is_day' => 2
  187. ]);
  188. } else {
  189. $usersData = Db::table('wa_users')->where('id', $cronTask->user_id)->first();
  190. StreamBusiness::addStream($usersData->id, $cronTask->money, streamType15, moldType1, moldTypefild1, $taskId);
  191. Db::table('wa_cron_task_sign')->where('id', $taskId)->update([
  192. 'is_finish' => 2
  193. ]);
  194. }
  195. Db::commit();
  196. } catch (\Throwable $exception) {
  197. Db::rollBack();
  198. Log::channel('task')->error($exception->getMessage(), []);
  199. }
  200. }
  201. }