(你的提交说明: 添加商品来源查询门店列表功能)
This commit is contained in:
parent
cfeb53e4f0
commit
fc9eff478e
@ -5,6 +5,7 @@ namespace app\admin\controller\system_store;
|
||||
|
||||
use app\admin\controller\BaseAdminController;
|
||||
use app\admin\lists\system_store\SystemStoreLists;
|
||||
use app\admin\lists\system_store\SystemStoreSourceLists;
|
||||
use app\admin\logic\system_store\SystemStoreLogic;
|
||||
use app\admin\validate\system_store\SystemStoreValidate;
|
||||
|
||||
@ -28,6 +29,16 @@ class SystemStoreController extends BaseAdminController
|
||||
{
|
||||
return $this->dataLists(new SystemStoreLists());
|
||||
}
|
||||
/**
|
||||
* @notes 根据商品源获取门店列表
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2024/05/31 17:45
|
||||
*/
|
||||
public function source_product_store_lists()
|
||||
{
|
||||
return $this->dataLists(new SystemStoreSourceLists());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
@ -8,6 +8,7 @@ use app\common\model\store_product\StoreProduct;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\store_category\StoreCategory;
|
||||
use app\common\model\store_product_unit\StoreProductUnit;
|
||||
use app\common\model\system_store\SystemStore;
|
||||
|
||||
/**
|
||||
* 商品列表列表
|
||||
@ -44,12 +45,17 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa
|
||||
public function lists(): array
|
||||
{
|
||||
return StoreProduct::where($this->searchWhere)
|
||||
->field(['id', 'image', 'store_name', 'cate_id', 'price', 'sales', 'stock', 'is_show', 'unit', 'cost','rose','purchase'])
|
||||
->field(['id', 'image', 'store_name', 'cate_id', 'price', 'sales', 'stock', 'is_show', 'unit', 'cost','rose','purchase','store_id','bar_code'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()->each(function ($item) {
|
||||
$item['unit_name'] = StoreProductUnit::where('id', $item['unit'])->value('name');
|
||||
$item['cate_name'] = StoreCategory::where('id', $item['cate_id'])->value('name');
|
||||
if($item['store_id'] == 0){
|
||||
$item['system_store_name'] = '平台';
|
||||
}else{
|
||||
$item['system_store_name'] = '门店:'.SystemStore::where('id', $item['store_id'])->value('name');
|
||||
}
|
||||
return $item;
|
||||
})
|
||||
->toArray();
|
||||
|
76
app/admin/lists/system_store/SystemStoreSourceLists.php
Normal file
76
app/admin/lists/system_store/SystemStoreSourceLists.php
Normal file
@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\lists\system_store;
|
||||
|
||||
|
||||
use app\admin\lists\BaseAdminDataLists;
|
||||
use app\common\model\system_store\SystemStore;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\store_product\StoreProduct;
|
||||
use PDO;
|
||||
|
||||
/**
|
||||
* 根据商品来源查询门店列表
|
||||
* Class SystemStoreSourceLists
|
||||
* @package app\admin\listssystem_store
|
||||
*/
|
||||
class SystemStoreSourceLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置搜索条件
|
||||
* @return \string[][]
|
||||
* @author admin
|
||||
* @date 2024/05/31 17:45
|
||||
*/
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['name', 'phone'],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取门店列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author admin
|
||||
* @date 2024/05/31 17:45
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
$store_arr=StoreProduct::where('source_id',$this->request->get('product_id'))->column('store_id');
|
||||
if($store_arr){
|
||||
$this->searchWhere[]=['id', 'in', $store_arr];
|
||||
}else{
|
||||
return [];
|
||||
}
|
||||
return SystemStore::where($this->searchWhere)
|
||||
->field(['id', 'name', 'phone', 'detailed_address', 'image'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取门店数量
|
||||
* @return int
|
||||
* @author admin
|
||||
* @date 2024/05/31 17:45
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
if($this->searchWhere){
|
||||
return SystemStore::where($this->searchWhere)->count();
|
||||
}else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -9,8 +9,9 @@ use app\common\model\store_branch_product\StoreBranchProduct;
|
||||
use app\common\model\store_branch_product_attr_value\StoreBranchProductAttrValue;
|
||||
use app\common\model\store_category\StoreCategory;
|
||||
use app\common\model\store_product_attr_value\StoreProductAttrValue;
|
||||
use app\common\model\system_store\SystemStore;
|
||||
use think\facade\Db;
|
||||
|
||||
use Webman\RedisQueue\Redis;
|
||||
|
||||
/**
|
||||
* 商品列表逻辑
|
||||
@ -61,6 +62,17 @@ class StoreProductLogic extends BaseLogic
|
||||
StoreCategory::where('id', $params['cate_id'])->inc('three')->update();
|
||||
|
||||
Db::commit();
|
||||
|
||||
if ($params['is_store_all'] == 1) {
|
||||
$store_arr = SystemStore::where('is_show', 1)->column('id');
|
||||
Redis::send('copy-product', ['product_id' => $res['id'], 'store_arr' => $store_arr]);
|
||||
} else {
|
||||
if (is_array($params['store_arr']) && count($params['store_arr']) > 0) {
|
||||
Redis::send('copy-product', ['product_id' => $res['id'], 'store_arr' => $params['store_arr']]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
@ -159,36 +171,49 @@ class StoreProductLogic extends BaseLogic
|
||||
/**
|
||||
* 复制商品到门店
|
||||
*/
|
||||
public static function copy($id,$store_id){
|
||||
$find= StoreProduct::where('id',$id)->findOrEmpty();
|
||||
$store_find= StoreProduct::where(['source_id',$id,'store_id'=>$store_id])->findOrEmpty();
|
||||
if($find && !$store_find){
|
||||
$attr_value=StoreProductAttrValue::where('product_id',$id)->findOrEmpty();
|
||||
$res=StoreProduct::create($find);
|
||||
$product=[
|
||||
'product_id'=>$res['id'],
|
||||
'image'=>$res['image'],
|
||||
'store_name'=>$res['store_name'],
|
||||
'store_info'=>$res['store_info'],
|
||||
'keyword'=>$res['keyword'],
|
||||
'bar_code'=>$res['bar_code'],
|
||||
'cate_id'=>$res['cate_id'],
|
||||
'store_id'=>$store_id,
|
||||
'sales'=>$res['sales'],
|
||||
'stock'=>$res['stock'],
|
||||
];
|
||||
StoreBranchProduct::create($product);
|
||||
$arr=[
|
||||
'product_id'=>$id,
|
||||
'store_id'=>$store_id,
|
||||
'unique'=>$attr_value['unique'],
|
||||
'sales'=>0,
|
||||
'stock'=>0,
|
||||
'type'=>0,
|
||||
'bar_code'=>$attr_value['bar_code']
|
||||
];
|
||||
StoreBranchProductAttrValue::create($arr);
|
||||
public static function copy($id, $store_id)
|
||||
{
|
||||
$find = StoreProduct::where('id', $id)->findOrEmpty()->toArray();
|
||||
$store_find = StoreProduct::where(['source_id' => $id, 'store_id' => $store_id])->findOrEmpty()->toArray();
|
||||
if ($find && !$store_find) {
|
||||
$attr_value = StoreProductAttrValue::where('product_id', $id)->findOrEmpty();
|
||||
Db::startTrans();
|
||||
try {
|
||||
unset($find['create_time'], $find['update_time'], $find['id'],$find['stock']);
|
||||
$find['store_id'] = $store_id;
|
||||
$find['source_id'] = $id;
|
||||
$res = StoreProduct::create($find);
|
||||
$product = [
|
||||
'product_id' => $res['id'],
|
||||
'image' => $res['image'],
|
||||
'store_name' => $res['store_name'],
|
||||
'store_info' => $res['store_info'],
|
||||
'keyword' => $res['keyword'],
|
||||
'bar_code' => $res['bar_code'],
|
||||
'cate_id' => $res['cate_id'],
|
||||
'store_id' => $store_id,
|
||||
'sales' => 0,
|
||||
'stock' =>0,
|
||||
];
|
||||
StoreBranchProduct::create($product);
|
||||
$arr = [
|
||||
'product_id' => $id,
|
||||
'store_id' => $store_id,
|
||||
'unique' => setUnique($res['id'], '', 0),
|
||||
'sales' => 0,
|
||||
'stock' => 0,
|
||||
'type' => 0,
|
||||
'bar_code' => $attr_value['bar_code']
|
||||
];
|
||||
StoreBranchProductAttrValue::create($arr);
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
d($e);
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
22
app/common/model/system_store_storage/SystemStoreStorage.php
Normal file
22
app/common/model/system_store_storage/SystemStoreStorage.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model\system_store_storage;
|
||||
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
use think\model\concern\SoftDelete;
|
||||
|
||||
|
||||
/**
|
||||
* 门店入库模型
|
||||
* Class SystemStoreStorage
|
||||
* @package app\common\model\system_store_storage
|
||||
*/
|
||||
class SystemStoreStorage extends BaseModel
|
||||
{
|
||||
use SoftDelete;
|
||||
protected $name = 'system_store_storage';
|
||||
protected $deleteTime = 'delete_time';
|
||||
|
||||
|
||||
}
|
34
app/queue/redis/CopyProductSend.php
Normal file
34
app/queue/redis/CopyProductSend.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace app\queue\redis;
|
||||
|
||||
use app\admin\logic\store_product\StoreProductLogic;
|
||||
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'];
|
||||
foreach ($store_arr as $key => $id) {
|
||||
StoreProductLogic::copy($data['product_id'],$id);
|
||||
}
|
||||
}
|
||||
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