ProductAssistDao.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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\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->Join('StoreSpu U', 'Product.product_id = U.product_id')->where('U.product_type', 3);
  31. $query->when(isset($where['product_assist_id']) && $where['product_assist_id'] !== '',function($query)use($where){
  32. $query->where('product_assist_id',$where['product_assist_id']);
  33. })
  34. ->when(isset($where['keyword']) && $where['keyword'] !== '',function($query)use($where){
  35. $query->whereLike('ProductAssist.store_name|ProductAssist.product_id',"%{$where['keyword']}%");
  36. })
  37. ->when(isset($where['mer_id']) && $where['mer_id'] !== '',function($query)use($where){
  38. $query->where('ProductAssist.mer_id',$where['mer_id']);
  39. })
  40. ->when(isset($where['type']) && $where['type'] !== '',function($query)use($where){
  41. switch ($where['type']){
  42. case 0: //未开始
  43. $query->whereTime('start_time','>',time());
  44. break;
  45. case 1: //进行中
  46. $query->whereTime('start_time','<=',time())->whereTime('end_time','>',time())
  47. ->where('ProductAssist.product_status',1)->where('ProductAssist.status',1)->where('ProductAssist.is_show',1);
  48. break;
  49. case 2: //已结束
  50. $query->where(function($query){
  51. $query->where('action_status',-1)->whereOr('end_time','<= TIME',time());
  52. });
  53. break;
  54. }
  55. })
  56. ->when(isset($where['status']) && $where['status'] !== '',function($query)use($where){
  57. $query->where('ProductAssist.status',$where['status']);
  58. })
  59. ->when(isset($where['is_show']) && $where['is_show'] !== '',function($query)use($where){
  60. $query->where('ProductAssist.is_show',$where['is_show']);
  61. })
  62. ->when(isset($where['mer_name']) && $where['mer_name'] !== '',function($query)use($where){
  63. $make = app()->make(MerchantRepository::class);
  64. $mer_id = $make->search(['keyword' => $where['mer_name']])->column('mer_id');
  65. $query->whereIn('ProductAssist.mer_id',$mer_id);
  66. })
  67. ->when(isset($where['product_status']) && $where['product_status'] !== '',function($query)use($where){
  68. if($where['product_status'] == -1){
  69. $query->where('ProductAssist.product_status','in',[-1,-2]);
  70. }else{
  71. $query->where('ProductAssist.product_status',$where['product_status']);
  72. }
  73. })
  74. ->when(isset($where['is_trader']) && $where['is_trader'] !== '',function($query)use($where){
  75. $make = app()->make(MerchantRepository::class);
  76. $mer_id = $make->search(['is_trader' => $where['is_trader']])->column('mer_id');
  77. $query->whereIn('ProductAssist.mer_id',$mer_id);
  78. })
  79. ->when(isset($where['us_status']) && $where['us_status'] !== '',function($query)use($where){
  80. if($where['us_status'] == 0) {
  81. $query->where('ProductAssist.is_show',0)->where('ProductAssist.status',1)->where('ProductAssist.product_status',1);
  82. }
  83. if($where['us_status'] == 1) {
  84. $query->where('ProductAssist.is_show',1)->where('ProductAssist.status',1)->where('ProductAssist.product_status',1);
  85. }
  86. if($where['us_status'] == -1) {
  87. $query->where(function($query){
  88. $query->where('ProductAssist.status',0)->whereOr('ProductAssist.product_status','<>',1);
  89. });
  90. }
  91. })
  92. ->when(isset($where['mer_labels']) && $where['mer_labels'] !== '', function ($query) use ($where) {
  93. $query->whereLike('U.mer_labels', "%,{$where['mer_labels']},%");
  94. })
  95. ->when(isset($where['sys_labels']) && $where['sys_labels'] !== '', function ($query) use ($where) {
  96. $query->whereLike('U.sys_labels', "%,{$where['sys_labels']},%");
  97. })
  98. ->when(isset($where['star']),function($query)use($where){
  99. $query->when($where['star'] !== '', function ($query) use ($where) {
  100. $query->where('U.star', $where['star']);
  101. });
  102. $query->order('U.star DESC,U.rank DESC,ProductAssist.create_time DESC');
  103. });
  104. $query->where('ProductAssist.is_del',0);
  105. return $query;
  106. }
  107. /**
  108. * TODO 移动端展示 条件
  109. * @return array
  110. * @author Qinii
  111. * @day 2020-10-19
  112. */
  113. public function assistShow()
  114. {
  115. return [
  116. 'product_show' => 1,
  117. 'product_status' => 1,
  118. 'status' => 1,
  119. 'is_show' => 1,
  120. 'type' => 1
  121. ];
  122. }
  123. /**
  124. * TODO
  125. * @author Qinii
  126. * @day 1/27/21
  127. */
  128. public function valActiveStatus()
  129. {
  130. $query = $this->getModel()::getDB()->whereTime('end_time','<=',time())->where('action_status',1);
  131. $id = $query->column($this->getPk());
  132. if($id) {
  133. $this->getModel()::getDB()->where($this->getPk(),'in',$id)->update(['action_status' => -1]);
  134. $where = [
  135. 'product_type' => 3,
  136. 'activity_ids' => $id
  137. ];
  138. app()->make(SpuRepository::class)->getSearch($where)->update(['status' => 0]);
  139. }
  140. }
  141. /**
  142. * TODO 软删除商户的所有商品
  143. * @param $merId
  144. * @author Qinii
  145. * @day 5/15/21
  146. */
  147. public function clearProduct($merId)
  148. {
  149. $this->getModel()::getDb()->where('mer_id', $merId)->update(['is_del' => 1]);
  150. }
  151. }