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(); } /** * 表格导入 * * */ public function import_execl( Request $request,Model $Model,Custom $Custom,FilesManager $FilesManager){ // 验证参数 $request->scene('import_execl')->validate(); // 获取表格信息 $file = request()->file('score_file'); // 返回结果 $sheetList = $FilesManager->excelToScore($file); // 如果不存在结果 if( isset($sheetList['error']) ) return json_send(['code'=>'error','msg'=>$sheetList['error']]); // 组合数据,写入订单表,子表 DB::beginTransaction(); // 循环表格数据 foreach ($sheetList as $value) { // 客户ID $customUid = $Custom->codeToId($value['custom_uid']); // 如果客户ID有误 if( !$customUid ) return json_send(['code'=>'error','msg'=>$value['custom_uid'].'编码有误']); // 写入数据表 $payId = $Model->trade($customUid,0,$value['score'],4,($value['score']>0?1:2),$value['description']); // 如果操作失败 if( isset($payId['error']) ) { // 回滚 DB::rollBack(); // 结果提示 return json_send(['code'=>'error','msg'=>$value['custom_uid'].'=>'.$payId['error']]); } } // 提交事务 DB::commit(); // 提示成功 return json_send(['code'=>'success','msg'=>'批量导入成功','path'=>'']); } /** * 表格导入 * * */ public function import_weiban( Request $request,Model $Model,Custom $Custom,FilesManager $FilesManager,WeiBanExternal $WeiBanExternal){ // 验证参数 $request->scene('import_execl')->validate(); // 获取表格信息 $file = request()->file('score_file'); // 返回结果 $sheetList = $FilesManager->weibanToScore($file); // 如果不存在结果 if( isset($sheetList['error']) ) return json_send(['code'=>'error','msg'=>$sheetList['error']]); // 通过微伴ID查询用户ID $uidList = $WeiBanExternal->query()->whereIn('id',array_column($sheetList,'weiban_extid'))->pluck('custom_uid','id')->toArray(); // 循环列表 foreach ($sheetList as $key=>$value) { // 如果查询不到数据 if( empty($uidList[$value['weiban_extid']]) ) return json_send(['code'=>'error','msg'=>$value['weiban_extid'].'不在系统内']); // 获取客户ID $value['custom_uid'] = $uidList[$value['weiban_extid']]; // 重组 $sheetList[$key] = $value; } // 组合数据,写入订单表,子表 DB::beginTransaction(); // 循环表格数据 foreach ($sheetList as $value) { // 写入数据表 $payId = $Model->trade($value['custom_uid'],0,$value['score'],4,($value['score']>0?1:2),$value['description']); // 如果操作失败 if( isset($payId['error']) ) { // 回滚 DB::rollBack(); // 结果提示 return json_send(['code'=>'error','msg'=>$value['weiban_extid'].'=>'.$payId['error']]); } } // 提交事务 DB::commit(); // 提示成功 return json_send(['code'=>'success','msg'=>'批量导入成功','path'=>'']); } }