Browse Source

积分

master
林一峰 7 years ago
parent
commit
f79b0925cc
  1. 7
      app/Common/ReturnData.php
  2. 56
      app/Http/Controllers/Api/UserMoneyController.php
  3. 56
      app/Http/Controllers/Api/UserPointController.php
  4. 4
      app/Http/Model/Slide.php
  5. 48
      app/Http/Model/User.php
  6. 82
      app/Http/Model/UserMoney.php
  7. 81
      app/Http/Model/UserPoint.php
  8. 26
      routes/web.php

7
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);
}
}

56
app/Http/Controllers/Api/UserMoneyController.php

@ -0,0 +1,56 @@
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Api\CommonController;
use Illuminate\Http\Request;
use App\Common\ReturnData;
use App\Http\Model\UserMoney;
class UserMoneyController extends CommonController
{
public function __construct()
{
parent::__construct();
}
public function userMoneyList(Request $request)
{
//参数
$data['limit'] = $request->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);
}
}

56
app/Http/Controllers/Api/UserPointController.php

@ -0,0 +1,56 @@
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Api\CommonController;
use Illuminate\Http\Request;
use App\Common\ReturnData;
use App\Http\Model\UserPoint;
class UserPointController extends CommonController
{
public function __construct()
{
parent::__construct();
}
public function userPointList(Request $request)
{
//参数
$data['limit'] = $request->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);
}
}

4
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;

48
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;
}
}

82
app/Http/Model/UserMoney.php

@ -0,0 +1,82 @@
<?php
namespace App\Http\Model;
use App\Common\Token;
use DB;
class UserMoney extends BaseModel
{
//用户余额明细
protected $table = 'user_money';
public $timestamps = false;
/**
* 不能被批量赋值的属性
*
* @var array
*/
protected $guarded = [];
//获取列表
public static function getList(array $param)
{
extract($param); //参数:limit,offset
$where['user_id'] = Token::$uid;
$limit = isset($limit) ? $limit : 10;
$offset = isset($offset) ? $offset : 0;
$model = new UserMoney;
if(isset($type)){$where['type'] = $type;}
$model = $model->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;
}
}

81
app/Http/Model/UserPoint.php

@ -0,0 +1,81 @@
<?php
namespace App\Http\Model;
use App\Common\Token;
class UserPoint extends BaseModel
{
//用户积分明细
protected $table = 'user_point';
public $timestamps = false;
/**
* 不能被批量赋值的属性
*
* @var array
*/
protected $guarded = [];
//获取列表
public static function getList(array $param)
{
extract($param); //参数:limit,offset
$where['user_id'] = Token::$uid;
$limit = isset($limit) ? $limit : 10;
$offset = isset($offset) ? $offset : 0;
$model = new UserPoint;
if(isset($type)){$where['type'] = $type;}
$model = $model->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;
}
}

26
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');

Loading…
Cancel
Save