123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- <?php
- // +----------------------------------------------------------------------
- // | Niucloud-admin 企业快速开发的saas管理平台
- // +----------------------------------------------------------------------
- // | 官方网址:https://www.niucloud.com
- // +----------------------------------------------------------------------
- // | niucloud团队 版权所有 开源版本可自由商用
- // +----------------------------------------------------------------------
- // | Author: Niucloud Team
- // +----------------------------------------------------------------------
- namespace app\model\pay;
- use app\dict\common\ChannelDict;
- use app\dict\pay\PayDict;
- use app\model\member\Member;
- use core\base\BaseModel;
- /**
- * 订单模型
- * Class Order
- * @package app\model\order
- */
- class Pay extends BaseModel
- {
- // 关闭自动写入update_time字段
- protected $updateTime = false;
- /**
- * 数据表主键
- * @var string
- */
- protected $pk = 'id';
- /**
- * 模型名称
- * @var string
- */
- protected $name = 'pay';
- //类型
- protected $type = [
- 'pay_time' => 'timestamp',
- 'close_time' => 'timestamp',
- ];
- protected $json = ['allow_type'];
- protected $jsonAssoc = true;
- public function member()
- {
- return $this->hasOne(Member::class, 'member_id', 'main_id');
- }
- /**
- * 状态字段转化
- * @param $value
- * @param $data
- * @return mixed
- */
- public function getStatusNameAttr($value, $data)
- {
- if (empty($data['status']))
- return '';
- return PayDict::getStatus()[$data['status']] ?? '';
- }
- /**
- * 支付方式字段转化
- * @param $value
- * @param $data
- * @return mixed
- */
- public function getTypeNameAttr($value, $data)
- {
- if (empty($data['type']))
- return '';
- $temp = PayDict::getPayType()[$data['type']] ?? [];
- return $temp['name'] ?? '';
- }
- /**
- * 支付渠道
- * @param $value
- * @param $data
- * @return array|mixed|string|void
- */
- public function getChannelNameAttr($value, $data){
- if (isset($data['channel'])) {
- if(!empty($data['channel']))
- {
- return ChannelDict::getType($data['channel']) ?? '';
- }else{
- return '';
- }
- }
- }
- /**
- * 创建时间搜索器
- * @param $query
- * @param $value
- * @param $data
- */
- 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]]);
- }
- }
- /**
- * 查询交易流水号
- * @param $query
- * @param $value
- * @return void
- */
- public function searchOutTradeNoAttr($query, $value) {
- if (!empty($value)) {
- $query->where([['out_trade_no', '=', $value]]);
- }
- }
- /**
- * 查询支付方式
- * @param $query
- * @param $value
- * @return void
- */
- public function searchTypeAttr($query, $value) {
- if (!empty($value)) {
- $query->where([['type', '=', $value]]);
- }
- }
- /**
- * 查询支付渠道
- * @param $query
- * @param $value
- * @return void
- */
- public function searchChannelAttr($query, $value) {
- if (!empty($value)) {
- $query->where([['channel', '=', $value]]);
- }
- }
- /**
- * 查询交易状态
- * @param $query
- * @param $value
- * @return void
- */
- public function searchStatusAttr($query, $value) {
- if ($value != '') {
- $query->where([['status', '=', $value]]);
- }
- }
- }
|