query()->insertGetId($data); // 如果操作失败 if( !$id ) return 0; // 返回结果 return $id; } /** * 添加数据 * */ public function edit($id,$data) { // 更新时间 $data['update_time'] = time(); // 写入数据表 $result = $this->query()->where(['id'=>$id])->update($data); // 如果操作失败 if( !$result ) return 0; // 返回结果 return $id; } /** * 获取优惠券信息 * */ public function getOne($id,$field=''){ // 返回结果 $result = $this->query()->find($id); // 返回结果 $result = $result ? $result->toArray() : []; // 返回值 return empty($field) ? $result : ( isset($result[$field]) ? $result[$field] : null); } }