SystemUserTask.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. <?php
  2. namespace app\models\system;
  3. use app\models\lala\LalaPinkJoin;
  4. use app\models\store\StoreOrder;
  5. use app\models\user\User;
  6. use app\models\user\UserBill;
  7. use app\models\user\UserLevel;
  8. use app\models\user\UserTaskFinish;
  9. use crmeb\traits\ModelTrait;
  10. use crmeb\basic\BaseModel;
  11. use think\db\exception\DataNotFoundException;
  12. use think\db\exception\DbException;
  13. use think\db\exception\ModelNotFoundException;
  14. /**
  15. * TODO 设置等级任务Model
  16. * Class SystemUserTask
  17. * @package app\models\system
  18. */
  19. class SystemUserTask extends BaseModel
  20. {
  21. /**
  22. * 数据表主键
  23. * @var string
  24. */
  25. protected $pk = 'id';
  26. /**
  27. * 模型名称
  28. * @var string
  29. */
  30. protected $name = 'system_user_task';
  31. use ModelTrait;
  32. /**
  33. * 任务类型
  34. * type 记录在数据库中用来区分任务
  35. * name 任务名 (任务名中的{$num}会自动替换成设置的数字 + 单位)
  36. * max_number 最大设定数值 0为不限定
  37. * min_number 最小设定数值
  38. * unit 单位
  39. * */
  40. protected static $TaskType = [
  41. [
  42. 'type' => 'SatisfactionIntegral',
  43. 'name' => '满足积分{$num}',
  44. 'real_name' => '积分数',
  45. 'max_number' => 0,
  46. 'min_number' => 0,
  47. 'unit' => '分'
  48. ],
  49. [
  50. 'type' => 'ConsumptionAmount',
  51. 'name' => '消费满{$num}',
  52. 'real_name' => '消费金额',
  53. 'max_number' => 0,
  54. 'min_number' => 0,
  55. 'unit' => '元'
  56. ],
  57. [
  58. 'type' => 'ConsumptionFrequency',
  59. 'name' => '消费{$num}',
  60. 'real_name' => '消费次数',
  61. 'max_number' => 0,
  62. 'min_number' => 0,
  63. 'unit' => '次'
  64. ],
  65. [
  66. 'type' => 'CumulativeAttendance',
  67. 'name' => '累计签到{$num}',
  68. 'real_name' => '累计签到',
  69. 'max_number' => 365,
  70. 'min_number' => 1,
  71. 'unit' => '天'
  72. ],
  73. [
  74. 'type' => 'SharingTimes',
  75. 'name' => '分享给朋友{$num}',
  76. 'real_name' => '分享给朋友',
  77. 'max_number' => 1000,
  78. 'min_number' => 1,
  79. 'unit' => '次'
  80. ],
  81. [
  82. 'type' => 'InviteGoodFriends',
  83. 'name' => '邀请好友{$num}成为下线',
  84. 'real_name' => '邀请好友成为下线',
  85. 'max_number' => 1000,
  86. 'min_number' => 1,
  87. 'unit' => '人'
  88. ],
  89. [
  90. 'type' => 'InviteGoodFriendsLevel',
  91. 'name' => '邀请好友{$num}成为会员',
  92. 'real_name' => '邀请好友成为会员',
  93. 'max_number' => 1000,
  94. 'min_number' => 1,
  95. 'unit' => '人'
  96. ],
  97. [
  98. 'type' => 'GroupNum',
  99. 'name' => '团队人数达到{$num}',
  100. 'real_name' => '团队人数',
  101. 'max_number' => 10000000,
  102. 'min_number' => 1,
  103. 'unit' => '人'
  104. ],
  105. [
  106. 'type' => 'OtherGroupNum',
  107. 'name' => '小区团队人数达到{$num}',
  108. 'real_name' => '小区团队人数',
  109. 'max_number' => 10000000,
  110. 'min_number' => 1,
  111. 'unit' => '人'
  112. ],
  113. [
  114. 'type' => 'Achievement',
  115. 'name' => '业绩达到{$num}',
  116. 'real_name' => '业绩',
  117. 'max_number' => 10000000,
  118. 'min_number' => 1,
  119. 'unit' => '元'
  120. ],
  121. [
  122. 'type' => 'RecommendAchievement',
  123. 'name' => '直推业绩达到{$num}',
  124. 'real_name' => '直推业绩',
  125. 'max_number' => 10000000,
  126. 'min_number' => 1,
  127. 'unit' => '元'
  128. ],
  129. [
  130. 'type' => 'OtherAchievement',
  131. 'name' => '小区业绩达到{$num}',
  132. 'real_name' => '小区业绩',
  133. 'max_number' => 10000000,
  134. 'min_number' => 1,
  135. 'unit' => '元'
  136. ],
  137. ];
  138. public function profile()
  139. {
  140. return $this->hasOne('SystemUserLevel', 'level_id', 'id')->field('name');
  141. }
  142. public static function getTaskTypeAll()
  143. {
  144. return self::$TaskType;
  145. }
  146. /**
  147. * 获取某个任务
  148. * @param string $type 任务类型
  149. * @return array
  150. * */
  151. public static function getTaskType($type)
  152. {
  153. foreach (self::$TaskType as $item) {
  154. if ($item['type'] == $type) return $item;
  155. }
  156. }
  157. /**
  158. * 设置任务名
  159. * @param string $type 任务类型
  160. * @param int $num 预设值
  161. * @return string
  162. * */
  163. public static function setTaskName($type, $num)
  164. {
  165. $systemType = self::getTaskType($type);
  166. return str_replace('{$num}', $num . $systemType['unit'], $systemType['name']);
  167. }
  168. /**
  169. * 累计消费金额
  170. * @param int $task_id 任务id
  171. * @param int $uid 用户id
  172. * @param int $start_time 开始时间
  173. * @param int $number 限定时间
  174. * @return boolean
  175. * */
  176. public static function ConsumptionAmount($task_id, $uid = 0, $start_time = 0, $number = 0)
  177. {
  178. $isComplete = false;
  179. $SumPayPrice = StoreOrder::where('paid', 1)
  180. ->where('refund_status', 0)
  181. ->where('is_del', 0)
  182. ->where('uid', $uid)
  183. ->where('add_time', '>', $start_time)
  184. ->sum('pay_price');
  185. if ($SumPayPrice >= $number) $isComplete = UserTaskFinish::setFinish($uid, $task_id) ? true : false;
  186. return ['还需消费{$num}元', $SumPayPrice, $isComplete];
  187. }
  188. /**
  189. * 累计消费次数
  190. * @param int $task_id 任务id
  191. * @param int $uid 用户id
  192. * @param int $start_time 开始时间
  193. * @param int $number 限定时间
  194. * @return boolean
  195. * */
  196. public static function ConsumptionFrequency($task_id, $uid = 0, $start_time = 0, $number = 0)
  197. {
  198. $isComplete = false;
  199. $countPay = StoreOrder::where('paid', 1)->where('refund_status', 0)->where('is_del', 0)->where('uid', $uid)->where('add_time', '>', $start_time)->count();
  200. if ($countPay >= $number) $isComplete = UserTaskFinish::setFinish($uid, $task_id) ? true : false;
  201. return ['还需消费{$num}次', $countPay, $isComplete];
  202. }
  203. /**
  204. * 邀请好友成为会员
  205. * @param int $task_id 任务id
  206. * @param int $uid 用户id
  207. * @param int $start_time 开始时间
  208. * @param int $number 限定时间
  209. * @return boolean
  210. * */
  211. public static function InviteGoodFriendsLevel($task_id, $uid = 0, $start_time = 0, $number = 0)
  212. {
  213. $isComplete = false;
  214. $uids = User::where('spread_uid', $uid)->where('spread_time', '>', $start_time)->column('uid', 'uid');
  215. $levelCount = count($uids) ? UserLevel::setUserLevelCount($uids) : 0;
  216. if ($levelCount >= $number) $isComplete = UserTaskFinish::setFinish($uid, $task_id) ? true : false;
  217. return ['还需邀请{$num}人成为会员', $levelCount, $isComplete];
  218. }
  219. /**
  220. * 团队人数
  221. * @param int $task_id 任务id
  222. * @param int $uid 用户id
  223. * @param int $start_time 开始时间
  224. * @param int $number 限定时间
  225. * @return boolean
  226. * */
  227. public static function GroupNum($task_id, $uid = 0, $start_time = 0, $number = 0)
  228. {
  229. $isComplete = false;
  230. $uids = [$uid];
  231. $all = [];
  232. while ($uids) {
  233. $uids = User::where('spread_uid', 'in', $uids)->column('uid');
  234. $all = array_merge($all, $uids);
  235. }
  236. $levelCount = count($all);
  237. if ($levelCount >= $number) $isComplete = UserTaskFinish::setFinish($uid, $task_id) ? true : false;
  238. return ['还需邀请{$num}人加入团队', $levelCount, $isComplete];
  239. }
  240. /**
  241. * 小区团队人数
  242. * @param int $task_id 任务id
  243. * @param int $uid 用户id
  244. * @param int $start_time 开始时间
  245. * @param int $number 限定时间
  246. * @return boolean
  247. * */
  248. public static function OtherGroupNum($task_id, $uid = 0, $start_time = 0, $number = 0)
  249. {
  250. $isComplete = false;
  251. $sub_uids = User::where('spread_uid', $uid)->column('uid');
  252. $max = 0;
  253. $all = 0;
  254. foreach ($sub_uids as $v) {
  255. $uids = [$v];
  256. $all_uids = [];
  257. while ($uids) {
  258. $uids = User::where('spread_uid', 'in', $uids)->column('uid');
  259. $all_uids = array_merge($all_uids, $uids);
  260. }
  261. if (count($all_uids) > $max) $max = count($all_uids);
  262. $all += count($all_uids);
  263. }
  264. $levelCount = $all - $max;
  265. if ($levelCount >= $number) $isComplete = UserTaskFinish::setFinish($uid, $task_id) ? true : false;
  266. return ['还需邀请{$num}人加入团队小区', $levelCount, $isComplete];
  267. }
  268. /**
  269. * 团队业绩
  270. * @param int $task_id 任务id
  271. * @param int $uid 用户id
  272. * @param int $start_time 开始时间
  273. * @param int $number 限定时间
  274. * @return boolean
  275. * */
  276. public static function OtherAchievement($task_id, $uid = 0, $start_time = 0, $number = 0)
  277. {
  278. $isComplete = false;
  279. $sub_uids = User::where('spread_uid', $uid)->column('uid');
  280. $max = 0;
  281. $all = 0;
  282. foreach ($sub_uids as $v) {
  283. $uids = [$v];
  284. $all_uids = [$v];
  285. while ($uids) {
  286. $uids = User::where('spread_uid', 'in', $uids)->column('uid');
  287. $all_uids = array_merge($all_uids, $uids);
  288. }
  289. // $achievement = LalaPinkJoin::where('paid', 1)
  290. // ->where('uid', '<>', 0)
  291. // ->where('status', 'in', [1, 2])
  292. // ->where('uid', 'in', $all_uids)
  293. // ->where('cost_money_type', 'USDT')
  294. // ->sum('cost');
  295. $achievement = StoreOrder::where('paid', 1)
  296. ->where('refund_status', 0)
  297. ->where('is_del', 0)
  298. ->where('uid', 'in', $all_uids)
  299. ->where('add_time', '>', $start_time)
  300. ->sum('pay_price');
  301. if ($achievement > $max) $max = $achievement;
  302. $all += $achievement;
  303. }
  304. $levelCount = $all - $max;
  305. if ($levelCount >= $number) $isComplete = UserTaskFinish::setFinish($uid, $task_id) ? true : false;
  306. return ['还需{$num}U业绩', $levelCount, $isComplete];
  307. }
  308. /**
  309. * 团队业绩
  310. * @param int $task_id 任务id
  311. * @param int $uid 用户id
  312. * @param int $start_time 开始时间
  313. * @param int $number 限定时间
  314. * @return boolean
  315. * */
  316. public static function Achievement($task_id, $uid = 0, $start_time = 0, $number = 0)
  317. {
  318. $isComplete = false;
  319. $uids = [$uid];
  320. $all = [];
  321. while ($uids) {
  322. $uids = User::where('spread_uid', 'in', $uids)->column('uid');
  323. $all = array_merge($all, $uids);
  324. }
  325. // $levelCount = LalaPinkJoin::where('paid', 1)
  326. // ->where('uid', '<>', 0)
  327. // ->where('status', 'in', [1, 2])
  328. // ->where('uid', 'in', $all)
  329. // ->where('cost_money_type', 'USDT')
  330. // ->sum('cost');
  331. $levelCount = StoreOrder::where('paid', 1)
  332. ->where('refund_status', 0)
  333. ->where('is_del', 0)
  334. ->where('uid', 'in', $all)
  335. ->where('add_time', '>', $start_time)
  336. ->sum('pay_price');
  337. if ($levelCount >= $number) $isComplete = UserTaskFinish::setFinish($uid, $task_id) ? true : false;
  338. return ['还需{$num}U业绩', $levelCount, $isComplete];
  339. }
  340. /**
  341. * 直推业绩
  342. * @param int $task_id 任务id
  343. * @param int $uid 用户id
  344. * @param int $start_time 开始时间
  345. * @param int $number 限定时间
  346. * @return boolean
  347. * */
  348. public static function RecommendAchievement($task_id, $uid = 0, $start_time = 0, $number = 0)
  349. {
  350. $isComplete = false;
  351. $uids = User::where('spread_uid', $uid)->column('uid');
  352. // $levelCount = LalaPinkJoin::where('paid', 1)->where('uid', '<>', 0)->where('status', 'in', [1, 2])->where('uid', 'in', $uids)->where('cost_money_type', 'USDT')->sum('cost');
  353. $levelCount = StoreOrder::where('paid', 1)
  354. ->where('refund_status', 0)
  355. ->where('is_del', 0)
  356. ->where('uid', 'in', $uids)
  357. ->where('add_time', '>', $start_time)
  358. ->sum('pay_price');
  359. if ($levelCount >= $number) $isComplete = UserTaskFinish::setFinish($uid, $task_id) ? true : false;
  360. return ['还需{$num}U业绩', $levelCount, $isComplete];
  361. }
  362. /**
  363. * 邀请好友成为下线
  364. * @param int $task_id 任务id
  365. * @param int $uid 用户id
  366. * @param int $start_time 查询开始时间
  367. * @param int $number 限定数量
  368. * */
  369. public static function InviteGoodFriends($task_id, $uid = 0, $start_time = 0, $number = 0)
  370. {
  371. $isComplete = false;
  372. $spreadCount = User::where('spread_uid', $uid)->where('spread_time', '>', $start_time)->count();
  373. if ($spreadCount >= $number) $isComplete = UserTaskFinish::setFinish($uid, $task_id) ? true : false;
  374. return ['还需邀请{$num}人成为下线', $spreadCount, $isComplete];
  375. }
  376. /**
  377. * 满足积分
  378. * @param int $task_id 任务id
  379. * @param int $uid 用户id
  380. * @param int $start_time 查询开始时间
  381. * @param int $number 限定数量
  382. * @return Boolean
  383. * */
  384. public static function SatisfactionIntegral($task_id, $uid = 0, $start_time = 0, $number = 0)
  385. {
  386. $isComplete = false;
  387. $sumNumber = UserBill::where('uid', $uid)->where('category', 'integral')->where('pm', 1)->where('add_time', '>', $start_time)->where('type', 'in', ['system_add', 'sign', 'gain'])->sum('number');
  388. if ($sumNumber >= $number) $isComplete = UserTaskFinish::setFinish($uid, $task_id) ? true : false;
  389. return ['还需要{$num}经验', $sumNumber, $isComplete];
  390. }
  391. /**
  392. * 分享给朋友次数完成情况
  393. * @param int $task_id 任务id
  394. * @param int $uid 用户id
  395. * @param int $start_time 查询开始时间
  396. * @param int $number 限定数量
  397. * @return Boolean
  398. * */
  399. public static function SharingTimes($task_id, $uid = 0, $start_time = 0, $number = 0)
  400. {
  401. $isComplete = false;
  402. $sumCount = UserBill::where('uid', $uid)->where('category', 'share')->where('pm', 1)->where('add_time', '>', $start_time)->where('type', 'share')->count();
  403. if ($sumCount >= $number) $isComplete = UserTaskFinish::setFinish($uid, $task_id) ? true : false;
  404. return ['还需分享{$num}次', $sumCount, $isComplete];
  405. }
  406. /**
  407. * 累计签到
  408. * @param int $task_id 任务id
  409. * @param int $uid 用户id
  410. * @param int $start_time 查询开始时间
  411. * @param int $number 限定数量
  412. * @return Boolean
  413. * */
  414. public static function CumulativeAttendance($task_id, $uid = 0, $start_time = 0, $number = 0)
  415. {
  416. $isComplete = false;
  417. $sumCount = UserBill::where('uid', $uid)->where('category', 'integral')->where('pm', 1)->where('add_time', '>', $start_time)->where('type', 'sign')->count();
  418. if ($sumCount >= $number) $isComplete = UserTaskFinish::setFinish($uid, $task_id) ? true : false;
  419. return ['还需签到{$num}天', $sumCount, $isComplete];
  420. }
  421. /**
  422. * 设置任务完成情况
  423. * @param int $task_id 任务id
  424. * @param int $uid 用户uid
  425. * @param int $start_time 查询开始时间
  426. * @return Boolean
  427. * */
  428. public static function setTaskFinish($task_id = 0, $uid = 0, $start_time = 0)
  429. {
  430. if (!$task_id) return self::setErrorInfo('缺少任务id参数');
  431. if (!$uid) return self::setErrorInfo('缺少用户uid');
  432. $task = self::where('id', $task_id)->where('is_show', 1)->find();
  433. if (!$task) return self::setErrorInfo('任务不存在');
  434. $task_type = $task->task_type;
  435. if ($task_type && method_exists(self::class, $task_type)) {
  436. try {
  437. $start_time = User::getCleanTime($uid);
  438. return self::$task_type($task_id, $uid, $start_time, $task->number);
  439. } catch (\Exception $e) {
  440. return self::setErrorInfo($e->getMessage());
  441. }
  442. }
  443. return self::setErrorInfo('没有此任务');
  444. }
  445. /**
  446. * 设置任务显示条件
  447. * @param string $alert 表别名
  448. * @param object $model 模型实例
  449. * @return object
  450. * */
  451. public static function visibleWhere($alert = '', $model = null)
  452. {
  453. $model = $model === null ? new self() : $model;
  454. if ($alert) $model = $model->alias($alert);
  455. $alert = $alert ? $alert . '.' : '';
  456. return $model->where("{$alert}is_show", 1);
  457. }
  458. /**
  459. * 获取等级会员任务列表
  460. * @param int $level_id 会员等级id
  461. * @param int $uid 用户id
  462. * @param null $level
  463. * @param int $expire
  464. * @return array
  465. * @throws DataNotFoundException
  466. * @throws DbException
  467. * @throws ModelNotFoundException
  468. */
  469. public static function getTashList($level_id, $uid = 0, $level = null, $expire = 1400)
  470. {
  471. $level_id = is_string($level_id) ? (int)$level_id : $level_id;
  472. $list = self::visibleWhere()->where('level_id', $level_id)->field('name,real_name,task_type,illustrate,number,id')->order('sort desc')->select();
  473. $list = count($list) ? $list->toArray() : [];
  474. if ($uid == 0) return $list;
  475. if ($level === null) $level = SystemUserLevel::getLevelInfo($uid);
  476. //获取下一个vip的id
  477. $LeveId = SystemUserLevel::getNextLevelId($level['id'], SystemUserLevel::setWhere()->where('grade', '>', $level ? $level['grade'] : 0)->min('grade'));
  478. $is_clear = SystemUserLevel::getClear($level['id']);
  479. if ($is_clear == false && $LeveId == $level_id) $is_clear = true;
  480. $reach_count = self::getTaskComplete($level_id, $uid, true);
  481. return [
  482. 'list' => $list,
  483. 'reach_count' => $reach_count,
  484. 'task' => self::tidyTask($list, $uid, $is_clear, User::getCleanTime($uid)),
  485. ];
  486. }
  487. /**
  488. * 获取未完成任务的详细值
  489. * @param array $item 任务
  490. * @param int $uid 用户id
  491. * @param int $startTime 开始时间
  492. * @return array
  493. * */
  494. protected static function set_task_type($item, $uid, $startTime = 0)
  495. {
  496. $task = ['task_type_title' => '', 'new_number' => 0, 'speed' => 0, 'finish' => 0];
  497. $task_type = $item['task_type'];
  498. switch ($task_type) {
  499. case 'SatisfactionIntegral':
  500. case 'ConsumptionAmount':
  501. case 'ConsumptionFrequency':
  502. case 'CumulativeAttendance':
  503. case 'SharingTimes':
  504. case 'InviteGoodFriends':
  505. case 'InviteGoodFriendsLevel':
  506. try {
  507. list($task_type_title, $num, $isComplete) = self::$task_type($item['id'], $uid, $startTime, $item['number']);
  508. if ($isComplete) {
  509. $task['finish'] = 1;
  510. $task['speed'] = 100;
  511. $task['speed'] = $item['number'];
  512. $task['new_number'] = $item['number'];
  513. } else {
  514. $numdata = bcsub($item['number'], $num, 0);
  515. $task['task_type_title'] = str_replace('{$num}', $numdata, $task_type_title);
  516. $task['speed'] = bcdiv($num, $item['number'], 2);
  517. $task['speed'] = bcmul($task['speed'], 100, 0);
  518. $task['new_number'] = $num;
  519. }
  520. } catch (\Exception $e) {
  521. }
  522. break;
  523. }
  524. return [$task['new_number'], $task['speed'], $task['task_type_title'], $task['finish']];
  525. }
  526. /**
  527. * 设置任务完成状态,已被使用
  528. * @param int $level_id 会员id
  529. * @param int $uid 用户id
  530. * @return Boolean
  531. * */
  532. public static function setTarkStatus($level_id, $uid)
  533. {
  534. $taskIds = self::visibleWhere()->where('level_id', $level_id)->column('id', 'id');
  535. if (!count($taskIds)) return true;
  536. return UserTaskFinish::where('uid', $uid)->where('task_id', 'in', $taskIds)->update(['status' => 1]);
  537. }
  538. /**
  539. * 检查当前等级是否完成全部任务
  540. * @param int $level_id 会员id
  541. * @param int $uid 用户uid
  542. * @return boolean
  543. * */
  544. public static function getTaskComplete($level_id, $uid, $isCount = false)
  545. {
  546. $taskIds = self::visibleWhere()->where('level_id', $level_id)->column('id', 'id');
  547. $taskIdsCount = count($taskIds);
  548. //如果当前会员没有任务默认为直接升级为下一等级
  549. if ($taskIdsCount) {
  550. if ($isCount) {
  551. return UserTaskFinish::group('task_id')->where('uid', $uid)->where('task_id', 'in', $taskIds)->count();
  552. } else {
  553. $finishCount = UserTaskFinish::group('task_id')->where('status', $isCount ? 1 : 0)->where('uid', $uid)->where('task_id', 'in', implode(',', $taskIds))->count();
  554. }
  555. //如果当前任务有完成其一的,查询当前完成的任务数量,如果有任务完成则达成当前vip
  556. if (self::visibleWhere()->where('id', 'in', implode(',', $taskIds))->where('is_must', 0)->count() && $finishCount) {
  557. return true;
  558. }
  559. return $finishCount >= $taskIdsCount;
  560. }
  561. if ($isCount) return 0;
  562. //如果没有设置任务当前等级无需购买则返回false
  563. if (SystemUserLevel::be(['id' => $level_id, 'is_pay' => 0])) return false;
  564. return true;
  565. }
  566. /**
  567. * 设置任务内容完成情况
  568. * @param array $task 任务列表
  569. * @param int $uid 用户id
  570. * @热图图呢 array
  571. * */
  572. public static function tidyTask($task, $uid, $is_clear, $startTime)
  573. {
  574. if (!is_array($task)) return $task;
  575. foreach ($task as &$item) {
  576. //如果已完成该任务进度直接为100
  577. if (UserTaskFinish::where('uid', $uid)->where('task_id', $item['id'])->count()) {
  578. $item['new_number'] = $item['number'];
  579. $item['speed'] = 100;
  580. $item['finish'] = 1;
  581. $item['task_type_title'] = '';
  582. } else {
  583. // if($is_clear){
  584. list($new_number, $speed, $task_type_title, $finish) = self::set_task_type($item, $uid, $startTime);
  585. $item['new_number'] = $new_number;
  586. $item['speed'] = $speed;
  587. $item['task_type_title'] = $task_type_title;
  588. $item['finish'] = $finish;
  589. // }else {
  590. // list($new_number, $speed, $task_type_title, $finish) = self::set_task_type($item,-1,time()+86400);
  591. // $item['new_number'] = $new_number;
  592. // $item['speed'] = $speed;
  593. // $item['task_type_title'] = $task_type_title;
  594. // $item['finish'] = $finish;
  595. // }
  596. }
  597. }
  598. return $task;
  599. }
  600. }