feat: 增加商品兑换功能

This commit is contained in:
mkm 2024-06-17 13:47:45 +08:00
parent ed5d63035b
commit b0bda50449
3 changed files with 132 additions and 2 deletions
app
admin
controller/store_branch_product
lists/store_branch_product exchange
api/controller/store

@ -5,6 +5,7 @@ namespace app\admin\controller\store_branch_product;
use app\admin\controller\BaseAdminController;
use app\admin\lists\store_branch_product\StoreBranchProductLists;
use app\admin\lists\store_branch_product_exchange\StoreBranchProductExchangeLists;
use app\admin\logic\store_branch_product\StoreBranchProductLogic;
use app\admin\logic\store_product\StoreProductLogic;
use app\admin\validate\store_product\StoreProductValidate;
@ -27,7 +28,11 @@ class StoreBranchProductController extends BaseAdminController
*/
public function lists()
{
return $this->dataLists(new StoreBranchProductLists());
if($this->request->get('exchange',0)==1){
return $this->dataLists(new StoreBranchProductExchangeLists());
}else{
return $this->dataLists(new StoreBranchProductLists());
}
}

@ -0,0 +1,125 @@
<?php
namespace app\admin\lists\store_branch_product_exchange;
use app\admin\lists\BaseAdminDataLists;
use app\common\model\cate\Cate;
use app\common\model\store_category\StoreCategory;
use app\common\model\store_product_unit\StoreProductUnit;
use app\common\model\system_store\SystemStore;
use app\common\lists\ListsSearchInterface;
use app\common\model\store_branch_product_exchange\StoreBranchProductExchange;
/**
* 门店商品辅助表
* Class StoreBranchProductLists
* @package app\admin\listssystem_store
*/
class StoreBranchProductExchangeLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author admin
* @date 2024/05/31 17:45
*/
public function setSearch(): array
{
return [
'=' => ['product_id', 'cate_id','store_id','status'],
'%pipe_like%' => ['store_name_code'=>'store_name|bar_code'],
'%like%' => ['store_name'],
];
}
/**
* @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
{
$status = $this->params['status'] ?? '';
$class_all=$this->request->get('class_all');
$where=[];
if($class_all){
$arr=Cate::where('pid',$class_all)->column('id');
if($arr){
$arr2=Cate::where('pid','in',$arr)->column('id');
$where[]=['cate_id','in',array_merge($arr,$arr2)];
}
}
return StoreBranchProductExchange::where($this->searchWhere)->where($where)
->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) {
$query->where('store_id', $this->adminInfo['store_id']);
})
->when(!empty($status), function ($query) use ($status) {
if ($status == 1) {
$query->where('status', $status);
} elseif ($status == 2) {
$query->where('status', 0);
} elseif ($status == 3) {
$query->where('stock', '<=', 0);
} elseif ($status == 4) {
$query->where('stock', '<', 10)->where('stock', '>', 0);
}
})
->limit($this->limitOffset, $this->limitLength)
->order(['sort' => 'desc','stock'=>'desc','id' => 'desc'])
->select()
->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['cate_name'] = StoreCategory::where('id', $item['cate_id'])->value('name');
return $item;
})
->toArray();
}
/**
* @notes 获取门店列表数量
* @return int
* @author admin
* @date 2024/05/31 17:45
*/
public function count(): int
{
$status = $this->params['status'] ?? '';
$class_all=$this->request->get('class_all');
$where=[];
if($class_all){
$arr=Cate::where('pid',$class_all)->column('id');
if($arr){
$arr2=Cate::where('pid','in',$arr)->column('id');
$where[]=['cate_id','in',array_merge($arr,$arr2)];
}
}
return StoreBranchProductExchange::where($this->searchWhere)->where($where)
->when(!empty($this->adminInfo['store_id']), function ($query) {
$query->where('store_id', $this->adminInfo['store_id']);
})
->when(!empty($status), function ($query) use ($status) {
if ($status == 1) {
$query->where('status', $status);
} elseif ($status == 2) {
$query->where('status', 0);
} elseif ($status == 3) {
$query->where('stock', '<=', 0);
} elseif ($status == 4) {
$query->where('stock', '<', 10)->where('stock', '>', 0);
}
})
->count();
}
}

@ -54,7 +54,7 @@ class StoreController extends BaseApiController
'uid'=>$find['id'],
'staff_id'=>0,
'order_id'=>getNewOrderId('CZ'),
'price'=>1000,
'price'=>0.01,
];
$order = UserRecharge::create($data);