Base.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. /**
  3. * Base.php UTF-8
  4. * 投放基类
  5. *
  6. * @date : 2018/7/13 23:19
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : ouzhongfu <ozf@huosdk.com>
  10. * @version : HUOSDK 7.2
  11. */
  12. namespace huolib\promotion;
  13. use think\Db;
  14. use think\Log;
  15. class Base {
  16. const FROM_ANDROID = 3;
  17. /**
  18. * 自定义错误处理
  19. *
  20. * @param string $msg
  21. * @param string $level
  22. *
  23. */
  24. private function _error($msg, $level = 'error') {
  25. $_info = 'promotion\Base Error:'.$msg;
  26. Log::record($_info, $level);
  27. }
  28. public function __construct() {
  29. }
  30. /**
  31. * 点击统计
  32. *
  33. * @param $agent_id
  34. * @param $app_id
  35. * @param int $is_distinct
  36. *
  37. * @return int|string
  38. */
  39. public function entVisitLog($agent_id, $app_id, $is_distinct = 0) {
  40. if (empty($agent_id) || empty($app_id)) {
  41. return false;
  42. }
  43. $_map['agent_id'] = $agent_id;
  44. $_map['app_id'] = $app_id;
  45. $_map['date'] = date('Y-m-d');
  46. $_day_check = Db::name('promotion_day')->where($_map)->find();
  47. if (empty($_day_check)) {
  48. /*3.2 不存在则插入*/
  49. $_inster_data['agent_id'] = $agent_id;
  50. $_inster_data['app_id'] = $app_id;
  51. $_inster_data['date'] = date('Y-m-d');
  52. $_inster_data['visit_cnt'] = 1;
  53. $_inster_data['distinct_visit_cnt'] = 1;
  54. $_rrs = Db::name('promotion_day')->data($_inster_data)->insert();
  55. } else {
  56. /*3.3 存在则修改*/
  57. $_day_data['visit_cnt'] = $_day_check['visit_cnt'] + 1;
  58. if ($is_distinct) {
  59. $_day_data['distinct_visit_cnt'] = $_day_check['distinct_visit_cnt'] + 1;
  60. } else {
  61. $_day_data['visit_cnt'] = $_day_check['visit_cnt'] + 1;
  62. }
  63. $_rrs = Db::name('promotion_day')->where($_map)->update($_day_data);
  64. }
  65. return $_rrs;
  66. }
  67. /**
  68. * 下载统计
  69. *
  70. * @param $agent_id
  71. * @param $app_id
  72. *
  73. * @return int|string
  74. */
  75. public function entDownLog($agent_id, $app_id) {
  76. if (empty($agent_id) || empty($app_id)) {
  77. return false;
  78. }
  79. $_map['agent_id'] = $agent_id;
  80. $_map['app_id'] = $app_id;
  81. $_map['date'] = date('Y-m-d');
  82. $_day_check = Db::name('promotion_day')->where($_map)->find();
  83. if (empty($_day_check)) {
  84. /*3.2 不存在则插入*/
  85. $_inster_data['agent_id'] = $agent_id;
  86. $_inster_data['app_id'] = $app_id;
  87. $_inster_data['date'] = date('Y-m-d');
  88. $_inster_data['down_cnt'] = 1;
  89. $_inster_data['distinct_down_cnt'] = 1;
  90. $_rrs = Db::name('promotion_day')->data($_inster_data)->insert();
  91. } else {
  92. /*3.3 存在则修改*/
  93. $_day_data['down_cnt'] = $_day_check['down_cnt'] + 1;
  94. $_day_data['distinct_down_cnt'] = $_day_check['distinct_down_cnt'] + 1;
  95. $_rrs = Db::name('promotion_day')->where($_map)->update($_day_data);
  96. }
  97. return $_rrs;
  98. }
  99. /**获取投放平台id
  100. *
  101. * @param $app_id
  102. * @param $agent_id
  103. *
  104. * @return int|mixed
  105. */
  106. public function getPlatformId($app_id, $agent_id) {
  107. if (empty($app_id) || empty($agent_id)) {
  108. return 0;
  109. }
  110. $_map['app_id'] = $app_id;
  111. $_map['agent_id'] = $agent_id;
  112. $_plan_id = Db::name('promotion_detail')->where($_map)->value('promotion_plan_id');
  113. $_pp_map['id'] = $_plan_id;
  114. $_platform_id = Db::name('promotion_plan')->where($_pp_map)->value('platform_id');
  115. if (empty($_platform_id)) {
  116. return 0;
  117. } else {
  118. return $_platform_id;
  119. }
  120. }
  121. }