* @version : HUOSDK 8.0 */ namespace huo\logic\member; use huo\model\common\CommonModel; use huo\model\game\CpModel; use huolib\constant\CommonConst; use huolib\constant\GameConst; class CpLogic extends CommonModel { public function getList() { $_model = (new CpModel())->select()->toArray(); return $_model; } /** * 获取CP列表 * * @param array $map * @param string $order * @param int $offset * * @return \think\Paginator * @throws \think\exception\DbException */ public function getCpList($map = [], $order = 'id desc', $offset = 10) { $field = 'id, company_name, link_man, mobile, position, create_time, update_time'; $_items = (new CpModel())->field($field)->where($map)->order($order)->paginate($offset); return $_items; } /** * 获取CP名称列表 * * @param int $type 类型 1 CP 2 媒体 * * @return array */ public static function getNamesById($type = GameConst::CP_TYPE_CP) { $_map = [ 'type' => $type, 'is_delete' => CommonConst::CONST_NOT_DELETE ]; $_arr = (new CpModel())->where($_map)->order('id desc')->column('company_name name', 'id'); return $_arr; } /*** * 添加cp * * @param $param * * @param bool $return_id * * @return false|int */ public function addCp($param, $return_id = false) { $_model = (new CpModel()); $_rs = $_model->allowField(true)->save($param); if (true == $return_id) { return $_model->id; } return $_rs; } /** * @param $id * * @return array|false|\PDOStatement|string|\think\Model * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function getCpById($id) { $_rs = (new CpModel())->where('id', $id)->find(); return $_rs; } public function getCpNameById($id) { $_rs = (new CpModel())->where('id', $id)->value('company_name'); return $_rs; } public function updateCp($id, $param) { $_rs = (new CpModel())->allowField(true)->save($param, ['id' => $id]); return $_rs; } /** * 获取指定CP名称 * * @return array */ public static function getNamesByData($where = []) { $_map = $where; $_map['is_delete'] = 2; $_arr = (new CpModel())->where($_map)->order('id desc')->column('company_name name', 'id'); return $_arr; } }