StoreLiveProduct.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * Created by PhpStorm
  4. * Author: 向往那片天空
  5. * Date: 2020/6/9
  6. * Time: 9:07
  7. * 微信/QQ: 250023777
  8. * 格言: 抓住中心,宁精勿杂,宁专勿多
  9. */
  10. namespace app\admin\model\ump;
  11. use app\admin\model\order\StoreOrder;
  12. use crmeb\basic\BaseModel;
  13. use crmeb\services\PHPExcelService;
  14. use crmeb\traits\ModelTrait;
  15. class StoreLiveProduct extends BaseModel
  16. {
  17. /**
  18. * 数据表主键
  19. * @var string
  20. */
  21. protected $pk = 'id';
  22. /**
  23. * 模型名称
  24. * @var string
  25. */
  26. protected $name = 'store_live_product';
  27. use ModelTrait;
  28. public static function validWhere()
  29. {
  30. return self::where('is_del', 0);
  31. }
  32. /**
  33. * 导出EXCEL表格,并下载
  34. * @param $where
  35. */
  36. public static function SaveExcel($where)
  37. {
  38. }
  39. /**
  40. * 设置拼团 where 条件
  41. * @param $where
  42. * @param null $model
  43. * @return mixed
  44. */
  45. public static function setWhere($where, $model = null)
  46. {
  47. $model = $model === null ? new self() : $model;
  48. $model = $model->alias('c');
  49. $model = $model->field('c.*,p.store_name,p.price as ot_price');
  50. $model = $model->join('StoreProduct p', 'p.id=c.product_id', 'LEFT');
  51. if (isset($where['is_show']) && $where['is_show'] != '') $model = $model->where('c.is_show', $where['is_show']);
  52. if (isset($where['is_host']) && $where['is_host'] != '') $model = $model->where('c.is_host', $where['is_host']);
  53. if (isset($where['store_name']) && $where['store_name'] != '') $model = $model->where('p.store_name|p.id|c.id|c.title', 'LIKE', "%$where[store_name]%");
  54. return $model->order('c.id desc')->where('c.is_del', 0);
  55. }
  56. /**
  57. * @param $where
  58. * @return array
  59. */
  60. public static function systemPage($where)
  61. {
  62. $model = self::setWhere($where)->where('c.is_del=0')->limit(bcmul($where['page'], $where['limit'], 0), $where['limit']);
  63. return self::page($model, function ($item) {
  64. $item['count_people_all'] = StoreOrder::where('live_id', $item['id'])->count();//参与人数
  65. }, $where, $where['limit']);
  66. }
  67. }