SystemUserTask.php 25 KB

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