MerchantCategoryDao.php 1.8 KB

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