1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- <?php
- namespace app\common\service;
- use app\common\constant\CommonConstant;
- use app\common\model\Goods;
- /**
- * 商品服务类
- */
- class GoodsService
- {
- /**
- * 商品列表
- *
- * @param integer $category_id 二级分类ID
- * @param string $search 搜索 商品名称
- * @return array
- **/
- public static function get_list($category_id, $search)
- {
- if (!$category_id && empty($search)) {
- return [];
- }
- $list = Goods::field('status,is_deleted,create_at', true)
- // ->where('status', CommonConstant::IS_WHO_1)
- ->where('is_deleted', CommonConstant::IS_DELETED_0)
- ->when($category_id > 0, function ($query) use ($category_id) {
- $query->where('goods_category_id', $category_id);
- })
- ->when(!empty($search), function ($query) use ($search) {
- $query->where('goods_name', 'LIKE', '%' . $search . '%');
- })
- ->with([
- 'goodsStock'
- ])
- ->order('sort desc,id desc')
- ->select();
- return $list;
- }
- }
|