123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- <?php
- /**
- * ShareLogic.php UTF-8
- * 分享逻辑
- *
- * @date : 2018/8/17 16:12
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : wuyonghong <wyh@huosdk.com>
- * @version : HuoMp 1.0
- */
- namespace huomp\logic\share;
- use huo\controller\game\GameCache;
- use huo\controller\request\Device;
- use huo\controller\wap\Option;
- use huo\model\common\CommonModel;
- use huo\model\posts\ShareLogModel;
- use huolib\constant\OptionConst;
- class ShareLogic extends CommonModel {
- public function __construct() {
- parent::__construct();
- }
- /**
- * 插入分享log
- *
- * @param $mem_id
- * @param $share_data
- *
- * @param Device $device
- *
- * @return bool|mixed
- */
- public function insertShareLog($mem_id, $share_data, Device $device) {
- $_share_data = $share_data;
- $_data = $device->toArray();
- $_data['mem_id'] = $mem_id;
- $_data['create_time'] = time();
- $_data['title'] = isset($_share_data['title']) ? $_share_data['title'] : '';
- $_data['content'] = isset($_share_data['content']) ? $_share_data['content'] : '';
- $_data['url'] = isset($_share_data['url']) ? $_share_data['url'] : '';
- $_data['to_target'] = isset($_share_data['to_target']) ? $_share_data['to_target'] : '';
- $_data['table_name'] = isset($_share_data['table_name']) ? $_share_data['table_name'] : '';
- $_data['object_id'] = isset($_share_data['object_id']) ? $_share_data['object_id'] : '';
- return (new ShareLogModel())->insertLog($_data);
- }
- /**
- * 更新分享log
- *
- * @param int $share_id
- * @param string $to_target
- * @param string $more
- *
- * @return bool|mixed
- */
- public function updateShareLog($share_id, $to_target, $more) {
- $_map['id'] = $share_id;
- $_data['to_target'] = $to_target;
- $_data['more'] = $more;
- return (new ShareLogModel())->where($_map)->update($_data);
- }
- /**
- * 获取分享配置
- * return array
- *
- * @param int $app_id
- *
- * @return array|string
- */
- public function getShareSetting($app_id = 0) {
- $_setting_name = OptionConst::SETTING_SHARE_IMG;
- $_option_value = [
- OptionConst::SETTING_SHARE_TITLE => '',
- OptionConst::SETTING_SHARE_IMG_GAME => '',
- OptionConst::SETTING_SHARE_IMG_MP => ''
- ];
- $_m = new Option();
- $_item = $_m->getOptionData($_setting_name, 1, true, json_encode($_option_value));
- if (!empty($_item['option_value'])) {
- $_item['option_value'] = json_decode($_item['option_value'], true);
- }
- $_option_value[OptionConst::SETTING_SHARE_TITLE]
- = empty($_item['option_value'][OptionConst::SETTING_SHARE_TITLE]) ? ''
- : $_item['option_value'][OptionConst::SETTING_SHARE_TITLE];
- if (!empty($_item['option_value'][OptionConst::SETTING_SHARE_IMG_GAME])) {
- $_share_img_game = $_item['option_value'][OptionConst::SETTING_SHARE_IMG_GAME];
- $_key = array_rand($_share_img_game, 1);
- $_option_value[OptionConst::SETTING_SHARE_IMG_GAME] = $_share_img_game[$_key];
- }
- if (!empty($_item['option_value'][OptionConst::SETTING_SHARE_IMG_MP])) {
- $_share_img_mp = $_item['option_value'][OptionConst::SETTING_SHARE_IMG_MP];
- $_key = array_rand($_share_img_mp, 1);
- $_option_value[OptionConst::SETTING_SHARE_IMG_MP] = $_share_img_mp[$_key];
- }
- if (!empty($app_id)) {
- $_game_data = (new GameCache())->getInfoByAppId($app_id);
- $_share_data = !empty($_game_data['ext_info']['share_img']) ? $_game_data['ext_info']['share_img'] : [];
- if (!empty($_share_data)) {
- if (false === is_array($_share_data)) {
- $_share_data = (array)$_share_data;
- }
- $_key = array_rand($_share_data, 1);
- if (false != is_array($_share_data[$_key])) {
- $_option_value[OptionConst::SETTING_SHARE_TITLE] = get_val($_share_data[$_key], 'title', '');
- $_option_value[OptionConst::SETTING_SHARE_IMG_GAME] = cmf_get_image_url(
- get_val($_share_data[$_key], 'url', '')
- );
- }
- }
- }
- return $_option_value;
- }
- }
|