Merge branch 'main' of https://gitea.lihaink.cn/mkm/multi-store
This commit is contained in:
commit
263882c4be
@ -826,7 +826,7 @@ class WorkbenchController extends BaseAdminController
|
|||||||
}
|
}
|
||||||
//-------------------------------交易统计---------------------------------------//
|
//-------------------------------交易统计---------------------------------------//
|
||||||
//当日订单金额
|
//当日订单金额
|
||||||
public function top__trade()
|
public function top_trade()
|
||||||
{
|
{
|
||||||
$data = [
|
$data = [
|
||||||
"left" => [
|
"left" => [
|
||||||
|
@ -4,7 +4,7 @@ namespace app\admin\controller\store_branch_product;
|
|||||||
|
|
||||||
|
|
||||||
use app\admin\controller\BaseAdminController;
|
use app\admin\controller\BaseAdminController;
|
||||||
use app\admin\lists\store_product\StoreProductLists;
|
use app\admin\lists\store_branch_product\StoreBranchProductLists;
|
||||||
use app\admin\logic\store_product\StoreProductLogic;
|
use app\admin\logic\store_product\StoreProductLogic;
|
||||||
use app\admin\validate\store_product\StoreProductValidate;
|
use app\admin\validate\store_product\StoreProductValidate;
|
||||||
use app\common\model\store_branch_product\StoreBranchProduct;
|
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||||
@ -26,7 +26,7 @@ class StoreBranchProductController extends BaseAdminController
|
|||||||
*/
|
*/
|
||||||
public function lists()
|
public function lists()
|
||||||
{
|
{
|
||||||
return $this->dataLists(new StoreProductLists());
|
return $this->dataLists(new StoreBranchProductLists());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ use app\admin\controller\BaseAdminController;
|
|||||||
use app\admin\lists\store_product\StoreProductLists;
|
use app\admin\lists\store_product\StoreProductLists;
|
||||||
use app\admin\logic\store_product\StoreProductLogic;
|
use app\admin\logic\store_product\StoreProductLogic;
|
||||||
use app\admin\validate\store_product\StoreProductValidate;
|
use app\admin\validate\store_product\StoreProductValidate;
|
||||||
|
use Webman\RedisQueue\Redis;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品列表控制器
|
* 商品列表控制器
|
||||||
@ -91,5 +91,25 @@ class StoreProductController extends BaseAdminController
|
|||||||
return $this->data($result);
|
return $this->data($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商品导入到门店
|
||||||
|
*/
|
||||||
|
public function import()
|
||||||
|
{
|
||||||
|
$product_arr = $this->request->post('product_arr');
|
||||||
|
$store_arr = $this->request->post('store_arr');
|
||||||
|
if (count($store_arr) == 1) {
|
||||||
|
$store_id = $store_arr[0];
|
||||||
|
foreach ($product_arr as $key => $arr) {
|
||||||
|
Redis::send('store-storage', ['product_arr' => $arr, 'store_id' => $store_id, 'admin_id' => $this->adminId]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
foreach ($product_arr as $key => $arr) {
|
||||||
|
foreach ($store_arr as $k => $store_id) {
|
||||||
|
Redis::send('store-storage', ['product_arr' => $arr, 'store_id' => $store_id, 'admin_id' => $this->adminId]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $this->success('已导入后台队列,请在门店入库记录中查看');
|
||||||
|
}
|
||||||
}
|
}
|
@ -28,7 +28,7 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI
|
|||||||
public function setSearch(): array
|
public function setSearch(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'=' => ['product_id', 'cate_id'],
|
'=' => ['product_id', 'cate_id','store_id'],
|
||||||
'%like%' => ['store_name'],
|
'%like%' => ['store_name'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@ -47,7 +47,7 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI
|
|||||||
{
|
{
|
||||||
$status = $this->params['status'] ?? '';
|
$status = $this->params['status'] ?? '';
|
||||||
return StoreBranchProduct::where($this->searchWhere)
|
return StoreBranchProduct::where($this->searchWhere)
|
||||||
->field(['id', 'product_id', 'image', 'store_name', 'cate_id', 'price', 'sales', 'stock', 'unit', 'cost', 'status'])
|
->field(['id','store_id','product_id', 'image', 'store_name', 'cate_id', 'price', 'sales', 'stock', 'unit', 'cost', 'status'])
|
||||||
->when(!empty($this->adminInfo['store_id']), function ($query) {
|
->when(!empty($this->adminInfo['store_id']), function ($query) {
|
||||||
$query->where('store_id', $this->adminInfo['store_id']);
|
$query->where('store_id', $this->adminInfo['store_id']);
|
||||||
})
|
})
|
||||||
@ -66,6 +66,7 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI
|
|||||||
->order(['sort' => 'desc', 'id' => 'desc'])
|
->order(['sort' => 'desc', 'id' => 'desc'])
|
||||||
->select()
|
->select()
|
||||||
->each(function ($item) {
|
->each(function ($item) {
|
||||||
|
$item['system_store_name']=SystemStore::where('id',$item['store_id'])->value('name');
|
||||||
$item['unit_name'] = StoreProductUnit::where('id', $item['unit'])->value('name');
|
$item['unit_name'] = StoreProductUnit::where('id', $item['unit'])->value('name');
|
||||||
$item['cate_name'] = StoreCategory::where('id', $item['cate_id'])->value('name');
|
$item['cate_name'] = StoreCategory::where('id', $item['cate_id'])->value('name');
|
||||||
return $item;
|
return $item;
|
||||||
|
@ -12,8 +12,9 @@ use support\Cache;
|
|||||||
use think\facade\Db;
|
use think\facade\Db;
|
||||||
use Webman\Config;
|
use Webman\Config;
|
||||||
use hg\apidoc\annotation as ApiDoc;
|
use hg\apidoc\annotation as ApiDoc;
|
||||||
|
use support\Log;
|
||||||
use Yansongda\Pay\Exception\InvalidSignException;
|
use Yansongda\Pay\Exception\InvalidSignException;
|
||||||
|
use Monolog\Handler\RotatingFileHandler;
|
||||||
#[ApiDoc\NotParse()]
|
#[ApiDoc\NotParse()]
|
||||||
|
|
||||||
class IndexController extends BaseApiController
|
class IndexController extends BaseApiController
|
||||||
@ -22,6 +23,8 @@ class IndexController extends BaseApiController
|
|||||||
|
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
|
Log::error(222);
|
||||||
|
d(2);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$wechat = new PayService(1);
|
$wechat = new PayService(1);
|
||||||
|
@ -3,8 +3,14 @@
|
|||||||
namespace app\queue\redis;
|
namespace app\queue\redis;
|
||||||
|
|
||||||
use app\admin\logic\store_product\StoreProductLogic;
|
use app\admin\logic\store_product\StoreProductLogic;
|
||||||
|
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||||
|
use app\common\model\store_branch_product_attr_value\StoreBranchProductAttrValue;
|
||||||
|
use app\common\model\store_product\StoreProduct;
|
||||||
|
use app\common\model\store_product_attr_value\StoreProductAttrValue;
|
||||||
|
use app\common\model\system_store_storage\SystemStoreStorage;
|
||||||
use Webman\RedisQueue\Consumer;
|
use Webman\RedisQueue\Consumer;
|
||||||
use support\Log;
|
use support\Log;
|
||||||
|
use think\facade\Db;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 门店库存记录商品
|
* 门店库存记录商品
|
||||||
@ -12,7 +18,7 @@ use support\Log;
|
|||||||
class StoreStorageSend implements Consumer
|
class StoreStorageSend implements Consumer
|
||||||
{
|
{
|
||||||
// 要消费的队列名
|
// 要消费的队列名
|
||||||
public $queue = 'store_storage';
|
public $queue = 'store-storage';
|
||||||
|
|
||||||
// 连接名,对应 plugin/webman/redis-queue/redis.php 里的连接`
|
// 连接名,对应 plugin/webman/redis-queue/redis.php 里的连接`
|
||||||
public $connection = 'default';
|
public $connection = 'default';
|
||||||
@ -20,15 +26,83 @@ class StoreStorageSend implements Consumer
|
|||||||
// 消费
|
// 消费
|
||||||
public function consume($data)
|
public function consume($data)
|
||||||
{
|
{
|
||||||
// $product_id=$data['product_id'];
|
$product_arr = $data['product_arr'];
|
||||||
// $store_id=$data['store_id'];
|
$store_id = $data['store_id'];
|
||||||
// $store_id=$data['store_id'];
|
$admin_id = $data['admin_id'];
|
||||||
// StoreBranchProduct::w
|
Log::error('StoreStorageSend: ' . json_encode($data));
|
||||||
|
$find = StoreProduct::where('id', $product_arr['id'])->findOrEmpty()->toArray();
|
||||||
|
$store_find = StoreBranchProduct::where(['product_id' => $product_arr['id'], 'store_id' => $store_id])->findOrEmpty()->toArray();
|
||||||
|
if ($find && !$store_find) {
|
||||||
|
$attr_value = StoreProductAttrValue::where('product_id', $product_arr['id'])->findOrEmpty();
|
||||||
|
Db::startTrans();
|
||||||
|
try {
|
||||||
|
$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'],
|
||||||
|
'price' => $find['price'],
|
||||||
|
'unit' => $find['unit'],
|
||||||
|
'store_id' => $store_id,
|
||||||
|
'sales' => 0,
|
||||||
|
'stock' => 0,
|
||||||
|
];
|
||||||
|
$branch=StoreBranchProduct::create($product);
|
||||||
|
$arr = [
|
||||||
|
'product_id' => $product_arr['id'],
|
||||||
|
'store_id' => $store_id,
|
||||||
|
'unique' => setUnique($branch['id'], '', 0),
|
||||||
|
'sales' => 0,
|
||||||
|
'type' => 0,
|
||||||
|
'bar_code' => $attr_value['bar_code']
|
||||||
|
];
|
||||||
|
StoreBranchProductAttrValue::create($arr);
|
||||||
|
$this->storage($find, $store_id, $admin_id, $product_arr);
|
||||||
|
Db::commit();
|
||||||
|
return true;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
Db::rollback();
|
||||||
|
Log::error('store-storage队列消费失败: ' . $e->getMessage().',line:'.$e->getLine().',file:'.$e->getFile());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Db::startTrans();
|
||||||
|
try {
|
||||||
|
$this->storage($find, $store_id, $admin_id, $product_arr);
|
||||||
|
Db::commit();
|
||||||
|
return true;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
Db::rollback();
|
||||||
|
Log::error('store-storage队列消费失败: ' . $e->getMessage().',line:'.$e->getLine().',file:'.$e->getFile());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function storage($find, $store_id, $admin_id, $product_arr)
|
||||||
|
{
|
||||||
|
$storage = [
|
||||||
|
'product_id' => $product_arr['id'],
|
||||||
|
'store_id' => $store_id,
|
||||||
|
'nums' => $product_arr['stock'],
|
||||||
|
'admin_id' => $admin_id,
|
||||||
|
];
|
||||||
|
if ($find['stock'] < $product_arr['stock']) {
|
||||||
|
$storage['status'] = -1;
|
||||||
|
$storage['mark'] = '库存不足,主库存为:' . $find['stock'];
|
||||||
|
SystemStoreStorage::create($storage);
|
||||||
|
}else{
|
||||||
|
SystemStoreStorage::create($storage);
|
||||||
|
StoreProduct::where('id', $product_arr['id'])->dec('stock',$product_arr['stock'])->update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function onConsumeFailure(\Throwable $e, $package)
|
public function onConsumeFailure(\Throwable $e, $package)
|
||||||
{
|
{
|
||||||
$package['max_attempts'] = 0;
|
$package['max_attempts'] = 0;
|
||||||
Log::error('复制商品失败product_id:'.$package['data']['product_id']);
|
|
||||||
return $package;
|
return $package;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -16,9 +16,9 @@ return [
|
|||||||
'default' => [
|
'default' => [
|
||||||
'handlers' => [
|
'handlers' => [
|
||||||
[
|
[
|
||||||
'class' => \support\log\MonologExtendHandler::class,
|
'class' => Monolog\Handler\RotatingFileHandler::class,
|
||||||
'constructor' => [
|
'constructor' => [
|
||||||
null,
|
runtime_path() . '/logs/'.date('Ym').'/.log',
|
||||||
2048,
|
2048,
|
||||||
Monolog\Logger::DEBUG,
|
Monolog\Logger::DEBUG,
|
||||||
true,
|
true,
|
||||||
|
@ -18,7 +18,7 @@ return [
|
|||||||
[
|
[
|
||||||
'class' => \support\log\MonologExtendHandler::class,
|
'class' => \support\log\MonologExtendHandler::class,
|
||||||
'constructor' => [
|
'constructor' => [
|
||||||
runtime_path() . '/logs/redis-queue/queue.log',
|
'/logs/redis-queue/queue.log',
|
||||||
7, //$maxFiles
|
7, //$maxFiles
|
||||||
Monolog\Logger::DEBUG,
|
Monolog\Logger::DEBUG,
|
||||||
],
|
],
|
||||||
|
@ -1,15 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
|
||||||
* Created by PhpStorm.
|
|
||||||
* User: hjl
|
|
||||||
* Date: 2023/6/21
|
|
||||||
* Time: 07:25
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace support\log;
|
namespace support\log;
|
||||||
|
|
||||||
use Monolog\Handler\StreamHandler;
|
use Monolog\Handler\StreamHandler;
|
||||||
use Monolog\Logger;
|
use Monolog\Logger;
|
||||||
|
use Monolog\DateFormatter;
|
||||||
|
use DateTime;
|
||||||
|
|
||||||
class MonologExtendHandler extends StreamHandler
|
class MonologExtendHandler extends StreamHandler
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user