123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- <?php
- namespace app\model\user;
- use app\model\order\StoreOrder;
- use crmeb\basic\BaseModel;
- use crmeb\traits\ModelTrait;
- use think\model;
- class UserBill extends BaseModel
- {
- use ModelTrait;
-
- protected $pk = 'id';
-
- protected $name = 'user_bill';
- protected $autoWriteTimestamp = 'int';
- protected $createTime = 'add_time';
-
- public function setAddTimeAttr()
- {
- return time();
- }
-
- public function getAddTimeAttr($value)
- {
- if (!empty($value)) {
- if (is_string($value)) {
- return $value;
- } elseif (is_int($value)) {
- return date('Y-m-d H:i:s', (int)$value);
- }
- }
- return '';
- }
-
- public function order()
- {
- return $this->hasOne(StoreOrder::class, 'id', 'link_id')->field(['id', 'total_num'])->bind(['total_num']);
- }
-
- public function user()
- {
- return $this->hasOne(User::class, 'uid', 'uid');
- }
-
- public function searchUidAttr($query, $value)
- {
- if ($value !== '') {
- if (is_array($value))
- $query->whereIn('uid', $value);
- else
- $query->where('uid', $value);
- }
- }
-
- public function searchLinkIdAttr($query, $value)
- {
- if (is_array($value))
- $query->whereIn('link_id', $value);
- else
- $query->where('link_id', $value);
- }
-
- public function searchPmAttr($query, $value)
- {
- if ($value !== '') $query->where('pm', $value);
- }
-
- public function searchCategoryAttr($query, $value)
- {
- if (is_array($value))
- $query->whereIn('category', $value);
- else
- $query->where('category', $value);
- }
-
- public function searchNotCategoryAttr($query, $value)
- {
- if (is_array($value))
- $query->whereNotIn('category', $value);
- else
- $query->where('category', '<>', $value);
- }
-
- public function searchTypeAttr($query, $value)
- {
- if (is_array($value))
- $query->whereIn('type', $value);
- else
- $query->where('type', $value);
- }
-
- public function searchNotTypeAttr($query, $value)
- {
- if (is_array($value))
- $query->whereNotIn('type', $value);
- else
- $query->where('type', '<>', $value);
- }
-
- public function searchStatusAttr($query, $value)
- {
- $query->where('status', $value);
- }
-
- public function searchTakeAttr($query, $value)
- {
- $query->where('take', $value);
- }
-
- public function searchLikeAttr($query, $value)
- {
- $query->where(function ($query) use ($value) {
- $query->where('id|uid|title', 'like', "%$value%")->whereOr('uid', 'in', function ($query) use ($value) {
- $query->name('user')->whereLike('uid|account|nickname|phone', '%' . $value . '%')->field('uid')->select();
- });
- });
- }
-
- public function searchAddTimeAttr($query, $value)
- {
- if (is_string($value)) $query->whereTime($query, $value);
- if (is_array($value) && count($value) == 2) $query->whereTime('add_time', 'between', $value);
- }
- }
|