Merge branch 'main' of https://gitea.lihaink.cn/mkm/multi-store
This commit is contained in:
commit
a0918ed516
app
ExceptionHandler.phpfunctions.php
admin
controller/store_order_cart_info
lists
logic/store_order
api/controller
common
controller
enum
model
service/wechat
store
controller
lists/store_product_attr_value
logic/store_branch_product
validate/store_product
@ -37,6 +37,6 @@ class ExceptionHandler extends Handler
|
||||
return response(json_encode($error, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
// 非json请求则返回一个页面
|
||||
return new Response(200, [], $exception->getMessage());
|
||||
return new Response(200, [], 'msg:'.$exception->getMessage().'。line:'.$exception->getLine().'。file:'.$exception->getFile());
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\store_order_cart_info;
|
||||
|
||||
|
||||
use app\admin\controller\BaseAdminController;
|
||||
use app\admin\lists\store_order_cart_info\StoreOrderCartInfoLists;
|
||||
|
||||
/**
|
||||
* 订单购物详情控制器
|
||||
* Class StoreOrderCartInfoController
|
||||
* @package app\admin\controller\store_order_cart_info
|
||||
*/
|
||||
class StoreOrderCartInfoController extends BaseAdminController
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取订单购物详情列表
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2024/05/31 16:02
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
return $this->dataLists(new StoreOrderCartInfoLists());
|
||||
}
|
||||
|
||||
}
|
@ -4,6 +4,7 @@ namespace app\admin\lists\store_order;
|
||||
|
||||
|
||||
use app\admin\lists\BaseAdminDataLists;
|
||||
use app\common\enum\OrderEnum;
|
||||
use app\common\enum\PayEnum;
|
||||
use app\common\model\store_order\StoreOrder;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
@ -44,11 +45,17 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
public function lists(): array
|
||||
{
|
||||
return StoreOrder::where($this->searchWhere)
|
||||
->when(!empty($this->request->adminInfo['store_id']), function ($query) {
|
||||
$query->where('store_id', '=', $this->request->adminInfo['store_id']);
|
||||
})
|
||||
->field(['id', 'order_id', 'pay_price', 'pay_time', 'pay_type', 'status'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()->each(function($item){
|
||||
$item['pay_type_name']=PayEnum::getPaySceneDesc($item['pay_type']);
|
||||
$item['pay_time']=$item['pay_time']>0?date('Y-m-d H:i:s',$item['pay_time']):'';
|
||||
$item['status_name']= OrderEnum::getOrderType($item['status'])??'';
|
||||
|
||||
return $item;
|
||||
})
|
||||
->toArray();
|
||||
@ -63,7 +70,11 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return StoreOrder::where($this->searchWhere)->count();
|
||||
return StoreOrder::where($this->searchWhere)
|
||||
->when(!empty($this->request->adminInfo['store_id']), function ($query) {
|
||||
$query->where('store_id', '=', $this->request->adminInfo['store_id']);
|
||||
})
|
||||
->count();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\lists\store_order_cart_info;
|
||||
|
||||
|
||||
use app\admin\lists\BaseAdminDataLists;
|
||||
use app\common\enum\PayEnum;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||
use app\common\model\store_order_cart_info\StoreOrderCartInfo;
|
||||
use app\common\model\store_product\StoreProduct;
|
||||
|
||||
/**
|
||||
* 订单购物详情列表
|
||||
* Class StoreOrderCartInfoLists
|
||||
* @package app\admin\store_order_cart_info
|
||||
*/
|
||||
class StoreOrderCartInfoLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置搜索条件
|
||||
* @return \string[][]
|
||||
* @author admin
|
||||
* @date 2024/05/31 16:02
|
||||
*/
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['oid'],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取订单购物详情列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author admin
|
||||
* @date 2024/05/31 16:02
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
return StoreOrderCartInfo::where($this->searchWhere)
|
||||
->field('cart_info,product_id')->limit($this->limitOffset, $this->limitLength)
|
||||
->select()->each(function ($item) {
|
||||
$item['cart_info'] = json_decode($item['cart_info'], true); //将json字符串转换为数组,方便使用其中的数据。
|
||||
$find=StoreBranchProduct::where('id',$item['product_id'])->field('image,store_name')->find();
|
||||
if($find){
|
||||
$item['image']=$find['image'];//商品图片
|
||||
$item['store_name']=$find['store_name'];//商品名称
|
||||
}else{
|
||||
$item['image']='';//商品图片
|
||||
$item['store_name']='';//商品名称
|
||||
}
|
||||
return $item; //返回处理后的数据。
|
||||
})
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取订单购物详情数量
|
||||
* @return int
|
||||
* @author admin
|
||||
* @date 2024/05/31 16:02
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return StoreOrderCartInfo::where($this->searchWhere)->count();
|
||||
}
|
||||
}
|
@ -90,14 +90,11 @@ class StoreOrderLogic extends BaseLogic
|
||||
*/
|
||||
public static function detail($params): array
|
||||
{
|
||||
$data= StoreOrder::findOrEmpty($params['id'])->toArray();
|
||||
$data= StoreOrder::findOrEmpty($params['id']);
|
||||
if($data){
|
||||
$data['_info']=StoreOrderCartInfo::where('oid',$data['id'])->field('cart_info')
|
||||
->select()->each(function ($item){
|
||||
$item['cart_info']=json_decode($item['cart_info'],true);//将json字符串转换为数组,方便使用其中的数据。
|
||||
return $item;//返回处理后的数据。
|
||||
});
|
||||
$data['status_name']=$data->status_name_text;
|
||||
$data['pay_time']=date('Y-m-d H:i:s',$data['pay_time']);
|
||||
}
|
||||
return $data;
|
||||
return $data?->toArray();
|
||||
}
|
||||
}
|
@ -5,24 +5,60 @@ namespace app\api\controller;
|
||||
use app\admin\validate\tools\GenerateTableValidate;
|
||||
use app\admin\logic\tools\GeneratorLogic;
|
||||
use app\common\logic\store_order\StoreOrderLogic;
|
||||
use app\common\service\pay\PayService;
|
||||
use app\common\service\wechat\WechatTemplate;
|
||||
use Exception;
|
||||
use think\facade\Db;
|
||||
use Webman\Config;
|
||||
use hg\apidoc\annotation as ApiDoc;
|
||||
use Yansongda\Pay\Exception\InvalidSignException;
|
||||
|
||||
#[ApiDoc\NotParse()]
|
||||
|
||||
class IndexController extends BaseApiController
|
||||
{
|
||||
public $notNeedLogin = ['index','app_update','express_list','province','city','area','street'];
|
||||
public $notNeedLogin = ['index', 'app_update', 'express_list', 'province', 'city', 'area', 'street'];
|
||||
|
||||
public function index()
|
||||
{
|
||||
try{
|
||||
$a=new WechatTemplate();
|
||||
$a->NewQuotationNotification(['openid'=>'ocqhF6UfFQXE-SbzbP5YVQJlQAh0','data1'=>'阿萨','data2'=>date('Y-m-d H:i:s'),'data3'=>'占山','data3'=>18982406440]);
|
||||
}catch (Exception $e){
|
||||
d($e);
|
||||
}
|
||||
|
||||
d(2);
|
||||
|
||||
$params=['store_id'=>2,'pay_type'=>17];
|
||||
$a=StoreOrderLogic::createOrder([1],0,null,$params);
|
||||
d(22);
|
||||
$auth_code = $this->request->get('code');
|
||||
$pay = (new PayService());
|
||||
$order = [
|
||||
'description' => '条码商品',
|
||||
'out_trade_no' => (string)time(),
|
||||
'payer' => [
|
||||
'auth_code' => (string)$auth_code
|
||||
],
|
||||
'amount' => [
|
||||
'total' =>1,
|
||||
],
|
||||
'scene_info' => [
|
||||
"store_info" => [
|
||||
'id' => '1'
|
||||
]
|
||||
],
|
||||
];
|
||||
|
||||
try{
|
||||
$a= $pay->wechat->pos($order);
|
||||
|
||||
}catch (\Exception $th) {
|
||||
d($th);
|
||||
}
|
||||
d($a);
|
||||
$params = ['store_id' => 2, 'pay_type' => 17];
|
||||
$a = StoreOrderLogic::createOrder([1], 0, null, $params);
|
||||
d($a);
|
||||
return json(['msg' =>create_password(123456, '11d3')]);
|
||||
return json(['msg' => create_password(123456, '11d3')]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -41,42 +77,46 @@ class IndexController extends BaseApiController
|
||||
/**
|
||||
* @notes 获取app更新信息
|
||||
*/
|
||||
public function app_update(){
|
||||
$find= Db::name('app_update')->where('type',2)->order('id','desc')->findOrEmpty();
|
||||
return $this->success('ok',$find);
|
||||
public function app_update()
|
||||
{
|
||||
$find = Db::name('app_update')->where('type', 2)->order('id', 'desc')->findOrEmpty();
|
||||
return $this->success('ok', $find);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取省列表
|
||||
*/
|
||||
public function province(){
|
||||
$list= Db::name('geo_province')->select()->toArray();
|
||||
return $this->success('ok',$list);
|
||||
public function province()
|
||||
{
|
||||
$list = Db::name('geo_province')->select()->toArray();
|
||||
return $this->success('ok', $list);
|
||||
}
|
||||
/**
|
||||
* @notes 获取市列表
|
||||
*/
|
||||
public function city(){
|
||||
$province_code=$this->request->get('code');
|
||||
$list= Db::name('geo_city')->where('province_code',$province_code)->select()?->toArray();
|
||||
return $this->success('ok',$list);
|
||||
public function city()
|
||||
{
|
||||
$province_code = $this->request->get('code');
|
||||
$list = Db::name('geo_city')->where('province_code', $province_code)->select()?->toArray();
|
||||
return $this->success('ok', $list);
|
||||
}
|
||||
/**
|
||||
* @notes 获取区列表
|
||||
*/
|
||||
public function area(){
|
||||
$city_code=$this->request->get('code');
|
||||
$list= Db::name('geo_area')->where('city_code',$city_code)->select()?->toArray();
|
||||
return $this->success('ok',$list);
|
||||
public function area()
|
||||
{
|
||||
$city_code = $this->request->get('code');
|
||||
$list = Db::name('geo_area')->where('city_code', $city_code)->select()?->toArray();
|
||||
return $this->success('ok', $list);
|
||||
}
|
||||
/**
|
||||
* @notes 获取街道列表
|
||||
*/
|
||||
public function street(){
|
||||
$area_code=$this->request->get('area_code');
|
||||
$list= Db::name('geo_street')->where('area_code',$area_code)->select()?->toArray();
|
||||
return $this->success('ok',$list);
|
||||
public function street()
|
||||
{
|
||||
$area_code = $this->request->get('area_code');
|
||||
$list = Db::name('geo_street')->where('area_code', $area_code)->select()?->toArray();
|
||||
return $this->success('ok', $list);
|
||||
}
|
||||
|
||||
}
|
||||
|
26
app/common/controller/Definitions.php
Normal file
26
app/common/controller/Definitions.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\controller;
|
||||
|
||||
use hg\apidoc\annotation as ApiDoc;
|
||||
|
||||
class Definitions
|
||||
{
|
||||
|
||||
#[
|
||||
ApiDoc\Header(name: "token", type: "string", require: true, desc: "token"),
|
||||
]
|
||||
public function token()
|
||||
{
|
||||
}
|
||||
|
||||
#[
|
||||
ApiDoc\Query("page_no", type: "int", require: false, default: 1, desc: "页码"),
|
||||
ApiDoc\Query("page_size", type: "int", require: false, default: 25, desc: "每页条数"),
|
||||
]
|
||||
public function page()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -36,16 +36,36 @@ class OrderEnum
|
||||
* @EXPENDITURE 支出
|
||||
* @INCOME 收入
|
||||
*/
|
||||
const EXPENDITURE =0;
|
||||
const INCOME =1;
|
||||
|
||||
const EXPENDITURE = 0;
|
||||
const INCOME = 1;
|
||||
|
||||
//-----------------------物流状态-----------------------//
|
||||
/**
|
||||
* 状态
|
||||
* @RECEIVED_GOODS 已收货
|
||||
*/
|
||||
const RECEIVED_GOODS = 2;
|
||||
|
||||
/**
|
||||
* @WAIT_EVALUATION 待评价
|
||||
*/
|
||||
const WAIT_EVALUATION = 3;
|
||||
/**
|
||||
* @WAIT_DELIVERY 待发货
|
||||
*/
|
||||
const WAIT_DELIVERY = 0;
|
||||
/**
|
||||
* @WAIT_RECEIVING 待收货
|
||||
*/
|
||||
const WAIT_RECEIVING = 1;
|
||||
/**
|
||||
* @ALREADY_REFUND 申请退款
|
||||
*/
|
||||
const ALREADY_REFUND = -1;
|
||||
|
||||
/**
|
||||
* @RETURN_SUCCESS 退款成功
|
||||
*/
|
||||
const RETURN_SUCCESS = -2;
|
||||
|
||||
/**
|
||||
* 核销
|
||||
@ -69,11 +89,11 @@ class OrderEnum
|
||||
* @SUPPLIER 供应链
|
||||
* @SYSTEM 系统
|
||||
*/
|
||||
const USER =0;
|
||||
const MERCHANT =1;
|
||||
const PLATFORM =2;
|
||||
const SUPPLIER =3;
|
||||
const SYSTEM=4;
|
||||
const USER = 0;
|
||||
const MERCHANT = 1;
|
||||
const PLATFORM = 2;
|
||||
const SUPPLIER = 3;
|
||||
const SYSTEM = 4;
|
||||
|
||||
/**
|
||||
* @notes 获取支付类型
|
||||
@ -85,14 +105,14 @@ class OrderEnum
|
||||
public static function getFinancialType($value = true)
|
||||
{
|
||||
$data = [
|
||||
self::USER_ORDER_PAY=>'用户订单支付',
|
||||
self::MERCHANT_ORDER_PAY=>'商户订单支付',
|
||||
self::PLATFORM_ORDER_PAY=>'平台订单支付',
|
||||
self::MERCHANT_ORDER_OBTAINS=>'商户订单获得',
|
||||
self::ORDER_HANDLING_FEES=>'订单手续费',
|
||||
self::PLATFORM_ORDER_OBTAINS=>'平台订单获得',
|
||||
self::SUPPLIER_ORDER_OBTAINS=>'供应商订单获得',
|
||||
self::SYSTEM_SET=>'平台设置',
|
||||
self::USER_ORDER_PAY => '用户订单支付',
|
||||
self::MERCHANT_ORDER_PAY => '商户订单支付',
|
||||
self::PLATFORM_ORDER_PAY => '平台订单支付',
|
||||
self::MERCHANT_ORDER_OBTAINS => '商户订单获得',
|
||||
self::ORDER_HANDLING_FEES => '订单手续费',
|
||||
self::PLATFORM_ORDER_OBTAINS => '平台订单获得',
|
||||
self::SUPPLIER_ORDER_OBTAINS => '供应商订单获得',
|
||||
self::SYSTEM_SET => '平台设置',
|
||||
|
||||
|
||||
];
|
||||
@ -102,5 +122,22 @@ class OrderEnum
|
||||
return $data[$value] ?? '';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
/**
|
||||
* @notes 获取订单状态类型
|
||||
*/
|
||||
public static function getOrderType($value = true)
|
||||
{
|
||||
$data = [
|
||||
self::RECEIVED_GOODS => '已收货',
|
||||
self::WAIT_EVALUATION => '待评价',
|
||||
self::WAIT_DELIVERY => '待发货',
|
||||
self::WAIT_RECEIVING => '待收货',
|
||||
self::RETURN_SUCCESS => '退货成功',
|
||||
self::ALREADY_REFUND => '已退款',
|
||||
];
|
||||
if ($value === true) {
|
||||
return $data;
|
||||
}
|
||||
return $data[$value] ?? '';
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ namespace app\common\model\store_branch_product_attr_value;
|
||||
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\store_product_attr_value\StoreProductAttrValue;
|
||||
use think\model\concern\SoftDelete;
|
||||
|
||||
|
||||
@ -18,5 +19,9 @@ class StoreBranchProductAttrValue extends BaseModel
|
||||
protected $name = 'store_branch_product_attr_value';
|
||||
protected $deleteTime = 'delete_time';
|
||||
|
||||
|
||||
}
|
||||
public function attr()
|
||||
{
|
||||
return $this->hasOne(StoreProductAttrValue::class, 'unique', 'unique')->bind(['image']);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,8 @@
|
||||
|
||||
namespace app\common\model\store_order;
|
||||
|
||||
|
||||
use app\common\enum\OrderEnum;
|
||||
use app\common\enum\PayEnum;
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\system_store\SystemStore;
|
||||
use think\model\concern\SoftDelete;
|
||||
@ -24,4 +25,15 @@ class StoreOrder extends BaseModel
|
||||
return $this->hasOne(SystemStore::class, 'id','store_id');
|
||||
}
|
||||
|
||||
public function getPayTypeAttr($value, $data)
|
||||
{
|
||||
$status = PayEnum::getPaySceneDesc($value)??'';
|
||||
return $status;
|
||||
}
|
||||
|
||||
public function getStatusNameTextAttr($value, $data)
|
||||
{
|
||||
$status = OrderEnum::getOrderType($data['status'])??'';
|
||||
return $status;
|
||||
}
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ class WechatTemplate
|
||||
'data' => [
|
||||
'thing2' => ['value' => $data['data1']],
|
||||
'thing3' => ['value' => $data['data2']],
|
||||
'const4' => ['value' => $data['data3']??08302669767],
|
||||
'const4' => ['value' => $data['data3']??'08302669767'],
|
||||
]
|
||||
];
|
||||
return $this->post($template);
|
||||
|
@ -340,7 +340,7 @@ if (!function_exists('setUnique')) {
|
||||
{
|
||||
return substr(md5($sku . $id), 12, 11) . $type;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -379,5 +379,42 @@ if (!function_exists('haversineDistance')) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('reset_index')) {
|
||||
/**
|
||||
* 重置数组索引
|
||||
* @param array $data
|
||||
* @param string $index
|
||||
* @return array
|
||||
*/
|
||||
function reset_index(array $data, string $index)
|
||||
{
|
||||
$return = [];
|
||||
foreach ($data as $item) {
|
||||
$return[$item[$index]] = $item;
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('append_to_array')) {
|
||||
/**
|
||||
* 追加元素到数组
|
||||
* @param array $data
|
||||
* @param array $append
|
||||
* @return array
|
||||
*/
|
||||
function append_to_array(array $data, array $append)
|
||||
{
|
||||
$return = [];
|
||||
foreach ($data as $item) {
|
||||
if (isset($append['relation'])) {
|
||||
$item[$append['value']] = $append['relation'][$item[$append['field']]];
|
||||
} else {
|
||||
$item[$append['value']] = $item[$append['field']];
|
||||
}
|
||||
$return[] = $item;
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ namespace app\store\controller\store_product;
|
||||
|
||||
|
||||
use app\admin\lists\store_branch_product\StoreBranchProductLists;
|
||||
use app\common\controller\Definitions;
|
||||
use app\store\controller\BaseAdminController;
|
||||
use app\store\logic\store_branch_product\StoreBranchProductLogic;
|
||||
use app\store\logic\store_product\StoreProductLogic;
|
||||
@ -28,7 +29,8 @@ class StoreProductController extends BaseAdminController
|
||||
ApiDoc\Query(name: 'cate_id', type: 'int', require: false, desc: '分类id'),
|
||||
ApiDoc\Query(name: 'store_name', type: 'string', require: false, desc: '商品名称'),
|
||||
ApiDoc\Query(name: 'status', type: 'int', require: false, desc: '状态:1上架,2下架,3售罄,4库存告警'),
|
||||
ApiDoc\Header(name: "token", type: "string", require: true, desc: "token"),
|
||||
ApiDoc\Header(ref: [Definitions::class, "token"]),
|
||||
ApiDoc\Query(ref: [Definitions::class, "page"]),
|
||||
ApiDoc\ResponseSuccess("data", type: "array", children: [
|
||||
['name' => 'id', 'desc' => 'ID', 'type' => 'int'],
|
||||
['name' => 'image', 'desc' => '图片', 'type' => 'string'],
|
||||
@ -52,7 +54,7 @@ class StoreProductController extends BaseAdminController
|
||||
ApiDoc\url('/store/store_product/storeProduct/add'),
|
||||
ApiDoc\Method('POST'),
|
||||
ApiDoc\NotHeaders(),
|
||||
ApiDoc\Header(name: "token", type: "string", require: true, desc: "token"),
|
||||
ApiDoc\Header(ref: [Definitions::class, "token"]),
|
||||
ApiDoc\ResponseSuccess("data", type: "array", children: [
|
||||
['name' => 'id', 'desc' => 'ID', 'type' => 'int'],
|
||||
['name' => 'image', 'desc' => '图片', 'type' => 'string'],
|
||||
@ -81,7 +83,7 @@ class StoreProductController extends BaseAdminController
|
||||
ApiDoc\Method('POST'),
|
||||
ApiDoc\NotHeaders(),
|
||||
ApiDoc\Query(name: "id", type: "int", require: true, desc: "id"),
|
||||
ApiDoc\Header(name: "token", type: "string", require: true, desc: "token"),
|
||||
ApiDoc\Header(ref: [Definitions::class, "token"]),
|
||||
ApiDoc\ResponseSuccess("data", type: "array", children: [
|
||||
['name' => 'id', 'desc' => 'ID', 'type' => 'int'],
|
||||
['name' => 'image', 'desc' => '图片', 'type' => 'string'],
|
||||
@ -110,7 +112,7 @@ class StoreProductController extends BaseAdminController
|
||||
ApiDoc\Method('POST'),
|
||||
ApiDoc\NotHeaders(),
|
||||
ApiDoc\Param(name: "id", type: "int", require: true, desc: "id"),
|
||||
ApiDoc\Header(name: "token", type: "string", require: true, desc: "token"),
|
||||
ApiDoc\Header(ref: [Definitions::class, "token"]),
|
||||
ApiDoc\ResponseSuccess("data", type: "array", children: [
|
||||
['name' => 'id', 'desc' => 'ID', 'type' => 'int'],
|
||||
['name' => 'image', 'desc' => '图片', 'type' => 'string'],
|
||||
@ -136,7 +138,7 @@ class StoreProductController extends BaseAdminController
|
||||
ApiDoc\Method('GET'),
|
||||
ApiDoc\NotHeaders(),
|
||||
ApiDoc\Query(name: "id", type: "int", require: true, desc: "id"),
|
||||
ApiDoc\Header(name: "token", type: "string", require: true, desc: "token"),
|
||||
ApiDoc\Header(ref: [Definitions::class, "token"]),
|
||||
ApiDoc\ResponseSuccess("data", type: "array", children: [
|
||||
['name' => 'id', 'desc' => 'ID', 'type' => 'int'],
|
||||
['name' => 'image', 'desc' => '图片', 'type' => 'string'],
|
||||
@ -162,7 +164,7 @@ class StoreProductController extends BaseAdminController
|
||||
ApiDoc\Method('POST'),
|
||||
ApiDoc\NotHeaders(),
|
||||
ApiDoc\Param(name: "id", type: "int", require: true, desc: "id"),
|
||||
ApiDoc\Header(name: "token", type: "string", require: true, desc: "token"),
|
||||
ApiDoc\Header(ref: [Definitions::class, "token"]),
|
||||
ApiDoc\ResponseSuccess("data", type: "array"),
|
||||
]
|
||||
public function status()
|
||||
@ -176,16 +178,19 @@ class StoreProductController extends BaseAdminController
|
||||
ApiDoc\Title('商品库存增减'),
|
||||
ApiDoc\url('/store/store_product/storeProduct/stock'),
|
||||
ApiDoc\Method('POST'),
|
||||
ApiDoc\Param(name: "id", type: "int", require: true, desc: "id"),
|
||||
ApiDoc\Param(name: "type", type: "int", require: true, desc: "类型:1增加,2减少"),
|
||||
ApiDoc\Param(name: "number", type: "int", require: true, desc: "数量"),
|
||||
ApiDoc\Param(name: "attrs", type: "array", require: true, desc: "id", children: [
|
||||
['name' => 'unique', 'desc' => '唯一值', 'type' => 'string'],
|
||||
['name' => 'type', 'desc' => '类型:1增加,2减少', 'type' => 'int'],
|
||||
['name' => 'number', 'desc' => '数量', 'type' => 'int'],
|
||||
]),
|
||||
ApiDoc\NotHeaders(),
|
||||
ApiDoc\Header(name: "token", type: "string", require: true, desc: "token"),
|
||||
ApiDoc\Header(ref: [Definitions::class, "token"]),
|
||||
ApiDoc\ResponseSuccess("data", type: "array"),
|
||||
]
|
||||
public function stock()
|
||||
{
|
||||
$params = (new StoreProductValidate())->post()->goCheck('stock');
|
||||
$params['store_id'] = $this->request->adminInfo['store_id'];
|
||||
StoreBranchProductLogic::stock($params);
|
||||
return $this->success('操作成功', [], 1, 1);
|
||||
}
|
||||
|
@ -3,12 +3,12 @@
|
||||
namespace app\store\controller\store_product_attr_value;
|
||||
|
||||
|
||||
use app\common\controller\Definitions;
|
||||
use app\store\controller\BaseAdminController;
|
||||
use app\store\lists\store_product_attr_value\StoreProductAttrValueLists;
|
||||
use app\store\logic\store_product_attr_value\StoreProductAttrValueLogic;
|
||||
use app\store\validate\store_product_attr_value\StoreProductAttrValueValidate;
|
||||
use hg\apidoc\annotation as ApiDoc;
|
||||
#[ApiDoc\NotParse()]
|
||||
|
||||
|
||||
/**
|
||||
@ -16,28 +16,47 @@ use hg\apidoc\annotation as ApiDoc;
|
||||
* Class StoreProductAttrValueController
|
||||
* @package app\store\controller\store_product_attr_value
|
||||
*/
|
||||
#[ApiDoc\title('商品属性值')]
|
||||
class StoreProductAttrValueController extends BaseAdminController
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取商品属性值列表
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2024/05/31 14:10
|
||||
*/
|
||||
#[
|
||||
ApiDoc\Title('商品属性值列表'),
|
||||
ApiDoc\url('/store/store_product_attr_value/storeProductAttrValue/lists'),
|
||||
ApiDoc\Method('GET'),
|
||||
ApiDoc\NotHeaders(),
|
||||
ApiDoc\Header(ref: [Definitions::class, "token"]),
|
||||
ApiDoc\Query(ref: [Definitions::class, "page"]),
|
||||
ApiDoc\Query(name: 'product_id', type: 'int', require: true, desc: '商品ID'),
|
||||
ApiDoc\Query(name: 'store_id', type: 'int', require: true, desc: '门店ID'),
|
||||
ApiDoc\ResponseSuccess("data", type: "array", children: [
|
||||
['name' => 'count', 'desc' => '总数', 'type' => 'int'],
|
||||
['name' => 'page_no', 'desc' => '页码', 'type' => 'int'],
|
||||
['name' => 'page_size', 'desc' => '每页数量', 'type' => 'int'],
|
||||
['name' => 'extend', 'desc' => '扩展数据', 'type' => 'array'],
|
||||
['name' => 'lists', 'desc' => '列表数据', 'type' => 'array', 'children' => [
|
||||
['name' => 'id', 'desc' => 'ID', 'type' => 'int'],
|
||||
['name' => 'product_id', 'desc' => '商品ID', 'type' => 'int'],
|
||||
['name' => 'stock', 'desc' => '库存', 'type' => 'int'],
|
||||
['name' => 'unique', 'desc' => '唯一值', 'type' => 'string'],
|
||||
['name' => 'sales', 'desc' => '销量', 'type' => 'int'],
|
||||
['name' => 'bar_code', 'desc' => '条码', 'type' => 'string'],
|
||||
['name' => 'image', 'desc' => '规格图片', 'type' => 'string'],
|
||||
]],
|
||||
]),
|
||||
]
|
||||
public function lists()
|
||||
{
|
||||
return $this->dataLists(new StoreProductAttrValueLists());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加商品属性值
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2024/05/31 14:10
|
||||
*/
|
||||
#[
|
||||
ApiDoc\Title('添加商品属性值'),
|
||||
ApiDoc\url('/store/store_product_attr_value/storeProductAttrValue/add'),
|
||||
ApiDoc\Method('POST'),
|
||||
ApiDoc\NotHeaders(),
|
||||
ApiDoc\Header(ref: [Definitions::class, "token"]),
|
||||
]
|
||||
public function add()
|
||||
{
|
||||
$params = (new StoreProductAttrValueValidate())->post()->goCheck('add');
|
||||
@ -48,13 +67,13 @@ class StoreProductAttrValueController extends BaseAdminController
|
||||
return $this->fail(StoreProductAttrValueLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑商品属性值
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2024/05/31 14:10
|
||||
*/
|
||||
#[
|
||||
ApiDoc\Title('编辑商品属性值'),
|
||||
ApiDoc\url('/store/store_product_attr_value/storeProductAttrValue/edit'),
|
||||
ApiDoc\Method('POST'),
|
||||
ApiDoc\NotHeaders(),
|
||||
ApiDoc\Header(ref: [Definitions::class, "token"]),
|
||||
]
|
||||
public function edit()
|
||||
{
|
||||
$params = (new StoreProductAttrValueValidate())->post()->goCheck('edit');
|
||||
@ -65,13 +84,13 @@ class StoreProductAttrValueController extends BaseAdminController
|
||||
return $this->fail(StoreProductAttrValueLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除商品属性值
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2024/05/31 14:10
|
||||
*/
|
||||
#[
|
||||
ApiDoc\Title('删除商品属性值'),
|
||||
ApiDoc\url('/store/store_product_attr_value/storeProductAttrValue/delete'),
|
||||
ApiDoc\Method('POST'),
|
||||
ApiDoc\NotHeaders(),
|
||||
ApiDoc\Header(ref: [Definitions::class, "token"]),
|
||||
]
|
||||
public function delete()
|
||||
{
|
||||
$params = (new StoreProductAttrValueValidate())->post()->goCheck('delete');
|
||||
@ -79,13 +98,14 @@ class StoreProductAttrValueController extends BaseAdminController
|
||||
return $this->success('删除成功', [], 1, 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取商品属性值详情
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2024/05/31 14:10
|
||||
*/
|
||||
#[
|
||||
ApiDoc\Title('获取商品属性值详情'),
|
||||
ApiDoc\url('/store/store_product_attr_value/storeProductAttrValue/detail'),
|
||||
ApiDoc\Method('GET'),
|
||||
ApiDoc\Author('中国队长'),
|
||||
ApiDoc\NotHeaders(),
|
||||
ApiDoc\Header(ref: [Definitions::class, "token"]),
|
||||
]
|
||||
public function detail()
|
||||
{
|
||||
$params = (new StoreProductAttrValueValidate())->goCheck('detail');
|
||||
|
@ -3,8 +3,8 @@
|
||||
namespace app\store\lists\store_product_attr_value;
|
||||
|
||||
|
||||
use app\common\model\store_branch_product_attr_value\StoreBranchProductAttrValue;
|
||||
use app\store\lists\BaseAdminDataLists;
|
||||
use app\common\model\store_product_attr_value\StoreProductAttrValue;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
|
||||
|
||||
@ -26,7 +26,7 @@ class StoreProductAttrValueLists extends BaseAdminDataLists implements ListsSear
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['product_id'],
|
||||
'=' => ['product_id', 'store_id'],
|
||||
];
|
||||
}
|
||||
|
||||
@ -42,8 +42,8 @@ class StoreProductAttrValueLists extends BaseAdminDataLists implements ListsSear
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
return StoreProductAttrValue::where($this->searchWhere)
|
||||
->field(['id', 'product_id'])
|
||||
return StoreBranchProductAttrValue::with('attr')->where($this->searchWhere)
|
||||
->field(['id', 'product_id', 'stock', 'unique', 'sales', 'bar_code'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()
|
||||
@ -59,7 +59,7 @@ class StoreProductAttrValueLists extends BaseAdminDataLists implements ListsSear
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return StoreProductAttrValue::where($this->searchWhere)->count();
|
||||
return StoreBranchProductAttrValue::with('attr')->where($this->searchWhere)->count();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ namespace app\store\logic\store_branch_product;
|
||||
|
||||
|
||||
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\logic\BaseLogic;
|
||||
use app\common\model\store_category\StoreCategory;
|
||||
@ -178,25 +179,43 @@ class StoreBranchProductLogic extends BaseLogic
|
||||
*/
|
||||
public static function stock(array $params): bool
|
||||
{
|
||||
$StoreProduct = StoreBranchProduct::where('id', $params['id'])->find();
|
||||
$attrs = reset_index($params['attrs'], 'unique');
|
||||
$attrValue = StoreBranchProductAttrValue::where('store_id', $params['store_id'])->whereIn('unique', array_keys($attrs))->select()->toArray();
|
||||
if (empty($attrValue)) {
|
||||
throw new \Exception('商品属性不存在');
|
||||
}
|
||||
$StoreProduct = StoreBranchProduct::where('store_id', $params['store_id'])->where('product_id', $attrValue[0]['product_id'])->find();
|
||||
if (empty($StoreProduct)) {
|
||||
throw new \Exception('商品不存在');
|
||||
}
|
||||
self::checkAuth($StoreProduct);
|
||||
Db::startTrans();
|
||||
try {
|
||||
$stock = $params['type'] == 1 ? $StoreProduct['stock'] + $params['number'] : $StoreProduct['stock'] - $params['number'];
|
||||
$stock = max($stock, 0);
|
||||
StoreBranchProduct::where('id', $params['id'])->update(['stock' => $stock]);
|
||||
$productStockIn = 0;
|
||||
foreach ($attrValue as $k => $v) {
|
||||
$current = $attrs[$v['unique']] ?? [];
|
||||
if (empty($current) || $v['unique'] != $current['unique']) {
|
||||
continue;
|
||||
}
|
||||
$stock = $current['type'] == 1 ? $v['stock'] + $current['number'] : $v['stock'] - $current['number'];
|
||||
$stock = max($stock, 0);
|
||||
$productStockIn = $current['type'] == 1 ? $StoreProduct['stock'] + $current['number'] : $StoreProduct['stock'] - $current['number'];
|
||||
$productStockIn = max($productStockIn, 0);
|
||||
StoreBranchProductAttrValue::where('id', $v['id'])->update(['stock' => $stock]);
|
||||
}
|
||||
StoreBranchProduct::where('id', $StoreProduct['id'])->update(['stock' => $productStockIn]);
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
throw new BusinessException($e->getMessage());
|
||||
throw new \Exception($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static function checkAuth($product)
|
||||
{
|
||||
if (request()->adminInfo['store_id'] != $product['store_id']) {
|
||||
throw new BusinessException('没有权限操作');
|
||||
throw new \Exception('没有权限操作');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@ class StoreProductValidate extends BaseValidate
|
||||
protected $rule = [
|
||||
'id' => 'require',
|
||||
'store_name' => 'require',
|
||||
'attrs' => 'require',
|
||||
];
|
||||
|
||||
|
||||
@ -31,6 +32,7 @@ class StoreProductValidate extends BaseValidate
|
||||
protected $field = [
|
||||
'id' => 'id',
|
||||
'store_name' => '商品名称',
|
||||
'attrs' => '商品名称',
|
||||
];
|
||||
|
||||
|
||||
@ -89,7 +91,7 @@ class StoreProductValidate extends BaseValidate
|
||||
*/
|
||||
public function sceneStock()
|
||||
{
|
||||
return $this->only(['id', 'type', 'number']);
|
||||
return $this->only(['attrs']);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user