wanghousheng 1 year ago
parent 591957bbf6
commit 0692f0e2ad
  1. 16
      app/api/controller/Goods.php
  2. 23
      app/api/controller/Index.php
  3. 27
      app/api/model/wxapp/Setting.php
  4. 22
      app/common/model/Goods.php
  5. 14
      app/common/model/wxapp/Setting.php
  6. 4
      app/store/model/wxapp/Setting.php

@ -18,6 +18,7 @@ use app\common\model\GoodsImage as GoodsImageModel;
use app\common\model\UploadFile as UploadFileModel; use app\common\model\UploadFile as UploadFileModel;
use app\common\service\qrcode\Goods as GoodsPoster; use app\common\service\qrcode\Goods as GoodsPoster;
use cores\exception\BaseException; use cores\exception\BaseException;
use think\db\exception\DbException;
use think\response\Json; use think\response\Json;
/** /**
@ -30,15 +31,13 @@ class Goods extends Controller
/** /**
* 商品列表 * 商品列表
* @return Json * @return Json
* @throws \think\db\exception\DbException * @throws DbException
*/ */
public function list(): Json public function list(): Json
{ {
// 获取列表数据 // 获取列表数据
$model = new GoodsModel; $model = new GoodsModel;
$storeid = request()->header()['storeid'];
$param = $this->request->param(); $param = $this->request->param();
$param['store_id'] = $storeid;
$list = $model->getList($param); $list = $model->getList($param);
return $this->renderSuccess(compact('list')); return $this->renderSuccess(compact('list'));
} }
@ -49,16 +48,13 @@ class Goods extends Controller
* @param bool $verifyStatus 是否验证商品状态(上架) * @param bool $verifyStatus 是否验证商品状态(上架)
* @return Json * @return Json
* @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
* @throws BaseException * @throws BaseException
*/ */
public function detail(int $goodsId, bool $verifyStatus = true): Json public function detail(int $goodsId, bool $verifyStatus = true): Json
{ {
// wmc商品详情 // wmc商品详情
$storeid = request()->header()['storeid'];
$param = $this->request->param();
$param['store_id'] = $storeid;
$model = new GoodsModel; $model = new GoodsModel;
$goodsInfo = $model->getDetails($goodsId, $verifyStatus); $goodsInfo = $model->getDetails($goodsId, $verifyStatus);
if (!empty($goodsInfo['content'])) { if (!empty($goodsInfo['content'])) {
@ -163,7 +159,7 @@ class Goods extends Controller
* @param int $goodsId * @param int $goodsId
* @return Json * @return Json
* @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
*/ */
public function specData(int $goodsId): Json public function specData(int $goodsId): Json
@ -190,7 +186,7 @@ class Goods extends Controller
* 推荐的商品列表 * 推荐的商品列表
* @return Json * @return Json
* @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
*/ */
public function recommended(): Json public function recommended(): Json
@ -289,7 +285,7 @@ class Goods extends Controller
* @param string $channel 二维码渠道(小程序码、h5码) * @param string $channel 二维码渠道(小程序码、h5码)
* @throws BaseException * @throws BaseException
* @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
*/ */
public function poster(int $goodsId, string $channel = 'H5'): Json public function poster(int $goodsId, string $channel = 'H5'): Json

@ -1,8 +1,14 @@
<?php <?php
namespace app\api\controller; namespace app\api\controller;
use app\common\model\Banner; use app\common\model\Banner;
use app\common\model\UploadFile; use app\common\model\UploadFile;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\response\Json;
/** /**
* 默认控制器 * 默认控制器
* Class Index * Class Index
@ -15,7 +21,8 @@ class Index extends Controller
echo '当前访问的index.php,请将index.html设为默认站点入口'; echo '当前访问的index.php,请将index.html设为默认站点入口';
} }
public function getBannerList(){ public function getBannerList()
{
$list = Banner::where("status", 10)->select()->toArray(); $list = Banner::where("status", 10)->select()->toArray();
foreach ($list as &$value) { foreach ($list as &$value) {
$file_path = UploadFile::where('file_id', $value['image_id'])->field('file_id,file_path,file_type,storage,domain')->find(); $file_path = UploadFile::where('file_id', $value['image_id'])->field('file_id,file_path,file_type,storage,domain')->find();
@ -23,4 +30,18 @@ class Index extends Controller
} }
return $this->renderSuccess($list); return $this->renderSuccess($list);
} }
/**
* @notes:获取小程序配置
* @return Json
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @author: wanghousheng
*/
public function wxAppSetting(): Json
{
$data = (new \app\api\model\wxapp\Setting())->info();
return $this->renderSuccess($data);
}
} }

@ -13,6 +13,9 @@ declare (strict_types=1);
namespace app\api\model\wxapp; namespace app\api\model\wxapp;
use app\common\model\wxapp\Setting as SettingModel; use app\common\model\wxapp\Setting as SettingModel;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
/** /**
* 微信小程序设置模型 * 微信小程序设置模型
@ -24,12 +27,30 @@ class Setting extends SettingModel
/** /**
* 验证当前是否允许访问 * 验证当前是否允许访问
* @return bool * @return bool
* @throws \think\db\exception\DataNotFoundException * @throws DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws ModelNotFoundException
*/ */
public static function checkStatus(): bool public static function checkStatus(): bool
{ {
return (bool)static::getItem('basic', static::$storeId)['enabled']; return (bool)static::getItem('basic', static::$storeId)['enabled'];
} }
/**
* @notes:获取小程序配置
* @return array
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @author: wanghousheng
*/
public function info(): array
{
$data = static::getItem('basic', static::$storeId);
if (!empty($data['app_secret'])) {
unset($data['app_secret']);
}
return $data;
}
} }

