123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- <?php
- declare (strict_types=1);
- namespace app\dao\order;
- use app\dao\BaseDao;
- use app\model\order\StoreOrder;
- use app\model\order\StoreOrderInvoice;
- class StoreOrderOrderInvoiceDao extends BaseDao
- {
-
- protected $withField = ['uid', 'order_id', 'real_name', 'user_phone', 'title'];
-
- protected $alias = '';
-
- protected $join_alis = '';
- protected function setModel(): string
- {
- return StoreOrderInvoice::class;
- }
- public function joinModel(): string
- {
- return StoreOrder::class;
- }
-
- public function getModel(string $alias = 'i', string $join_alias = 'o', $join = 'left')
- {
- $this->alias = $alias;
- $this->join_alis = $join_alias;
-
- $storeOrder = app()->make($this->joinModel());
- $table = $storeOrder->getName();
- return parent::getModel()->alias($alias)->join($table . ' ' . $join_alias, $alias . '.order_id = ' . $join_alias . '.id', $join);
- }
- public function getSearch($where)
- {
- $realName = $where['real_name'] ?? '';
- $fieldKey = $where['field_key'] ?? '';
- $fieldKey = $fieldKey == 'all' ? '' : $fieldKey;
- return $this->getModel()->when(isset($where['data']) && $where['data'], function ($query) use ($where) {
- if (strstr($where['data'], '-') !== false) {
- [$startTime, $endTime] = explode('-', $where['data']);
- $query->whereBetween($this->alias . '.add_time', [strtotime($startTime), strtotime($endTime) + 86400]);
- }
- })->when(isset($where['status']) && $where['status'] !== '', function ($query) use ($where) {
- switch ((int)$where['status']) {
- case 0:
- $query->where($this->join_alis . '.paid', 0)->where($this->join_alis . '.status', 0)->where($this->join_alis . '.refund_status', 0)->where($this->join_alis . '.is_del', 0);
- break;
- case 1:
- $query->where($this->join_alis . '.paid', 1)->where($this->join_alis . '.status', 0)->where($this->join_alis . '.refund_status', 0)->when(isset($where['shipping_type']), function ($query) {
- $query->where($this->join_alis . '.shipping_type', 1);
- })->where($this->join_alis . '.is_del', 0);
- break;
- case 2:
- $query->where($this->join_alis . '.paid', 1)->where($this->join_alis . '.status', 1)->where($this->join_alis . '.refund_status', 0)->where($this->join_alis . '.is_del', 0);
- break;
- case 3:
- $query->where($this->join_alis . '.paid', 1)->where($this->join_alis . '.status', 2)->where($this->join_alis . '.refund_status', 0)->where($this->join_alis . '.is_del', 0);
- break;
- case 4:
- $query->where($this->join_alis . '.paid', 1)->where($this->join_alis . '.status', 3)->where($this->join_alis . '.refund_status', 0)->where($this->join_alis . '.is_del', 0);
- break;
- case 5:
- $query->where($this->join_alis . '.paid', 1)->where($this->join_alis . '.status', 0)->where($this->join_alis . '.refund_status', 0)->where($this->join_alis . '.shipping_type', 2)->where($this->join_alis . '.is_del', 0);
- break;
- case 6:
- $query->where($this->join_alis . '.paid', 1)->where($this->join_alis . '.status', 2)->where($this->join_alis . '.refund_status', 0)->where($this->join_alis . '.shipping_type', 2)->where($this->join_alis . '.is_del', 0);
- break;
- case -1:
- $query->where($this->join_alis . '.paid', 1)->where($this->join_alis . '.refund_status', 1)->where($this->join_alis . '.is_del', 0);
- break;
- case -2:
- $query->where($this->join_alis . '.paid', 1)->where($this->join_alis . '.refund_status', 2)->where($this->join_alis . '.is_del', 0);
- break;
- case -3:
- $query->where($this->join_alis . '.paid', 1)->where($this->join_alis . '.refund_status', 'in', '1,2')->where($this->join_alis . '.is_del', 0);
- break;
- case -4:
- $query->where($this->join_alis . '.is_del', 1);
- break;
- }
- })->when(isset($where['type']), function ($query) use ($where) {
- switch ($where['type']) {
- case 1:
- $query->where($this->join_alis . '.type', 0);
- break;
- case 2:
- $query->where($this->join_alis . '.type', 3);
- break;
- case 3:
- $query->where($this->join_alis . '.type', 1);
- break;
- case 4:
- $query->where($this->join_alis . '.type', 2);
- break;
- }
- })->when($realName && $fieldKey && in_array($fieldKey, $this->withField), function ($query) use ($where, $realName, $fieldKey) {
- if ($fieldKey !== 'title') {
- $query->where($this->join_alis . '.' . trim($fieldKey), trim($realName));
- } else {
- $query->where($this->join_alis . '.id', 'in', function ($que) use ($where) {
- $que->name('store_order_cart_info')->whereIn('product_id', function ($q) use ($where) {
- $q->name('store_product')->whereLike('store_name|keyword', '%' . $where['real_name'] . '%')->field(['id'])->select();
- })->field(['oid'])->select();
- });
- }
- })->when($realName && !$fieldKey, function ($query) use ($where) {
- $query->where(function ($que) use ($where) {
- $que->whereLike($this->alias . '.order_id|' . $this->alias . '.invoice_id|' . $this->alias . '.name|' . $this->alias . '.drawer_phone|' . $this->alias . '.email|' . $this->alias . '.tell|' . $this->alias . '.address|' . $this->alias . '.bank', "%{$where['real_name']}%")
- ->whereOr($this->join_alis . '.uid|' . $this->join_alis . '.real_name|' . $this->join_alis . '.order_id', 'LIKE', "%{$where['real_name']}%")
- ->whereOr($this->join_alis . '.uid', 'in', function ($q) use ($where) {
- $q->name('user')->whereLike('nickname|uid|phone', '%' . $where['real_name'] . '%')->field(['uid'])->select();
- })->whereOr($this->join_alis . '.id', 'in', function ($que) use ($where) {
- $que->name('store_order_cart_info')->whereIn('product_id', function ($q) use ($where) {
- $q->name('store_product')->whereLike('store_name|keyword', '%' . $where['real_name'] . '%')->field(['id'])->select();
- })->field(['oid'])->select();
- });
- });
- });
- }
- public function getCount(array $where)
- {
- return $this->getSearch($where)->count();
- }
-
- public function getList(array $where, string $field = '*', string $order = '', int $page = 0, int $limit = 0)
- {
- return $this->getSearch($where)->field($field)->when($order != '', function ($query) use ($order) {
- $query->order($order);
- })->when($page && $limit, function ($query) use ($page, $limit) {
- $query->page($page, $limit);
- })->select()->toArray();
- }
- }
|