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