123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- <?php
- namespace app\model\member;
- use app\dict\member\MemberAccountChangeTypeDict;
- use app\dict\member\MemberAccountTypeDict;
- use core\base\BaseModel;
- use think\db\Query;
- use think\model\relation\HasOne;
- class MemberAccountLog extends BaseModel
- {
-
- protected $pk = 'id';
-
- protected $name = 'member_account_log';
-
- public function getAccountTypeNameAttr($value, $data)
- {
- if (empty($data['account_type']))
- return '';
- return MemberAccountTypeDict::getType()[$data['account_type']] ?? '';
- }
-
- public function memberInfo()
- {
- return $this->hasOne(Member::class, 'member_id', 'member_id')->joinType('left')
- ->withField('member_id,member_no, username, mobile, nickname, headimg')
- ->bind(['username', 'mobile', 'nickname', 'headimg']);
- }
-
- public function member()
- {
- return $this->hasOne(Member::class, 'member_id', 'member_id')->withField('member_id, member_no, username, mobile, nickname, headimg')->joinType('inner');
- }
-
- public function getAccountDataAttr($value, $data)
- {
- if ($data['account_type'] == 'point' || $data['account_type'] == 'growth')
- return (int)$data['account_data'];
- else
- return $data['account_data'];
- }
-
- public function getAccountSumAttr($value, $data)
- {
- if ($data['account_type'] == 'point' || $data['account_type'] == 'growth')
- return (int)$data['account_sum'];
- else
- return $data['account_sum'];
- }
-
- public function getFromTypeNameAttr($value, $data)
- {
- if (isset($data['from_type'], $data['account_type']))
- return MemberAccountChangeTypeDict::getType($data['account_type'])[$data['from_type']]['name'] ?? '';
- else
- return '';
- }
-
- public function searchMemberIdAttr($query, $value, $data)
- {
- if ($value) {
- $query->where('member_id', $value);
- }
- }
-
- public function searchKeywordAttr(Query $query, $value, $data)
- {
- if ($value != '') {
- $query->whereLike('memo', '%'.$value.'%');
- }
- }
-
- public function searchAccountDataGtAttr($query, $value, $data)
- {
- if ($value !== '' && $value !== null) {
- $query->where('account_data', '>',$value);
- }
- }
-
- public function searchAccountDataLtAttr($query, $value, $data)
- {
- if ($value !== '' && $value !== null) {
- $query->where('account_data', '<',$value);
- }
- }
-
- public function searchJoinMemberIdAttr($query, $value, $data)
- {
- if ($value) {
- $query->where('member_account_log.member_id', $value);
- }
- }
-
- public function searchFromTypeAttr($query, $value, $data)
- {
- if ($value) {
- $query->where('from_type', $value);
- }
- }
-
- public function searchAccountTypeAttr($query, $value, $data)
- {
- if ($value) {
- $query->where('account_type', $value);
- }
- }
-
- public function searchCreateTimeAttr($query, $value, $data)
- {
- $start_time = empty($value[0]) ? 0 : strtotime($value[0]);
- $end_time = empty($value[1]) ? 0 : strtotime($value[1]);
- if ($start_time > 0 && $end_time > 0) {
- $query->whereBetweenTime('create_time', $start_time, $end_time);
- } else if ($start_time > 0 && $end_time == 0) {
- $query->where([['create_time', '>=', $start_time]]);
- } else if ($start_time == 0 && $end_time > 0) {
- $query->where([['create_time', '<=', $end_time]]);
- }
- }
-
- public function searchJoinCreateTimeAttr($query, $value, $data)
- {
- $start_time = empty($value[0]) ? 0 : strtotime($value[0]);
- $end_time = empty($value[1]) ? 0 : strtotime($value[1]);
- if ($start_time > 0 && $end_time > 0) {
- $query->whereBetweenTime('member_account_log.create_time', $start_time, $end_time);
- } else if ($start_time > 0 && $end_time == 0) {
- $query->where([['member_account_log.create_time', '>=', $start_time]]);
- } else if ($start_time == 0 && $end_time > 0) {
- $query->where([['member_account_log.create_time', '<=', $end_time]]);
- }
- }
- }
|