123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- <?php
- /**
- * Base.php UTF-8
- * 投放基类
- *
- * @date : 2018/7/13 23:19
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : ouzhongfu <ozf@huosdk.com>
- * @version : HUOSDK 7.2
- */
- namespace huolib\promotion;
- use think\Db;
- use think\Log;
- class Base {
- const FROM_ANDROID = 3;
- /**
- * 自定义错误处理
- *
- * @param string $msg
- * @param string $level
- *
- */
- private function _error($msg, $level = 'error') {
- $_info = 'promotion\Base Error:'.$msg;
- Log::record($_info, $level);
- }
- public function __construct() {
- }
- /**
- * 点击统计
- *
- * @param $agent_id
- * @param $app_id
- * @param int $is_distinct
- *
- * @return int|string
- */
- public function entVisitLog($agent_id, $app_id, $is_distinct = 0) {
- if (empty($agent_id) || empty($app_id)) {
- return false;
- }
- $_map['agent_id'] = $agent_id;
- $_map['app_id'] = $app_id;
- $_map['date'] = date('Y-m-d');
- $_day_check = Db::name('promotion_day')->where($_map)->find();
- if (empty($_day_check)) {
- /*3.2 不存在则插入*/
- $_inster_data['agent_id'] = $agent_id;
- $_inster_data['app_id'] = $app_id;
- $_inster_data['date'] = date('Y-m-d');
- $_inster_data['visit_cnt'] = 1;
- $_inster_data['distinct_visit_cnt'] = 1;
- $_rrs = Db::name('promotion_day')->data($_inster_data)->insert();
- } else {
- /*3.3 存在则修改*/
- $_day_data['visit_cnt'] = $_day_check['visit_cnt'] + 1;
- if ($is_distinct) {
- $_day_data['distinct_visit_cnt'] = $_day_check['distinct_visit_cnt'] + 1;
- } else {
- $_day_data['visit_cnt'] = $_day_check['visit_cnt'] + 1;
- }
- $_rrs = Db::name('promotion_day')->where($_map)->update($_day_data);
- }
- return $_rrs;
- }
- /**
- * 下载统计
- *
- * @param $agent_id
- * @param $app_id
- *
- * @return int|string
- */
- public function entDownLog($agent_id, $app_id) {
- if (empty($agent_id) || empty($app_id)) {
- return false;
- }
- $_map['agent_id'] = $agent_id;
- $_map['app_id'] = $app_id;
- $_map['date'] = date('Y-m-d');
- $_day_check = Db::name('promotion_day')->where($_map)->find();
- if (empty($_day_check)) {
- /*3.2 不存在则插入*/
- $_inster_data['agent_id'] = $agent_id;
- $_inster_data['app_id'] = $app_id;
- $_inster_data['date'] = date('Y-m-d');
- $_inster_data['down_cnt'] = 1;
- $_inster_data['distinct_down_cnt'] = 1;
- $_rrs = Db::name('promotion_day')->data($_inster_data)->insert();
- } else {
- /*3.3 存在则修改*/
- $_day_data['down_cnt'] = $_day_check['down_cnt'] + 1;
- $_day_data['distinct_down_cnt'] = $_day_check['distinct_down_cnt'] + 1;
- $_rrs = Db::name('promotion_day')->where($_map)->update($_day_data);
- }
- return $_rrs;
- }
- /**获取投放平台id
- *
- * @param $app_id
- * @param $agent_id
- *
- * @return int|mixed
- */
- public function getPlatformId($app_id, $agent_id) {
- if (empty($app_id) || empty($agent_id)) {
- return 0;
- }
- $_map['app_id'] = $app_id;
- $_map['agent_id'] = $agent_id;
- $_plan_id = Db::name('promotion_detail')->where($_map)->value('promotion_plan_id');
- $_pp_map['id'] = $_plan_id;
- $_platform_id = Db::name('promotion_plan')->where($_pp_map)->value('platform_id');
- if (empty($_platform_id)) {
- return 0;
- } else {
- return $_platform_id;
- }
- }
- }
|