ShareLogic.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. /**
  3. * ShareLogic.php UTF-8
  4. * 分享逻辑
  5. *
  6. * @date : 2018/8/17 16:12
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : HuoMp 1.0
  11. */
  12. namespace huomp\logic\share;
  13. use huo\controller\game\GameCache;
  14. use huo\controller\request\Device;
  15. use huo\controller\wap\Option;
  16. use huo\model\common\CommonModel;
  17. use huo\model\posts\ShareLogModel;
  18. use huolib\constant\OptionConst;
  19. class ShareLogic extends CommonModel {
  20. public function __construct() {
  21. parent::__construct();
  22. }
  23. /**
  24. * 插入分享log
  25. *
  26. * @param $mem_id
  27. * @param $share_data
  28. *
  29. * @param Device $device
  30. *
  31. * @return bool|mixed
  32. */
  33. public function insertShareLog($mem_id, $share_data, Device $device) {
  34. $_share_data = $share_data;
  35. $_data = $device->toArray();
  36. $_data['mem_id'] = $mem_id;
  37. $_data['create_time'] = time();
  38. $_data['title'] = isset($_share_data['title']) ? $_share_data['title'] : '';
  39. $_data['content'] = isset($_share_data['content']) ? $_share_data['content'] : '';
  40. $_data['url'] = isset($_share_data['url']) ? $_share_data['url'] : '';
  41. $_data['to_target'] = isset($_share_data['to_target']) ? $_share_data['to_target'] : '';
  42. $_data['table_name'] = isset($_share_data['table_name']) ? $_share_data['table_name'] : '';
  43. $_data['object_id'] = isset($_share_data['object_id']) ? $_share_data['object_id'] : '';
  44. return (new ShareLogModel())->insertLog($_data);
  45. }
  46. /**
  47. * 更新分享log
  48. *
  49. * @param int $share_id
  50. * @param string $to_target
  51. * @param string $more
  52. *
  53. * @return bool|mixed
  54. */
  55. public function updateShareLog($share_id, $to_target, $more) {
  56. $_map['id'] = $share_id;
  57. $_data['to_target'] = $to_target;
  58. $_data['more'] = $more;
  59. return (new ShareLogModel())->where($_map)->update($_data);
  60. }
  61. /**
  62. * 获取分享配置
  63. * return array
  64. *
  65. * @param int $app_id
  66. *
  67. * @return array|string
  68. */
  69. public function getShareSetting($app_id = 0) {
  70. $_setting_name = OptionConst::SETTING_SHARE_IMG;
  71. $_option_value = [
  72. OptionConst::SETTING_SHARE_TITLE => '',
  73. OptionConst::SETTING_SHARE_IMG_GAME => '',
  74. OptionConst::SETTING_SHARE_IMG_MP => ''
  75. ];
  76. $_m = new Option();
  77. $_item = $_m->getOptionData($_setting_name, 1, true, json_encode($_option_value));
  78. if (!empty($_item['option_value'])) {
  79. $_item['option_value'] = json_decode($_item['option_value'], true);
  80. }
  81. $_option_value[OptionConst::SETTING_SHARE_TITLE]
  82. = empty($_item['option_value'][OptionConst::SETTING_SHARE_TITLE]) ? ''
  83. : $_item['option_value'][OptionConst::SETTING_SHARE_TITLE];
  84. if (!empty($_item['option_value'][OptionConst::SETTING_SHARE_IMG_GAME])) {
  85. $_share_img_game = $_item['option_value'][OptionConst::SETTING_SHARE_IMG_GAME];
  86. $_key = array_rand($_share_img_game, 1);
  87. $_option_value[OptionConst::SETTING_SHARE_IMG_GAME] = $_share_img_game[$_key];
  88. }
  89. if (!empty($_item['option_value'][OptionConst::SETTING_SHARE_IMG_MP])) {
  90. $_share_img_mp = $_item['option_value'][OptionConst::SETTING_SHARE_IMG_MP];
  91. $_key = array_rand($_share_img_mp, 1);
  92. $_option_value[OptionConst::SETTING_SHARE_IMG_MP] = $_share_img_mp[$_key];
  93. }
  94. if (!empty($app_id)) {
  95. $_game_data = (new GameCache())->getInfoByAppId($app_id);
  96. $_share_data = !empty($_game_data['ext_info']['share_img']) ? $_game_data['ext_info']['share_img'] : [];
  97. if (!empty($_share_data)) {
  98. if (false === is_array($_share_data)) {
  99. $_share_data = (array)$_share_data;
  100. }
  101. $_key = array_rand($_share_data, 1);
  102. if (false != is_array($_share_data[$_key])) {
  103. $_option_value[OptionConst::SETTING_SHARE_TITLE] = get_val($_share_data[$_key], 'title', '');
  104. $_option_value[OptionConst::SETTING_SHARE_IMG_GAME] = cmf_get_image_url(
  105. get_val($_share_data[$_key], 'url', '')
  106. );
  107. }
  108. }
  109. }
  110. return $_option_value;
  111. }
  112. }