wang hou sheng 7 months ago
parent bc2be7fe76
commit e2b9fa6323
  1. 40
      app/api/controller/Goods.php
  2. 4
      app/api/controller/Wxserver.php
  3. 109
      app/api/model/Goods.php
  4. 46
      app/common/library/wxserver/Server.php

@ -13,6 +13,7 @@ declare (strict_types=1);
namespace app\api\controller; namespace app\api\controller;
use app\api\model\{Goods as GoodsModel, Store as StoreModel}; use app\api\model\{Goods as GoodsModel, Store as StoreModel};
use app\api\model\Region;
use app\api\service\{Goods as GoodsService, User as UserService}; use app\api\service\{Goods as GoodsService, User as UserService};
use app\common\model\GoodsImage as GoodsImageModel; use app\common\model\GoodsImage as GoodsImageModel;
use app\common\model\UploadFile as UploadFileModel; use app\common\model\UploadFile as UploadFileModel;
@ -20,7 +21,7 @@ use app\common\service\qrcode\Goods as GoodsPoster;
use cores\exception\BaseException; use cores\exception\BaseException;
use think\db\exception\DbException; use think\db\exception\DbException;
use think\response\Json; use think\response\Json;
use app\api\model\Region;
/** /**
* 商品控制器 * 商品控制器
* Class Goods * Class Goods
@ -57,12 +58,13 @@ class Goods extends Controller
// wmc商品详情 // wmc商品详情
$model = new GoodsModel; $model = new GoodsModel;
$goodsInfo = $model->getDetails($goodsId, $verifyStatus); $goodsInfo = $model->getDetails($goodsId, $verifyStatus);
if (!empty($goodsInfo['content'])) { if (!empty($goodsInfo['content'])) {
$goodsInfo['content'] = str_ireplace('onload="if(this.width>750){this.height=this.height*(750.0/this.width); this.width = 750;}', '', $goodsInfo['content']); $goodsInfo['content'] = str_ireplace('onload="if(this.width>750){this.height=this.height*(750.0/this.width); this.width = 750;}', '', $goodsInfo['content']);
} }
return $this->renderSuccess(['detail' => $goodsInfo]); return $this->renderSuccess(['detail' => $goodsInfo]);
} }
/** /**
* 获取商品详情(详细信息) * 获取商品详情(详细信息)
* @param int $goodsId 商品ID * @param int $goodsId 商品ID
@ -86,8 +88,8 @@ class Goods extends Controller
$goods = GoodsModel::where('goods_id', $value['goods_id'])->find(); $goods = GoodsModel::where('goods_id', $value['goods_id'])->find();
switch ($goods->channel) { switch ($goods->channel) {
case 'sn': case 'sn':
$city = Region::where('name',$params['city'])->where('level',2)->find(); $city = Region::where('name', $params['city'])->where('level', 2)->find();
$district = Region::where('name',$params['district'])->where('level',3)->find(); $district = Region::where('name', $params['district'])->where('level', 3)->find();
// var_dump($city); // var_dump($city);
// var_dump($district); // var_dump($district);
$suning = new \app\common\service\Suning(); $suning = new \app\common\service\Suning();
@ -97,12 +99,12 @@ class Goods extends Controller
$data['goods_id'] = $goods['goods_id']; $data['goods_id'] = $goods['goods_id'];
break; break;
case 'jd': case 'jd':
$province = Region::where('name',$params['province'])->where('level',1)->find(); $province = Region::where('name', $params['province'])->where('level', 1)->find();
$city = Region::where('name',$params['city'])->where('level',2)->find(); $city = Region::where('name', $params['city'])->where('level', 2)->find();
$district = Region::where('name',$params['district'])->where('level',3)->find(); $district = Region::where('name', $params['district'])->where('level', 3)->find();
$jd = new \app\common\service\Jd(); $jd = new \app\common\service\Jd();
$arr = []; $arr = [];
$ret = $jd->getGoodsStock($province->jd_code, $city->jd_code, $district->jd_code, $goods['goods_no'], $value['num'] ?? 1); $ret = $jd->getGoodsStock($province->jd_code, $city->jd_code, $district->jd_code, $goods['goods_no'], $value['num'] ?? 1);
if ($ret) { if ($ret) {
$res = $ret['stockResp']['desc']; $res = $ret['stockResp']['desc'];
@ -113,9 +115,9 @@ class Goods extends Controller
} }
} }
$data = [ $data = [
'state'=> $res, 'state' => $res,
'goods_name'=> $goods['goods_name'], 'goods_name' => $goods['goods_name'],
'goods_id'=> $goods['goods_id'], 'goods_id' => $goods['goods_id'],
]; ];
break; break;
default: default:
@ -123,18 +125,19 @@ class Goods extends Controller
$res = "有货"; $res = "有货";
} }
$data = [ $data = [
'state'=> $res, 'state' => $res,
'goods_name'=> $goods['goods_name'], 'goods_name' => $goods['goods_name'],
'goods_id'=> $goods['goods_id'], 'goods_id' => $goods['goods_id'],
]; ];
break; break;
} }
$return[] = $data; $return[] = $data;
} }
return $this->renderSuccess($return); return $this->renderSuccess($return);
} }
public function browseLog(): Json public function browseLog(): Json
{ {
$model = new GoodsModel; $model = new GoodsModel;
@ -189,12 +192,11 @@ class Goods extends Controller
return $this->renderSuccess($list); return $this->renderSuccess($list);
} }
public function presaleGoodsList() public function presaleGoodsList(): Json
{ {
$param = $this->request->param(); $param = $this->request->param();
$model = new GoodsModel; $model = new GoodsModel;
$list = $model->presaleGoodsList($param); $list = $model->presaleGoodss($param);
return $this->renderSuccess(compact('list')); return $this->renderSuccess(compact('list'));
} }

@ -83,11 +83,11 @@ class Wxserver extends BaseController
} elseif ($data['MsgType'] == 'text' && !empty($data['Content'])) { } elseif ($data['MsgType'] == 'text' && !empty($data['Content'])) {
if ($data['Content'] == 'TESTCOMPONENT_MSG_TYPE_TEXT') { if ($data['Content'] == 'TESTCOMPONENT_MSG_TYPE_TEXT') {
$data['Content'] = 'TESTCOMPONENT_MSG_TYPE_TEXT_callback'; $data['Content'] = 'TESTCOMPONENT_MSG_TYPE_TEXT_callback';
echo $this->responseText($data);
} elseif (strpos($data['Content'], 'QUERY_AUTH_CODE:') !== false) { } elseif (strpos($data['Content'], 'QUERY_AUTH_CODE:') !== false) {
$query_auth_code = trim(str_replace("QUERY_AUTH_CODE:", "", $data['Content'])); $query_auth_code = trim(str_replace("QUERY_AUTH_CODE:", "", $data['Content']));
$obj->apiText($query_auth_code, $data['FromUserName']); $obj->apiText($query_auth_code, $data['FromUserName']);
} }
echo $this->responseText($data);
} }
} }
} }
@ -106,7 +106,7 @@ class Wxserver extends BaseController
</xml>"; </xml>";
$fromUser = $data['ToUserName']; $fromUser = $data['ToUserName'];
$toUser = $data['FromUserName']; $toUser = $data['FromUserName'];
$content = $data['Content']; $content = !empty($data['Content']) ? $data['Content'] : 'success';
$time = time(); $time = time();
$msgType = 'text'; $msgType = 'text';
return sprintf($template, $toUser, $fromUser, $time, $msgType, $content); return sprintf($template, $toUser, $fromUser, $time, $msgType, $content);

@ -24,7 +24,6 @@ use app\common\model\Goods as GoodsModel;
use app\common\model\GoodsCategoryRel as GoodsCategoryRelModel; use app\common\model\GoodsCategoryRel as GoodsCategoryRelModel;
use app\common\model\GoodsImage as GoodsImageModel; use app\common\model\GoodsImage as GoodsImageModel;
use app\common\model\UploadFile as UploadFileModel; use app\common\model\UploadFile as UploadFileModel;
use app\store\model\goods\GoodsPrice as GoodsPriceModel;
use cores\exception\BaseException; use cores\exception\BaseException;
use think\db\exception\DataNotFoundException; use think\db\exception\DataNotFoundException;
use think\db\exception\DbException; use think\db\exception\DbException;
@ -45,8 +44,6 @@ class Goods extends GoodsModel
'images', 'images',
'delivery', 'delivery',
'deduct_stock_type', 'deduct_stock_type',
'sales_initial',
'sales_actual',
'sort', 'sort',
'is_delete', 'is_delete',
'store_id', 'store_id',
@ -232,6 +229,43 @@ class Goods extends GoodsModel
return $info; return $info;
} }
public function presaleGoodss(array $param): array
{
$list = [];
$cate_goods_id = [];
if (!empty($param['category_id'])) {
$cate_model = new \app\store\model\GoodsCategoryRel();
$cate_goods_id = $cate_model
->where(['category_id' => $param['category_id']])
->column('goods_id');
}
$model = new PreSale();
$info = $model->where(['is_change' => 0, 'status' => 1])->field('goods_list,p_time')->find();
if (!$info->isEmpty()) {
$info = $info->toArray();
$goods_ids = explode(',', $info['goods_list']);
if ($cate_goods_id) {
$goods_ids = array_unique(array_values(array_intersect($cate_goods_id, $goods_ids)));
}
$result = $this->getListByIds($goods_ids);
if (!$result->isEmpty()) {
$result = $result->toArray();
foreach ($result as $v) {
$list[] = [
'goods_id' => $v['goods_id'],
'goods_name' => $v['goods_name'],
'goods_price_min' => $v['goods_price_min'],
'sales_initial' => $v['sales_initial'],
'sales_actual' => $v['sales_actual'],
'image' => $v['goods_image'],
'end_time' => strtotime($info['p_time']) - time()
];
}
}
}
return $list;
}
public function presaleGoodsList() public function presaleGoodsList()
{ {
$info = PreSale::where([ $info = PreSale::where([
@ -318,13 +352,15 @@ class Goods extends GoodsModel
return $info; return $info;
} }
/** /**
* 商品主图、商品轮播图、商品详情处理 * 商品主图、商品轮播图、商品详情处理
* [dealGoodsImage description] * [dealGoodsImage description]
* @param [type] &$goodsInfo [description] * @param [type] &$goodsInfo [description]
* @return [type] [description] * @return [type] [description]
*/ */
public function dealGoodsImage(&$goodsInfo){ public function dealGoodsImage(&$goodsInfo)
{
switch ($goodsInfo->channel) { switch ($goodsInfo->channel) {
case 'jd': case 'jd':
$jd = new \app\common\service\Jd(); $jd = new \app\common\service\Jd();
@ -342,9 +378,9 @@ class Goods extends GoodsModel
} }
$goodsInfo->goods_images = $goods_images; $goodsInfo->goods_images = $goods_images;
$goodsInfo->goods_image = $res['mainImageList'][0]; $goodsInfo->goods_image = $res['mainImageList'][0];
} }
if ($res['infoImageList']) { if ($res['infoImageList']) {
$content = ""; $content = "";
foreach ($res['infoImageList'] as $value) { foreach ($res['infoImageList'] as $value) {
@ -352,7 +388,7 @@ class Goods extends GoodsModel
} }
$goodsInfo->content = $content; $goodsInfo->content = $content;
} }
} }
break; break;
case 'sn': case 'sn':
@ -362,8 +398,9 @@ class Goods extends GoodsModel
// code... // code...
break; break;
} }
} }
/** /**
* 获取商品详情 (详细数据用于页面展示) * 获取商品详情 (详细数据用于页面展示)
* @param int $goodsId 商品ID * @param int $goodsId 商品ID
@ -389,7 +426,7 @@ class Goods extends GoodsModel
$goodsInfo = $this->getGoodsMain($goodsId, $with, $verifyStatus); $goodsInfo = $this->getGoodsMain($goodsId, $with, $verifyStatus);
$this->dealGoodsImage($goodsInfo); $this->dealGoodsImage($goodsInfo);
// 商品规格列表 // 商品规格列表
$goodsInfo['specList'] = GoodsSpecRelModel::getSpecList($goodsInfo['goods_id']); $goodsInfo['specList'] = GoodsSpecRelModel::getSpecList($goodsInfo['goods_id']);
$GoodsCategoryRelModel = new GoodsCategoryRelModel(); $GoodsCategoryRelModel = new GoodsCategoryRelModel();
@ -453,7 +490,7 @@ class Goods extends GoodsModel
{ {
// 关联查询(商品图片) // 关联查询(商品图片)
$with = ['images.file']; $with = ['images.file'];
// 获取商品记录 // 获取商品记录
return $this->getGoodsMain($goodsId, $with, $verifyStatus); return $this->getGoodsMain($goodsId, $with, $verifyStatus);
@ -491,15 +528,15 @@ class Goods extends GoodsModel
$goodsInfo = static::detail($goodsId, $with); $goodsInfo = static::detail($goodsId, $with);
if ($goodsInfo->skuList) { if ($goodsInfo->skuList) {
foreach ($goodsInfo->skuList as &$value) { foreach ($goodsInfo->skuList as &$value) {
$goods_image = GoodsImage::where('goods_id', $value['goods_id'])->order("id asc")->find(); $goods_image = GoodsImage::where('goods_id', $value['goods_id'])->order("id asc")->find();
$file_path = UploadFile::where('file_id',$goods_image['image_id'] ?? 0)->find(); $file_path = UploadFile::where('file_id', $goods_image['image_id'] ?? 0)->find();
if ($file_path) { if ($file_path) {
$value['image_url'] = getUrl($file_path['file_path'], $file_path['domain']); $value['image_url'] = getUrl($file_path['file_path'], $file_path['domain']);
} }
$goods = GoodsModel::where('goods_id',$value['goods_id'])->find(); $goods = GoodsModel::where('goods_id', $value['goods_id'])->find();
$value['stock_num'] = $goods['stock_total'] ?? 0; $value['stock_num'] = $goods['stock_total'] ?? 0;
} }
} }
// 判断商品是否存在 // 判断商品是否存在
@ -597,14 +634,14 @@ class Goods extends GoodsModel
$goods['goods_price_min_plus'] = $priceArr['membershipPrice']; $goods['goods_price_min_plus'] = $priceArr['membershipPrice'];
$goods['goods_price_min_dealer'] = $priceArr['distributionPrice']; $goods['goods_price_min_dealer'] = $priceArr['distributionPrice'];
$goods['goods_price_min'] = $goods['goods_price_min_plus'];//$goods['cost_price_min'];//店长售价,展示为成本价 $goods['goods_price_min'] = $goods['goods_price_min_plus'];//$goods['cost_price_min'];//店长售价,展示为成本价
} elseif (UserService::isPlusMember()) { } elseif (UserService::isPlusMember()) {
$membershipPrice = \app\common\model\PriceSet::membershipPrice($goods['goods_price_min'], $goods['cost_price_min'], $catIds); $membershipPrice = \app\common\model\PriceSet::membershipPrice($goods['goods_price_min'], $goods['cost_price_min'], $catIds);
$goods['discount'] = bcdiv((string)($membershipPrice*10), (string)$goods['goods_price_min'], 1); $goods['discount'] = bcdiv((string)($membershipPrice * 10), (string)$goods['goods_price_min'], 1);
$goods['goods_price_min'] = $membershipPrice; $goods['goods_price_min'] = $membershipPrice;
} elseif (UserService::isDealerMember()) { } elseif (UserService::isDealerMember()) {
$priceArr = \app\common\model\PriceSet::distributionPrice($goods['goods_price_min'], $goods['cost_price_min'], $catIds); $priceArr = \app\common\model\PriceSet::distributionPrice($goods['goods_price_min'], $goods['cost_price_min'], $catIds);
$goods['discount'] = bcdiv((string)($priceArr['distributionPrice']*10), (string)$goods['goods_price_min'], 1); $goods['discount'] = bcdiv((string)($priceArr['distributionPrice'] * 10), (string)$goods['goods_price_min'], 1);
//$goods['goods_price_min'] = $membershipPrice; //$goods['goods_price_min'] = $membershipPrice;
$goods['goods_price_min'] = $priceArr['distributionPrice']; $goods['goods_price_min'] = $priceArr['distributionPrice'];
} }
@ -629,7 +666,7 @@ class Goods extends GoodsModel
} }
} }
//exit(); //exit();
// var_dump(111); // var_dump(111);
// exit(); // exit();
@ -709,7 +746,8 @@ class Goods extends GoodsModel
* @throws DbException * @throws DbException
* @throws ModelNotFoundException * @throws ModelNotFoundException
*/ */
public function editGoodsPrice($data) { public function editGoodsPrice($data)
{
if (empty($data['goods_price']) || empty($data['cost_price']) || empty($data['id'])) { if (empty($data['goods_price']) || empty($data['cost_price']) || empty($data['id'])) {
$this->error = "请补全信息"; $this->error = "请补全信息";
return false; return false;
@ -737,17 +775,18 @@ class Goods extends GoodsModel
// $skuList = GoodsSkuModel::getSkuList((int)$data['id']); // $skuList = GoodsSkuModel::getSkuList((int)$data['id']);
// [$data['goods_price_min'], $data['goods_price_max']] = GoodsSkuModel::getGoodsPrices($skuList->toArray()); // [$data['goods_price_min'], $data['goods_price_max']] = GoodsSkuModel::getGoodsPrices($skuList->toArray());
// } elseif ($detail['spec_type'] == GoodsSpecTypeEnum::SINGLE) { // } elseif ($detail['spec_type'] == GoodsSpecTypeEnum::SINGLE) {
//} //}
$data['goods_price_min'] = $data['goods_price_max'] = $data['line_price_min'] = $data['line_price_max'] = $data['goods_price']; $data['goods_price_min'] = $data['goods_price_max'] = $data['line_price_min'] = $data['line_price_max'] = $data['goods_price'];
$data['cost_price_min'] = $data['cost_price']; $data['cost_price_min'] = $data['cost_price'];
$detail->save($data); $detail->save($data);
//更新sku的价格 //更新sku的价格
GoodsSkuModel::where('goods_id', $data['id'])->update(['cost_price'=>$data['cost_price'], 'goods_price' => $data['goods_price']]); GoodsSkuModel::where('goods_id', $data['id'])->update(['cost_price' => $data['cost_price'], 'goods_price' => $data['goods_price']]);
return true; return true;
} }
public function editGoodsSeckillPrice($data) { public function editGoodsSeckillPrice($data)
{
if (empty($data['seckill_price']) || empty($data['is_limit']) || empty($data['limit_times']) || empty($data['goods_id'])) { if (empty($data['seckill_price']) || empty($data['is_limit']) || empty($data['limit_times']) || empty($data['goods_id'])) {
$this->error = "请补全信息"; $this->error = "请补全信息";
return false; return false;
@ -758,7 +797,7 @@ class Goods extends GoodsModel
return false; return false;
} }
if(empty($data['sku_id'])) { if (empty($data['sku_id'])) {
$this->error = "请输入sku_id"; $this->error = "请输入sku_id";
return false; return false;
} }
@ -766,18 +805,18 @@ class Goods extends GoodsModel
// var_dump($data['sku_id']); // var_dump($data['sku_id']);
$sku_id = $data['sku_id']; $sku_id = $data['sku_id'];
// foreach ($sku_ids as $sku_id) { // foreach ($sku_ids as $sku_id) {
$skuData = GoodsSkuModel::get(['id' => $sku_id,'goods_id' => $data['goods_id']]); $skuData = GoodsSkuModel::get(['id' => $sku_id, 'goods_id' => $data['goods_id']]);
if ($skuData) { if ($skuData) {
$up_data = [ $up_data = [
'seckill_price' => $data['seckill_price'], 'seckill_price' => $data['seckill_price'],
'is_limit' => $data['is_limit'], 'is_limit' => $data['is_limit'],
'limit_times' => $data['limit_times'], 'limit_times' => $data['limit_times'],
'sec_start_time' => $data['sec_start_time'], 'sec_start_time' => $data['sec_start_time'],
// 'sec_end_time' => $data['sec_end_time'], // 'sec_end_time' => $data['sec_end_time'],
'sec_hour' => $data['sec_hour'], 'sec_hour' => $data['sec_hour'],
]; ];
$skuData->save($up_data); $skuData->save($up_data);
} }
// } // }
return true; return true;
} }

@ -486,7 +486,7 @@ class Server
* @notes:设置域名 * @notes:设置域名
* @param $appid * @param $appid
* @param $domain * @param $domain
* @return bool|void * @return bool
* @author: wanghousheng * @author: wanghousheng
*/ */
public function setDomain($appid, $domain) public function setDomain($appid, $domain)
@ -503,8 +503,8 @@ class Server
if ($result && !empty($result['errmsg']) && $result['errmsg'] == 'ok') { if ($result && !empty($result['errmsg']) && $result['errmsg'] == 'ok') {
return true; return true;
} }
return false;
} }
return false;
} }
/** /**
@ -606,14 +606,48 @@ class Server
$insert_data['create_time'] = time(); $insert_data['create_time'] = time();
$model->insertGetId($insert_data); $model->insertGetId($insert_data);
} }
//设置域名信息 $this->setOther($appid, $domain);
$this->setDomain($appid, $domain);
//设置隐私
$this->getPrivacySetting($appid);
} }
} }
} }
private function setOther($appid, $domain)
{
$up = [];
//设置域名信息
if ($this->setDomain($appid, $domain)) {
$up['domain_status'] = 1;
}
//设置隐私
if ($this->getPrivacySetting($appid)) {
$up['privacy_status'] = 1;
}
//设置业务域名
if ($this->modifyJumpDomain($appid)) {
$up['jump_domain_status'] = 1;
}
if ($up) {
$model = new WxserverAccount();
$model->update($up, ['appid' => $appid]);
}
}
private function modifyJumpDomain($appid, $domain): bool
{
$token = $this->authorizerAccessToken($appid);
if ($token) {
$url = "https://api.weixin.qq.com/wxa/setwebviewdomain?access_token=$token";
$data['action'] = 'set';
$data['webviewdomain'] = $domain;
$result = $this->curlPost($url, json_encode($data));
$result = json_decode($result, true);
if ($result && !empty($result['errmsg']) && $result['errmsg'] == 'ok') {
return true;
}
}
return false;
}
/** /**
* @notes:获取店铺ID * @notes:获取店铺ID
* @param $appid * @param $appid

Loading…
Cancel
Save