|
@@ -60,13 +60,18 @@ class ScoreClockin extends Auth{
|
|
|
$data['reward'] = (int) request('reward',0);
|
|
|
$data['active_id'] = request('active_id',0);
|
|
|
$data['status'] = 0;
|
|
|
- $coupon_code = request('coupon_code',0);
|
|
|
- if ($coupon_code)
|
|
|
- $data['coupon_id'] = $Coupon->codeToId($coupon_code);
|
|
|
+ $coupon_code = request('coupon_code','');
|
|
|
+ $data['coupon_id'] = $Coupon->codeToId($coupon_code);
|
|
|
+ // 查询是否已经有
|
|
|
+ $oldDId = $Model->query()->where([['what_day','=',$data['what_day']],['active_id','=',$data['active_id']]])->value('id');
|
|
|
+ // 提示新增失败
|
|
|
+ if( $oldDId ) return json_send(['code'=>'error','msg'=>'打卡天数已存在']);
|
|
|
// 写入用户表
|
|
|
- $result = $Model->add($data);
|
|
|
+ $id = $Model->add($data);
|
|
|
// 提示新增失败
|
|
|
- if( isset($result['error']) ) return json_send(['code'=>'error','msg'=>$result['error']]);
|
|
|
+ if( isset($id['error']) ) return json_send(['code'=>'error','msg'=>$id['error']]);
|
|
|
+ // 记录行为
|
|
|
+ $this->addAdminHistory(admin('uid'),$Model->getTable(),$id,1,[],$data);
|
|
|
// 告知结果
|
|
|
return json_send(['code'=>'success','msg'=>'新增成功','action'=>'add']);
|
|
|
}
|
|
@@ -83,29 +88,34 @@ class ScoreClockin extends Auth{
|
|
|
public function edit( Request $request,Model $Model,Coupon $Coupon){
|
|
|
// 接收参数
|
|
|
$id = request('id',0);
|
|
|
+ // 查询用户
|
|
|
+ $oldData = $Model->where(['id'=>$id])->first();
|
|
|
// 如果是post
|
|
|
if(request()->isMethod('post')){
|
|
|
// 验证参数
|
|
|
$request->scene('edit')->validate();
|
|
|
$data['what_day'] = (int) request('what_day',0);
|
|
|
$data['reward'] = (int) request('reward',0);
|
|
|
- $coupon_code = request('coupon_code',0);
|
|
|
- if ($coupon_code)
|
|
|
- $data['coupon_id'] = $Coupon->codeToId($coupon_code);
|
|
|
+ $coupon_code = request('coupon_code','');
|
|
|
+ $data['coupon_id'] = $Coupon->codeToId($coupon_code);
|
|
|
+ // 查询是否已经有
|
|
|
+ $oldDId = $Model->query()->where([['what_day','=',$data['what_day']],['active_id','=',$oldData['active_id']]])->value('id');
|
|
|
+ // 提示
|
|
|
+ if( $oldDId && $id != $oldDId ) return json_send(['code'=>'error','msg'=>'打卡天数已存在']);
|
|
|
// 写入用户表
|
|
|
$result = $Model->edit($id,$data);
|
|
|
// 提示新增失败
|
|
|
if( isset($result['error']) ) return json_send(['code'=>'error','msg'=>$result['error']]);
|
|
|
+ // 记录行为
|
|
|
+ $this->addAdminHistory(admin('uid'),$Model->getTable(),$id,2,$oldData,$data);
|
|
|
// 告知结果
|
|
|
- return json_send(['code'=>'success','msg'=>'修改成功','action'=>'edit']);
|
|
|
+ return json_send(['code'=>'success','msg'=>'修改成功','action'=>'edit']);
|
|
|
}
|
|
|
- // 查询数据
|
|
|
- $oldData = $Model->where(['id'=>$id])->first();
|
|
|
- if ($oldData['coupon_id']) {
|
|
|
- $oldData['coupon_code'] = $Coupon->idToCode($oldData['coupon_id']);
|
|
|
- }
|
|
|
// 如果是没有数据
|
|
|
if( !$oldData ) return $this->error('查无数据');
|
|
|
+ // 查询数据
|
|
|
+ $oldData = $Model->where(['id'=>$id])->first();
|
|
|
+ $oldData['coupon_code'] = $oldData['coupon_id'] ? $Coupon->idToCode($oldData['coupon_id']) : '';
|
|
|
// 分配数据
|
|
|
$this->assign('crumbs','修改');
|
|
|
$this->assign('oldData',$oldData);
|
|
@@ -123,12 +133,18 @@ class ScoreClockin extends Auth{
|
|
|
// 接收参数
|
|
|
$id = request('id',0);
|
|
|
$status = request('status',0);
|
|
|
+ // 查询用户
|
|
|
+ $oldData = $Model->where(['id'=>$id])->first();
|
|
|
+ // 如果是没有数据
|
|
|
+ if( !$oldData ) return json_send(['code'=>'error','msg'=>'查无数据']);
|
|
|
// 查询数据
|
|
|
- $result = $Model->edit($id,['status'=>$status,'update_time'=>time()]);
|
|
|
+ $result = $Model->edit($id,['status'=>$status]);
|
|
|
// 提示新增失败
|
|
|
if( !$result ) return json_send(['code'=>'error','msg'=>'设置失败']);
|
|
|
+ // 记录行为
|
|
|
+ $this->addAdminHistory(admin('uid'),$Model->getTable(),$id,2,$oldData,['status'=>$status]);
|
|
|
// 告知结果
|
|
|
- return json_send(['code'=>'success','msg'=>'设置成功','path'=>'']);
|
|
|
+ return json_send(['code'=>'success','msg'=>'设置成功','path'=>'']);
|
|
|
}
|
|
|
|
|
|
}
|