CpTaskModel.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace App\Models\Fpdx;
  3. use App\Models\Model;
  4. /**
  5. * App\Models\Fpdx\CpTaskModel
  6. *
  7. * @property int $id
  8. * @property string $uid 用户
  9. * @property int $task_id 任务id
  10. * @property int $trem 期数
  11. * @property string $data 数据
  12. * @property int $create_at 时间
  13. * @property int $is_show 是否展示
  14. * @property int $thumb 点赞数
  15. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Fpdx\CpTaskModel newModelQuery()
  16. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Fpdx\CpTaskModel newQuery()
  17. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Fpdx\CpTaskModel query()
  18. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Fpdx\CpTaskModel whereCreateAt($value)
  19. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Fpdx\CpTaskModel whereData($value)
  20. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Fpdx\CpTaskModel whereId($value)
  21. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Fpdx\CpTaskModel whereIsShow($value)
  22. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Fpdx\CpTaskModel whereTaskId($value)
  23. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Fpdx\CpTaskModel whereThumb($value)
  24. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Fpdx\CpTaskModel whereTrem($value)
  25. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Fpdx\CpTaskModel whereUid($value)
  26. * @mixin \Eloquent
  27. */
  28. class CpTaskModel extends Model
  29. {
  30. protected $table = 'kdgx_partner_charge_cptask';
  31. public $timestamps = false;
  32. /**
  33. * 某人某期任务完成情况
  34. * @param term 期数
  35. * @param uid 用户id
  36. * @return array
  37. */
  38. public static function complateData($term, $uid)
  39. {
  40. // 每天任务的数量
  41. $taskModel = new TaskModel();
  42. $datas = array();
  43. for ($i = 1; $i <= 3; $i++) {
  44. $where = [
  45. ['term', '=', $term],
  46. ['day', '=', $i]
  47. ];
  48. $datas[$i]['count'] = $taskModel->where($where)->count();
  49. $tmp = array();
  50. array_map(function ($task) use (&$tmp) {
  51. array_push($tmp, $task['id']);
  52. }, $taskModel->where($where)->get()->toArray());
  53. $datas[$i]['tasks'] = $tmp;
  54. if (self::where(['uid' => $uid])->whereIn('task_id', $tmp)->count() < $datas[$i]['count']) {
  55. $datas[$i]['complated'] = 0;
  56. } else {
  57. $datas[$i]['complated'] = 1;
  58. }
  59. }
  60. return $datas;
  61. }
  62. /**
  63. * 获取某人某期任务完成比例
  64. * @param $term 期数
  65. * @param $uid 用户
  66. * @return array
  67. */
  68. public function complate($term, $uid)
  69. {
  70. // 每天任务的数量
  71. $taskModel = new TaskModel();
  72. $data = $taskModel->where('term', $term)->get()->toArray();
  73. $tmp = array();
  74. array_map(function ($task) use (&$tmp) {
  75. array_push($tmp, $task['id']);
  76. }, $data);
  77. $count = self::where('uid', $uid)->whereIn('task_id', $tmp)->count();
  78. return array(
  79. 'total' => count($data),
  80. 'complated' => $count
  81. );
  82. }
  83. }