where($map)->order($order, $sort)->page($page, $limit)->select(); foreach ($list as $k => &$v) { $v['base_image'] = localpath_to_netpath($v['base_image']); } $data = []; $data['count'] = db::name('gift')->where($map)->count(); $data['list'] = $list; return ['code' => 200, 'msg' => '获取成功', 'data' => $data]; } //编辑礼物 public function edit_gift($data) { if (empty($data)) { return ['code' => 201, 'msg' => '参数异常', 'data' => null]; } $room_info = db::name('gift')->find($data['gid']); if (empty($room_info)) { return ['code' => 201, 'msg' => '参数异常', 'data' => null]; } // dump($data);exit; $update_data = []; $update_data['type'] = $data['type']; $update_data['gift_type'] = $data['gift_type']; $update_data['gift_name'] = $data['gift_name']; $update_data['gift_price'] = $data['gift_price']; $update_data['base_image'] = $data['base_image']; $update_data['file_type'] = $data['file_type']; if($data['file_type'] == 1){ $update_data['play_image'] = $data['play_image']; }else{ $update_data['play_image'] = $data['plays_image']; } $update_data['nid'] = $data['nid']; $update_data['mid'] = $data['mid']; $update_data['position'] = $data['position']; $update_data['pendant_image'] = $data['pendant_image']; $update_data['is_public_screen'] = $data['is_public_screen']; $update_data['is_public_server'] = $data['is_public_server']; $update_data['is_show'] = $data['is_show']; $update_data['is_can_buy'] = $data['is_can_buy']; $update_data['sort'] = $data['sort']; $update_data['update_time'] = time(); $update_data['tag_name'] = trim($data['tag_name']); $reslut = db::name('gift')->where(['gid' => $data['gid']])->update($update_data); if (!$reslut) { return ['code' => 201, 'msg' => '修改失败', 'data' => null]; } else { return ['code' => 200, 'msg' => '修改成功', 'data' => null]; } } //添加礼物 public function add_gift($data) { $add_data = []; $add_data['type'] = $data['type']; $add_data['gift_type'] = $data['gift_type']; $add_data['gift_name'] = $data['gift_name']; $add_data['gift_price'] = $data['gift_price']; $add_data['base_image'] = $data['base_image']; $add_data['file_type'] = $data['file_type']; // $add_data['play_image'] = $data['play_image']; if($data['file_type'] == 1){ $add_data['play_image'] = $data['play_image']; }else{ $add_data['play_image'] = $data['plays_image']; } $add_data['nid'] = $data['nid']; $add_data['mid'] = $data['mid']; $add_data['position'] = $data['position']; $add_data['pendant_image'] = $data['pendant_image']; $add_data['is_public_screen'] = $data['is_public_screen']; $add_data['is_public_server'] = $data['is_public_server']; $add_data['is_show'] = $data['is_show']; $add_data['is_can_buy'] = $data['is_can_buy']; $add_data['sort'] = $data['sort']; $add_data['update_time'] = time(); $add_data['add_time'] = time(); $add_data['tag_name'] = trim($data['tag_name']); $reslut = db::name('gift')->insert($add_data); if (!$reslut) { return ['code' => 201, 'msg' => '添加失败', 'data' => null]; } else { return ['code' => 200, 'msg' => '添加成功', 'data' => null]; } } //获取礼物信息 public function gift_info($gid) { if (empty($gid)) { return ['code' => 201, 'msg' => '参数异常', 'data' => null]; } $gift_info = db::name('gift')->where(['gid' => $gid])->find(); $gift_info['http_base_image'] = localpath_to_netpath($gift_info['base_image']); $gift_info['http_play_image'] = localpath_to_netpath($gift_info['play_image']); $gift_info['pendant_image_path'] = localpath_to_netpath($gift_info['pendant_image']); $gift_info['plays_image'] = $gift_info['play_image']; return ['code' => 200, 'msg' => '获取成功', 'data' => $gift_info]; } //删除礼物 public function del_gift($gid) { if (empty($gid)) { return ['code' => 201, 'msg' => '参数异常', 'data' => null]; } if($gid == 37 || $gid == 38 || $gid == 36){ return ['code' => 201, 'msg' => '该礼物无法删除', 'data' => null]; } $reslut = db::name('gift')->where(['gid' => $gid])->update(['is_delete' => 2, 'delete_time' => time()]); if (!$reslut) { return ['code' => 201, 'msg' => '删除失败', 'data' => null]; } else { return ['code' => 200, 'msg' => '删除成功', 'data' => null]; } } //批量删除礼物 public function batch_delete_gift($data){ if(empty($data)){ return ['code' => 201, 'msg' => '参数异常', 'data' => null]; } $gid_list = []; foreach ($data as $k => $v){ if(in_array($v['gid'], [36,37,38])) { ['code' => 201, 'msg' => '包含不能删除礼物', 'data' => null]; } $gid_list[] = $v['gid']; } $map = []; $map[] = ['gid', 'in', $gid_list]; $date = []; $date['is_delete'] = 2; $date['delete_time'] = time(); $reslut = db::name('gift')->where($map)->update($date); if($reslut){ return ['code' => 200, 'msg' => '删除成功', 'data' => null]; }else{ return ['code' => 201, 'msg' => '删除失败', 'data' => null]; } } //列表 public function get_gift_position_list($order, $sort, $page = 1, $limit = 20) { $list = db::name('gift_position')->order($order, $sort)->page($page, $limit)->select(); $data = []; $data['count'] = db::name('gift_position')->count(); $data['list'] = $list; return ['code' => 200, 'msg' => '获取成功', 'data' => $data]; } //列表 public function get_privacy_gift_list($gid, $order, $sort, $page = 1, $limit = 20) { $map = []; if (!empty($gid)) { $map[] = ['a.gid', '=', $gid]; } $map[] = ['a.is_delete', '=', 1]; // $map[] = ['b.is_gift_debris', '=', 2]; $list = db::name('room_privacy_gift')->alias('a')->join('yy_gift b', 'a.gid = b.gid')->field('b.*, a.id, a.duration')->where($map)->order($order, $sort)->page($page, $limit)->select(); foreach ($list as $k => &$v) { $v['base_image'] = localpath_to_netpath($v['base_image']); } $data = []; $data['count'] = db::name('room_privacy_gift')->alias('a')->join('yy_gift b', 'a.gid = b.gid')->where($map)->count(); $data['list'] = $list; return ['code' => 200, 'msg' => '获取成功', 'data' => $data]; } //编辑礼物 public function edit_privacy_gift($data) { if (empty($data)) { return ['code' => 201, 'msg' => '参数异常', 'data' => null]; } $room_info = db::name('room_privacy_gift')->find($data['id']); if (empty($room_info)) { return ['code' => 201, 'msg' => '参数异常', 'data' => null]; } $map = []; $map[] = ['gid', '=', $data['gid']]; $map[] = ['id', 'neq', $data['id']]; $map[] = ['is_delete', '=', 1]; $room_privacy_gift = db::name('room_privacy_gift')->where($map)->find(); if($room_privacy_gift){ return ['code' => 201, 'msg' => '该礼物已添加过', 'data' => null]; } // dump($data);exit; $update_data = []; $update_data['gid'] = $data['gid']; $update_data['duration'] = $data['duration']; $update_data['update_time'] = time(); $reslut = db::name('room_privacy_gift')->where(['id' => $data['id']])->update($update_data); if (!$reslut) { return ['code' => 201, 'msg' => '修改失败', 'data' => null]; } else { return ['code' => 200, 'msg' => '修改成功', 'data' => null]; } } //添加 public function add_privacy_gift($data) { $map = []; $map[] = ['gid', '=', $data['gid']]; $map[] = ['is_delete', '=', 1]; $room_privacy_gift = db::name('room_privacy_gift')->where($map)->find(); if($room_privacy_gift){ return ['code' => 201, 'msg' => '该礼物已添加过', 'data' => null]; } $add_data = []; $add_data['gid'] = $data['gid']; $add_data['duration'] = $data['duration']; $add_data['update_time'] = time(); $add_data['add_time'] = time(); $reslut = db::name('room_privacy_gift')->insert($add_data); if (!$reslut) { return ['code' => 201, 'msg' => '添加失败', 'data' => null]; } else { return ['code' => 200, 'msg' => '添加成功', 'data' => null]; } } //获取信息 public function get_privacy_gift_info($id) { if (empty($id)) { return ['code' => 201, 'msg' => '参数异常', 'data' => null]; } $gift_info = db::name('room_privacy_gift')->where(['id' => $id])->find(); return ['code' => 200, 'msg' => '获取成功', 'data' => $gift_info]; } //删除礼物 public function del_privacy_gift($id) { if (empty($id)) { return ['code' => 201, 'msg' => '参数异常', 'data' => null]; } $reslut = db::name('room_privacy_gift')->where(['id' => $id])->update(['is_delete' => 2, 'update_time' => time()]); if (!$reslut) { return ['code' => 201, 'msg' => '删除失败', 'data' => null]; } else { return ['code' => 200, 'msg' => '删除成功', 'data' => null]; } } //可选礼物列表 public function get_optional_gift_list($gid, $order, $sort, $page, $limit){ $config = get_uncache_system_config(); $map = []; $map[] = ['type', '=', 1]; $map[] = ['is_show', '=', 1]; $map[] = ['is_can_buy', '=', 1]; // $map[] = ['is_gift_debris', '=', 2]; if(!empty($config['cp_gift_id'])){ $map[] = ['gid', 'neq', $config['cp_gift_id']]; } $list = db::name('gift')->where($map)->select(); $data = []; $data['count'] = db::name('gift')->where($map)->count(); $data['list'] = $list; return ['code' => 200, 'msg' => '获取成功', 'data' => $data]; } }