SystemUserTask.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  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) {
  241. $isComplete = UserTaskFinish::setFinish($uid, $task_id) ? true : false;
  242. $order = StoreOrder::where('paid', 1)
  243. ->where('refund_status', 0)
  244. ->where('is_del', 0)
  245. ->where('uid', $uid)
  246. ->where('add_time', '>', $start_time)
  247. ->order('add_time', 'desc')
  248. ->find();
  249. $order->over = $count - $number;
  250. $order->save();
  251. }
  252. return ['还需购买升级商品{$num}台', 0, $isComplete];
  253. }
  254. /**
  255. * 累计消费次数
  256. * @param int $task_id 任务id
  257. * @param int $uid 用户id
  258. * @param int $start_time 开始时间
  259. * @param int $number 限定时间
  260. * @return boolean
  261. * */
  262. public static function ConsumptionFrequency($task_id, $uid = 0, $start_time = 0, $number = 0)
  263. {
  264. $isComplete = false;
  265. $countPay = StoreOrder::where('paid', 1)->where('refund_status', 0)->where('is_del', 0)->where('uid', $uid)->where('add_time', '>', $start_time)->count();
  266. if ($countPay >= $number) $isComplete = UserTaskFinish::setFinish($uid, $task_id) ? true : false;
  267. return ['还需消费{$num}次', $countPay, $isComplete];
  268. }
  269. /**
  270. * 邀请好友成为会员
  271. * @param int $task_id 任务id
  272. * @param int $uid 用户id
  273. * @param int $start_time 开始时间
  274. * @param int $number 限定时间
  275. * @return boolean
  276. * */
  277. public static function InviteGoodFriendsLevel($task_id, $uid = 0, $start_time = 0, $number = 0)
  278. {
  279. $isComplete = false;
  280. $uids = User::where('spread_uid', $uid)->where('spread_time', '>', $start_time)->column('uid', 'uid');
  281. $levelCount = count($uids) ? UserLevel::setUserLevelCount($uids) : 0;
  282. if ($levelCount >= $number) $isComplete = UserTaskFinish::setFinish($uid, $task_id) ? true : false;
  283. return ['还需邀请{$num}人成为会员', $levelCount, $isComplete];
  284. }
  285. /**
  286. * 团队人数
  287. * @param int $task_id 任务id
  288. * @param int $uid 用户id
  289. * @param int $start_time 开始时间
  290. * @param int $number 限定时间
  291. * @return boolean
  292. * */
  293. public static function GroupNum($task_id, $uid = 0, $start_time = 0, $number = 0)
  294. {
  295. $isComplete = false;
  296. $uids = [$uid];
  297. $all = [];
  298. while ($uids) {
  299. $uids = User::where('spread_uid', 'in', $uids)->column('uid');
  300. $all = array_merge($all, $uids);
  301. }
  302. $levelCount = count($all);
  303. if ($levelCount >= $number) $isComplete = UserTaskFinish::setFinish($uid, $task_id) ? true : false;
  304. return ['还需邀请{$num}人加入团队', $levelCount, $isComplete];
  305. }
  306. /**
  307. * 小区团队人数
  308. * @param int $task_id 任务id
  309. * @param int $uid 用户id
  310. * @param int $start_time 开始时间
  311. * @param int $number 限定时间
  312. * @return boolean
  313. * */
  314. public static function OtherGroupNum($task_id, $uid = 0, $start_time = 0, $number = 0)
  315. {
  316. $isComplete = false;
  317. $sub_uids = User::where('spread_uid', $uid)->column('uid');
  318. $max = 0;
  319. $all = 0;
  320. foreach ($sub_uids as $v) {
  321. $uids = [$v];
  322. $all_uids = [];
  323. while ($uids) {
  324. $uids = User::where('spread_uid', 'in', $uids)->column('uid');
  325. $all_uids = array_merge($all_uids, $uids);
  326. }
  327. if (count($all_uids) > $max) $max = count($all_uids);
  328. $all += count($all_uids);
  329. }
  330. $levelCount = $all - $max;
  331. if ($levelCount >= $number) $isComplete = UserTaskFinish::setFinish($uid, $task_id) ? true : false;
  332. return ['还需邀请{$num}人加入团队小区', $levelCount, $isComplete];
  333. }
  334. /**
  335. * 团队业绩
  336. * @param int $task_id 任务id
  337. * @param int $uid 用户id
  338. * @param int $start_time 开始时间
  339. * @param int $number 限定时间
  340. * @return boolean
  341. * */
  342. public static function OtherAchievement($task_id, $uid = 0, $start_time = 0, $number = 0)
  343. {
  344. $isComplete = false;
  345. $sub_uids = User::where('spread_uid', $uid)->column('uid');
  346. $max = 0;
  347. $all = 0;
  348. foreach ($sub_uids as $v) {
  349. $uids = [$v];
  350. $all_uids = [$v];
  351. while ($uids) {
  352. $uids = User::where('spread_uid', 'in', $uids)->column('uid');
  353. $all_uids = array_merge($all_uids, $uids);
  354. }
  355. // $achievement = LalaPinkJoin::where('paid', 1)
  356. // ->where('uid', '<>', 0)
  357. // ->where('status', 'in', [1, 2])
  358. // ->where('uid', 'in', $all_uids)
  359. // ->where('cost_money_type', 'USDT')
  360. // ->sum('cost');
  361. $achievement = StoreOrder::where('paid', 1)
  362. ->where('refund_status', 0)
  363. ->where('is_del', 0)
  364. ->where('uid', 'in', $all_uids)
  365. ->where('add_time', '>', $start_time)
  366. ->sum('pay_price');
  367. if ($achievement > $max) $max = $achievement;
  368. $all += $achievement;
  369. }
  370. $levelCount = $all - $max;
  371. if ($levelCount >= $number) $isComplete = UserTaskFinish::setFinish($uid, $task_id) ? true : false;
  372. return ['还需{$num}U业绩', $levelCount, $isComplete];
  373. }
  374. /**
  375. * 团队业绩
  376. * @param int $task_id 任务id
  377. * @param int $uid 用户id
  378. * @param int $start_time 开始时间
  379. * @param int $number 限定时间
  380. * @return boolean
  381. * */
  382. public static function Achievement($task_id, $uid = 0, $start_time = 0, $number = 0)
  383. {
  384. $isComplete = false;
  385. $uids = [$uid];
  386. $all = [];
  387. while ($uids) {
  388. $uids = User::where('spread_uid', 'in', $uids)->column('uid');
  389. $all = array_merge($all, $uids);
  390. }
  391. // $levelCount = LalaPinkJoin::where('paid', 1)
  392. // ->where('uid', '<>', 0)
  393. // ->where('status', 'in', [1, 2])
  394. // ->where('uid', 'in', $all)
  395. // ->where('cost_money_type', 'USDT')
  396. // ->sum('cost');
  397. $levelCount = StoreOrder::where('paid', 1)
  398. ->where('refund_status', 0)
  399. ->where('is_del', 0)
  400. ->where('uid', 'in', $all)
  401. ->where('add_time', '>', $start_time)
  402. ->sum('pay_price');
  403. if ($levelCount >= $number) $isComplete = UserTaskFinish::setFinish($uid, $task_id) ? true : false;
  404. return ['还需{$num}U业绩', $levelCount, $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 RecommendAchievement($task_id, $uid = 0, $start_time = 0, $number = 0)
  415. {
  416. $isComplete = false;
  417. $uids = User::where('spread_uid', $uid)->column('uid');
  418. // $levelCount = LalaPinkJoin::where('paid', 1)->where('uid', '<>', 0)->where('status', 'in', [1, 2])->where('uid', 'in', $uids)->where('cost_money_type', 'USDT')->sum('cost');
  419. $levelCount = StoreOrder::where('paid', 1)
  420. ->where('refund_status', 0)
  421. ->where('is_del', 0)
  422. ->where('uid', 'in', $uids)
  423. ->where('add_time', '>', $start_time)
  424. ->sum('pay_price');
  425. if ($levelCount >= $number) $isComplete = UserTaskFinish::setFinish($uid, $task_id) ? true : false;
  426. return ['还需{$num}U业绩', $levelCount, $isComplete];
  427. }
  428. /**
  429. * 邀请好友成为下线
  430. * @param int $task_id 任务id
  431. * @param int $uid 用户id
  432. * @param int $start_time 查询开始时间
  433. * @param int $number 限定数量
  434. * */
  435. public static function InviteGoodFriends($task_id, $uid = 0, $start_time = 0, $number = 0)
  436. {
  437. $isComplete = false;
  438. $spreadCount = User::where('spread_uid', $uid)->where('spread_time', '>', $start_time)->count();
  439. if ($spreadCount >= $number) $isComplete = UserTaskFinish::setFinish($uid, $task_id) ? true : false;
  440. return ['还需邀请{$num}人成为下线', $spreadCount, $isComplete];
  441. }
  442. /**
  443. * 满足积分
  444. * @param int $task_id 任务id
  445. * @param int $uid 用户id
  446. * @param int $start_time 查询开始时间
  447. * @param int $number 限定数量
  448. * @return Boolean
  449. * */
  450. public static function SatisfactionIntegral($task_id, $uid = 0, $start_time = 0, $number = 0)
  451. {
  452. $isComplete = false;
  453. $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');
  454. if ($sumNumber >= $number) $isComplete = UserTaskFinish::setFinish($uid, $task_id) ? true : false;
  455. return ['还需要{$num}经验', $sumNumber, $isComplete];
  456. }
  457. /**
  458. * 分享给朋友次数完成情况
  459. * @param int $task_id 任务id
  460. * @param int $uid 用户id
  461. * @param int $start_time 查询开始时间
  462. * @param int $number 限定数量
  463. * @return Boolean
  464. * */
  465. public static function SharingTimes($task_id, $uid = 0, $start_time = 0, $number = 0)
  466. {
  467. $isComplete = false;
  468. $sumCount = UserBill::where('uid', $uid)->where('category', 'share')->where('pm', 1)->where('add_time', '>', $start_time)->where('type', 'share')->count();
  469. if ($sumCount >= $number) $isComplete = UserTaskFinish::setFinish($uid, $task_id) ? true : false;
  470. return ['还需分享{$num}次', $sumCount, $isComplete];
  471. }
  472. /**
  473. * 累计签到
  474. * @param int $task_id 任务id
  475. * @param int $uid 用户id
  476. * @param int $start_time 查询开始时间
  477. * @param int $number 限定数量
  478. * @return Boolean
  479. * */
  480. public static function CumulativeAttendance($task_id, $uid = 0, $start_time = 0, $number = 0)
  481. {
  482. $isComplete = false;
  483. $sumCount = UserBill::where('uid', $uid)->where('category', 'integral')->where('pm', 1)->where('add_time', '>', $start_time)->where('type', 'sign')->count();
  484. if ($sumCount >= $number) $isComplete = UserTaskFinish::setFinish($uid, $task_id) ? true : false;
  485. return ['还需签到{$num}天', $sumCount, $isComplete];
  486. }
  487. /**
  488. * 设置任务完成情况
  489. * @param int $task_id 任务id
  490. * @param int $uid 用户uid
  491. * @param int $start_time 查询开始时间
  492. * @return Boolean
  493. * */
  494. public static function setTaskFinish($task_id = 0, $uid = 0, $start_time = 0)
  495. {
  496. if (!$task_id) return self::setErrorInfo('缺少任务id参数');
  497. if (!$uid) return self::setErrorInfo('缺少用户uid');
  498. $task = self::where('id', $task_id)->where('is_show', 1)->find();
  499. if (!$task) return self::setErrorInfo('任务不存在');
  500. $task_type = $task->task_type;
  501. if ($task_type && method_exists(self::class, $task_type)) {
  502. try {
  503. $start_time = User::getCleanTime($uid);
  504. return self::$task_type($task_id, $uid, $start_time, $task->number);
  505. } catch (\Exception $e) {
  506. return self::setErrorInfo($e->getMessage());
  507. }
  508. }
  509. return self::setErrorInfo('没有此任务');
  510. }
  511. /**
  512. * 设置任务显示条件
  513. * @param string $alert 表别名
  514. * @param object $model 模型实例
  515. * @return object
  516. * */
  517. public static function visibleWhere($alert = '', $model = null)
  518. {
  519. $model = $model === null ? new self() : $model;
  520. if ($alert) $model = $model->alias($alert);
  521. $alert = $alert ? $alert . '.' : '';
  522. return $model->where("{$alert}is_show", 1);
  523. }
  524. /**
  525. * 获取等级会员任务列表
  526. * @param int $level_id 会员等级id
  527. * @param int $uid 用户id
  528. * @param null $level
  529. * @param int $expire
  530. * @return array
  531. * @throws DataNotFoundException
  532. * @throws DbException
  533. * @throws ModelNotFoundException
  534. */
  535. public static function getTashList($level_id, $uid = 0, $level = null, $expire = 1400)
  536. {
  537. $level_id = is_string($level_id) ? (int)$level_id : $level_id;
  538. $list = self::visibleWhere()->where('level_id', $level_id)->field('name,real_name,task_type,illustrate,number,id')->order('sort desc')->select();
  539. $list = count($list) ? $list->toArray() : [];
  540. if ($uid == 0) return $list;
  541. if ($level === null) $level = SystemUserLevel::getLevelInfo($uid);
  542. //获取下一个vip的id
  543. $LeveId = SystemUserLevel::getNextLevelId($level['id'], SystemUserLevel::setWhere()->where('grade', '>', $level ? $level['grade'] : 0)->min('grade'));
  544. $is_clear = SystemUserLevel::getClear($level['id']);
  545. if ($is_clear == false && $LeveId == $level_id) $is_clear = true;
  546. $reach_count = self::getTaskComplete($level_id, $uid, true);
  547. return [
  548. 'list' => $list,
  549. 'reach_count' => $reach_count,
  550. 'task' => self::tidyTask($list, $uid, $is_clear, User::getCleanTime($uid)),
  551. ];
  552. }
  553. /**
  554. * 获取未完成任务的详细值
  555. * @param array $item 任务
  556. * @param int $uid 用户id
  557. * @param int $startTime 开始时间
  558. * @return array
  559. * */
  560. protected static function set_task_type($item, $uid, $startTime = 0)
  561. {
  562. $task = ['task_type_title' => '', 'new_number' => 0, 'speed' => 0, 'finish' => 0];
  563. $task_type = $item['task_type'];
  564. switch ($task_type) {
  565. case 'SatisfactionIntegral':
  566. case 'ConsumptionAmount':
  567. case 'ConsumptionFrequency':
  568. case 'CumulativeAttendance':
  569. case 'SharingTimes':
  570. case 'InviteGoodFriends':
  571. case 'InviteGoodFriendsLevel':
  572. try {
  573. list($task_type_title, $num, $isComplete) = self::$task_type($item['id'], $uid, $startTime, $item['number']);
  574. if ($isComplete) {
  575. $task['finish'] = 1;
  576. $task['speed'] = 100;
  577. $task['speed'] = $item['number'];
  578. $task['new_number'] = $item['number'];
  579. } else {
  580. $numdata = bcsub($item['number'], $num, 0);
  581. $task['task_type_title'] = str_replace('{$num}', $numdata, $task_type_title);
  582. $task['speed'] = bcdiv($num, $item['number'], 2);
  583. $task['speed'] = bcmul($task['speed'], 100, 0);
  584. $task['new_number'] = $num;
  585. }
  586. } catch (\Exception $e) {
  587. }
  588. break;
  589. }
  590. return [$task['new_number'], $task['speed'], $task['task_type_title'], $task['finish']];
  591. }
  592. /**
  593. * 设置任务完成状态,已被使用
  594. * @param int $level_id 会员id
  595. * @param int $uid 用户id
  596. * @return Boolean
  597. * */
  598. public static function setTarkStatus($level_id, $uid)
  599. {
  600. $taskIds = self::visibleWhere()->where('level_id', $level_id)->column('id', 'id');
  601. if (!count($taskIds)) return true;
  602. return UserTaskFinish::where('uid', $uid)->where('task_id', 'in', $taskIds)->update(['status' => 1]);
  603. }
  604. /**
  605. * 检查当前等级是否完成全部任务
  606. * @param int $level_id 会员id
  607. * @param int $uid 用户uid
  608. * @return boolean
  609. * */
  610. public static function getTaskComplete($level_id, $uid, $isCount = false)
  611. {
  612. $taskIds = self::visibleWhere()->where('level_id', $level_id)->column('id', 'id');
  613. $taskIdsCount = count($taskIds);
  614. //如果当前会员没有任务默认为直接升级为下一等级
  615. if ($taskIdsCount) {
  616. if ($isCount) {
  617. return UserTaskFinish::group('task_id')->where('uid', $uid)->where('task_id', 'in', $taskIds)->count();
  618. } else {
  619. $finishCount = UserTaskFinish::group('task_id')->where('status', $isCount ? 1 : 0)->where('uid', $uid)->where('task_id', 'in', implode(',', $taskIds))->count();
  620. }
  621. //如果当前任务有完成其一的,查询当前完成的任务数量,如果有任务完成则达成当前vip
  622. if (self::visibleWhere()->where('id', 'in', implode(',', $taskIds))->where('is_must', 0)->count() && $finishCount) {
  623. return true;
  624. }
  625. return $finishCount >= $taskIdsCount;
  626. }
  627. if ($isCount) return 0;
  628. //如果没有设置任务当前等级无需购买则返回false
  629. if (SystemUserLevel::be(['id' => $level_id, 'is_pay' => 0])) return false;
  630. return true;
  631. }
  632. /**
  633. * 设置任务内容完成情况
  634. * @param array $task 任务列表
  635. * @param int $uid 用户id
  636. * @热图图呢 array
  637. * */
  638. public static function tidyTask($task, $uid, $is_clear, $startTime)
  639. {
  640. if (!is_array($task)) return $task;
  641. foreach ($task as &$item) {
  642. //如果已完成该任务进度直接为100
  643. if (UserTaskFinish::where('uid', $uid)->where('task_id', $item['id'])->count()) {
  644. $item['new_number'] = $item['number'];
  645. $item['speed'] = 100;
  646. $item['finish'] = 1;
  647. $item['task_type_title'] = '';
  648. } else {
  649. // if($is_clear){
  650. list($new_number, $speed, $task_type_title, $finish) = self::set_task_type($item, $uid, $startTime);
  651. $item['new_number'] = $new_number;
  652. $item['speed'] = $speed;
  653. $item['task_type_title'] = $task_type_title;
  654. $item['finish'] = $finish;
  655. // }else {
  656. // list($new_number, $speed, $task_type_title, $finish) = self::set_task_type($item,-1,time()+86400);
  657. // $item['new_number'] = $new_number;
  658. // $item['speed'] = $speed;
  659. // $item['task_type_title'] = $task_type_title;
  660. // $item['finish'] = $finish;
  661. // }
  662. }
  663. }
  664. return $task;
  665. }
  666. }