feat: 更新商品分类逻辑

This commit is contained in:
mkm 2024-06-13 17:49:42 +08:00
parent 7c35d4e504
commit 192169542e
8 changed files with 48 additions and 58 deletions

View File

@ -69,7 +69,7 @@ class StoreBranchProductLogic extends BaseLogic
}else{
if($params['statis']!=$StoreProduct['statis']){
if($params['statis']==1){
StoreProductLogic::updateGoodsclass($params['cate_id']);
StoreProductLogic::updateGoodsclass($params['cate_id'],$StoreProduct['store_id']);
}else{
self::store_product_cate_update($params['id'], $StoreProduct['cate_id'], $StoreProduct['store_id'],0);
@ -101,7 +101,7 @@ class StoreBranchProductLogic extends BaseLogic
}
}
if($type==1){
StoreProductLogic::updateGoodsclass($cate_id);
StoreProductLogic::updateGoodsclass($cate_id,$store_id);
}
}
/**

View File

@ -177,7 +177,7 @@ class StoreProductLogic extends BaseLogic
/**
* 更新商品分类
*/
public static function updateGoodsclass($cate_id, $type = 0)
public static function updateGoodsclass($cate_id, $store_id=0,$type = 0)
{
$one = StoreCategory::where('id', $cate_id)->find();
if ($one) {
@ -185,21 +185,21 @@ class StoreProductLogic extends BaseLogic
$two = StoreCategory::where('id', $one['pid'])->find();
if ($two) {
if ($two['pid'] != 0) {
self::cate_update($cate_id, $two['id'], 0, 3);
self::cate_update($two['id'], $two['pid'], 0, 2);
self::cate_update($two['pid'], 0, 0, 1);
self::cate_update($cate_id, $two['id'], $store_id, 3);
self::cate_update($two['id'], $two['pid'], $store_id, 2);
self::cate_update($two['pid'], 0, $store_id, 1);
}
}
}
}
public static function cate_update($cate_id = 0, $pid = 0, $product_id = 0, $level = 1)
public static function cate_update($cate_id = 0, $pid = 0, $store_id = 0, $level = 1)
{
$find = Db::name('store_product_cate')->where(['store_id' => 1, 'cate_id' => $cate_id, 'level' => $level])->find();
$find = Db::name('store_product_cate')->where(['store_id' => $store_id, 'cate_id' => $cate_id, 'level' => $level])->find();
if ($find) {
Db::name('store_product_cate')->where('id', $find['id'])->inc('count', 1)->update();
} else {
Db::name('store_product_cate')->insert(['pid' => $pid, 'store_id' => 1, 'cate_id' => $cate_id, 'count' => 1, 'level' => $level, 'create_time' => time(), 'update_time' => time()]);
Db::name('store_product_cate')->insert(['pid' => $pid, 'store_id' => $store_id, 'cate_id' => $cate_id, 'count' => 1, 'level' => $level, 'create_time' => time(), 'update_time' => time()]);
}
}
/**

View File

@ -2,9 +2,11 @@
namespace app\api\controller;
use app\admin\logic\store_product\StoreProductLogic;
use app\admin\validate\tools\GenerateTableValidate;
use app\admin\logic\tools\GeneratorLogic;
use app\common\logic\store_order\StoreOrderLogic;
use app\common\model\store_branch_product\StoreBranchProduct;
use app\common\service\pay\PayService;
use app\common\service\wechat\WechatTemplate;
use Exception;
@ -25,9 +27,11 @@ class IndexController extends BaseApiController
public function index()
{
Redis::send('push-platform-print', ['order_id' => 119]);
d(2);
$arr=StoreBranchProduct::where('store_id',5)->select();
foreach ($arr as $item){
StoreProductLogic::updateGoodsclass($item['cate_id'],5);
}
try {
$wechat = new PayService(1);
$time = time();

View File

@ -79,6 +79,7 @@ class PayNotifyLogic extends BaseLogic
$capitalFlowDao->userExpense('user_order_pay', 'order', $order['id'], $order['pay_price']);
self::afterPay($order);
Redis::send('push-platform-print', ['id' => $order['id']], 60);
PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'store_merchant', 'msg' => '您有一笔新的订单']);
}

View File

@ -65,7 +65,7 @@ class StoreStorageSend implements Consumer
if ($product_arr['stock'] > 0) {
$this->storage($find, $store_id, $admin_id, $product_arr);
}
StoreProductLogic::updateGoodsclass($find['cate_id']);
StoreProductLogic::updateGoodsclass($find['cate_id'],$store_id);
Db::commit();
return true;
} catch (\Exception $e) {

View File

@ -0,0 +1,31 @@
<?php
namespace app\store\controller\cate;
use app\store\controller\BaseAdminController;
use app\api\lists\cate\CateLists;
use hg\apidoc\annotation as ApiDoc;
#[ApiDoc\NotParse()]
/**
* 商品分类控制器
* Class CateController
* @package app\admin\controller\goods
*/
class CateController extends BaseAdminController
{
public $notNeedLogin = ['lists'];
/**
* @notes 获取商品分类列表
* @return
* @author likeadmin
* @date 2024/04/23 10:27
*/
public function lists()
{
return $this->dataLists(new CateLists());
}
}

View File

@ -127,29 +127,6 @@ class StoreBranchProductLogic extends BaseLogic
return StoreProduct::findOrEmpty($params['id'])->toArray();
}
/**
* 更新商品分类
*/
public static function updateGoodsclass($id, $type = 0)
{
$pid = StoreCategory::where('id', $id)->value('pid');
if ($pid) {
$goodsclass = StoreCategory::where('id', $pid)->field('pid,children')->find();
if ($goodsclass) {
if (count($goodsclass['children']) >= 1) {
if (!in_array($id, $goodsclass['children'])) {
$arr = $goodsclass['children'];
array_push($arr, $id);
StoreCategory::where('id', $pid)->update(['children' => $arr]);
if ($goodsclass['pid'] != 0 && $type == 0) {
self::updateGoodsclass($pid, 1);
}
}
}
}
}
}
/**
* @notes 商品上下架
* @param array $params

View File

@ -122,27 +122,4 @@ class StoreProductLogic extends BaseLogic
{
return StoreProduct::findOrEmpty($params['id'])->toArray();
}
/**
* 更新商品分类
*/
public static function updateGoodsclass($id, $type = 0)
{
$pid = StoreCategory::where('id', $id)->value('pid');
if ($pid) {
$goodsclass = StoreCategory::where('id', $pid)->field('pid,children')->find();
if ($goodsclass) {
if (count($goodsclass['children']) >= 1) {
if (!in_array($id, $goodsclass['children'])) {
$arr = $goodsclass['children'];
array_push($arr, $id);
StoreCategory::where('id', $pid)->update(['children' => $arr]);
if ($goodsclass['pid'] != 0 && $type == 0) {
self::updateGoodsclass($pid, 1);
}
}
}
}
}
}
}