'全部', self::Normal => '待成交', self::SaleOut => '已成交', self::Close => '已取消', ]; public static function getProductBuyingMaxPrice(int $productId) { return self::where('product_id', $productId)->max('min_price'); } //用户购买套数 public static function getProductBuyingCount(int $userId, int $productId) { return self::where('user_id', $userId)->where('status', self::Normal)->count(); } //创建订单 public static function setCreateBuying(int $userId, int $productId, int $stock, float $minPrice, float $totalPrice) { return self::create([ 'user_id' => $userId, 'product_id' => $productId, 'stock' => $stock, 'min_price' => $minPrice, 'total_price' => $totalPrice ]); } //求购详情 public static function getProductBuyingDetail(int $buyingId, string $lan) { return self::alias('a') ->join('product_list p', 'a.product_id = p.id') ->field('a.*,p.' . $lan . '_name as name,p.thum') ->where('a.id', $buyingId) ->find(); } //获取订单列表 public static function getBuyingList(int $productId) { return self::where('product_id', $productId)->where('status', self::Normal)->field('id,min_price')->order('id desc')->select(); } //获取订单列表 public static function getUserBuyingList(int $uid, string $lan, int $page) { return self::alias('a')->where('user_id', $uid) ->join('product_list p', 'a.product_id = p.id') ->field('a.*,p.' . $lan . '_name as name,p.thum') ->order('id desc') ->paginate($page); } //用户 public function users() { return $this->hasOne('UserModel', 'id', 'user_id', [], 'LEFT')->setEagerlyType(0); } //产品 public function productlists() { return $this->hasOne('ProductLists', 'id', 'product_id', [], 'LEFT')->setEagerlyType(0); } public function getCreateTimeTextAttr($value, $data) { $value = $value ? $value : (isset($data['create_time']) ? $data['create_time'] : ''); return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value; } public function getUpdateTimeTextAttr($value, $data) { $value = $value ? $value : (isset($data['update_time']) ? $data['update_time'] : ''); return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value; } protected function setCreateTimeAttr($value) { return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value); } protected function setUpdateTimeAttr($value) { return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value); } }