Merge branch 'main' of https://gitea.lihaink.cn/mkm/multi-store
This commit is contained in:
commit
337873c199
@ -33,6 +33,7 @@ class OrderController extends BaseApiController
|
||||
ApiDoc\url('/api/order/order/write_list'),
|
||||
ApiDoc\Method('POST'),
|
||||
ApiDoc\Param(name: "status", type: "int", require: true, desc: "1:待核销;2:已核销"),
|
||||
ApiDoc\Param(name: "name", type: "string", require: false, desc: "搜商品或者订单id"),
|
||||
ApiDoc\Param(name: "page_no", type: "int", require: true, desc: "默认1页数"),
|
||||
ApiDoc\Param(name: "page_size", type: "int", require: false, desc: "条数默认15"),
|
||||
ApiDoc\NotHeaders(),
|
||||
@ -56,6 +57,24 @@ class OrderController extends BaseApiController
|
||||
return $this->success('ok',$res);
|
||||
|
||||
}
|
||||
|
||||
#[
|
||||
ApiDoc\Title('核销数量'),
|
||||
ApiDoc\url('/api/order/order/write_count'),
|
||||
ApiDoc\Method('POST'),
|
||||
ApiDoc\Param(name: "name", type: "string", require: false, desc: "搜商品或者订单id"),
|
||||
ApiDoc\NotHeaders(),
|
||||
ApiDoc\Header(name: "token", type: "string", require: true, desc: "token"),
|
||||
ApiDoc\ResponseSuccess("data", type: "array"),
|
||||
]
|
||||
public function write_count()
|
||||
{
|
||||
$info = $this->userInfo;
|
||||
$params = $this->request->post();
|
||||
$res = OrderLogic::write_count($info,$params);
|
||||
return $this->success('ok',$res);
|
||||
}
|
||||
|
||||
#[
|
||||
ApiDoc\Title('订单校验'),
|
||||
ApiDoc\url('/api/order/order/checkOrder'),
|
||||
|
35
app/api/controller/user/UserVisitController.php
Normal file
35
app/api/controller/user/UserVisitController.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller\user;
|
||||
|
||||
use app\api\controller\BaseApiController;
|
||||
use app\api\logic\user\UserVisitLogic;
|
||||
use app\api\validate\VisitValidate;
|
||||
use hg\apidoc\annotation as ApiDoc;
|
||||
#[ApiDoc\title('用户访问')]
|
||||
class UserVisitController extends BaseApiController
|
||||
{
|
||||
|
||||
#[
|
||||
ApiDoc\Title('添加访问商品记录'),
|
||||
ApiDoc\url('/api/user/UserVisit/productLog'),
|
||||
ApiDoc\Method('POST'),
|
||||
ApiDoc\Param(name: "product_id", type: "int", require: true, desc: "product_id商品id"),
|
||||
ApiDoc\Param(name: "cate_id", type: "int", require: true, desc: "分类id"),
|
||||
ApiDoc\NotHeaders(),
|
||||
ApiDoc\Header(name: "token", type: "string", require: true, desc: "token"),
|
||||
ApiDoc\ResponseSuccess("data", type: "array"),
|
||||
]
|
||||
public function productLog()
|
||||
{
|
||||
$params = (new VisitValidate())->post()->goCheck('add');
|
||||
|
||||
$result = UserVisitLogic::add($params,$this->userId);
|
||||
if (true === $result) {
|
||||
return $this->success('添加成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(UserVisitLogic::getError());
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -442,6 +442,46 @@ class OrderLogic extends BaseLogic
|
||||
}
|
||||
|
||||
|
||||
public static function write_count($info,$params)
|
||||
{
|
||||
$store_id = SystemStoreStaff::where('phone',$info['mobile'])->value('store_id');
|
||||
if(empty($store_id)){
|
||||
throw new \Exception('该用户未绑定店铺请查看');
|
||||
}
|
||||
$query = StoreOrderCartInfo::alias('o')
|
||||
->leftJoin('store_branch_product p','p.id = o.product_id')
|
||||
->leftJoin('store_order s','s.id = o.oid')
|
||||
->field('o.oid,p.store_name,s.order_id')
|
||||
->where('o.store_id',$store_id);
|
||||
|
||||
if(isset($params['name']) && $params['name']){
|
||||
if($params['name'] && preg_match('/[\x{4e00}-\x{9fff}]+/u', $params['name'])==1){
|
||||
$query->where('p.store_name','like','%'.$params['name'].'%');
|
||||
}else{
|
||||
$query->where('s.order_id',$params['name']);
|
||||
}
|
||||
}
|
||||
$product = $query->select();
|
||||
if(empty($product)){
|
||||
return [
|
||||
'no_send'=>0,
|
||||
'send'=>0
|
||||
];
|
||||
}
|
||||
$oids = array_column($product->toArray(), 'oid');
|
||||
$uniqueOids = array_unique($oids);
|
||||
$no_send = StoreOrder::whereIn('id',$uniqueOids)
|
||||
->where('status',1)->count();
|
||||
$send = StoreOrder::whereIn('id',$uniqueOids)
|
||||
->where('status',2)->count();
|
||||
return [
|
||||
'no_send'=>$no_send,
|
||||
'send'=>$send
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static function write_list($info,$status,$params)
|
||||
{
|
||||
|
||||
@ -463,7 +503,6 @@ class OrderLogic extends BaseLogic
|
||||
}else{
|
||||
$query->where('s.order_id',$params['name']);
|
||||
}
|
||||
|
||||
}
|
||||
$product = $query->select();
|
||||
if(empty($product)){
|
||||
|
47
app/api/logic/user/UserVisitLogic.php
Normal file
47
app/api/logic/user/UserVisitLogic.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\logic\user;
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\store_visit\StoreVisit;
|
||||
use app\common\model\user\UserVisit;
|
||||
use think\facade\Db;
|
||||
|
||||
class UserVisitLogic extends BaseLogic
|
||||
{
|
||||
/**
|
||||
* @notes 添加用户访问
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author likeadmin
|
||||
* @date 2024/05/13 16:56
|
||||
*/
|
||||
public static function add(array $params,$uid): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$check = StoreVisit::where(['product_id'=>$params['product_id'],
|
||||
'uid'=>$uid
|
||||
])
|
||||
->whereDay('create_time')
|
||||
->find();
|
||||
if($check){
|
||||
StoreVisit::where('id',$check['id'])->inc('count')->update();
|
||||
}else{
|
||||
StoreVisit::create([
|
||||
'uid' => $uid,
|
||||
'product_id' => $params['product_id'],
|
||||
'cate_id' => $params['cate_id'],
|
||||
'count' => 1,
|
||||
'create_time' => time(),
|
||||
]);
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
50
app/api/validate/VisitValidate.php
Normal file
50
app/api/validate/VisitValidate.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\validate;
|
||||
|
||||
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
|
||||
/**
|
||||
* 访问表验证器
|
||||
* Class VisitValidate
|
||||
* @package app\admin\validate\order
|
||||
*/
|
||||
class VisitValidate extends BaseValidate
|
||||
{
|
||||
|
||||
/**
|
||||
* 设置校验规则
|
||||
* @var string[]
|
||||
*/
|
||||
protected $rule = [
|
||||
'product_id' => 'require|number',
|
||||
'cate_id' => 'require|number',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* 参数描述
|
||||
* @var string[]
|
||||
*/
|
||||
protected $field = [
|
||||
'product_id' => '商品id',
|
||||
'cate_id' => '分类',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加场景
|
||||
* @return VisitValidate
|
||||
* @author likeadmin
|
||||
* @date 2024/04/24 10:37
|
||||
*/
|
||||
public function sceneAdd()
|
||||
{
|
||||
return $this->only(['product_id','cate_id']);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
22
app/common/model/store_visit/StoreVisit.php
Normal file
22
app/common/model/store_visit/StoreVisit.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model\store_visit;
|
||||
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
use think\model\concern\SoftDelete;
|
||||
|
||||
|
||||
/**
|
||||
* 计量单位
|
||||
* Class StoreProductUnit
|
||||
* @package app\common\model\store_product_unit
|
||||
*/
|
||||
class StoreVisit extends BaseModel
|
||||
{
|
||||
use SoftDelete;
|
||||
protected $name = 'store_visit';
|
||||
protected $deleteTime = 'delete_time';
|
||||
|
||||
|
||||
}
|
22
app/common/model/user/UserVisit.php
Normal file
22
app/common/model/user/UserVisit.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\common\model\user;
|
||||
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
use think\model\concern\SoftDelete;
|
||||
|
||||
/**
|
||||
* 用户访问表
|
||||
* Class UserVisit
|
||||
* @package app\common\model
|
||||
*/
|
||||
class UserVisit extends BaseModel
|
||||
{
|
||||
use SoftDelete;
|
||||
protected $pk = 'id';
|
||||
|
||||
protected $deleteTime = 'delete_time';
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user