PromotionMonitor.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace app\store\model;
  3. use app\common\library\helper;
  4. use app\common\model\PromotionMonitor as PromotionMonitorModel;
  5. /**
  6. * 推广监控模型
  7. * @package app\store\model
  8. */
  9. class PromotionMonitor extends PromotionMonitorModel
  10. {
  11. public function getList($params = [])
  12. {
  13. $filter = [];
  14. $query = self::alias('m')
  15. ->where($filter)
  16. ->leftJoin('promotion_monitor_statistics stat', 'stat.monitor_id=m.id')
  17. ->field("m.*,sum(stat.pv) as pv,sum(stat.uv) as uv,sum(stat.uv_new) as uv_new,
  18. sum(stat.pay_order_count) as pay_order_count,sum(stat.pay_user_count) as pay_user_count,
  19. sum(stat.pay_amount) as pay_amount,convert((sum(stat.pay_user_count)/sum(stat.uv))*100,decimal(10,2)) as ratio")
  20. ->group('m.id')
  21. ->order('m.id', 'desc');
  22. return $query->paginate(15)
  23. ->each(function ($item) {
  24. $item['qrcode'] = self::getPageQrcode($item['id'], $item['page_type'], $item['page_id']);
  25. $item['pv'] = (int)$item['pv'];
  26. $item['uv'] = (int)$item['uv'];
  27. $item['uv_new'] = (int)$item['uv_new'];
  28. $item['pay_order_count'] = (int)$item['pay_order_count'];
  29. $item['pay_user_count'] = (int)$item['pay_user_count'];
  30. $item['pay_amount'] = helper::number2($item['pay_amount']);
  31. $item['ratio'] = helper::number2($item['ratio']);
  32. });
  33. }
  34. /**
  35. * 新增记录
  36. * @param array $data
  37. * @return bool
  38. */
  39. public function add(array $data)
  40. {
  41. $this->transaction(function () use ($data) {
  42. $this->save($data);
  43. });
  44. return true;
  45. }
  46. /**
  47. * 更新记录
  48. * @param array $data
  49. * @return bool
  50. */
  51. public function edit(array $data)
  52. {
  53. $this->transaction(function () use ($data) {
  54. $this->save($data);
  55. });
  56. return true;
  57. }
  58. }