SystemUserTask.php 24 KB

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