feat: spu
This commit is contained in:
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace App\Model;
|
||||
|
||||
use Hyperf\DbConnection\Model\Model;
|
||||
use Hyperf\Tappable\HigherOrderTapProxy;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
@@ -34,4 +35,13 @@ class Category extends Model
|
||||
|
||||
const string UPDATED_AT = 'update_time';
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return HigherOrderTapProxy|mixed|null
|
||||
*/
|
||||
public function getNameById(int $id): mixed
|
||||
{
|
||||
return $this->where('id', $id)->value('name');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace App\Model;
|
||||
use App\Constants\Admin\UserCode;
|
||||
use Hyperf\Database\Model\Builder;
|
||||
use Hyperf\DbConnection\Model\Model;
|
||||
use Hyperf\Tappable\HigherOrderTapProxy;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
@@ -56,4 +57,13 @@ class Chef extends Model
|
||||
return $this->where('is_del',UserCode::IS_NO_DEL)->where('user_id', $userId)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return HigherOrderTapProxy|mixed|null
|
||||
*/
|
||||
public function getChineseNameById(int $id): mixed
|
||||
{
|
||||
return $this->leftJoin('admin_user', 'admin_user.id', '=', 'chef.user_id')->where('admin_user.id', $id)->value('admin.chinese_name');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace App\Model;
|
||||
use App\Constants\Common\SiteCode;
|
||||
use Hyperf\Database\Model\Builder;
|
||||
use Hyperf\DbConnection\Model\Model;
|
||||
use Hyperf\Tappable\HigherOrderTapProxy;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
@@ -52,6 +53,15 @@ class Kitchen extends Model
|
||||
return $this->where('name', $name)->where('is_del',SiteCode::KITCHEN_NO_DEL)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return HigherOrderTapProxy|mixed|null
|
||||
*/
|
||||
public function getNameById(int $id)
|
||||
{
|
||||
return $this->where('id', $id)->value('name');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return \Hyperf\Database\Model\Model|Builder|null
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace App\Model;
|
||||
use App\Constants\Common\CityCode;
|
||||
use Hyperf\Database\Model\Builder;
|
||||
use Hyperf\DbConnection\Model\Model;
|
||||
use Hyperf\Tappable\HigherOrderTapProxy;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
@@ -68,6 +69,15 @@ class SystemCity extends Model
|
||||
return $this->whereIn('id',$ids)->pluck('title','id')->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return HigherOrderTapProxy|mixed|null
|
||||
*/
|
||||
public function getCityNameById(int $id)
|
||||
{
|
||||
return $this->where('id',$id)->where('is_del',CityCode::IS_NOT_DELETE)->value('title');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有数据
|
||||
* @param array $ids
|
||||
|
||||
@@ -15,11 +15,13 @@ use App\Constants\Common\GoodCode;
|
||||
use App\Constants\Common\SiteCode;
|
||||
use App\Exception\ErrException;
|
||||
use App\Model\AdminUser;
|
||||
use App\Model\Category;
|
||||
use App\Model\Chef;
|
||||
use App\Model\Cycle;
|
||||
use App\Model\Kitchen;
|
||||
use App\Model\Sku;
|
||||
use App\Model\Spu;
|
||||
use App\Model\SystemCity;
|
||||
use App\Service\Admin\BaseService;
|
||||
use App\Service\ServiceTrait\Admin\GetUserInfoTrait;
|
||||
use App\Service\ServiceTrait\Common\OssTrait;
|
||||
@@ -242,6 +244,19 @@ class SpuService extends BaseService
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* @var SystemCity $systemCityModel
|
||||
*/
|
||||
#[Inject]
|
||||
protected SystemCity $systemCityModel;
|
||||
|
||||
/**
|
||||
* @var Category $categoryModel
|
||||
*/
|
||||
#[Inject]
|
||||
protected Category $categoryModel;
|
||||
|
||||
|
||||
/**
|
||||
* spu 详情
|
||||
* @return array
|
||||
@@ -253,6 +268,13 @@ class SpuService extends BaseService
|
||||
$info = $this->spuModel->getInfoById($id);
|
||||
if (empty($info)) throw new ErrException('数据不存在');
|
||||
|
||||
return $this->return->success('success',$info->toArray());
|
||||
$info = $info->toArray();
|
||||
|
||||
$info['city_name'] = $this->systemCityModel->getCityNameById((int)$info['city_id']);
|
||||
$info['kitchen_name'] = $this->kitchenModel->getNameById((int)$info['kitchen_id']);
|
||||
$info['chef_name'] = $this->chefModel->getChineseNameById((int)$info['chef_id']);
|
||||
$info['category_name'] = $this->categoryModel->getNameById((int)$info['category_id']);
|
||||
|
||||
return $this->return->success('success',$info);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user