ProductAssistDao.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\common\dao\store\product;
  12. use app\common\dao\BaseDao;
  13. use app\common\model\store\product\ProductAssist;
  14. use app\common\repositories\store\product\SpuRepository;
  15. use app\common\repositories\system\merchant\MerchantRepository;
  16. class ProductAssistDao extends BaseDao
  17. {
  18. protected function getModel(): string
  19. {
  20. return ProductAssist::class;
  21. }
  22. public function search(array $where)
  23. {
  24. $query = ProductAssist::hasWhere('product',function($query)use($where){
  25. $query->when(isset($where['product_show']) && $where['product_show'] !== '',function($query)use($where){
  26. $query->where('is_del',0)->where('mer_status',1)->where('product_type',3);
  27. })
  28. ->where('status',1);
  29. });
  30. $query->when(isset($where['product_assist_id']) && $where['product_assist_id'] !== '',function($query)use($where){
  31. $query->where('product_assist_id',$where['product_assist_id']);
  32. })
  33. ->when(isset($where['keyword']) && $where['keyword'] !== '',function($query)use($where){
  34. $query->whereLike('ProductAssist.store_name|ProductAssist.product_id',"%{$where['keyword']}%");
  35. })
  36. ->when(isset($where['mer_id']) && $where['mer_id'] !== '',function($query)use($where){
  37. $query->where('ProductAssist.mer_id',$where['mer_id']);
  38. })
  39. ->when(isset($where['type']) && $where['type'] !== '',function($query)use($where){
  40. switch ($where['type']){
  41. case 0: //未开始
  42. $query->whereTime('start_time','>',time());
  43. break;
  44. case 1: //进行中
  45. $query->whereTime('start_time','<=',time())->whereTime('end_time','>',time())
  46. ->where('ProductAssist.product_status',1)->where('ProductAssist.status',1)->where('ProductAssist.is_show',1);
  47. break;
  48. case 2: //已结束
  49. $query->where(function($query){
  50. $query->where('action_status',-1)->whereOr('end_time','<= TIME',time());
  51. });
  52. break;
  53. }
  54. })
  55. ->when(isset($where['status']) && $where['status'] !== '',function($query)use($where){
  56. $query->where('ProductAssist.status',$where['status']);
  57. })
  58. ->when(isset($where['is_show']) && $where['is_show'] !== '',function($query)use($where){
  59. $query->where('ProductAssist.is_show',$where['is_show']);
  60. })
  61. ->when(isset($where['mer_name']) && $where['mer_name'] !== '',function($query)use($where){
  62. $make = app()->make(MerchantRepository::class);
  63. $mer_id = $make->search(['keyword' => $where['mer_name']])->column('mer_id');
  64. $query->whereIn('ProductAssist.mer_id',$mer_id);
  65. })
  66. ->when(isset($where['product_status']) && $where['product_status'] !== '',function($query)use($where){
  67. if($where['product_status'] == -1){
  68. $query->where('ProductAssist.product_status','in',[-1,-2]);
  69. }else{
  70. $query->where('ProductAssist.product_status',$where['product_status']);
  71. }
  72. })
  73. ->when(isset($where['is_trader']) && $where['is_trader'] !== '',function($query)use($where){
  74. $make = app()->make(MerchantRepository::class);
  75. $mer_id = $make->search(['is_trader' => $where['is_trader']])->column('mer_id');
  76. $query->whereIn('ProductAssist.mer_id',$mer_id);
  77. })
  78. ->when(isset($where['us_status']) && $where['us_status'] !== '',function($query)use($where){
  79. if($where['us_status'] == 0) {
  80. $query->where('ProductAssist.is_show',0)->where('ProductAssist.status',1)->where('ProductAssist.product_status',1);
  81. }
  82. if($where['us_status'] == 1) {
  83. $query->where('ProductAssist.is_show',1)->where('ProductAssist.status',1)->where('ProductAssist.product_status',1);
  84. }
  85. if($where['us_status'] == -1) {
  86. $query->where(function($query){
  87. $query->where('ProductAssist.status',0)->whereOr('ProductAssist.product_status','<>',1);
  88. });
  89. }
  90. })
  91. ->when(isset($where['star']),function($query)use($where){
  92. $query->Join('StoreSpu U', 'Product.product_id = U.product_id')->where('U.product_type', 3);
  93. $query->when($where['star'] !== '', function ($query) use ($where) {
  94. $query->where('U.star', $where['star']);
  95. });
  96. $query->order('U.star DESC,U.rank DESC,ProductAssist.create_time DESC');
  97. });
  98. $query->where('ProductAssist.is_del',0);
  99. return $query;
  100. }
  101. /**
  102. * TODO 移动端展示 条件
  103. * @return array
  104. * @author Qinii
  105. * @day 2020-10-19
  106. */
  107. public function assistShow()
  108. {
  109. return [
  110. 'product_show' => 1,
  111. 'product_status' => 1,
  112. 'status' => 1,
  113. 'is_show' => 1,
  114. 'type' => 1
  115. ];
  116. }
  117. /**
  118. * TODO
  119. * @author Qinii
  120. * @day 1/27/21
  121. */
  122. public function valActiveStatus()
  123. {
  124. $query = $this->getModel()::getDB()->whereTime('end_time','<=',time())->where('action_status',1);
  125. $id = $query->column($this->getPk());
  126. if($id) {
  127. $this->getModel()::getDB()->where($this->getPk(),'in',$id)->update(['action_status' => -1]);
  128. $where = [
  129. 'product_type' => 3,
  130. 'activity_ids' => $id
  131. ];
  132. app()->make(SpuRepository::class)->getSearch($where)->update(['status' => 0]);
  133. }
  134. }
  135. }