feat: 添加新功能合并订单

This commit is contained in:
mkm 2024-08-16 17:51:38 +08:00
parent 9a1002367c
commit c462958325
6 changed files with 98 additions and 26 deletions

View File

@ -1,11 +1,16 @@
<?php
namespace app\admin\controller\purchase_order;
use app\admin\controller\BaseAdminController;
use app\admin\lists\purchase_order\PurchaseOrderLists;
use app\admin\lists\purchase_order_info\PurchaseOrderInfoLists;
use app\admin\lists\store_order\StoreOrderLists;
use app\admin\logic\purchase_order\PurchaseOrderLogic;
use app\common\model\purchase_order\PurchaseOrder;
class PurchaseOrderController extends BaseAdminController{
class PurchaseOrderController extends BaseAdminController
{
public function lists()
{
@ -15,27 +20,41 @@ class PurchaseOrderController extends BaseAdminController{
{
return $this->dataLists(new PurchaseOrderInfoLists());
}
public function order_lists()
{
$id = $this->request->get('id');
$order_arr = PurchaseOrder::where('id', $id)->value('order_arr');
$this->request->__set('order_arr', $order_arr);
return $this->dataLists(new StoreOrderLists);
}
/**
* 合并今日商户订单
*/
public function add(){
PurchaseOrderLogic::StoreTodayOrder();
public function add()
{
$data = $this->request->post();
PurchaseOrderLogic::mergeOrder($data);
if (PurchaseOrderLogic::hasError()) {
return $this->fail(PurchaseOrderLogic::getError());
}
return $this->success('合并成功');
}
/**
/**
* 合并今日平台订单
*/
public function platform(){
public function platform()
{
PurchaseOrderLogic::platformTodayOrder();
return $this->success('合并成功');
}
/**
/**
* 详情
*/
public function detail(){
$id=$this->request->get('id');
$res=PurchaseOrderLogic::detail($id);
public function detail()
{
$id = $this->request->get('id');
$res = PurchaseOrderLogic::detail($id);
return $this->data($res);
}
}

View File

@ -28,7 +28,7 @@ class PurchaseProductOfferLists extends BaseAdminDataLists implements ListsSearc
public function setSearch(): array
{
return [
'=' => [],
'=' => ['order_id'],
];
}
@ -51,6 +51,7 @@ class PurchaseProductOfferLists extends BaseAdminDataLists implements ListsSearc
->select()->each(function($item){
$find=StoreProduct::where('id',$item->product_id)->find();
$item->store_name=$find->store_name;
$item->store_info=$find->store_info;
$item->image=$find->image;
$item->unit_name=StoreProductUnit::where('id',$item->unit)->value('name');
if($item->is_buyer==1){

View File

@ -30,7 +30,7 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface
public function setSearch(): array
{
return [
'=' => ['order_id','store_id', 'pay_type', 'staff_id', 'shipping_type', 'delivery_id','paid', 'status', 'is_writeoff'],
'=' => ['order_id','store_id', 'pay_type', 'staff_id', 'shipping_type', 'delivery_id','paid', 'status', 'is_writeoff','is_merge'],
'between_time' => 'create_time'
];
}
@ -50,6 +50,9 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface
if($this->request->get('is_delivery')>=1){
$this->searchWhere[]=['delivery_uid','>',0];
}
if($this->request->__get('order_arr')){
$this->searchWhere[]=['id','in',$this->request->__get('order_arr')];
}
return StoreOrder::with(['staff','store'])->where($this->searchWhere)
->when(!empty($this->request->adminInfo['store_id']), function ($query) {
$query->where('store_id', $this->request->adminInfo['store_id']);
@ -62,7 +65,7 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface
$query->whereIn('status', $status);
}
})
->field(['id', 'store_id', 'staff_id', 'order_id', 'paid', 'pay_price', 'pay_time', 'pay_type', 'status', 'uid','refund_status','create_time','delivery_name','delivery_id'])
->field(['id', 'store_id', 'staff_id', 'order_id', 'paid', 'pay_price','total_price', 'pay_time', 'pay_type', 'status', 'uid','refund_status','create_time','delivery_name','delivery_id'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function ($item) {

View File

@ -6,8 +6,10 @@ namespace app\admin\logic\purchase_order;
use app\common\model\purchase_order\PurchaseOrder;
use app\common\logic\BaseLogic;
use app\common\model\purchase_order_info\PurchaseOrderInfo;
use app\common\model\purchase_product_offer\PurchaseProductOffer;
use app\common\model\store_order\StoreOrder;
use app\common\model\store_order_cart_info\StoreOrderCartInfo;
use app\common\model\store_product\StoreProduct;
use app\common\model\system_store\SystemStore;
use think\facade\Db;
@ -20,6 +22,54 @@ use think\facade\Db;
class PurchaseOrderLogic extends BaseLogic
{
public static function mergeOrder($params)
{
$oid_arr = [];
$store_arr = [];
foreach ($params as $k => $v) {
$oid_arr[] = $v['oid'];
$store_arr[] = $v['store_id'];
}
$store_arr = array_unique($store_arr);
Db::startTrans();
try {
$price = StoreOrder::whereIn('id', $oid_arr)->field('SUM(pay_price) as pay_price,SUM(total_price) as total_price')->find();
$data = [
'store_id' => 0,
'store_arr' => json_encode($store_arr),
'order_arr' => json_encode($oid_arr),
'order_id' => getNewOrderId('PT'),
'total' => $price['total_price'],
'actual' => $price['pay_price'],
'money' => $price['pay_price'],
'paid' => 1,
'is_mer' => 2,
'create_time' => time(),
'update_time' => time(),
];
$res = PurchaseOrder::create($data);
$info = StoreOrderCartInfo::where('oid', 'in', $oid_arr)->field('store_id, product_id,price,SUM(total_price) as total_price, SUM(cart_num) as cart_num')->group('product_id')->select();
$purchase_order_info = [];
foreach ($info as $item) {
$arr['order_id'] = $res['id'];
$arr['product_id'] = $item['product_id'];
$arr['price'] = $item['price'];
$arr['total_price'] = $item['total_price'];
$arr['need_num'] = $item['cart_num'];
$arr['unit'] = StoreProduct::where('id',$item['product_id'])->value('unit');
$purchase_order_info[] = $arr;
}
$purchaseOrderInfo = new PurchaseProductOffer();
$purchaseOrderInfo->saveAll($purchase_order_info);
StoreOrder::whereIn('id', $oid_arr)->update(['is_merge' => 1]);
Db::commit();
return true;
} catch (\Throwable $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 合并今日商户订单
@ -85,8 +135,8 @@ class PurchaseOrderLogic extends BaseLogic
Db::startTrans();
try {
$purchaseOrderInfo = new PurchaseOrderInfo();
$purchase_order_info=[];
$order_arr = PurchaseOrder::whereDay('create_time')->where('is_mer',1)->column('id');
$purchase_order_info = [];
$order_arr = PurchaseOrder::whereDay('create_time')->where('is_mer', 1)->column('id');
$price = PurchaseOrder::whereDay('create_time')->field('SUM(actual) as pay_price,SUM(total) as total_price')->find();
$data = [
'store_id' => 0,
@ -118,7 +168,6 @@ class PurchaseOrderLogic extends BaseLogic
return true;
} catch (\Exception $e) {
Db::rollback();
d($e);
self::setError($e->getMessage());
return false;
}
@ -146,12 +195,12 @@ class PurchaseOrderLogic extends BaseLogic
*/
public static function detail($id): array
{
$data= PurchaseOrder::findOrEmpty($id)->toArray();
if($data){
if($data['store_id']){
$data['system_store']=SystemStore::where('id',$data['store_id'])->value('name');
}else{
$data['system_store']='平台';
$data = PurchaseOrder::findOrEmpty($id)->toArray();
if ($data) {
if ($data['store_id']) {
$data['system_store'] = SystemStore::where('id', $data['store_id'])->value('name');
} else {
$data['system_store'] = '平台';
}
switch ($data['storage']) {
case 0:

View File

@ -294,7 +294,7 @@ class UserController extends BaseApiController
public function cash_info()
{
$info = User::where('id', $this->userId)->field('id,real_name,mobile,now_money,id_card')->find();
$info['notes'] = '提现金额需大于1元提现到微信零钱并财务审核审核通过后提现金额将自动到账';
$info['notes'] = '提现金额需大于1元提现到微信零钱并财务审核审核通过后提现金额将自动到账。若本月提现超过800元将产生个人所得税款具体税率及金额根据《中华人民共和国个人所得税法》第二条、第三条、第六条规定扣缴。';
$info['extract_price'] =StoreExtract::where('uid',$this->userId)->sum('extract_price');
return $this->data($info);
}

View File

@ -17,6 +17,6 @@ class PurchaseOrder extends BaseModel
use SoftDelete;
protected $name = 'purchase_order';
protected $deleteTime = 'delete_time';
protected $json = ['order_arr'];
protected $json = ['order_arr','store_arr'];
}