feat: 更新商品分类逻辑
This commit is contained in:
parent
7c35d4e504
commit
192169542e
@ -69,7 +69,7 @@ class StoreBranchProductLogic extends BaseLogic
|
|||||||
}else{
|
}else{
|
||||||
if($params['statis']!=$StoreProduct['statis']){
|
if($params['statis']!=$StoreProduct['statis']){
|
||||||
if($params['statis']==1){
|
if($params['statis']==1){
|
||||||
StoreProductLogic::updateGoodsclass($params['cate_id']);
|
StoreProductLogic::updateGoodsclass($params['cate_id'],$StoreProduct['store_id']);
|
||||||
}else{
|
}else{
|
||||||
self::store_product_cate_update($params['id'], $StoreProduct['cate_id'], $StoreProduct['store_id'],0);
|
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){
|
if($type==1){
|
||||||
StoreProductLogic::updateGoodsclass($cate_id);
|
StoreProductLogic::updateGoodsclass($cate_id,$store_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -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();
|
$one = StoreCategory::where('id', $cate_id)->find();
|
||||||
if ($one) {
|
if ($one) {
|
||||||
@ -185,21 +185,21 @@ class StoreProductLogic extends BaseLogic
|
|||||||
$two = StoreCategory::where('id', $one['pid'])->find();
|
$two = StoreCategory::where('id', $one['pid'])->find();
|
||||||
if ($two) {
|
if ($two) {
|
||||||
if ($two['pid'] != 0) {
|
if ($two['pid'] != 0) {
|
||||||
self::cate_update($cate_id, $two['id'], 0, 3);
|
self::cate_update($cate_id, $two['id'], $store_id, 3);
|
||||||
self::cate_update($two['id'], $two['pid'], 0, 2);
|
self::cate_update($two['id'], $two['pid'], $store_id, 2);
|
||||||
self::cate_update($two['pid'], 0, 0, 1);
|
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) {
|
if ($find) {
|
||||||
Db::name('store_product_cate')->where('id', $find['id'])->inc('count', 1)->update();
|
Db::name('store_product_cate')->where('id', $find['id'])->inc('count', 1)->update();
|
||||||
} else {
|
} 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()]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -2,9 +2,11 @@
|
|||||||
|
|
||||||
namespace app\api\controller;
|
namespace app\api\controller;
|
||||||
|
|
||||||
|
use app\admin\logic\store_product\StoreProductLogic;
|
||||||
use app\admin\validate\tools\GenerateTableValidate;
|
use app\admin\validate\tools\GenerateTableValidate;
|
||||||
use app\admin\logic\tools\GeneratorLogic;
|
use app\admin\logic\tools\GeneratorLogic;
|
||||||
use app\common\logic\store_order\StoreOrderLogic;
|
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\pay\PayService;
|
||||||
use app\common\service\wechat\WechatTemplate;
|
use app\common\service\wechat\WechatTemplate;
|
||||||
use Exception;
|
use Exception;
|
||||||
@ -25,9 +27,11 @@ class IndexController extends BaseApiController
|
|||||||
|
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
Redis::send('push-platform-print', ['order_id' => 119]);
|
$arr=StoreBranchProduct::where('store_id',5)->select();
|
||||||
d(2);
|
foreach ($arr as $item){
|
||||||
|
StoreProductLogic::updateGoodsclass($item['cate_id'],5);
|
||||||
|
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
$wechat = new PayService(1);
|
$wechat = new PayService(1);
|
||||||
$time = time();
|
$time = time();
|
||||||
|
@ -79,6 +79,7 @@ class PayNotifyLogic extends BaseLogic
|
|||||||
$capitalFlowDao->userExpense('user_order_pay', 'order', $order['id'], $order['pay_price']);
|
$capitalFlowDao->userExpense('user_order_pay', 'order', $order['id'], $order['pay_price']);
|
||||||
self::afterPay($order);
|
self::afterPay($order);
|
||||||
Redis::send('push-platform-print', ['id' => $order['id']], 60);
|
Redis::send('push-platform-print', ['id' => $order['id']], 60);
|
||||||
|
PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'store_merchant', 'msg' => '您有一笔新的订单']);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ class StoreStorageSend implements Consumer
|
|||||||
if ($product_arr['stock'] > 0) {
|
if ($product_arr['stock'] > 0) {
|
||||||
$this->storage($find, $store_id, $admin_id, $product_arr);
|
$this->storage($find, $store_id, $admin_id, $product_arr);
|
||||||
}
|
}
|
||||||
StoreProductLogic::updateGoodsclass($find['cate_id']);
|
StoreProductLogic::updateGoodsclass($find['cate_id'],$store_id);
|
||||||
Db::commit();
|
Db::commit();
|
||||||
return true;
|
return true;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
31
app/store/controller/cate/CateController.php
Normal file
31
app/store/controller/cate/CateController.php
Normal 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());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -127,29 +127,6 @@ class StoreBranchProductLogic extends BaseLogic
|
|||||||
return StoreProduct::findOrEmpty($params['id'])->toArray();
|
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 商品上下架
|
* @notes 商品上下架
|
||||||
* @param array $params
|
* @param array $params
|
||||||
|
@ -122,27 +122,4 @@ class StoreProductLogic extends BaseLogic
|
|||||||
{
|
{
|
||||||
return StoreProduct::findOrEmpty($params['id'])->toArray();
|
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user