SystemUserTask.php 25 KB

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