error('优惠券不存在或已删除!'); } switch($coupon->status){ case 0: case 3: // 判断活动时间 还未判断 $coupon->status = 1; if(!$coupon->save()){ return $this->error('发布失败!'); } // 删除领取方式 $delRes = ReceiveTypeModel::where('coupon_id',$id)->delete(); if($delRes === false){ return $this->error('发布失败!'); } // 添加领取方式 $receiveModel = new ReceiveTypeModel(); $receiveModel->coupon_id = $id; $receiveModel->receive_type = $receiveType; // 获取一次可领取数量 $receiveNumber = SettingModel::getSettingInfo($receiveType,'value'); $receiveModel->one_receive_number = empty($receiveNumber) ? 1 : $receiveNumber->value; if($receiveModel->save()){ return $this->success('发布成功','/coupon'); } break; case 1: return $this->error('优惠券已发布!'); break; case 2: return $this->error('优惠券已领完!'); break; case -1: return $this->error('优惠券已删除!'); break; } return $this->error('发布失败!'); } /** * Build a form here. */ public function form() { $id = $this->getKey(); $receiveTypeInfo = ReceiveTypeModel::getReceiveTypeInfo($id,'receive_type'); $list = SettingModel::getSettingArray(); $receiveType = empty($receiveTypeInfo->receive_type)? 0 :$receiveTypeInfo->receive_type; $this->hidden('id')->value($id); $this->select('receive_type','领取方式')->required()->options($list)->value($receiveType); } /** * The data of the form. * * @return array */ public function default() { return []; } }