UserPartakeController.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. namespace app\api\controller\user;
  3. use app\admin\model\order\StoreOrder;
  4. use app\models\system\SystemGroupData;
  5. use app\models\user\Out;
  6. use app\models\user\User;
  7. use app\models\user\UserPartake;
  8. use app\Request;
  9. use crmeb\services\GroupDataService;
  10. use crmeb\services\SystemConfigService;
  11. use crmeb\services\UtilService;
  12. use think\facade\Db;
  13. class UserPartakeController
  14. {
  15. /**
  16. * 出局奖励列表
  17. * @return void
  18. */
  19. public function out_list(Request $request)
  20. {
  21. [$page, $limit] = UtilService::getMore([['page', 1], ['limit', 10]], $request, true);
  22. $list = Out::where('status', 1)->where($page, $limit)->order('id DESC')->select()->toArray();
  23. return app('json')->success($list);
  24. }
  25. /**
  26. * 出局奖励列表
  27. * @return void
  28. */
  29. public function out_detail($id, Request $request)
  30. {
  31. $list = Out::where('status', 1)->where('id', $id)->order('id DESC')->find();
  32. $partake = UserPartake::where('uid', $request->uid())->where('status', 0)->find();
  33. $list['partake'] = $partake;
  34. $list = $list ? $list->toArray() : [];
  35. return app('json')->success($list);
  36. }
  37. /**
  38. * 参加
  39. * @return void
  40. */
  41. public function participate_in(Request $request)
  42. {
  43. $data = UtilService::postMore([
  44. 'out_id'
  45. ]);
  46. Db::startTrans();
  47. $user = User::where('uid', $request->uid())->find();
  48. if ($user['level'] < 2) return app('json')->fail('等级为团队合伙人才能参与');
  49. $out = Out::where('id', $data['out_id'])->find();
  50. if (empty($out)) return app('json')->fail('参与项目不存在');
  51. if ($out['status'] == 0) return app('json')->fail('参与项目已关闭');
  52. $partake = UserPartake::where('uid', $request->uid())->where('status', 0)->find();
  53. if ($partake) return app('json')->fail('当前已有参与中项目,无法参加');
  54. $res = UserPartake::create([
  55. 'uid' => $request->uid(),
  56. 'out_id' => $data['out_id'],
  57. ]);
  58. if ($res) {
  59. Db::commit();
  60. return app('json')->success('参与成功');
  61. } else {
  62. Db::rollback();
  63. return app('json')->fail('参与失败');
  64. }
  65. }
  66. /**
  67. * 参与记录
  68. * @param Request $request
  69. * @return mixed
  70. * @throws \think\db\exception\DataNotFoundException
  71. * @throws \think\db\exception\DbException
  72. * @throws \think\db\exception\ModelNotFoundException
  73. */
  74. public function partake(Request $request)
  75. {
  76. $where = UtilService::getMore([
  77. ['page', 1],
  78. ['limit', 20],
  79. ]);
  80. $data = UserPartake::alias('a')
  81. ->field('a.*,c.name,c.number')
  82. ->order('a.id DESC')
  83. ->leftJoin('out c', 'c.id = a.out_id')
  84. ->where('uid', $request->uid())
  85. ->page($where['page'], $where['limit'])
  86. ->select();
  87. $data = count($data) ? $data->toArray() : [];
  88. foreach ($data as &$item) {
  89. if ($item['money'] == 0) {
  90. $item['money'] = User::where('uid', $item['uid'])->find()['pay_price'];
  91. }
  92. }
  93. return app('json')->success($data);
  94. }
  95. public function user_push_list(Request $request)
  96. {
  97. $where = UtilService::getMore([
  98. ['page', 1],
  99. ['limit', 20],
  100. ['uid'],
  101. ['spread_uid']
  102. ]);
  103. $where['spread_uid'] = $request->uid();
  104. $data = StoreOrder::list($where);
  105. return app('json')->success($data);
  106. }
  107. }