diff --git a/app/Common/ReturnData.php b/app/Common/ReturnData.php index c720ac4..2380144 100644 --- a/app/Common/ReturnData.php +++ b/app/Common/ReturnData.php @@ -104,7 +104,7 @@ class ReturnData { $msg = self::$codeTexts[$code]; } - + return array('code' => $code, 'msg' => $msg, 'data' => $data); } @@ -133,4 +133,9 @@ class ReturnData return array('code' => $code, 'msg' => $msg, 'data' => $data); } + + public static function custom($code, $msg = '', $data = null) + { + return array('code' => $code, 'msg' => $msg, 'data' => $data); + } } \ No newline at end of file diff --git a/app/Http/Controllers/Api/UserMoneyController.php b/app/Http/Controllers/Api/UserMoneyController.php new file mode 100644 index 0000000..1f33e55 --- /dev/null +++ b/app/Http/Controllers/Api/UserMoneyController.php @@ -0,0 +1,56 @@ +input('limit', 10); + $data['offset'] = $request->input('offset', 0); + if($request->input('type', null) !== null){$data['type'] = $request->input('type');}; + + $res = UserMoney::getList($data); + if(!$res) + { + return ReturnData::create(ReturnData::SYSTEM_FAIL); + } + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + //添加余额明细 + public function userMoneyAdd(Request $request) + { + //参数 + $data['user_id'] = Token::$uid; + $data['type'] = $request->input('type',null); + $data['money'] = $request->input('money',null); + $data['add_time'] = time(); + $data['des'] = $request->input('des',null); + + if($data['type']===null || $data['money']===null || $data['des']===null) + { + return ReturnData::create(ReturnData::PARAMS_ERROR); + } + + $res = UserMoney::add($data); + if(!$res) + { + return ReturnData::create(ReturnData::SYSTEM_FAIL); + } + + return ReturnData::create(ReturnData::SUCCESS,$res); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Api/UserPointController.php b/app/Http/Controllers/Api/UserPointController.php new file mode 100644 index 0000000..059af43 --- /dev/null +++ b/app/Http/Controllers/Api/UserPointController.php @@ -0,0 +1,56 @@ +input('limit', 10); + $data['offset'] = $request->input('offset', 0); + if($request->input('type', null) !== null){$data['type'] = $request->input('type');}; + + $res = UserPoint::getList($data); + if(!$res) + { + return ReturnData::create(ReturnData::SYSTEM_FAIL); + } + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + //添加积分明细 + public function userPointAdd(Request $request) + { + //参数 + $data['user_id'] = Token::$uid; + $data['type'] = $request->input('type',null); + $data['point'] = $request->input('point',null); + $data['add_time'] = time(); + $data['des'] = $request->input('des',null); + + if($data['type']===null || $data['point']===null || $data['des']===null) + { + return ReturnData::create(ReturnData::PARAMS_ERROR); + } + + $res = UserMoney::add($data); + if(!$res) + { + return ReturnData::create(ReturnData::SYSTEM_FAIL); + } + + return ReturnData::create(ReturnData::SUCCESS,$res); + } +} \ No newline at end of file diff --git a/app/Http/Model/Slide.php b/app/Http/Model/Slide.php index 2891e21..1d9fc5b 100644 --- a/app/Http/Model/Slide.php +++ b/app/Http/Model/Slide.php @@ -52,7 +52,7 @@ class Slide extends Model public static function add(array $data) { - if ($id = DB::table('slide')->insertGetId($data)) + if ($id = DB::table(self::$table)->insertGetId($data)) { return $id; } @@ -62,7 +62,7 @@ class Slide extends Model public static function modify($where, array $data) { - $slide = DB::table('slide'); + $slide = DB::table(self::$table); if ($slide->where($where)->update($data)) { return true; diff --git a/app/Http/Model/User.php b/app/Http/Model/User.php index 80e8cca..40bf924 100644 --- a/app/Http/Model/User.php +++ b/app/Http/Model/User.php @@ -26,57 +26,21 @@ class User extends BaseModel } //签到 - public static function signin(array $param) + public static function signin() { - extract($param); //参数:limit,offset - $user = self::where(['id'=>Token::$uid])->first(); - if($user){}else{return false;} $signin_time=''; if(!empty($user->signin_time)){$signin_time = date('Ymd',strtotime($user->signin_time));} //签到时间 $today = date('Ymd',time()); //今日日期 - if($signin_time==$today){return ReturnCode::create(101,'已经签到啦,请明天再来!');} + if($signin_time==$today){return '今日已签到!';} - $signin_point = (int)DB::table('system')->where(['keyword'=>'signin_point'])->value('value'); //签到积分 - DB::table('user')->where(['id'=>Token::$uid])->update(['point'=>($user->point+$signin_point),'signin_time'=>date('Y-m-d H:i:s')]); //更新用户积分,及签到时间 - DB::table('user_point_log')->insert(['type'=>1,'point'=>$signin_point,'des'=>'签到','user_id'=>Token::$uid]); //添加签到积分记录 + $signin_point = (int)Sysconfig::where(['varname'=>'CMS_SIGN_POINT'])->value('value'); //签到积分 + User::where(['id'=>Token::$uid])->update(['point'=>($user->point+$signin_point),'signin_time'=>date('Y-m-d H:i:s')]); //更新用户积分,及签到时间 + UserPoint::insert(['type'=>1,'point'=>$signin_point,'des'=>'签到','user_id'=>Token::$uid]); //添加签到积分记录 - return ReturnCode::create(ReturnCode::SUCCESS,'恭喜您今日签到成功!+'.$signin_point.'积分'); - - - - - $limit = isset($limit) ? $limit : 10; - $offset = isset($offset) ? $offset : 0; - - $model = self::where('user_id', Token::$uid); - - $res['count'] = $model->count(); - $res['list'] = array(); - - if($res['count']>0) - { - $res['list'] = $model->skip($offset)->take($limit)->get()->toArray(); - - if($res['list']) - { - foreach($res['list'] as $k=>$v) - { - $res['list'][$k]['country_name'] = Region::getRegionName($v['country']); - $res['list'][$k]['province_name'] = Region::getRegionName($v['province']); - $res['list'][$k]['city_name'] = Region::getRegionName($v['city']); - $res['list'][$k]['district_name'] = Region::getRegionName($v['district']); - } - } - } - else - { - return false; - } - - return $res; + return true; } } diff --git a/app/Http/Model/UserMoney.php b/app/Http/Model/UserMoney.php new file mode 100644 index 0000000..9e5573f --- /dev/null +++ b/app/Http/Model/UserMoney.php @@ -0,0 +1,82 @@ +where($where); + + $res['count'] = $model->count(); + $res['list'] = array(); + + if($res['count']>0) + { + $res['list'] = $model->skip($offset)->take($limit)->get()->toArray(); + } + else + { + return false; + } + + return $res; + } + + public static function add(array $data) + { + if ($id = DB::table(self::$table)->insertGetId($data)) + { + return $id; + } + + return false; + } + + public static function modify($where, array $data) + { + $slide = DB::table(self::$table); + if ($slide->where($where)->update($data)) + { + return true; + } + + return false; + } + + //删除一条记录 + public static function remove($id) + { + if (!self::whereIn('id', explode(',', $id))->delete()) + { + return false; + } + + return true; + } +} \ No newline at end of file diff --git a/app/Http/Model/UserPoint.php b/app/Http/Model/UserPoint.php new file mode 100644 index 0000000..b1c1651 --- /dev/null +++ b/app/Http/Model/UserPoint.php @@ -0,0 +1,81 @@ +where($where); + + $res['count'] = $model->count(); + $res['list'] = array(); + + if($res['count']>0) + { + $res['list'] = $model->skip($offset)->take($limit)->get()->toArray(); + } + else + { + return false; + } + + return $res; + } + + public static function add(array $data) + { + if ($id = DB::table(self::$table)->insertGetId($data)) + { + return $id; + } + + return false; + } + + public static function modify($where, array $data) + { + $slide = DB::table(self::$table); + if ($slide->where($where)->update($data)) + { + return true; + } + + return false; + } + + //删除一条记录 + public static function remove($id) + { + if (!self::whereIn('id', explode(',', $id))->delete()) + { + return false; + } + + return true; + } +} \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index 614e781..20aa0e2 100644 --- a/routes/web.php +++ b/routes/web.php @@ -185,7 +185,30 @@ Route::group(['prefix' => 'dataapi', 'namespace' => 'Api', 'middleware' => ['web }); //接口路由,需token验证 -Route::group(['prefix' => 'dataapi', 'namespace' => 'Api', 'middleware' => ['token']], function () { +Route::group(['prefix' => 'dataapi', 'namespace' => 'Api', 'middleware' => ['web','token']], function () { + //用户中心 + //浏览记录 + //商品 + //商品评价 + //商品收藏 + //订单 + + //购物车 + + //分销 + + //积分 + + //优惠券 + + //微信 + + + + //其它 + //图片上传 + //二维码 + //轮播图 Route::get('/slide_list', 'SlideController@slideList'); //收货地址 @@ -195,7 +218,6 @@ Route::group(['prefix' => 'dataapi', 'namespace' => 'Api', 'middleware' => ['tok Route::post('/user_address_add', 'UserAddressController@userAddressAdd'); Route::post('/user_address_update', 'UserAddressController@userAddressUpdate'); Route::post('/user_address_delete', 'UserAddressController@userAddressDelete'); - //地区,省市区 Route::get('/region_list', 'RegionController@regionList'); Route::get('/region_detail', 'RegionController@regionDetail');