TaskBusiness.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. /** @var $has 查询今天是否已经发奖 */
  27. $has = Db::table('wa_stream')
  28. ->where('user_id', $cronTask->user_id)
  29. ->where('type', streamType14)
  30. ->where('mold', moldType1)
  31. ->whereBetween('add_time', [strtotime(date('Y-m-d') . ' 00:00:00'), strtotime(date('Y-m-d') . ' 23:59:59')])
  32. ->where('source_id', $taskId)
  33. ->exists();
  34. /** @var $usersData 查询会员信息 */
  35. $usersData = Db::table('wa_users')->where('id', $cronTask->user_id)->first();
  36. if (empty($has) && !empty($usersData)) {
  37. StreamBusiness::addStream($usersData->id, $cronTask->bonus, streamType14, moldType1, moldTypefild1, $taskId);
  38. }
  39. Db::table('wa_cron_task')->where('id', $taskId)->update([
  40. 'day_dividend_time' => strtotime("+1 days"),
  41. 'is_day' => 2
  42. ]);
  43. Db::commit();
  44. } catch (\Throwable $exception) {
  45. Db::rollBack();
  46. Log::channel('task')->error($exception->getMessage(), $taskId);
  47. }
  48. }
  49. static public function taskFj(int $taskId)
  50. {
  51. Db::beginTransaction();
  52. try {
  53. StreamBusiness::addStream($taskId, 88888, streamType13, moldType4, moldTypefild4, $taskId);
  54. Db::table('wa_users')->where('id', $taskId)->update([
  55. 'is_f' => 2,
  56. ]);
  57. Db::commit();
  58. } catch (\Throwable $exception) {
  59. Db::rollBack();
  60. Log::channel('task_jr')->error($exception->getMessage(), $taskId);
  61. }
  62. }
  63. /** 申请通过
  64. * @param $taskId
  65. * @return void
  66. */
  67. static public function TaskRefund($taskId)
  68. {
  69. Db::beginTransaction();
  70. try {
  71. $has = Db::table('wa_apply_record')
  72. ->where('id', $taskId)
  73. ->first();
  74. if (!$has) {
  75. throw new \Exception('没有查询当申请!');
  76. }
  77. Db::table('wa_apply_record')
  78. ->where('id', $taskId)->update(['status'=>2]);
  79. StreamBusiness::addStream($has->uid,$has->money, streamType12, moldType2, moldTypefild2);
  80. Db::commit();
  81. } catch (\Throwable $exception) {
  82. Db::rollBack();
  83. Log::channel('task_refund')->error($exception->getMessage(), [$taskId]);
  84. }
  85. }
  86. }