Guideappcollect.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Elton
  5. * Date: 2019/8/9
  6. * Time: 14:05
  7. */
  8. namespace app\admin\controller;
  9. use app\common\controller\Backend;
  10. use app\main\constants\OrderContents;
  11. use app\main\constants\PayConstants;
  12. class Guideappcollect extends Backend
  13. {
  14. protected $model = null;
  15. protected $noNeedRight = ['*'];
  16. public function _initialize()
  17. {
  18. parent::_initialize(); // TODO: Change the autogenerated stub
  19. $this->model = model('GuideAppCollect');
  20. }
  21. public function index()
  22. {
  23. $admin_id = $this->auth->id;
  24. if ($this->request->isAjax()) {
  25. // 判断管理员身份 [普通代理商 | 渠道商 | 配号代理商]
  26. if ($this->group == 4) {
  27. //普通代理商
  28. $data = $this->onlyOrderCollectData($admin_id);
  29. } else {
  30. //渠道商 | 配号代理商
  31. $data = $this->mergeData($admin_id);
  32. }
  33. $total = count($data);
  34. $result = array("total" => $total, "rows" => $data);
  35. return json($result);
  36. }
  37. $this->assign('admin_groupid', $this->group);
  38. $this->assignconfig('admin_groupid', $this->group);
  39. return $this->view->fetch();
  40. }
  41. /**
  42. * 普通代理商仅显示充值人数和充值金额
  43. * @param $admin_id
  44. * @return array
  45. */
  46. public function onlyOrderCollectData($admin_id)
  47. {
  48. $order_data = $this->getOrdersCollect($admin_id);
  49. $result = [];
  50. if(is_array($order_data)){
  51. $order_data = array_values($order_data);
  52. foreach ($order_data as $key => $item) {
  53. if (!empty($item)) {
  54. $result[$key]['createdate'] = $item['createdate'];
  55. $result[$key]['recharge_money'] = $item['recharge_money'];
  56. $result[$key]['recharge_user_num'] = $item['recharge_user_suc_count'];
  57. }
  58. }
  59. }
  60. return $result;
  61. }
  62. public function mergeData($admin_id)
  63. {
  64. $base_data = $this->getBaseData($admin_id);
  65. $order_data = $this->getOrdersCollect($admin_id);
  66. $user_app_data = $this->getUserAppCollect($admin_id);
  67. $result = [];
  68. if($base_data){
  69. foreach ($base_data as $key => $item) {
  70. if(!empty($order_data[$key])){
  71. $base_data[$key]['recharge_money'] = $order_data[$key]['recharge_money'];
  72. $base_data[$key]['recharge_user_num'] = $order_data[$key]['recharge_user_suc_count'];
  73. }else{
  74. $base_data[$key]['recharge_money'] = 0;
  75. $base_data[$key]['recharge_user_num'] = 0;
  76. }
  77. if(!empty($user_app_data[$key])){
  78. $base_data[$key]['import_num'] = $user_app_data[$key]['increase_bind_code'];
  79. }else{
  80. $base_data[$key]['import_num'] = 0;
  81. }
  82. // uv_view_total 曝光量
  83. if ($base_data[$key]['uv_view_total']) {
  84. $base_data[$key]['importapp_rate'] = sprintf("%.2f", ($base_data[$key]['import_num'] / $base_data[$key]['uv_view_total']) * 100) . '%';
  85. } else {
  86. $base_data[$key]['importapp_rate'] = 0;
  87. }
  88. // uv_view_total 曝光量
  89. if ($base_data[$key]['uv_total']) {
  90. $base_data[$key]['click_rate'] = sprintf("%.2f", ($base_data[$key]['import_num'] / $base_data[$key]['uv_total']) * 100) . '%';
  91. } else {
  92. $base_data[$key]['click_rate'] = 0;
  93. }
  94. $result[] = $base_data[$key];
  95. }
  96. }
  97. return $result;
  98. }
  99. /**
  100. * @param $admin_id 渠道商ID
  101. * @return array 按日期汇总打点统计数据
  102. */
  103. public function getBaseData($admin_id)
  104. {
  105. $res = [];
  106. $data = $this->model->where(['type' => 1, 'admin_id' => $admin_id])->select();
  107. if ($data) {
  108. foreach ($data as $key => $item) {
  109. $key = $item['createdate'];
  110. $res[$key] = $item;
  111. if( $item['uv_total'] == 0){
  112. $res[$key]['click_rate'] = 0;
  113. }else{
  114. $res[$key]['click_rate'] = $item['import_num'] / $item['uv_total']; //点击率
  115. }
  116. if($item['uv_view_total'] == 0){
  117. $res[$key]['importapp_rate'] = 0; //导端率
  118. }else{
  119. $res[$key]['importapp_rate'] = $item['import_num'] / $item['uv_view_total']; //导端率
  120. }
  121. }
  122. return $res;
  123. }
  124. }
  125. /**
  126. * 获取订单统计数据
  127. * @param $admin_id
  128. * @return array
  129. */
  130. public function getOrdersCollect($admin_id)
  131. {
  132. $res = [];
  133. if ($this->group == 4) {
  134. // 普通代理商
  135. $data = model('OrdersCollect')->where([
  136. 'type' => OrderContents::ORDER_COLLECT_TYPE_DAY,
  137. 'admin_id' => $admin_id,
  138. 'flag' => OrderContents::ORDER_COLLECT_FLAG_SELF,
  139. 'business_line' => PayConstants::BUSINESS_APP
  140. ])->select();
  141. } else {
  142. $data = model('OrdersCollect')->where([
  143. 'type' => OrderContents::ORDER_COLLECT_TYPE_DAY,
  144. 'admin_id' => $admin_id,
  145. 'flag' => OrderContents::ORDER_COLLECT_FLAG_ALL,
  146. 'business_line' => PayConstants::BUSINESS_APP
  147. ])->select();
  148. }
  149. if ($data) {
  150. foreach ($data as $key => $item) {
  151. $key = $item['createdate'];
  152. $res[$key] = $item;
  153. }
  154. }
  155. return $res;
  156. }
  157. /**
  158. * 获取导端用户统计数据
  159. * @param $admin_id
  160. * @return array
  161. */
  162. public function getUserAppCollect($admin_id)
  163. {
  164. $res = [];
  165. $data = model('UserAppCollect')->where(['type' => 1, 'admin_id' => $admin_id])->select();
  166. if ($data) {
  167. foreach ($data as $key => $item) {
  168. $key = $item['createdate'];
  169. $res[$key] = $item;
  170. }
  171. }
  172. return $res;
  173. }
  174. }