// +---------------------------------------------------------------------- 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; } public function getList(array $where) { return $this->where($where)->order('sort', 'asc')->select(); } /** * 返回消息提示 * @return string */ public function getMessage(): string { return $this->message; } // public static function detail(array $where = []) : array // { // $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; } }