where('mer_id', $merId)->order('attr_template_id DESC'); } /** * @param int $merId * @param int $id * @param null $except * @return bool * @author zfy * @day 2020-04-15 */ public function merExists(int $merId, int $id, $except = null) { return $this->merFieldExists($merId, $this->getPk(), $id, $except); } /** * @param int $merId * @param $field * @param $value * @param null $except * @return bool * @author zfy * @day 2020-04-15 */ public function merFieldExists(int $merId, $field, $value, $except = null) { return ($this->getModel())::getDB()->when($except, function ($query, $except) use ($field) { $query->where($field, '<>', $except); })->where('mer_id', $merId)->where($field, $value)->count() > 0; } /** * @param int $id * @param int $merId * @return array|Model|null * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException * @author zfy * @day 2020-04-15 */ public function get( $id, $merId = 0) { return ($this->getModel())::getDB()->where('mer_id', $merId)->find($id); } /** * @param int $id * @param int $merId * @return int * @throws DbException * @author zfy * @day 2020-04-15 */ public function delete(int $id, $merId = 0) { return ($this->getModel())::getDB()->where($this->getPk(), $id)->where('mer_id', $merId)->delete(); } public function getList($merId) { return ($this->getModel())::getDB()->where('mer_id',$merId)->field('attr_template_id,template_name,template_value')->select(); } }