VoteSub.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. <?php
  2. namespace app\models\vote;
  3. use app\models\point_plan\UserPointPlan;
  4. use app\models\user\User;
  5. use app\models\user\UserLevel;
  6. use app\models\user\UserMoney;
  7. use app\models\user\UserMoneyOrder;
  8. use crmeb\basic\BaseModel;
  9. use crmeb\services\CacheService;
  10. use crmeb\traits\ModelTrait;
  11. use think\db\exception\DataNotFoundException;
  12. use think\db\exception\DbException;
  13. use think\db\exception\ModelNotFoundException;
  14. use think\Exception;
  15. class VoteSub extends BaseModel
  16. {
  17. /**
  18. * 数据表主键
  19. * @var string
  20. */
  21. protected $pk = 'id';
  22. /**
  23. * 模型名称
  24. * @var string
  25. */
  26. protected $name = 'vote_sub';
  27. use ModelTrait;
  28. /**
  29. * @param bool $doing
  30. * @return VoteSub
  31. */
  32. public static function ing($doing = true)
  33. {
  34. return $doing == false ? self::where('status', 1) : self::where('status', 1)->where('start_time', '<=', time());
  35. }
  36. /**
  37. * @param string $name
  38. * @param mixed $data
  39. * @return bool
  40. */
  41. public static function setC($name, $data, $success = false)
  42. {
  43. CacheService::set($name, $data);
  44. CacheService::set($name . "_success", $success);
  45. return true;
  46. }
  47. /**
  48. * @param $data
  49. * @return bool
  50. * @throws DataNotFoundException
  51. * @throws DbException
  52. * @throws ModelNotFoundException
  53. */
  54. public static function doVote($data)
  55. {
  56. $num = $data['num'] ?? 0;
  57. $id = $data['id'] ?? 0;
  58. $uid = $data['uid'] ?? 0;
  59. $wait_id = $data['wait_id'] ?? '';
  60. if ($uid == 0 || !$wait_id) {
  61. return true;
  62. }
  63. $vote = VoteSub::ing()->where('id', $id)->find();
  64. if (!$vote) {
  65. return self::setC($wait_id, '该投票已结束');
  66. }
  67. $vote_parent = Vote::ing()->where('id', $vote['vote_id'])->find();
  68. if (!$vote_parent) {
  69. return self::setC($wait_id, '该投票已结束');
  70. }
  71. $num = bcadd($num, 0, $vote_parent['money_precision']);
  72. if ($num <= 0) {
  73. return self::setC($wait_id, '请输入大于0的投票数额');
  74. }
  75. if (!$id) {
  76. return self::setC($wait_id, '请选择要参与的投票');
  77. }
  78. $my_money = UserMoney::initialUserMoney($uid, $vote_parent['money_type']);
  79. if ($my_money['money'] < $num) return self::setC($wait_id, $vote_parent['money_type'] . '余额不足');
  80. $vote_sum = UserVote::where('sub_vote_id', $id)->sum('vote_num');
  81. $all_num = bcsub($vote['vote_num'], $vote_sum, $vote_parent['money_precision']);
  82. if ($all_num < $num) return self::setC($wait_id, '本期投票额度不足,最多还可投' . $all_num . $vote_parent['money_type']);
  83. $vote_sum = UserVote::where('uid', $uid)->where('sub_vote_id', $id)->sum('vote_num');
  84. $all_num = bcsub($vote['max_vote_num'], $vote_sum, $vote_parent['money_precision']);
  85. if ($all_num < $num) return self::setC($wait_id, '本期投票额度不足,最多还可投' . $all_num . $vote_parent['money_type']);
  86. //检查手续费
  87. $vote_commission_type = sys_config('vote_commission_type', '');
  88. $vote_commission_ratio = 0;
  89. if ($vote_commission_type) {
  90. $vote_commission_ratio = sys_config('vote_commission_ratio', 0);
  91. }
  92. if ($vote_commission_ratio > 0) {
  93. $need = bcmul(bcdiv($vote_commission_ratio, 100, 4), $num, $vote_parent['money_precision']);
  94. $my_money = UserMoney::initialUserMoney($uid, $vote_commission_type);
  95. if ($need > $my_money) {
  96. return self::setC($wait_id, '手续费' . $vote_commission_type . '余额不足');
  97. }
  98. }
  99. BaseModel::beginTrans();
  100. try {
  101. $res2 = true;
  102. $res1 = UserVote::create(['uid' => $uid, 'sub_vote_id' => $id, 'vote_id' => $vote_parent['id'], 'vote_num' => $num, 'add_time' => time()]);
  103. if (isset($need) && $need > 0)
  104. $res2 = UserMoney::expendMoney($uid, $vote_commission_type, $need, 'join_vote_commission', '参与投票手续费', '参与投票' . $vote_parent['vote_name'] . ' 第' . $vote['loop'] . '期' . $vote['vote_sub_name'] . ' 手续费', $vote_parent['id'], $vote['id']);
  105. $res2 = $res2 && UserMoney::expendMoney($uid, $vote_parent['money_type'], $num, 'join_vote', '参与投票', '参与投票' . $vote_parent['vote_name'] . ' 第' . $vote['loop'] . '期' . $vote['vote_sub_name'], $vote_parent['id'], $vote['id']);
  106. $res6 = User::addAchievement($uid, $num);
  107. $res7 = UserPointPlan::checkPass();
  108. $res4 = self::uperAward($uid, $num, $vote_parent['money_type'], $vote_parent['money_precision']) && self::layerAward($uid, $num, $vote_parent['money_type'], $vote_parent['money_precision']);
  109. // $res4 = true;
  110. $res3 = self::checkVote($id);
  111. // $res3= true;
  112. $res = $res1 && $res2 && $res3 && $res4 && $res6 && $res7;
  113. if ($res) {
  114. BaseModel::commitTrans();
  115. return self::setC($wait_id, '投票成功', true);
  116. } else {
  117. BaseModel::rollbackTrans();
  118. return self::setC($wait_id,
  119. '$res1=' . ($res1 ? 'true' : 'false') .
  120. '$res2=' . ($res2 ? 'true' : 'false') .
  121. '$res3=' . ($res3 ? 'true' : 'false') .
  122. '$res4=' . ($res4 ? 'true' : 'false') . '-----' .
  123. UserVote::getErrorInfo('') . ',' . UserMoney::getErrorInfo('') . ',' . self::getErrorInfo(''));
  124. }
  125. } catch (Exception $e) {
  126. BaseModel::rollbackTrans();
  127. CacheService::set($wait_id, $e->getMessage() . '出现错误');
  128. return false;
  129. }
  130. }
  131. /**
  132. * @param $uid
  133. * @param $num
  134. * @param $money_type
  135. * @param $money_precision
  136. * @return bool
  137. * @throws DataNotFoundException
  138. * @throws DbException
  139. * @throws ModelNotFoundException
  140. */
  141. public static function uperAward($uid, $num, $money_type, $money_precision)
  142. {
  143. $user = User::getUserInfo($uid);
  144. if (!$user['spread_uid']) return true;
  145. $uper = User::getUserInfo($user['spread_uid']);
  146. $vote_recommend_award = sys_data('vote_recommend_award');
  147. $key = array_column($vote_recommend_award, 'spread_num');
  148. array_multisort($key, SORT_DESC, $vote_recommend_award);
  149. $layer = 1;
  150. $res = true;
  151. while ($uper) {
  152. foreach ($vote_recommend_award as $v) {
  153. if ($v['spread_num'] <= $uper['spread_count']) {
  154. if ($layer == $v['award_layer']) {
  155. //发奖
  156. $brokerage = bcmul($num, bcdiv($v['ratio'], 100, 4), $money_precision);
  157. if ($brokerage > 0) {
  158. $res = $res && UserMoney::incomeMoney($uper['uid'], $money_type, $brokerage, 'vote_spread_brokerage', '推荐投票', '下级用户' . $user['nickname'] . '(' . $uid . ')' . '参与投票,获得推荐奖');
  159. }
  160. }
  161. break;
  162. }
  163. }
  164. $uper = User::getUserInfo($uper['spread_uid']);
  165. $layer++;
  166. }
  167. return $res;
  168. }
  169. /**
  170. * @param $uid
  171. * @param $num
  172. * @param $money_type
  173. * @param $money_precision
  174. * @return bool
  175. * @throws DataNotFoundException
  176. * @throws DbException
  177. * @throws ModelNotFoundException
  178. */
  179. public static function layerAward($uid, $num, $money_type, $money_precision)
  180. {
  181. $user = User::getUserInfo($uid);
  182. if (!$user['spread_uid']) return true;
  183. $uper = User::getUserInfo($user['spread_uid']);
  184. $send = 0;
  185. $layer = 1;
  186. $res = true;
  187. while ($uper) {
  188. $uper_level = UserLevel::getUserLevelInfo(UserLevel::getUserLevel($uper['uid']));
  189. $uper_point = UserPointPlan::is_point($uper['uid']);
  190. if ($uper_point) {
  191. if ($uper_point['layer_award_ratio'] > $uper_level['layer_award_ratio'])
  192. $uper_level['layer_award_ratio'] = $uper_point['layer_award_ratio'];
  193. if ($uper_point['layer_award_layer'] > $uper_level['layer_award_layer'])
  194. $uper_level['layer_award_layer'] = $uper_point['layer_award_layer'];
  195. }
  196. if ($uper_level['layer_award_ratio'] > 0 && $uper_level['layer_award_layer'] >= $layer) {
  197. $brokerage = bcmul($num, bcdiv($uper_level['layer_award_ratio'], 100, 4), $money_precision);
  198. if ($brokerage > $send) {
  199. $res = $res && UserMoney::incomeMoney($uper['uid'], $money_type, bcsub($brokerage, $send, $money_precision), 'vote_layer_brokerage', '投票极差奖', '下级用户' . $user['nickname'] . '(' . $uid . ')' . '参与投票,获得级差奖');
  200. $send = $brokerage;
  201. }
  202. }
  203. $uper = User::getUserInfo($uper['spread_uid']);
  204. $layer++;
  205. }
  206. return $res;
  207. }
  208. /**
  209. * @param $id
  210. * @return bool|void
  211. * @throws DataNotFoundException
  212. * @throws DbException
  213. * @throws ModelNotFoundException
  214. */
  215. private static function checkVote($id)
  216. {
  217. $vote = VoteSub::ing()->where('id', $id)->find();
  218. if (!$vote) {
  219. return self::setErrorInfo('该投票已结束');
  220. }
  221. $vote_parent = Vote::ing()->where('id', $vote['vote_id'])->find();
  222. if (!$vote_parent) {
  223. return self::setErrorInfo('该投票已结束');
  224. }
  225. $vote_sum = UserVote::where('sub_vote_id', $id)->sum('vote_num');
  226. if ($vote_sum >= $vote['vote_num']) {
  227. $res = true;
  228. if ($vote['loop'] >= 3) {
  229. //投票成功发放奖金
  230. $send_vote = VoteSub::where('vote_id', $vote_parent['id'])->where('loop', $vote['loop'] - 2)->find();
  231. $list = UserVote::where('vote_id', $send_vote['id'])->where('uid', '<>', 0)->field('uid,SUM(vote_num) as sum')->group('uid')->select();
  232. $back = bcdiv($vote_parent['success_back'] + 100, 100, 4);
  233. foreach ($list as $v) {
  234. $money = bcmul($v['sum'], $back, $vote_parent['money_precision']);
  235. $res = $res && UserMoney::incomeMoney($v['uid'], $vote_parent['money_type'], $money, 'vote_success', '投票完成', '投票' . $vote_parent['vote_name'] . ' 第' . $vote['loop'] . '期' . $vote['vote_sub_name'] . ' 完成,返还第' . $send_vote['loop'] . '期' . $send_vote['vote_sub_name'] . '投票收益', $vote_parent['id'], $vote['id']);
  236. }
  237. VoteSub::where('id', $send_vote['id'])->update(['status' => 4, 'finish_time' => time()]);
  238. }
  239. $res = $res && VoteSub::where('id', $id)->update(['status' => 2, 'success_time' => time()]);
  240. // $vote->status = 2;
  241. // $vote->success_time = time();
  242. // $res = $res && $vote->save();
  243. //开启下一期(默认生成为第二天早上10点开始)
  244. if (!VoteSub::where('loop', $vote['loop'] + 1)->where('vote_id', $vote_parent['id'])->find()) {
  245. $vote_up = bcdiv($vote_parent['step_vote_num'] + 100, 100, 4);
  246. $vote_all = bcpow($vote_up, $vote['loop'], 100);
  247. $vote_all_now = bcmul($vote_all, $vote_parent['start_vote_num'], $vote_parent['money_precision']);
  248. $vote_user_max = bcadd($vote_parent['start_max_vote_num'], bcmul($vote_parent['step_max_vote_num'], $vote['loop'], $vote_parent['money_precision']), $vote_parent['money_precision']);
  249. $create = [
  250. 'vote_sub_name' => $vote_parent['vote_name'] . '第' . $vote['loop'] . '期',
  251. 'vote_id' => $vote_parent['id'],
  252. 'vote_num' => $vote_all_now,
  253. 'max_vote_num' => $vote_user_max,
  254. 'start_time' => strtotime(date('Y-m-d', strtotime('+1day')) . ' ' . $vote_parent['day_start']),
  255. 'end_time' => bcadd(strtotime(date('Y-m-d', strtotime('+1day')) . ' ' . $vote_parent['day_start']), bcadd($vote_parent['start_still_time'], bcmul($vote_parent['start_still_time'], $vote['loop'])) * 3600),
  256. 'loop' => $vote['loop'] + 1,
  257. 'status' => 1,
  258. 'add_time' => time(),
  259. ];
  260. $res = $res && VoteSub::create($create);
  261. }
  262. return $res;
  263. }
  264. return true;
  265. }
  266. /**
  267. * //自动结束
  268. * @throws DataNotFoundException
  269. * @throws DbException
  270. * @throws ModelNotFoundException
  271. */
  272. public static function checkAllStop()
  273. {
  274. $votes = VoteSub::ing()->where('end_time', '<=', time())->select();
  275. $res = true;
  276. foreach ($votes as $vote) {
  277. $vote_parent = Vote::ing()->where('id', $vote['vote_id'])->find();
  278. $res = VoteSub::where('id', $vote['id'])->update(['status' => 3, 'finish_time' => time()]);
  279. $list = UserVote::where('sub_vote_id', $vote['id'])->where('uid', '<>', 0)->field('uid,SUM(vote_num) as sum')->group('uid')->select();
  280. $back = bcdiv($vote_parent['fail_back_now'], 100, 4);
  281. //倒叙
  282. $vote_end_brokerage = sys_config('vote_end_brokerage', 0);
  283. $money_all = UserVote::where('vote_id', $vote['vote_id'])->sum('vote_num');
  284. $vote_end_brokerage = bcmul($money_all, bcdiv($vote_end_brokerage, 100, 4), $vote_parent['money_precision']);
  285. $last_vote_all = UserVote::where('sub_vote_id', $vote['id'])->sum('vote_num');
  286. //----
  287. foreach ($list as $v) {
  288. $money = bcmul($v['sum'], $back, $vote['money_precision']);
  289. $left_money = bcsub($v['sum'], $money, $vote_parent['money_precision']);
  290. $res = $res && UserMoney::incomeMoney($v['uid'], $vote_parent['money_type'], $money, 'vote_fail', '投票失败', '投票' . $vote_parent['vote_name'] . ' 第' . $vote['loop'] . '期' . $vote['vote_sub_name'] . ' 失败,返还第' . $vote['loop'] . '期' . $vote['vote_sub_name'] . '投票金额', $vote_parent['id'], $vote['id']);
  291. if ($left_money > 0 && $vote_parent['other_back_money_type'])
  292. $res = $res && UserMoney::incomeMoney($v['uid'], $vote_parent['other_back_money_type'], $left_money, 'vote_fail', '投票失败', '投票' . $vote_parent['vote_name'] . ' 第' . $vote['loop'] . '期' . $vote['vote_sub_name'] . ' 失败,返还第' . $vote['loop'] . '期' . $vote['vote_sub_name'] . '部分投票金额' . $vote_parent['other_back_money_type'], $vote_parent['id'], $vote['id']);
  293. //倒叙
  294. if ($vote_end_brokerage > 0) {
  295. //加权值
  296. $single_money = bcmul(bcdiv($v['sum'], $last_vote_all, 4), $vote_end_brokerage, $vote_parent['money_precision']);
  297. if ($single_money > 0) {
  298. $res = $res && UserMoney::incomeMoney($v['uid'], $vote_parent['money_type'], $single_money, 'vote_end_brokerage', '投票倒叙分红', '投票' . $vote_parent['vote_name'] . ' 第' . $vote['loop'] . '期' . $vote['vote_sub_name'] . ' 失败,投票结束,获得倒叙分红', $vote_parent['id'], $vote['id']);
  299. }
  300. }
  301. //------
  302. }
  303. $send_vote_1 = VoteSub::where('vote_id', $vote_parent['id'])->where('loop', $vote['loop'] - 1)->find();
  304. if ($send_vote_1) {
  305. $list = UserVote::where('sub_vote_id', $send_vote_1['id'])->where('uid', '<>', 0)->field('uid,SUM(vote_num) as sum')->group('uid')->select();
  306. $back = bcdiv($vote_parent['fail_back_last'], 100, 4);
  307. foreach ($list as $v) {
  308. $money = bcmul($v['sum'], $back, $vote['money_precision']);
  309. $left_money = bcsub($v['sum'], $money, $vote_parent['money_precision']);
  310. $res = $res && UserMoney::incomeMoney($v['uid'], $vote_parent['money_type'], $money, 'vote_fail', '投票失败', '投票' . $vote_parent['vote_name'] . ' 第' . $vote['loop'] . '期' . $vote['vote_sub_name'] . ' 失败,返还第' . ($vote['loop'] - 1) . '期' . $send_vote_1['vote_sub_name'] . '部分投票金额', $vote_parent['id'], $vote['id']);
  311. if ($left_money > 0)
  312. $res = $res && UserMoney::incomeMoney($v['uid'], $vote_parent['other_back_money_type'], $left_money, 'vote_fail', '投票失败', '投票' . $vote_parent['vote_name'] . ' 第' . $vote['loop'] . '期' . $vote['vote_sub_name'] . ' 失败,返还第' . ($vote['loop'] - 1) . '期' . $send_vote_1['vote_sub_name'] . '部分投票金额' . $vote_parent['other_back_money_type'], $vote_parent['id'], $vote['id']);
  313. }
  314. }
  315. $res = VoteSub::where('id', $send_vote_1['id'])->update(['status' => 3, 'finish_time' => time()]);
  316. $send_vote_2 = VoteSub::where('vote_id', $vote_parent['id'])->where('loop', $vote['loop'] - 2)->find();
  317. if ($send_vote_2) {
  318. $list = UserVote::where('sub_vote_id', $send_vote_2['id'])->where('uid', '<>', 0)->field('uid,SUM(vote_num) as sum')->group('uid')->select();
  319. $back = bcdiv($vote_parent['fail_back_before_last'], 100, 4);
  320. foreach ($list as $v) {
  321. $money = bcmul($v['sum'], $back, $vote['money_precision']);
  322. $left_money = bcsub($v['sum'], $money, $vote_parent['money_precision']);
  323. $res = $res && UserMoney::incomeMoney($v['uid'], $vote_parent['money_type'], $money, 'vote_fail', '投票失败', '投票' . $vote_parent['vote_name'] . ' 第' . $vote['loop'] . '期' . $vote['vote_sub_name'] . ' 失败,返还第' . ($vote['loop'] - 2) . '期' . $send_vote_2['vote_sub_name'] . '部分投票金额', $vote_parent['id'], $vote['id']);
  324. if ($left_money > 0)
  325. $res = $res && UserMoney::incomeMoney($v['uid'], $vote_parent['other_back_money_type'], $left_money, 'vote_fail', '投票失败', '投票' . $vote_parent['vote_name'] . ' 第' . $vote['loop'] . '期' . $vote['vote_sub_name'] . ' 失败,返还第' . ($vote['loop'] - 2) . '期' . $send_vote_2['vote_sub_name'] . '部分投票金额' . $vote_parent['other_back_money_type'], $vote_parent['id'], $vote['id']);
  326. }
  327. }
  328. $res = VoteSub::where('id', $send_vote_2['id'])->update(['status' => 3, 'finish_time' => time()]);
  329. //节点奖励
  330. $point_award = sys_config('point_ratio', 0);
  331. if ($point_award > 0) {
  332. $vote_point_brokerage = bcmul($money_all, bcdiv($point_award, 100, 4), $vote_parent['money_precision']);
  333. $all_point = UserPointPlan::all_point();
  334. if (count($all_point) > 0) {
  335. $single_get = bcdiv($vote_point_brokerage, count($all_point), $vote_parent['money_precision']);
  336. if ($single_get > 0) {
  337. foreach ($all_point as $v) {
  338. $res = $res && UserMoney::incomeMoney($v['uid'], $vote_parent['money_type'], $single_get, 'vote_point_brokerage', '投票节点分红', '投票' . $vote_parent['vote_name'] . ' 第' . $vote['loop'] . '期' . $vote['vote_sub_name'] . ' 失败,投票结束,获得节点分红', $vote_parent['id'], $vote['id']);
  339. }
  340. }
  341. }
  342. }
  343. $vote_parent->status = 2;
  344. $res = $res && $vote_parent->save();
  345. }
  346. return $res;
  347. }
  348. /**
  349. * //机器人
  350. * @throws DataNotFoundException
  351. * @throws DbException
  352. * @throws ModelNotFoundException
  353. */
  354. public static function robotOrder()
  355. {
  356. $robots = Robot::ing()->select();
  357. $res = true;
  358. foreach ($robots as $robot) {
  359. //查询机器人负责的投票情况
  360. $vote = VoteSub::ing()->where('id', $robot['sub_vote_id'])->find();
  361. if (!$vote) {
  362. $res = $res && Robot::where('id', $robot['id'])->update(['status' => 2]);
  363. continue;
  364. }
  365. $last = UserVote::where('uid', 0)->where('sub_vote_id', $vote['id'])->order('add_time', 'desc')->find();
  366. if ($last && ($last['add_time'] + $robot['step_time'] * 60 > time())) {
  367. continue;
  368. }
  369. $vote_parent = Vote::ing()->where('id', $vote['vote_id'])->find();
  370. $all_num = UserVote::where('sub_vote_id', $vote['id'])->sum('vote_num');
  371. //缺值
  372. $need = bcsub($vote['vote_num'], $all_num, $vote_parent['money_precision']);
  373. //机器人本次投值
  374. $post = bcadd($robot['start_num'], bcmul(UserVote::where('uid', 0)->where('sub_vote_id', $vote['id'])->count(), $robot['step_num'], $vote_parent['money_precision']), $vote_parent['money_precision']);
  375. $post = $need < $post ? $need : $post;
  376. $res = $res && UserVote::create(['uid' => 0, 'sub_vote_id' => $vote['id'], 'vote_id' => $vote_parent['id'], 'vote_num' => $post, 'add_time' => time()]);
  377. $res = $res && self::checkVote($vote['id']);
  378. }
  379. return $res;
  380. }
  381. /**
  382. * @param $where
  383. * @return array
  384. */
  385. public static function getList($where)
  386. {
  387. $model = new self();
  388. if (isset($where['id']) && $where['id']) $model = $model->where('vote_id', $where['id']);
  389. $count = $model->count();
  390. $data = $model->page((int)$where['page'], (int)$where['limit'])->select()->each(function ($item) {
  391. switch ($item['status']) {
  392. case 1:
  393. $item['_status'] = '进行中';
  394. break;
  395. case 2:
  396. $item['_status'] = '投票成功';
  397. break;
  398. case 3:
  399. $item['_status'] = '投票失败';
  400. break;
  401. case 0:
  402. $item['_status'] = '未开始';
  403. break;
  404. default:
  405. $item['_status'] = '未知';
  406. break;
  407. }
  408. $item['_start_time'] = date('Y-m-d H:i:s', $item['start_time']);
  409. $item['_end_time'] = date('Y-m-d H:i:s', $item['end_time']);
  410. $item['_add_time'] = date('Y-m-d H:i:s', $item['add_time']);
  411. $item['now_vote_num'] = UserVote::where('sub_vote_id', $item['id'])->sum('vote_num');
  412. });
  413. return compact('count', 'data');
  414. }
  415. }