123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- <?php
- namespace app\dao\activity\integral;
- use app\dao\BaseDao;
- use app\model\activity\integral\StoreIntegralOrder;
- class StoreIntegralOrderDao extends BaseDao
- {
-
- protected $withField = ['uid', 'order_id', 'real_name', 'user_phone', 'store_name'];
-
- protected function setModel(): string
- {
- return StoreIntegralOrder::class;
- }
-
- public function search(array $where = [])
- {
- $isDel = isset($where['is_del']) && $where['is_del'] !== '' && $where['is_del'] != -1;
- $realName = $where['real_name'] ?? '';
- $fieldKey = $where['field_key'] ?? '';
- $fieldKey = $fieldKey == 'all' ? '' : $fieldKey;
- return parent::search($where)->when($isDel, function ($query) use ($where) {
- $query->where('is_del', $where['is_del']);
- })->when(isset($where['is_system_del']), function ($query) {
- $query->where('is_system_del', 0);
- })->when(isset($where['paid']) && $where['paid'] == 1, function ($query) {
- $query->where('paid', 1);
- })->when(isset($where['is_price']) && $where['is_price'] == 1, function ($query) {
- $query->where('price', '>', 0);
- })->when(isset($where['is_integral']) && $where['is_integral'] == 1, function ($query) {
- $query->where('integral', '>', 0);
- })->when($realName && $fieldKey && in_array($fieldKey, $this->withField), function ($query) use ($where, $realName, $fieldKey) {
- if ($fieldKey !== 'store_name') {
- $query->where(trim($fieldKey), trim($realName));
- } else {
- $query->whereLike('store_name', '%' . $realName . '%');
- }
- })->when($realName && !$fieldKey, function ($query) use ($where) {
- $query->where(function ($que) use ($where) {
- $que->whereLike('order_id|real_name|store_name', '%' . $where['real_name'] . '%')->whereOr('uid', 'in', function ($q) use ($where) {
- $q->name('user')->whereLike('nickname|uid|phone', '%' . $where['real_name'] . '%')->field(['uid'])->select();
- });
- });
- });
- }
-
- public function getOrderList(array $where, array $field, int $page, int $limit, array $with = [])
- {
- return $this->search($where)->field($field)->with(array_merge(['user'], $with))->page($page, $limit)->order('add_time DESC,id DESC')->select()->toArray();
- }
-
- public function getIntegralOrderList(array $where)
- {
- return $this->search($where)->order('id asc')->select()->toArray();
- }
-
- public function count(array $where = []): int
- {
- return $this->search($where)->count();
- }
-
- public function column(array $where, string $field, string $key = '', string $group = '')
- {
- return $this->search($where)->when($group, function ($query) use ($group) {
- $query->group($group);
- })->column($field, $key);
- }
-
- public function getUserOrderDetail(string $key, int $uid)
- {
- return $this->getOne(['order_id' => $key, 'uid' => $uid, 'is_del' => 0]);
- }
-
- public function getBuyCount($uid, $productId): int
- {
- return $this->getModel()
- ->where('uid', $uid)
- ->where('is_del', 0)
- ->where('product_id', $productId)
- ->value('sum(total_num)') ?? 0;
- }
- }
|