1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <?php namespace App\Http\Controllers\Admin;
- use App\Models\RecruitmentActivePrize as Model;
- use App\Models\Coupon;
- use function PHPUnit\Framework\isNull;
- /**
- * 拉新活动
- *
- * @author 刘相欣
- *
- */
- class RecruitmentActivePrize extends Auth{
-
- protected function _initialize(){
- parent::_initialize();
- $this->assign('breadcrumb1','拉新活动');
- $this->assign('breadcrumb2','拉新活动奖励配置');
- }
- /**
- * 修改
- *
- * */
- public function edit(Model $Model,Coupon $Coupon){
- // 接收参数
- $id = request('id',0);
- $activeId = request('active_id',0);
- // 错误告知
- if( !$activeId ) return $this->error('缺失活动id');
- $oldData = $Model->where(['active_id'=>$activeId])->first();
- if($oldData){
- if ($oldData['old_prize_type'] == 2){
- $oldData['old_prize'] = $Coupon->idToCode($oldData['old_prize']);
- }
- if ($oldData['new_prize_type'] == 2){
- $oldData['new_prize'] = $Coupon->idToCode($oldData['new_prize']);
- }
- if ($oldData['higher_prize_type'] == 2){
- $oldData['higher_prize'] = $Coupon->idToCode($oldData['higher_prize']);
- }
- }
- // 修改
- if(request()->isMethod('post')){
- // 接收数据
- $data['old_prize_type'] = request('old_prize_type','');
- $data['old_prize'] = request('old_prize','');
- $data['new_prize_type'] = request('new_prize_type','');
- $data['new_prize'] = request('new_prize','');
- $data['higher_prize_type'] = request('higher_prize_type','');
- $data['higher_prize'] = request('higher_prize','');
- $data['active_id'] = $activeId;
- if ($data['old_prize_type'] == 2){
- $data['old_prize'] = $Coupon->codeToId($data['old_prize']);
- }
- if ($data['new_prize_type'] == 2){
- $data['new_prize'] = $Coupon->codeToId($data['new_prize']);
- }
- if ($data['higher_prize_type'] == 2){
- $data['higher_prize'] = $Coupon->codeToId($data['higher_prize']);
- }
- if ($oldData){
- // 写入数据表
- $result = $Model->edit($oldData['id'],$data);
- }else{
- $result = $Model->add($data);
- }
- // 如果操作失败
- if( !$result ) return json_send(['code'=>'error','msg'=>'修改失败']);
- // 记录行为
- $this->addAdminHistory(admin('uid'),$Model->getTable(),$id,2,$oldData,$data);
- // 告知结果
- return json_send(['code'=>'success','msg'=>'修改成功','action'=>'edit']);
- }
- $this->assign('oldData',$oldData);
- $this->assign('activeId',$activeId);
- $this->assign('crumbs','修改');
- // 加载模板
- return $this->fetch();
- }
- }
|