123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- <?php namespace App\Http\Controllers\Admin;
- use App\Http\Requests\Admin\CustomScore as Request;
- use App\Models\Custom;
- use App\Models\CustomScore as Model;
- use Illuminate\Support\Facades\DB;
- /**
- * 客户管理
- *
- * @author 刘相欣
- *
- */
- class CustomScore extends Auth{
- protected function _initialize(){
- parent::_initialize();
- $this->assign('breadcrumb1','积分管理');
- $this->assign('breadcrumb2','客户积分');
- }
- /**
- * 添加
- *
- * */
- public function incr(Request $request,Model $Model,Custom $Custom){
- // 接收参数
- $customUid = request('custom_uid',0);
- // 查询数据
- $custom = $Custom->getOne($customUid);
- // 提交
- if( request()->isMethod('post') ){
- // 验证参数
- $request->scene('incr')->validate();
- // 接收数据
- // 接收数据
- $incrScore = request('incr_score',0);
- // 组合数据,写入订单表,子表
- DB::beginTransaction();
- // 写入数据表
- $payId = $Model->trade($customUid,0,$incrScore,4,1);
- // 如果操作失败
- if( isset($payId['error']) ) {
- // 回滚
- DB::rollBack();
- // 结果提示
- return json_send(['code'=>'error','msg'=>$payId['error']]);
- }
- // 提交事务
- DB::commit();
- // 告知结果
- return json_send(['code'=>'success','msg'=>'增加成功','action'=>'add']);
- }
- // 如果不存在
- if( !$custom ) return $this->error('用户不存在');
- // 分配数据
- $this->assign('crumbs','增加积分');
- $this->assign('custom',$custom);
- // 加载模板
- return $this->fetch();
- }
- /**
- * 扣减
- *
- * */
- public function decr(Request $request,Model $Model,Custom $Custom){
- // 接收参数
- $customUid = request('custom_uid',0);
- // 查询数据
- $custom = $Custom->getOne($customUid);
- // 提交
- if( request()->isMethod('post') ){
- // 验证参数
- $request->scene('decr')->validate();
- // 接收数据
- $decrScore = request('decr_score',0);
- // 组合数据,写入订单表,子表
- DB::beginTransaction();
- // 写入数据表
- $payId = $Model->trade($customUid,0,($decrScore*-1),4,2);
- // 如果操作失败
- if( isset($payId['error']) ) {
- // 回滚
- DB::rollBack();
- // 结果提示
- return json_send(['code'=>'error','msg'=>$payId['error']]);
- }
- // 提交事务
- DB::commit();
- // 告知结果
- return json_send(['code'=>'success','msg'=>'扣减成功','action'=>'add']);
- }
- // 如果不存在
- if( !$custom ) return $this->error('用户不存在');
- // 分配数据
- $this->assign('crumbs','扣减积分');
- $this->assign('custom',$custom);
- // 加载模板
- return $this->fetch();
- }
- }
|