MerchantCategoryDao.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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\system\merchant;
  12. use app\common\dao\BaseDao;
  13. use app\common\model\BaseModel;
  14. use app\common\model\system\merchant\MerchantCategory;
  15. use think\db\BaseQuery;
  16. use think\facade\Db;
  17. /**
  18. * Class MerchantCategoryDao
  19. * @package app\common\dao\system\merchant
  20. * @author xaboy
  21. * @day 2020-05-06
  22. */
  23. class MerchantCategoryDao extends BaseDao
  24. {
  25. /**
  26. * @return BaseModel
  27. * @author xaboy
  28. * @day 2020-03-30
  29. */
  30. protected function getModel(): string
  31. {
  32. return MerchantCategory::class;
  33. }
  34. /**
  35. * @param array $where
  36. * @return BaseQuery
  37. * @author xaboy
  38. * @day 2020-05-06
  39. */
  40. public function search(array $where = [])
  41. {
  42. return MerchantCategory::getDB();
  43. }
  44. /**
  45. * @return array
  46. * @author xaboy
  47. * @day 2020-05-06
  48. */
  49. public function allOptions()
  50. {
  51. return MerchantCategory::getDB()->column('category_name', 'merchant_category_id');
  52. }
  53. public function dateMerchantPriceGroup($date, $limit = 4)
  54. {
  55. return MerchantCategory::getDB()->alias('A')->leftJoin('Merchant B', 'A.merchant_category_id = B.category_id')
  56. ->leftJoin('StoreOrder C', 'C.mer_id = B.mer_id')->field(Db::raw('sum(C.pay_price) as pay_price,A.category_name'))
  57. ->when($date, function ($query, $date) {
  58. getModelTime($query, $date, 'C.pay_time');
  59. })->group('A.merchant_category_id')->where('pay_price', '>', 0)->order('pay_price DESC')->limit($limit)->select();
  60. }
  61. public function names(array $ids)
  62. {
  63. return MerchantCategory::getDB()->whereIn('merchant_category_id', $ids)->column('category_name');
  64. }
  65. }