feat: 添加预订单表和预订单购物详情表的API接口
This commit is contained in:
parent
9da0f8942d
commit
3a100dc662
@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\beforehand_order;
|
||||
|
||||
|
||||
use app\admin\controller\BaseAdminController;
|
||||
use app\admin\lists\beforehand_order\BeforehandOrderLists;
|
||||
use app\admin\logic\beforehand_order\BeforehandOrderLogic;
|
||||
|
||||
|
||||
/**
|
||||
* 预订单表控制器
|
||||
* Class BeforehandOrderController
|
||||
* @package app\admin\controller\beforehand_order
|
||||
*/
|
||||
class BeforehandOrderController extends BaseAdminController
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取预订单表列表
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2024/09/30 11:26
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
return $this->dataLists(new BeforehandOrderLists());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加预订单表
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2024/09/30 11:26
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$params =$this->request->post();
|
||||
$params['admin_id'] = $this->adminId;
|
||||
$result = BeforehandOrderLogic::add($params);
|
||||
return $this->success('添加成功', [], 1, 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑预订单表
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2024/09/30 11:26
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
$params =$this->request->post();
|
||||
$result = BeforehandOrderLogic::edit($params);
|
||||
if (true === $result) {
|
||||
return $this->success('编辑成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(BeforehandOrderLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除预订单表
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2024/09/30 11:26
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$params =$this->request->post();
|
||||
BeforehandOrderLogic::delete($params);
|
||||
return $this->success('删除成功', [], 1, 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取预订单表详情
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2024/09/30 11:26
|
||||
*/
|
||||
public function detail()
|
||||
{
|
||||
$params = (new BeforehandOrderValidate())->goCheck('detail');
|
||||
$result = BeforehandOrderLogic::detail($params);
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\beforehand_order_cart_info;
|
||||
|
||||
|
||||
use app\admin\controller\BaseAdminController;
|
||||
use app\admin\lists\beforehand_order_cart_info\BeforehandOrderCartInfoLists;
|
||||
use app\admin\logic\beforehand_order_cart_info\BeforehandOrderCartInfoLogic;
|
||||
use app\admin\validate\beforehand_order_cart_info\BeforehandOrderCartInfoValidate;
|
||||
|
||||
|
||||
/**
|
||||
* 预订单购物详情表控制器
|
||||
* Class BeforehandOrderCartInfoController
|
||||
* @package app\admin\controller\beforehand_order_cart_info
|
||||
*/
|
||||
class BeforehandOrderCartInfoController extends BaseAdminController
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取预订单购物详情表列表
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2024/09/30 11:32
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
return $this->dataLists(new BeforehandOrderCartInfoLists());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加预订单购物详情表
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2024/09/30 11:32
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$result = BeforehandOrderCartInfoLogic::add($params);
|
||||
return $this->success('添加成功', [], 1, 1);
|
||||
|
||||
}
|
||||
/**
|
||||
* @notes 添加预订单购物详情表
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2024/09/30 11:32
|
||||
*/
|
||||
public function append_add()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$result = BeforehandOrderCartInfoLogic::appendAdd($params);
|
||||
return $this->success('追加成功', [], 1, 1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑预订单购物详情表
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2024/09/30 11:32
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$result = BeforehandOrderCartInfoLogic::edit($params);
|
||||
return $this->success('编辑成功', [], 1, 1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除预订单购物详情表
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2024/09/30 11:32
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
BeforehandOrderCartInfoLogic::delete($params);
|
||||
return $this->success('删除成功', [], 1, 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取预订单购物详情表详情
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2024/09/30 11:32
|
||||
*/
|
||||
public function detail()
|
||||
{
|
||||
$params = $this->request->get();
|
||||
$result = BeforehandOrderCartInfoLogic::detail($params);
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
|
||||
}
|
65
app/admin/lists/beforehand_order/BeforehandOrderLists.php
Normal file
65
app/admin/lists/beforehand_order/BeforehandOrderLists.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\lists\beforehand_order;
|
||||
|
||||
|
||||
use app\admin\lists\BaseAdminDataLists;
|
||||
use app\common\model\beforehand_order\BeforehandOrder;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
|
||||
|
||||
/**
|
||||
* 预订单表列表
|
||||
* Class BeforehandOrderLists
|
||||
* @package app\admin\listsbeforehand_order
|
||||
*/
|
||||
class BeforehandOrderLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置搜索条件
|
||||
* @return \string[][]
|
||||
* @author admin
|
||||
* @date 2024/09/30 11:26
|
||||
*/
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['store_id', 'order_id', 'uid','paid','status',],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取预订单表列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author admin
|
||||
* @date 2024/09/30 11:26
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
return BeforehandOrder::where($this->searchWhere)
|
||||
->field(['id', 'store_id', 'order_id', 'uid', 'total_num', 'total_price', 'pay_price', 'deduction_price','create_time', 'source', 'status', 'mark'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取预订单表数量
|
||||
* @return int
|
||||
* @author admin
|
||||
* @date 2024/09/30 11:26
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return BeforehandOrder::where($this->searchWhere)->count();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\lists\beforehand_order_cart_info;
|
||||
|
||||
|
||||
use app\admin\lists\BaseAdminDataLists;
|
||||
use app\common\model\beforehand_order_cart_info\BeforehandOrderCartInfo;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\store_product\StoreProduct;
|
||||
|
||||
/**
|
||||
* 预订单购物详情表列表
|
||||
* Class BeforehandOrderCartInfoLists
|
||||
* @package app\admin\listsbeforehand_order_cart_info
|
||||
*/
|
||||
class BeforehandOrderCartInfoLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置搜索条件
|
||||
* @return \string[][]
|
||||
* @author admin
|
||||
* @date 2024/09/30 11:32
|
||||
*/
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['bhoid', 'uid', 'product_id'],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取预订单购物详情表列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author admin
|
||||
* @date 2024/09/30 11:32
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
return BeforehandOrderCartInfo::where($this->searchWhere)
|
||||
->field(['id', 'bhoid', 'uid', 'product_id', 'attr_value_id', 'is_pay', 'purchase', 'price', 'total_price', 'cart_num'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()->each(function($item){
|
||||
$find=StoreProduct::where('id',$item['product_id'])->field('store_name,image')->withTrashed()->find();
|
||||
$item['store_name']=$find['store_name'];
|
||||
$item['image']=$find['image'];
|
||||
return $item;
|
||||
})
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取预订单购物详情表数量
|
||||
* @return int
|
||||
* @author admin
|
||||
* @date 2024/09/30 11:32
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return BeforehandOrderCartInfo::where($this->searchWhere)->count();
|
||||
}
|
||||
|
||||
}
|
135
app/admin/logic/beforehand_order/BeforehandOrderLogic.php
Normal file
135
app/admin/logic/beforehand_order/BeforehandOrderLogic.php
Normal file
@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\logic\beforehand_order;
|
||||
|
||||
|
||||
use app\common\model\beforehand_order\BeforehandOrder;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\beforehand_order_cart_info\BeforehandOrderCartInfo;
|
||||
use support\exception\BusinessException;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
/**
|
||||
* 预订单表逻辑
|
||||
* Class BeforehandOrderLogic
|
||||
* @package app\admin\logic\beforehand_order
|
||||
*/
|
||||
class BeforehandOrderLogic extends BaseLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加预订单表
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2024/09/30 11:26
|
||||
*/
|
||||
public static function add(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$datas = [];
|
||||
$total_num=0;
|
||||
$total_price=0;
|
||||
$uid=$params['uid'] ?? 0;
|
||||
foreach ($params['product_arr'] as $k => $v) {
|
||||
$datas[$k]['product_id'] = $v['product_id'];
|
||||
$datas[$k]['uid'] = $uid;
|
||||
$datas[$k]['cart_num'] = $v['nums'];
|
||||
$datas[$k]['price'] = $v['purchase'];
|
||||
$datas[$k]['total_price'] = $v['total_price'];
|
||||
$datas[$k]['create_time'] = time();
|
||||
$datas[$k]['update_time'] =time();
|
||||
$total_num += $v['nums'];
|
||||
$total_price += $v['total_price'];
|
||||
}
|
||||
$order = BeforehandOrder::create([
|
||||
'order_id' => getNewOrderId('YG'),
|
||||
'admin_id' => $params['admin_id']??0,
|
||||
'uid' => $uid,
|
||||
'total_num' => $total_num,
|
||||
'total_price' => $total_price,
|
||||
'pay_price' => 0,
|
||||
'pay_type' => 0,
|
||||
'deduction_price' => 0,
|
||||
'paid' => 0,
|
||||
'source' => 0,
|
||||
'mark' => $params['mark']??''
|
||||
]);
|
||||
foreach ($datas as $k => $v) {
|
||||
$datas[$k]['bhoid'] = $order['id'];
|
||||
}
|
||||
(new BeforehandOrderCartInfo())->saveAll($datas);
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑预订单表
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2024/09/30 11:26
|
||||
*/
|
||||
public static function edit(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
BeforehandOrder::where('id', $params['id'])->update([
|
||||
'store_id' => $params['store_id'],
|
||||
'order_id' => $params['order_id'],
|
||||
'uid' => $params['uid'],
|
||||
'cart_id' => $params['cart_id'],
|
||||
'total_num' => $params['total_num'],
|
||||
'total_price' => $params['total_price'],
|
||||
'pay_price' => $params['pay_price'],
|
||||
'deduction_price' => $params['deduction_price'],
|
||||
'paid' => $params['paid'],
|
||||
'pay_time' => $params['pay_time'],
|
||||
'pay_type' => $params['pay_type'],
|
||||
'source' => $params['source'],
|
||||
'status' => $params['status'],
|
||||
'mark' => $params['mark']
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除预订单表
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2024/09/30 11:26
|
||||
*/
|
||||
public static function delete(array $params): bool
|
||||
{
|
||||
return BeforehandOrder::destroy($params['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取预订单表详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author admin
|
||||
* @date 2024/09/30 11:26
|
||||
*/
|
||||
public static function detail($params): array
|
||||
{
|
||||
return BeforehandOrder::findOrEmpty($params['id'])->toArray();
|
||||
}
|
||||
}
|
@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\logic\beforehand_order_cart_info;
|
||||
|
||||
|
||||
use app\common\model\beforehand_order_cart_info\BeforehandOrderCartInfo;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\beforehand_order\BeforehandOrder;
|
||||
use support\exception\BusinessException;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
/**
|
||||
* 预订单购物详情表逻辑
|
||||
* Class BeforehandOrderCartInfoLogic
|
||||
* @package app\admin\logic\beforehand_order_cart_info
|
||||
*/
|
||||
class BeforehandOrderCartInfoLogic extends BaseLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加预订单购物详情表
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2024/09/30 11:32
|
||||
*/
|
||||
public static function add(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
BeforehandOrderCartInfo::create([
|
||||
'oid' => $params['oid'],
|
||||
'uid' => $params['uid'],
|
||||
'product_id' => $params['product_id'],
|
||||
'attr_value_id' => $params['attr_value_id'],
|
||||
'is_pay' => $params['is_pay'],
|
||||
'purchase' => $params['purchase'],
|
||||
'price' => $params['price'],
|
||||
'total_price' => $params['total_price'],
|
||||
'cart_num' => $params['cart_num'],
|
||||
'old_cart_id' => $params['old_cart_id']
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @notes 追加预订单购物详情表
|
||||
*/
|
||||
public static function appendAdd(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$datas = [];
|
||||
$uid=$params['uid'] ?? 0;
|
||||
$bhoid=$params['id'];
|
||||
foreach ($params['product_arr'] as $k => $v) {
|
||||
$datas[$k]['product_id'] = $v['id'];
|
||||
$datas[$k]['uid'] = $uid;
|
||||
$datas[$k]['bhoid'] = $bhoid;
|
||||
$datas[$k]['cart_num'] = $v['nums'];
|
||||
$datas[$k]['price'] = $v['purchase'];
|
||||
$datas[$k]['total_price'] = $v['total_price'];
|
||||
$datas[$k]['create_time'] = time();
|
||||
$datas[$k]['update_time'] =time();
|
||||
}
|
||||
(new BeforehandOrderCartInfo())->saveAll($datas);
|
||||
|
||||
$info=BeforehandOrderCartInfo::where('bhoid',$bhoid)->field('sum(cart_num) as cart_num,sum(total_price) as total_price')->find();
|
||||
BeforehandOrder::where('id',$bhoid)->update(['total_price'=>$info['total_price'],'total_num'=>$info['cart_num']]);
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑预订单购物详情表
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2024/09/30 11:32
|
||||
*/
|
||||
public static function edit(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
BeforehandOrderCartInfo::where('id', $params['id'])->update([
|
||||
'price' => $params['purchase'],
|
||||
'total_price' => $params['total_price'],
|
||||
'cart_num' => $params['nums'],
|
||||
]);
|
||||
$bhoid=$params['bhoid'];
|
||||
$info=BeforehandOrderCartInfo::where('bhoid',$bhoid)->field('sum(cart_num) as cart_num,sum(total_price) as total_price')->find();
|
||||
BeforehandOrder::where('id',$bhoid)->update(['total_price'=>$info['total_price'],'total_num'=>$info['cart_num']]);
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除预订单购物详情表
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2024/09/30 11:32
|
||||
*/
|
||||
public static function delete(array $params): bool
|
||||
{
|
||||
return BeforehandOrderCartInfo::destroy($params['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取预订单购物详情表详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author admin
|
||||
* @date 2024/09/30 11:32
|
||||
*/
|
||||
public static function detail($params): array
|
||||
{
|
||||
return BeforehandOrderCartInfo::findOrEmpty($params['id'])->toArray();
|
||||
}
|
||||
}
|
22
app/common/model/beforehand_order/BeforehandOrder.php
Normal file
22
app/common/model/beforehand_order/BeforehandOrder.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model\beforehand_order;
|
||||
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
use think\model\concern\SoftDelete;
|
||||
|
||||
|
||||
/**
|
||||
* 预订单表模型
|
||||
* Class BeforehandOrder
|
||||
* @package app\common\model\beforehand_order
|
||||
*/
|
||||
class BeforehandOrder extends BaseModel
|
||||
{
|
||||
use SoftDelete;
|
||||
protected $name = 'beforehand_order';
|
||||
protected $deleteTime = 'delete_time';
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model\beforehand_order_cart_info;
|
||||
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
use think\model\concern\SoftDelete;
|
||||
|
||||
|
||||
/**
|
||||
* 预订单购物详情表模型
|
||||
* Class BeforehandOrderCartInfo
|
||||
* @package app\common\model\beforehand_order_cart_info
|
||||
*/
|
||||
class BeforehandOrderCartInfo extends BaseModel
|
||||
{
|
||||
use SoftDelete;
|
||||
protected $name = 'beforehand_order_cart_info';
|
||||
protected $deleteTime = 'delete_time';
|
||||
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user