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/Retail.php

114 lines
3.1 KiB

<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\api\model;
use app\common\model\Retail as RetailModel;
use app\api\model\Payment as PaymentModel;
use app\api\service\identity\Payment;
use app\api\service\User as UserService;
class Retail extends RetailModel
{
// 提示信息
private string $message = '';
// 支付方式 (微信支付、支付宝、余额)
private string $method;
// 下单的客户端
private string $client;
//隐藏字段
protected $hidden = [
'create_time',
'update_time',
'store_id',
];
public function setMethod(string $method): Retail
{
$this->method = $method;
return $this;
}
public static function getRetailList()
{
return self::select();
}
/**
* 设置下单的客户端
* @param string $client 客户端
* @return $this
*/
public function setClient(string $client): Retail
{
$this->client = $client;
return $this;
}
/**
* 返回消息提示
* @return string
*/
public function getMessage(): string
{
return $this->message;
}
public static function detail(array $where = [])
{
$where = [
'retail_price_id'=>$where['retail_price_id'],
'retail_status'=>10
];
return RetailModel::where($where)->select();
}
private function cheapPrice($data): array
{
$one_data = $data[0];
foreach ($data as $key => $value) {
$data[$key]['cheap_price'] = 0;
if (!empty($one_data)) {
if ($key > 0) {
$price = $value['month'] * $one_data['price'];
$data[$key]['cheap_price'] = $price - $value['price'];
}
}
}
return $data;
}
/**
* 确认订单支付事件
* @param int $identityId
* @param array $extra 附加数据
* @return array[]
* @throws BaseException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function orderPay(int $identityId, array $extra = []): array
{
$PaymentService = new Payment();
$result = $PaymentService->setMethod($this->method)
->setClient($this->client)
->orderPay($identityId, $extra);
$this->message = $PaymentService->getMessage();
return $result;
}
}