uid(); $list = \app\models\many\ManyGreen::list($where); return app('json')->success($list); } /** * 兑换绿卡 * @param Request $request * @param $num * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function exchange(Request $request, $num) { if ($num < 1) return app('json')->fail('传入需要兑换数量'); if (CacheService::get($request->uid())) return app('json')->fail('操作太快'); $user = User::where('uid', $request->uid())->find(); $money = $num * SystemConfig::getConfigValue('green'); if ($user['green_integral'] < $money) return app('json')->fail('水滴不足'); $user['green_integral'] -= $money; Db::startTrans(); try { for ($i = 1; $i <= (int)$num; $i++){ ManyGreen::create(['uid' => $request->uid(), 'type' => 1]); } $user->save(); UserBill::income('兑换洒水壶',$request->uid(), 'green_integral', 'exchange', $money, 0,$user['green_integral'], '兑换'.$num.'个洒水壶'); CacheService::set($request->uid(), 1, 3); Db::commit(); return app('json')->success('兑换成功'); } catch (\Exception $e) { Db::rollback(); return app('json')->fail($e->getMessage()); } } /** * 赠送绿卡 * @param Request $request * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function give(Request $request) { $data = UtilService::postMore([ ['id'], ['uid'] ]); if (empty($data['uid'])) return app('json')->fail('填写赠送用户ID'); $user = User::where('uid', $data['uid'])->find(); $green = ManyGreen::where('id', $data['id'])->where('uid', $request->uid())->find(); if (!$user) return app('json')->fail('没有此用户'); if (!$green) return app('json')->fail('没有这张绿卡'); if ($green['type'] == 2) return app('json')->fail('赠送绿卡,不能进行赠送'); $green['uid'] = $data['uid']; $green['type'] = 2; $res = $green->save(); if ($res) return app('json')->success('赠送成功'); return app('json')->fail('赠送失败'); } public function ratio(Request $request) { return app('json')->success(['bl' => SystemConfig::getConfigValue('green')]); } }