RecruitmentActivePrize.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php namespace App\Http\Controllers\Admin;
  2. use App\Models\RecruitmentActivePrize as Model;
  3. use App\Models\Coupon;
  4. use function PHPUnit\Framework\isNull;
  5. /**
  6. * 拉新活动
  7. *
  8. * @author 刘相欣
  9. *
  10. */
  11. class RecruitmentActivePrize extends Auth{
  12. protected function _initialize(){
  13. parent::_initialize();
  14. $this->assign('breadcrumb1','拉新活动');
  15. $this->assign('breadcrumb2','拉新活动奖励配置');
  16. }
  17. /**
  18. * 修改
  19. *
  20. * */
  21. public function edit(Model $Model,Coupon $Coupon){
  22. // 接收参数
  23. $id = request('id',0);
  24. $activeId = request('active_id',0);
  25. // 错误告知
  26. if( !$activeId ) return $this->error('缺失活动id');
  27. $oldData = $Model->where(['active_id'=>$activeId])->first();
  28. if($oldData){
  29. if ($oldData['old_prize_type'] == 2){
  30. $oldData['old_prize'] = $Coupon->idToCode($oldData['old_prize']);
  31. }
  32. if ($oldData['new_prize_type'] == 2){
  33. $oldData['new_prize'] = $Coupon->idToCode($oldData['new_prize']);
  34. }
  35. if ($oldData['higher_prize_type'] == 2){
  36. $oldData['higher_prize'] = $Coupon->idToCode($oldData['higher_prize']);
  37. }
  38. }
  39. // 修改
  40. if(request()->isMethod('post')){
  41. // 接收数据
  42. $data['old_prize_type'] = request('old_prize_type','');
  43. $data['old_prize'] = request('old_prize','');
  44. $data['new_prize_type'] = request('new_prize_type','');
  45. $data['new_prize'] = request('new_prize','');
  46. $data['higher_prize_type'] = request('higher_prize_type','');
  47. $data['higher_prize'] = request('higher_prize','');
  48. $data['active_id'] = $activeId;
  49. if ($data['old_prize_type'] == 2){
  50. $data['old_prize'] = $Coupon->codeToId($data['old_prize']);
  51. }
  52. if ($data['new_prize_type'] == 2){
  53. $data['new_prize'] = $Coupon->codeToId($data['new_prize']);
  54. }
  55. if ($data['higher_prize_type'] == 2){
  56. $data['higher_prize'] = $Coupon->codeToId($data['higher_prize']);
  57. }
  58. if ($oldData){
  59. // 写入数据表
  60. $result = $Model->edit($oldData['id'],$data);
  61. }else{
  62. $result = $Model->add($data);
  63. }
  64. // 如果操作失败
  65. if( !$result ) return json_send(['code'=>'error','msg'=>'修改失败']);
  66. // 记录行为
  67. $this->addAdminHistory(admin('uid'),$Model->getTable(),$id,2,$oldData,$data);
  68. // 告知结果
  69. return json_send(['code'=>'success','msg'=>'修改成功','action'=>'edit']);
  70. }
  71. $this->assign('oldData',$oldData);
  72. $this->assign('activeId',$activeId);
  73. $this->assign('crumbs','修改');
  74. // 加载模板
  75. return $this->fetch();
  76. }
  77. }