LiveGoods.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\wap\model\live;
  12. use app\wap\model\store\StoreOrder;
  13. use app\wap\model\store\StoreProduct;
  14. use basic\ModelBasic;
  15. use service\SystemConfigService;
  16. use traits\ModelTrait;
  17. use app\wap\model\user\User;
  18. use app\wap\model\special\Special;
  19. /**直播带货
  20. * Class LiveGoods
  21. * @package app\wap\model\live
  22. */
  23. class LiveGoods extends ModelBasic
  24. {
  25. use ModelTrait;
  26. /**直播带货列表
  27. * @param $where
  28. * @param int $is_member
  29. * @param int $page
  30. * @param int $limit
  31. * @return array
  32. * @throws \think\Exception
  33. * @throws \think\db\exception\DataNotFoundException
  34. * @throws \think\db\exception\ModelNotFoundException
  35. * @throws \think\exception\DbException
  36. */
  37. public static function getLiveGoodsList($where, $is_member = 0, $page = 0, $limit = 10)
  38. {
  39. $model = self::alias('g');
  40. $model = $model->where('g.is_delete', 0);
  41. if ($where['is_show'] != "" && isset($where['is_show'])) {
  42. $model = $model->where('g.is_show', $where['is_show']);
  43. }
  44. if ($where['live_id'] != 0 && isset($where['live_id'])) {
  45. $model = $model->where('g.live_id', $where['live_id']);
  46. }
  47. $model = $model->field('g.id as live_goods_id,g.special_id, g.sort as gsort, g.fake_sales as gfake_sales,g.type as gfake_type, g.is_show as gis_show, g.sales as gsales');
  48. $model = $model->order('g.sort desc');
  49. if ($page && $limit) {
  50. $list = $model->page((int)$page, (int)$limit)->select();
  51. } else {
  52. $list = $model->select();
  53. }
  54. $list = count($list) ? $list->toArray() : [];
  55. foreach ($list as $key => &$item) {
  56. if ($item['gfake_type'] == 0) {
  57. $special = Special::PreWhere()->where('id', $item['special_id'])->find();
  58. if (!$special) {
  59. array_splice($list, $key, 1);
  60. continue;
  61. }
  62. if (!$is_member && $special['is_mer_visible'] == 1) {
  63. array_splice($list, $key, 1);
  64. continue;
  65. }
  66. $item['id'] = $special['id'];
  67. $item['image'] = $special['image'];
  68. $item['title'] = $special['title'];
  69. $item['is_light'] = $special['is_light'];
  70. $item['member_pay_type'] = $special['member_pay_type'];
  71. $item['member_money'] = $special['member_money'];
  72. $item['money'] = $special['money'];
  73. $item['label'] = $special['label'];
  74. $item['_add_time'] = $special['add_time'];
  75. $item['pink_end_time'] = $special['pink_end_time'] ? strtotime($special['pink_end_time']) : 0;
  76. $item['sales'] = StoreOrder::where(['paid' => 1, 'cart_id' => $special['id'], 'refund_status' => 0, 'type' => 0])->count();
  77. //查看拼团状态,如果已结束关闭拼团
  78. if ($special['is_pink'] && $special['pink_end_time'] < time()) {
  79. self::update(['is_pink' => 0], ['id' => $item['live_goods_id']]);
  80. $item['is_pink'] = 0;
  81. }
  82. } else {
  83. $store = StoreProduct::where('id', $item['special_id'])->where('is_del', 0)->find();
  84. if (!$store) {
  85. array_splice($list, $key, 1);
  86. continue;
  87. }
  88. $item['id'] = $store['id'];
  89. $item['image'] = $store['image'];
  90. $item['title'] = $store['store_name'];
  91. $item['member_pay_type'] = 0;
  92. $item['member_money'] = $store['vip_price'];
  93. $item['money'] = $store['price'];
  94. $item['label'] = explode(',', $store['keyword']);
  95. $item['_add_time'] = date('Y-m-d H:i:s', $store['add_time']);
  96. $item['sales'] = $store['sales'];
  97. }
  98. }
  99. $page++;
  100. return ['list' => $list, 'page' => $page];
  101. }
  102. }