CouponStat.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace addon\coupon\model;
  11. use app\model\BaseModel;
  12. use app\model\system\Stat;
  13. /**
  14. * 优惠券统计
  15. */
  16. class CouponStat extends BaseModel
  17. {
  18. /**
  19. * 领取优惠券统计
  20. * @param $params
  21. * @return array
  22. */
  23. public function addReceiveCouponStat($params)
  24. {
  25. $coupon_id = $params[ 'coupon_id' ];
  26. $site_id = $params[ 'site_id' ] ?? 0;
  27. $order_condition = array (
  28. [ 'coupon_id', '=', $coupon_id ],
  29. [ 'site_id', '=', $site_id ]
  30. );
  31. $info = model('promotion_coupon')->getInfo($order_condition);
  32. if (empty($info))
  33. return $this->error();
  34. $stat_data = array (
  35. 'site_id' => $site_id,
  36. 'coupon_count' => 1
  37. );
  38. $member_id = $info[ 'member_id' ];
  39. //如果是第一笔订单才能累加下单会员数
  40. $time_region = getDayStartAndEndTime();
  41. $today_start_time = $time_region[ 'start_time' ];
  42. $today_end_time = $time_region[ 'end_time' ];
  43. $today_order_condition = array (
  44. [ 'member_id', '=', $member_id ],
  45. [ 'fetch_time', 'between', [ $today_start_time, $today_end_time ] ],
  46. [ 'coupon_id', '<>', $coupon_id ]
  47. );
  48. $count = model('promotion_coupon')->getCount($today_order_condition);
  49. if ($count == 0) {
  50. $stat_data[ 'coupon_member_count' ] = 1;
  51. }
  52. $stat_model = new Stat();
  53. $result = $stat_model->addShopStat($stat_data);
  54. return $result;
  55. }
  56. }