feat: 修改了门店商品的编辑逻辑,并移除了相关库存更新代码;同时修复了用户提现记录的查询逻辑,并修复了更新商品分类的错误逻辑;此外,还删除了复制商品到门店的功能代码。
This commit is contained in:
parent
c459d0adc9
commit
f8a566655b
@ -70,13 +70,8 @@ class StoreBranchProductController extends BaseAdminController
|
|||||||
public function edit()
|
public function edit()
|
||||||
{
|
{
|
||||||
$params = $this->request->post();
|
$params = $this->request->post();
|
||||||
foreach ($params['data'] as $k => $v) {
|
|
||||||
StoreProductLogic::stock($v);
|
return $this->fail('不能编辑');
|
||||||
if (StoreProductLogic::hasError()) {
|
|
||||||
return $this->fail(StoreProductLogic::getError());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $this->success('操作成功,等待门店确认', [], 1, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -60,7 +60,7 @@ class StoreExtractLists extends BaseAdminDataLists implements ListsSearchInterfa
|
|||||||
}else{
|
}else{
|
||||||
$name=$find['mobile'];
|
$name=$find['mobile'];
|
||||||
}
|
}
|
||||||
$openid=UserAuth::where('uid',$find['id'])->value('openid');
|
$openid=UserAuth::where('user_id',$find['id'])->value('openid');
|
||||||
$user_ship=UserShip::where('id',$find['user_ship'])->value('title');
|
$user_ship=UserShip::where('id',$find['user_ship'])->value('title');
|
||||||
$item->nickname=$name.'('.$user_ship.')';
|
$item->nickname=$name.'('.$user_ship.')';
|
||||||
$item->id_card=$find['id_card'];
|
$item->id_card=$find['id_card'];
|
||||||
|
@ -65,25 +65,7 @@ class StoreBranchProductLogic extends BaseLogic
|
|||||||
'unit'=>$params['unit'],
|
'unit'=>$params['unit'],
|
||||||
'status'=>$params['status'],
|
'status'=>$params['status'],
|
||||||
];
|
];
|
||||||
if(isset($params['cate_id'])){
|
|
||||||
if ($StoreProduct['cate_id'] != $params['cate_id']) {
|
|
||||||
self::store_product_cate_update($params['id'], $StoreProduct['cate_id'], $StoreProduct['store_id']);
|
|
||||||
}
|
|
||||||
$data['cate_id']=$params['cate_id'];
|
|
||||||
}else{
|
|
||||||
if($params['status']!=$StoreProduct['status']){
|
|
||||||
if($params['status']==1){
|
|
||||||
StoreProductLogic::updateGoodsclass($StoreProduct['cate_id'],$StoreProduct['store_id']);
|
|
||||||
}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']);
|
|
||||||
|
|
||||||
}
|
|
||||||
StoreBranchProduct::where('id', $params['id'])->update($data);
|
StoreBranchProduct::where('id', $params['id'])->update($data);
|
||||||
|
|
||||||
Db::commit();
|
Db::commit();
|
||||||
return true;
|
return true;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
@ -92,22 +74,6 @@ class StoreBranchProductLogic extends BaseLogic
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function store_product_cate_update($id,$cate_id,$store_id,$type=1)
|
|
||||||
{
|
|
||||||
$find=Db::name('store_product_cate')->where(['cate_id'=>$cate_id,'store_id'=>$store_id])->find();
|
|
||||||
if($find &&$find['pid']>0){
|
|
||||||
$two=Db::name('store_product_cate')->where(['cate_id'=>$find['pid'],'store_id'=>$store_id])->find();
|
|
||||||
Db::name('store_product_cate')->where('id',$find['id'])->dec('count',1)->update();
|
|
||||||
Db::name('store_product_cate')->where('id',$two['id'])->dec('count',1)->update();
|
|
||||||
if($two['pid']>0){
|
|
||||||
Db::name('store_product_cate')->where('id',$two['pid'])->dec('count',1)->update();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if($type==1){
|
|
||||||
StoreProductLogic::updateGoodsclass($cate_id,$store_id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* @notes 删除门店商品
|
* @notes 删除门店商品
|
||||||
* @param array $params
|
* @param array $params
|
||||||
|
@ -84,7 +84,6 @@ class StoreProductLogic extends BaseLogic
|
|||||||
foreach ($store_arr as $store_id) {
|
foreach ($store_arr as $store_id) {
|
||||||
Redis::send('store-storage', ['product_arr' => ['id' => $res['id'], 'stock' => 0], 'store_id' => $store_id, 'stock_type' => 1, 'admin_id' => Request()->adminId]);
|
Redis::send('store-storage', ['product_arr' => ['id' => $res['id'], 'stock' => 0], 'store_id' => $store_id, 'stock_type' => 1, 'admin_id' => Request()->adminId]);
|
||||||
}
|
}
|
||||||
// Redis::send('copy-product', ['product_id' => $res['id'], 'store_arr' => $store_arr]);
|
|
||||||
} else {
|
} else {
|
||||||
if (is_array($params['store_arr']) && count($params['store_arr']) > 0) {
|
if (is_array($params['store_arr']) && count($params['store_arr']) > 0) {
|
||||||
foreach ($params['store_arr'] as $key => $store_id) {
|
foreach ($params['store_arr'] as $key => $store_id) {
|
||||||
@ -92,7 +91,6 @@ class StoreProductLogic extends BaseLogic
|
|||||||
Redis::send('store-storage', ['product_arr' => ['id' => $res['id'], 'stock' => 0], 'store_id' => $store_id, 'stock_type' => 1, 'admin_id' => Request()->adminId]);
|
Redis::send('store-storage', ['product_arr' => ['id' => $res['id'], 'stock' => 0], 'store_id' => $store_id, 'stock_type' => 1, 'admin_id' => Request()->adminId]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Redis::send('copy-product', ['product_id' => $res['id'], 'store_arr' => $params['store_arr']]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (getenv('STORE_ID')) {
|
if (getenv('STORE_ID')) {
|
||||||
@ -267,90 +265,6 @@ class StoreProductLogic extends BaseLogic
|
|||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新商品分类
|
|
||||||
*/
|
|
||||||
public static function updateGoodsclass($cate_id, $store_id = 0, $type = 0)
|
|
||||||
{
|
|
||||||
$one = StoreCategory::where('id', $cate_id)->find();
|
|
||||||
if ($one) {
|
|
||||||
//查二级分类
|
|
||||||
$two = StoreCategory::where('id', $one['pid'])->find();
|
|
||||||
if ($two) {
|
|
||||||
if ($two['pid'] != 0) {
|
|
||||||
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);
|
|
||||||
} else {
|
|
||||||
if ($one['pid'] == 0) {
|
|
||||||
self::cate_update($one['id'], 0, $store_id, 1);
|
|
||||||
} else {
|
|
||||||
self::cate_update($one['id'], $one['pid'], $store_id, 2);
|
|
||||||
self::cate_update($one['pid'], 0, $store_id, 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' => $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' => $store_id, 'cate_id' => $cate_id, 'count' => 1, 'level' => $level, 'create_time' => time(), 'update_time' => time()]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 复制商品到门店
|
|
||||||
*/
|
|
||||||
public static function copy($id, $store_id, $stock = 0)
|
|
||||||
{
|
|
||||||
$find = StoreProduct::where('id', $id)->findOrEmpty()->toArray();
|
|
||||||
$store_find = StoreBranchProduct::where(['product_id' => $id, 'store_id' => $store_id])->findOrEmpty()->toArray();
|
|
||||||
if ($find && !$store_find) {
|
|
||||||
$attr_value = StoreProductAttrValue::where('product_id', $id)->findOrEmpty();
|
|
||||||
Db::startTrans();
|
|
||||||
try {
|
|
||||||
$dealCate = self::dealChangeCate($find['cate_id']);
|
|
||||||
$product = [
|
|
||||||
'product_id' => $find['id'],
|
|
||||||
'image' => $find['image'],
|
|
||||||
'store_name' => $find['store_name'],
|
|
||||||
'store_info' => $find['store_info'],
|
|
||||||
'keyword' => $find['keyword'],
|
|
||||||
'bar_code' => $find['bar_code'],
|
|
||||||
'cate_id' => $find['cate_id'],
|
|
||||||
'top_cate_id' => $dealCate['top_cate_id'],
|
|
||||||
'two_cate_id' => $dealCate['two_cate_id'],
|
|
||||||
'price' => $find['price'],
|
|
||||||
'unit' => $find['unit'],
|
|
||||||
'store_id' => $store_id,
|
|
||||||
'sales' => 0,
|
|
||||||
'stock' => $stock,
|
|
||||||
'manufacturer_information' => $find['manufacturer_information'] ?? '',
|
|
||||||
];
|
|
||||||
StoreBranchProduct::create($product);
|
|
||||||
$arr = [
|
|
||||||
'product_id' => $id,
|
|
||||||
'store_id' => $store_id,
|
|
||||||
'sales' => 0,
|
|
||||||
'type' => 0,
|
|
||||||
'bar_code' => $attr_value['bar_code']
|
|
||||||
];
|
|
||||||
StoreBranchProductAttrValue::create($arr);
|
|
||||||
Db::commit();
|
|
||||||
return true;
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
Db::rollback();
|
|
||||||
self::setError($e->getMessage());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除门店商品
|
* 删除门店商品
|
||||||
*/
|
*/
|
||||||
@ -370,83 +284,47 @@ class StoreProductLogic extends BaseLogic
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 增加库存
|
|
||||||
*/
|
|
||||||
public static function stock($data)
|
|
||||||
{
|
|
||||||
Db::startTrans();
|
|
||||||
try {
|
|
||||||
$find = StoreBranchProduct::where(['id' => $data['id']])->find();
|
|
||||||
SystemStoreStorage::create([
|
|
||||||
'product_id' => $find['product_id'],
|
|
||||||
'store_id' => $find['store_id'],
|
|
||||||
'nums' => $data['stock'],
|
|
||||||
'admin_id' => Request()->adminId,
|
|
||||||
]);
|
|
||||||
Db::commit();
|
|
||||||
return true;
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
Db::rollback();
|
|
||||||
self::setError($e->getMessage());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**普通 */
|
/**普通 */
|
||||||
public static function ordinary($product_arr, $store_id, $admin_id, $find)
|
public static function ordinary($product_arr, $store_id, $admin_id, $find)
|
||||||
{
|
{
|
||||||
$store_find = StoreBranchProduct::where(['product_id' => $product_arr['id'], 'store_id' => $store_id])->findOrEmpty()->toArray();
|
$dealCate = self::dealChangeCate($find['cate_id']);
|
||||||
if ($find && !$store_find) {
|
$product = [
|
||||||
//创建门店商品
|
'product_id' => $find['id'],
|
||||||
$attr_value = StoreProductAttrValue::where('product_id', $product_arr['id'])->findOrEmpty();
|
'image' => $find['image'],
|
||||||
Db::startTrans();
|
'store_name' => $find['store_name'],
|
||||||
try {
|
'store_info' => $find['store_info'],
|
||||||
$dealCate = self::dealChangeCate($find['cate_id']);
|
'keyword' => $find['keyword'],
|
||||||
$product = [
|
'bar_code' => $find['bar_code'],
|
||||||
'product_id' => $find['id'],
|
'cate_id' => $find['cate_id'],
|
||||||
'image' => $find['image'],
|
'top_cate_id' => $dealCate['top_cate_id'],
|
||||||
'store_name' => $find['store_name'],
|
'two_cate_id' => $dealCate['two_cate_id'],
|
||||||
'store_info' => $find['store_info'],
|
'price' => $find['price'],
|
||||||
'keyword' => $find['keyword'],
|
// 'cost' => $find['cost'], //v1.0
|
||||||
'bar_code' => $find['bar_code'],
|
'cost' => $find['cost'],
|
||||||
'cate_id' => $find['cate_id'],
|
'purchase' => $find['purchase'],
|
||||||
'top_cate_id' => $dealCate['top_cate_id'],
|
'vip_price' => $find['vip_price'],
|
||||||
'two_cate_id' => $dealCate['two_cate_id'],
|
'manufacturer_information' => $find['manufacturer_information'] ?? '',
|
||||||
'price' => $find['price'],
|
'unit' => $find['unit'],
|
||||||
// 'cost' => $find['cost'], //v1.0
|
'batch' => $find['batch'],
|
||||||
'cost' => $find['cost'],
|
'store_batch' => $find['store_batch'],
|
||||||
'purchase' => $find['purchase'],
|
'store_id' => $store_id,
|
||||||
'vip_price' => $find['vip_price'],
|
'sales' => 0,
|
||||||
'manufacturer_information' => $find['manufacturer_information'] ?? '',
|
'product_type' => $find['product_type'],
|
||||||
'unit' => $find['unit'],
|
'stock' => 0,
|
||||||
'batch' => $find['batch'],
|
'rose' => $find['rose'],
|
||||||
'store_batch' => $find['store_batch'],
|
];
|
||||||
'store_id' => $store_id,
|
$branch = StoreBranchProduct::create($product);
|
||||||
'sales' => 0,
|
$arr = [
|
||||||
'product_type' => $find['product_type'],
|
'product_id' => $product_arr['id'],
|
||||||
'stock' => 0,
|
'store_id' => $store_id,
|
||||||
'rose' => $find['rose'],
|
'unique' => setUnique($branch['id'], '', 0),
|
||||||
];
|
'sales' => 0,
|
||||||
$branch = StoreBranchProduct::create($product);
|
'type' => 0,
|
||||||
$arr = [
|
'bar_code' => $find['bar_code']
|
||||||
'product_id' => $product_arr['id'],
|
];
|
||||||
'store_id' => $store_id,
|
StoreBranchProductAttrValue::create($arr);
|
||||||
'unique' => setUnique($branch['id'], '', 0),
|
return $branch;
|
||||||
'sales' => 0,
|
|
||||||
'type' => 0,
|
|
||||||
'bar_code' => $attr_value['bar_code']
|
|
||||||
];
|
|
||||||
StoreBranchProductAttrValue::create($arr);
|
|
||||||
Db::commit();
|
|
||||||
return $branch;
|
|
||||||
} catch (\Throwable $e) {
|
|
||||||
Db::rollback();
|
|
||||||
Log::error('store-storage队列消费失败: ' . $e->getMessage() . ',line:' . $e->getLine() . ',file:' . $e->getFile());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**兑换 */
|
/**兑换 */
|
||||||
|
@ -1,48 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace app\queue\redis;
|
|
||||||
|
|
||||||
use app\admin\logic\store_product\StoreProductLogic;
|
|
||||||
use app\common\model\store_product\StoreProduct;
|
|
||||||
use app\common\model\system_store_storage\SystemStoreStorage;
|
|
||||||
use Webman\RedisQueue\Consumer;
|
|
||||||
use support\Log;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 复制商品
|
|
||||||
*/
|
|
||||||
class CopyProductSend implements Consumer
|
|
||||||
{
|
|
||||||
// 要消费的队列名
|
|
||||||
public $queue = 'copy-product';
|
|
||||||
|
|
||||||
// 连接名,对应 plugin/webman/redis-queue/redis.php 里的连接`
|
|
||||||
public $connection = 'default';
|
|
||||||
|
|
||||||
// 消费
|
|
||||||
public function consume($data)
|
|
||||||
{
|
|
||||||
$store_arr=$data['store_arr'];
|
|
||||||
$stock=$data['stock']??0;
|
|
||||||
$admin_id=$data['admin_id']??0;
|
|
||||||
foreach ($store_arr as $key => $id) {
|
|
||||||
StoreProductLogic::copy($data['product_id'],$id,0);
|
|
||||||
if($stock>0){
|
|
||||||
$stocks=StoreProduct::where('id',$data['product_id'])->value('stock');
|
|
||||||
if($stocks>=$stock){
|
|
||||||
SystemStoreStorage::create(['product_id'=>$data['product_id'],'store_id'=>$id,'nums'=>$stock,'admin_id'=>$admin_id]);//设置库存
|
|
||||||
StoreProduct::where('id',$data['product_id'])->dec('stock',$stock)->update();//减少库存
|
|
||||||
}else{
|
|
||||||
SystemStoreStorage::create(['product_id'=>$data['product_id'],'store_id'=>$id,'nums'=>$stock,'admin_id'=>$admin_id,'status'=>-1,'mark'=>'库存不足']);//设置库存
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public function onConsumeFailure(\Throwable $e, $package)
|
|
||||||
{
|
|
||||||
$package['max_attempts']=0;
|
|
||||||
Log::error('复制商品失败product_id:'.$package['data']['product_id']);
|
|
||||||
return $package;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user