@ -25,7 +25,6 @@ use think\model\relation\BelongsTo;
use think\model\relation\HasMany; use think\model\relation\HasMany;
use think\model\relation\HasOne; use think\model\relation\HasOne;
use think\Paginator; use think\Paginator;
use app\common\model\Channel;
/** /**
* 商品模型 * 商品模型
@ -130,16 +129,18 @@ class Goods extends BaseModel
*/ */
public function skuList(): HasMany public function skuList(): HasMany
{ {
return $this->hasMany('GoodsSku','spu_id')->order(['id' => 'asc']); return $this->hasMany('GoodsSku', 'spu_id')->order(['id' => 'asc']);
} }
/** /**
* 关联商品规格表 * 关联商品规格表
* @return HasMany * @return HasMany
*/ */
public function skuList1(): HasMany public function skuList1(): HasMany
{ {
return $this->hasMany('GoodsSku','goods_id')->order(['id' => 'asc']); return $this->hasMany('GoodsSku', 'goods_id')->order(['id' => 'asc']);
} }
/** /**
* 关联商品规格关系表 * 关联商品规格关系表
* @return HasMany * @return HasMany
@ -175,6 +176,7 @@ class Goods extends BaseModel
{ {
return $this->hasMany('Comment'); return $this->hasMany('Comment');
} }
/** /**
* 获取商品列表 * 获取商品列表
* @param array $param 查询条件 * @param array $param 查询条件
@ -206,7 +208,7 @@ class Goods extends BaseModel
// 执行查询 // 执行查询
$list = $query $list = $query
->alias($this->name) ->alias($this->name)
->field(['goods.goods_id','goods.goods_name','cmmdty_model','link','cost_price_min','stock_total','link_other','goods_price_min']) ->field(['goods.goods_id', 'goods.goods_name', 'cmmdty_model', 'link', 'cost_price_min', 'stock_total', 'link_other', 'goods_price_min'])
->where('is_delete', '=', 0) ->where('is_delete', '=', 0)
->order($sort) ->order($sort)
->paginate($listRows); ->paginate($listRows);
@ -307,6 +309,12 @@ class Goods extends BaseModel
$field = $this->getAliasFields($this->name, ['content']); $field = $this->getAliasFields($this->name, ['content']);
$field[] = 'selling_point'; $field[] = 'selling_point';
//关键字搜索 wanghousheng
if (!empty($param['keyword'])) {
$query = $query->where('goods_name', 'like', "%{$param['keyword']}%")
->whereOr('goods_no', 'like', "%{$param['keyword']}%");
}
// 执行查询 // 执行查询
$list = $query->with(['images.file']) $list = $query->with(['images.file'])
->alias($this->name) ->alias($this->name)
@ -398,7 +406,7 @@ class Goods extends BaseModel
$GoodsCategoryRelName = (new GoodsCategoryRelModel())->getName(); $GoodsCategoryRelName = (new GoodsCategoryRelModel())->getName();
$query->join($GoodsCategoryRelName, "{$GoodsCategoryRelName}.goods_id = {$this->name}.goods_id"); $query->join($GoodsCategoryRelName, "{$GoodsCategoryRelName}.goods_id = {$this->name}.goods_id");
// 设置分类ID条件 // 设置分类ID条件
$query->where('goods_category_rel.category_id', 'in', explode(",", (string)$params['categoryId'])); $query->where('goods_category_rel.category_id', 'in', explode(",", (string)$params['categoryId']));
// $query->where([ // $query->where([
// 'goods_category_rel.category_id' => (int)$params['categoryId'], // 'goods_category_rel.category_id' => (int)$params['categoryId'],
// //'goods.store_id' => (int)$params['store_id'], // //'goods.store_id' => (int)$params['store_id'],
@ -407,7 +415,7 @@ class Goods extends BaseModel
} }
// 商品名称 // 商品名称
foreach (explode(",", $params['keywords']?? '') as $val) { foreach (explode(",", $params['keywords'] ?? '') as $val) {
$filter[] = ['goods_name', 'like', "%{$val}%"]; $filter[] = ['goods_name', 'like', "%{$val}%"];
} }
@ -439,7 +447,7 @@ class Goods extends BaseModel
$filter[] = ['is_in_store', '=', $params['is_in_store']]; $filter[] = ['is_in_store', '=', $params['is_in_store']];
} }
if (isset($param['role']) && $param['role'] == 1) { if (isset($param['role']) && $param['role'] == 1) {
$filter[] = ['channel', 'in', ['jd','sn','zy']]; $filter[] = ['channel', 'in', ['jd', 'sn', 'zy']];
} }
if (isset($param['store_id']) && $param['store_id'] !== '') { if (isset($param['store_id']) && $param['store_id'] !== '') {
$filter[] = ['goods.store_id', '=', $params['store_id']]; $filter[] = ['goods.store_id', '=', $params['store_id']];

@ -139,7 +139,19 @@ class Setting extends BaseModel
// 小程序AppID // 小程序AppID
'app_id' => '', 'app_id' => '',
// 小程序AppSecret // 小程序AppSecret
'app_secret' => '' 'app_secret' => '',
//同城送
'same_city' => true,
//新人首礼
'new_first_gift' => true,
//大牌正品
'big_brand' => true,
//新品首发
'new_product' => true,
//排行榜
'ranking_list' => true,
//服务
'service' => true,
] ]
] ]
]; ];

@ -12,9 +12,9 @@ declare (strict_types=1);
namespace app\store\model\wxapp; namespace app\store\model\wxapp;
use think\facade\Cache;
use app\common\library\helper; use app\common\library\helper;
use app\common\model\wxapp\Setting as SettingModel; use app\common\model\wxapp\Setting as SettingModel;
use think\facade\Cache;
/** /**
* 微信小程序设置模型 * 微信小程序设置模型
@ -44,7 +44,7 @@ class Setting extends SettingModel
return $model->save([ return $model->save([
'key' => $key, 'key' => $key,
'describe' => $this->describe[$key], 'describe' => $this->describe[$key],
'values' => helper::pick($values, ['enabled', 'app_id', 'app_secret']), 'values' => helper::pick($values, ['enabled', 'app_id', 'app_secret', 'same_city', 'new_first_gift', 'big_brand', 'new_product', 'ranking_list', 'service']),
'update_time' => time(), 'update_time' => time(),
'store_id' => self::$storeId, 'store_id' => self::$storeId,
]); ]);

Loading…
Cancel
Save