You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
yanzong/app/api/model/user/IdentityOrder.php

120 lines
3.4 KiB

11 months ago
<?php
namespace app\api\model\user;
use app\api\service\User as UserService;
11 months ago
use app\common\enum\order\PayStatus;
11 months ago
use app\common\model\user\IdentityOrder as BaseIdentityOrder;
use app\common\service\Order as OrderService;
use cores\exception\BaseException;
11 months ago
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\model\relation\HasOne;
11 months ago
use function getPlatform;
class IdentityOrder extends BaseIdentityOrder
{
/**
* 隐藏字段
* @var array
*/
protected $hidden = [
'order_type',
'create_time',
'update_time',
'store_id',
];
/**
* @notes:创建订单
* @param array $identityInfo
8 months ago
* @param $method
11 months ago
* @return bool
* @throws BaseException
* @author: wanghousheng
*/
8 months ago
public function createOrder(array $identityInfo, $method): bool
11 months ago
{
$data = [
'user_id' => UserService::getCurrentLoginUserId(),
'order_no' => OrderService::createOrderNo(),
'identity_id' => $identityInfo['identity_id'],
'order_type' => $identityInfo['type'],
'pay_price' => $identityInfo['price'],
'month' => $identityInfo['month'],
'platform' => getPlatform(),
8 months ago
'pay_method' => $method,
11 months ago
'store_id' => self::$storeId,
];
return $this->save($data);
}
/**
* 获取订单详情 (待付款状态)
* @param string $orderNo 订单号
* @return array|null|static
*/
public static function getPayDetail(string $orderNo)
{
return self::detail(['order_no' => $orderNo]);
}
/**
* @notes:编辑
* @param $data
* @return bool
* @author: wanghousheng
*/
public function edit($data): bool
{
return $this->save($data) !== false;
}
11 months ago
public function identity(): HasOne
{
return $this->hasOne(Identity::class, 'identity_id', 'identity_id')
->bind(['identity_name' => 'name']);
}
/**
* @notes:开卡记录
* @param array $where
* @return array
* @throws BaseException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @author: wanghousheng
*/
public function cardList(array $where = []): array
{
$userId = UserService::getCurrentLoginUserId();
$params['user_id'] = $userId;
$params['pay_status'] = PayStatus::SUCCESS;
$where = array_merge($where, $params);
$list = $this->where($where)
->with(['identity'])
->order('pay_time', 'desc')
->limit(20)
->select();
$data = [];
if (!empty($list)) {
foreach ($list as $value) {
11 months ago
$end_time = date("Y-m-d", strtotime("+{$value['month']} months", $value['pay_time']));
$is_valid = false;
if (strtotime(date("Y-m-d")) < strtotime($end_time)) {
$is_valid = true;
}
11 months ago
$data[] = [
'start_time' => date("Y-m-d", $value['pay_time']),
11 months ago
'end_time' => $end_time,
11 months ago
'name' => $value['identity_name'],
11 months ago
'month' => $value['month'],
11 months ago
'is_valid' => $is_valid
11 months ago
];
}
}
return $data;
}
11 months ago
}