TaskBusiness.php 3.2 KB

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