调整订单核销
This commit is contained in:
parent
34cad62c8e
commit
0298e42057
@ -47,7 +47,7 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI
|
|||||||
{
|
{
|
||||||
$status = $this->params['status'] ?? '';
|
$status = $this->params['status'] ?? '';
|
||||||
return StoreBranchProduct::where($this->searchWhere)
|
return StoreBranchProduct::where($this->searchWhere)
|
||||||
->field(['id', 'image', 'store_name', 'cate_id', 'price', 'sales', 'stock', 'unit', 'cost'])
|
->field(['id', 'image', 'store_name', 'cate_id', 'price', 'sales', 'stock', 'unit', 'cost', 'status'])
|
||||||
->when(!empty($this->adminInfo['store_id']), function ($query) {
|
->when(!empty($this->adminInfo['store_id']), function ($query) {
|
||||||
$query->where('store_id', $this->adminInfo['store_id']);
|
$query->where('store_id', $this->adminInfo['store_id']);
|
||||||
})
|
})
|
||||||
|
@ -7,6 +7,7 @@ use app\common\enum\PayEnum;
|
|||||||
use app\common\enum\YesNoEnum;
|
use app\common\enum\YesNoEnum;
|
||||||
use app\common\logic\BaseLogic;
|
use app\common\logic\BaseLogic;
|
||||||
use app\common\logic\CapitalFlowLogic;
|
use app\common\logic\CapitalFlowLogic;
|
||||||
|
use app\common\logic\StoreFinanceFlowLogic;
|
||||||
use app\common\model\merchant\Merchant;
|
use app\common\model\merchant\Merchant;
|
||||||
use app\common\model\order\Cart;
|
use app\common\model\order\Cart;
|
||||||
use app\common\model\store_branch_product\StoreBranchProduct;
|
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||||
@ -15,6 +16,7 @@ use app\common\model\store_order_cart_info\StoreOrderCartInfo;
|
|||||||
use app\common\model\store_product\StoreProduct;
|
use app\common\model\store_product\StoreProduct;
|
||||||
use app\common\model\store_product_attr_value\StoreProductAttrValue;
|
use app\common\model\store_product_attr_value\StoreProductAttrValue;
|
||||||
use app\common\model\store_product_unit\StoreProductUnit;
|
use app\common\model\store_product_unit\StoreProductUnit;
|
||||||
|
use app\common\model\system_store\SystemStore;
|
||||||
use app\common\model\user\User;
|
use app\common\model\user\User;
|
||||||
use app\common\model\user\UserAddress;
|
use app\common\model\user\UserAddress;
|
||||||
use app\Request;
|
use app\Request;
|
||||||
@ -32,6 +34,7 @@ use Yansongda\Pay\Event\PayEnd;
|
|||||||
class OrderLogic extends BaseLogic
|
class OrderLogic extends BaseLogic
|
||||||
{
|
{
|
||||||
public static $total;
|
public static $total;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @notes 获取购物车商品信息
|
* @notes 获取购物车商品信息
|
||||||
* @param $params
|
* @param $params
|
||||||
@ -209,6 +212,7 @@ class OrderLogic extends BaseLogic
|
|||||||
];
|
];
|
||||||
return ['order' => $order, 'cart_list' => $cart_select];
|
return ['order' => $order, 'cart_list' => $cart_select];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建购货订单
|
* 创建购货订单
|
||||||
* @return Object|bool
|
* @return Object|bool
|
||||||
@ -256,6 +260,7 @@ class OrderLogic extends BaseLogic
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @notes 获取订单号
|
* @notes 获取订单号
|
||||||
* @param $type
|
* @param $type
|
||||||
@ -272,8 +277,6 @@ class OrderLogic extends BaseLogic
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 余额订单支付
|
* 余额订单支付
|
||||||
* @param User $user
|
* @param User $user
|
||||||
@ -349,7 +352,8 @@ class OrderLogic extends BaseLogic
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function purchaseAgain($order_id){
|
public static function purchaseAgain($order_id)
|
||||||
|
{
|
||||||
$arr = StoreOrderCartInfo::where('oid', $order_id)->field('product_id,cart_num,staff_id')->select();
|
$arr = StoreOrderCartInfo::where('oid', $order_id)->field('product_id,cart_num,staff_id')->select();
|
||||||
$data = [];
|
$data = [];
|
||||||
foreach ($arr as $k => $v) {
|
foreach ($arr as $k => $v) {
|
||||||
@ -381,7 +385,6 @@ class OrderLogic extends BaseLogic
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static function detail($params): array
|
public static function detail($params): array
|
||||||
{
|
{
|
||||||
$find = StoreOrder::where($params)->findOrEmpty()->toArray();
|
$find = StoreOrder::where($params)->findOrEmpty()->toArray();
|
||||||
@ -416,32 +419,29 @@ class OrderLogic extends BaseLogic
|
|||||||
*/
|
*/
|
||||||
public static function writeOff($params, $uid): bool
|
public static function writeOff($params, $uid): bool
|
||||||
{
|
{
|
||||||
$data = StoreOrderCartInfo::where([
|
$data = StoreOrder::with('store')->where([
|
||||||
'oid'=>$params['order_id'],
|
|
||||||
'verify_code' => $params['verify_code'],
|
'verify_code' => $params['verify_code'],
|
||||||
'uid' => $uid
|
'uid' => $uid
|
||||||
])->select()->toArray();
|
])->find();
|
||||||
if (empty($data)) {
|
if (empty($data)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Db::startTrans();
|
Db::startTrans();
|
||||||
try {
|
try {
|
||||||
$newArr = [];
|
StoreOrder::update([
|
||||||
$oid = [];
|
|
||||||
foreach ($data as $k =>$value){
|
|
||||||
$oid [] = $value['oid'];
|
|
||||||
$newArr[$k]['writeoff_time'] = time();
|
|
||||||
$newArr[$k]['id'] = $value['id'];
|
|
||||||
$newArr[$k]['is_writeoff'] = YesNoEnum::YES;
|
|
||||||
$newArr[$k]['update_time'] = time();
|
|
||||||
}
|
|
||||||
(new StoreOrderCartInfo())->saveAll($newArr);
|
|
||||||
$oidArr = array_values(array_unique($oid));
|
|
||||||
StoreOrder::whereIn('id',$oidArr)
|
|
||||||
->update([
|
|
||||||
'status' => OrderEnum::RECEIVED_GOODS,
|
'status' => OrderEnum::RECEIVED_GOODS,
|
||||||
'update_time' => time(),
|
'update_time' => time(),
|
||||||
]);
|
], ['id' => $data['id']]);
|
||||||
|
(new StoreOrderCartInfo())->update([
|
||||||
|
'writeoff_time' => time(),
|
||||||
|
'is_writeoff' => YesNoEnum::YES,
|
||||||
|
'update_time' => time(),
|
||||||
|
], ['oid' => $data['id']]);
|
||||||
|
$financeFlow = (new StoreFinanceFlowLogic)->getStoreOrder($data['id'], $data['store_id']);
|
||||||
|
if (!empty($financeFlow)) {
|
||||||
|
$capitalFlowLogic = new CapitalFlowLogic($data->store, 'store');
|
||||||
|
$capitalFlowLogic->storeIncome('store_order_income', 'order', $data['id'], $financeFlow['number']);
|
||||||
|
}
|
||||||
Db::commit();
|
Db::commit();
|
||||||
return true;
|
return true;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
@ -453,6 +453,4 @@ class OrderLogic extends BaseLogic
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,6 @@ class OrderValidate extends BaseValidate
|
|||||||
* @var string[]
|
* @var string[]
|
||||||
*/
|
*/
|
||||||
protected $rule = [
|
protected $rule = [
|
||||||
'order_id' => 'require|number',
|
|
||||||
'verify_code' => 'require',
|
'verify_code' => 'require',
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -27,7 +26,6 @@ class OrderValidate extends BaseValidate
|
|||||||
* @var string[]
|
* @var string[]
|
||||||
*/
|
*/
|
||||||
protected $field = [
|
protected $field = [
|
||||||
'order_id' => '订单',
|
|
||||||
'verify_code' => '验证码',
|
'verify_code' => '验证码',
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -40,7 +38,7 @@ class OrderValidate extends BaseValidate
|
|||||||
*/
|
*/
|
||||||
public function sceneCheck()
|
public function sceneCheck()
|
||||||
{
|
{
|
||||||
return $this->only(['order_id','verify_code']);
|
return $this->only(['verify_code']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,10 +8,15 @@ class CapitalFlowLogic extends BaseLogic
|
|||||||
{
|
{
|
||||||
|
|
||||||
public $user;
|
public $user;
|
||||||
|
public $store;
|
||||||
|
|
||||||
public function __construct($user)
|
public function __construct($obj, $type = 'user')
|
||||||
{
|
{
|
||||||
$this->user = $user;
|
if (isset($type)) {
|
||||||
|
$this->user = $obj;
|
||||||
|
} else {
|
||||||
|
$this->store = $obj;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -77,21 +82,22 @@ class CapitalFlowLogic extends BaseLogic
|
|||||||
* @param $mark
|
* @param $mark
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function merchantIncome($category, $linkType, $linkId, $amount, $mark = '')
|
public function storeIncome($category, $linkType, $linkId, $amount, $mark = '')
|
||||||
{
|
{
|
||||||
$model = new CapitalFlow();
|
$model = new CapitalFlow();
|
||||||
$model->mer_id = $this->user['mer_id'];
|
$model->store_id = $this->store['store_id'];
|
||||||
$model->category = $category;
|
$model->category = $category;
|
||||||
$model->link_type = $linkType;
|
$model->link_type = $linkType;
|
||||||
$model->link_id = $linkId;
|
$model->link_id = $linkId;
|
||||||
$model->amount = $amount;
|
$model->amount = $amount;
|
||||||
$model->before_balance = $this->user['mer_money'];
|
$model->before_balance = $this->store['balance'];
|
||||||
$model->balance = bcadd($this->user['mer_money'], $amount, 2);
|
$model->balance = bcadd($this->store['balance'], $amount, 2);
|
||||||
$model->create_time = date('Y-m-d H:i:s');
|
$model->create_time = date('Y-m-d H:i:s');
|
||||||
$model->type = 'in';
|
$model->type = 'in';
|
||||||
$model->title = $this->getTitle($category, $amount);
|
$model->title = $this->getTitle($category, $amount);
|
||||||
$model->mark = empty($mark) ? $model->title : $mark;
|
$model->mark = empty($mark) ? $model->title : $mark;
|
||||||
$model->save();
|
$model->save();
|
||||||
|
$this->store->update(['balance' => $model->balance], ['id' => $this->store['id']]);
|
||||||
return $model->id;
|
return $model->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,22 +110,23 @@ class CapitalFlowLogic extends BaseLogic
|
|||||||
* @param $mark
|
* @param $mark
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function merchantExpense($category, $linkType, $linkId, $amount, $mark = '')
|
public function storeExpense($category, $linkType, $linkId, $amount, $mark = '')
|
||||||
{
|
{
|
||||||
$model = new CapitalFlow();
|
$model = new CapitalFlow();
|
||||||
$model->mer_id = $this->user['mer_id'];
|
$model->store_id = $this->store['store_id'];
|
||||||
$model->uid = $this->user['uid'];
|
$model->uid = 0;
|
||||||
$model->category = $category;
|
$model->category = $category;
|
||||||
$model->link_type = $linkType;
|
$model->link_type = $linkType;
|
||||||
$model->link_id = $linkId;
|
$model->link_id = $linkId;
|
||||||
$model->amount = $amount;
|
$model->amount = $amount;
|
||||||
$model->before_balance = $this->user['mer_money'];
|
$model->before_balance = $this->store['balance'];
|
||||||
$model->balance = bcsub($this->user['mer_money'], $amount, 2);
|
$model->balance = bcsub($this->store['balance'], $amount, 2);
|
||||||
$model->create_time = date('Y-m-d H:i:s');
|
$model->create_time = date('Y-m-d H:i:s');
|
||||||
$model->type = 'out';
|
$model->type = 'out';
|
||||||
$model->title = $this->getTitle($category, $amount);
|
$model->title = $this->getTitle($category, $amount);
|
||||||
$model->mark = empty($mark) ? $model->title : $mark;
|
$model->mark = empty($mark) ? $model->title : $mark;
|
||||||
$model->save();
|
$model->save();
|
||||||
|
$this->store->update(['balance' => $model->balance], ['id' => $this->store['id']]);
|
||||||
return $model->id;
|
return $model->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,15 +135,15 @@ class CapitalFlowLogic extends BaseLogic
|
|||||||
switch ($category) {
|
switch ($category) {
|
||||||
case 'user_balance_recharge':
|
case 'user_balance_recharge':
|
||||||
return "用户充值{$amount}元";
|
return "用户充值{$amount}元";
|
||||||
case 'merchant_margin':
|
case 'store_margin':
|
||||||
return "店铺自动扣除保证金{$amount}元";
|
return "店铺自动扣除保证金{$amount}元";
|
||||||
case 'merchant_order_income':
|
case 'store_order_income':
|
||||||
return "店铺订单收入{$amount}元";
|
return "店铺订单收入{$amount}元";
|
||||||
case 'user_order_refund':
|
case 'user_order_refund':
|
||||||
return "用户订单退款{$amount}元";
|
return "用户订单退款{$amount}元";
|
||||||
case 'merchant_order_refund':
|
case 'store_order_refund':
|
||||||
return "店铺订单退款{$amount}元";
|
return "店铺订单退款{$amount}元";
|
||||||
case 'merchant_margin_refund':
|
case 'store_margin_refund':
|
||||||
return "店铺退还保证金{$amount}元";
|
return "店铺退还保证金{$amount}元";
|
||||||
case 'user_order_promotion':
|
case 'user_order_promotion':
|
||||||
return "订单推广佣金{$amount}元";
|
return "订单推广佣金{$amount}元";
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace app\common\logic;
|
namespace app\common\logic;
|
||||||
|
|
||||||
|
use app\common\enum\OrderEnum;
|
||||||
use app\common\model\store_finance_flow\StoreFinanceFlow;
|
use app\common\model\store_finance_flow\StoreFinanceFlow;
|
||||||
|
|
||||||
class StoreFinanceFlowLogic extends BaseLogic
|
class StoreFinanceFlowLogic extends BaseLogic
|
||||||
@ -72,4 +73,13 @@ class StoreFinanceFlowLogic extends BaseLogic
|
|||||||
return 'fn' . $msectime . mt_rand(10000, max(intval($msec * 10000) + 10000, 98369));
|
return 'fn' . $msectime . mt_rand(10000, max(intval($msec * 10000) + 10000, 98369));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getStoreOrder($orderId, $storeId = 0, $status = 0)
|
||||||
|
{
|
||||||
|
return StoreFinanceFlow::where('order_id', $orderId)
|
||||||
|
->where('store_id', $storeId)
|
||||||
|
->where('status', $status)
|
||||||
|
->where('financial_type', OrderEnum::MERCHANT_ORDER_OBTAINS)
|
||||||
|
->find();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ namespace app\common\model\store_order;
|
|||||||
|
|
||||||
|
|
||||||
use app\common\model\BaseModel;
|
use app\common\model\BaseModel;
|
||||||
|
use app\common\model\system_store\SystemStore;
|
||||||
use think\model\concern\SoftDelete;
|
use think\model\concern\SoftDelete;
|
||||||
|
|
||||||
|
|
||||||
@ -18,5 +19,9 @@ class StoreOrder extends BaseModel
|
|||||||
protected $name = 'store_order';
|
protected $name = 'store_order';
|
||||||
protected $deleteTime = 'delete_time';
|
protected $deleteTime = 'delete_time';
|
||||||
|
|
||||||
|
public function store()
|
||||||
|
{
|
||||||
|
return $this->hasOne(SystemStore::class, 'id','store_id');
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -80,6 +80,7 @@ class StoreProductController extends BaseAdminController
|
|||||||
ApiDoc\url('/store/store_product/storeProduct/edit'),
|
ApiDoc\url('/store/store_product/storeProduct/edit'),
|
||||||
ApiDoc\Method('POST'),
|
ApiDoc\Method('POST'),
|
||||||
ApiDoc\NotHeaders(),
|
ApiDoc\NotHeaders(),
|
||||||
|
ApiDoc\Query(name: "id", type: "int", require: true, desc: "id"),
|
||||||
ApiDoc\Header(name: "token", type: "string", require: true, desc: "token"),
|
ApiDoc\Header(name: "token", type: "string", require: true, desc: "token"),
|
||||||
ApiDoc\ResponseSuccess("data", type: "array", children: [
|
ApiDoc\ResponseSuccess("data", type: "array", children: [
|
||||||
['name' => 'id', 'desc' => 'ID', 'type' => 'int'],
|
['name' => 'id', 'desc' => 'ID', 'type' => 'int'],
|
||||||
@ -108,6 +109,7 @@ class StoreProductController extends BaseAdminController
|
|||||||
ApiDoc\url('/store/store_product/storeProduct/delete'),
|
ApiDoc\url('/store/store_product/storeProduct/delete'),
|
||||||
ApiDoc\Method('POST'),
|
ApiDoc\Method('POST'),
|
||||||
ApiDoc\NotHeaders(),
|
ApiDoc\NotHeaders(),
|
||||||
|
ApiDoc\Param(name: "id", type: "int", require: true, desc: "id"),
|
||||||
ApiDoc\Header(name: "token", type: "string", require: true, desc: "token"),
|
ApiDoc\Header(name: "token", type: "string", require: true, desc: "token"),
|
||||||
ApiDoc\ResponseSuccess("data", type: "array", children: [
|
ApiDoc\ResponseSuccess("data", type: "array", children: [
|
||||||
['name' => 'id', 'desc' => 'ID', 'type' => 'int'],
|
['name' => 'id', 'desc' => 'ID', 'type' => 'int'],
|
||||||
@ -133,6 +135,7 @@ class StoreProductController extends BaseAdminController
|
|||||||
ApiDoc\url('/store/store_product/storeProduct/detail'),
|
ApiDoc\url('/store/store_product/storeProduct/detail'),
|
||||||
ApiDoc\Method('GET'),
|
ApiDoc\Method('GET'),
|
||||||
ApiDoc\NotHeaders(),
|
ApiDoc\NotHeaders(),
|
||||||
|
ApiDoc\Query(name: "id", type: "int", require: true, desc: "id"),
|
||||||
ApiDoc\Header(name: "token", type: "string", require: true, desc: "token"),
|
ApiDoc\Header(name: "token", type: "string", require: true, desc: "token"),
|
||||||
ApiDoc\ResponseSuccess("data", type: "array", children: [
|
ApiDoc\ResponseSuccess("data", type: "array", children: [
|
||||||
['name' => 'id', 'desc' => 'ID', 'type' => 'int'],
|
['name' => 'id', 'desc' => 'ID', 'type' => 'int'],
|
||||||
@ -158,6 +161,7 @@ class StoreProductController extends BaseAdminController
|
|||||||
ApiDoc\url('/store/store_product/storeProduct/status'),
|
ApiDoc\url('/store/store_product/storeProduct/status'),
|
||||||
ApiDoc\Method('POST'),
|
ApiDoc\Method('POST'),
|
||||||
ApiDoc\NotHeaders(),
|
ApiDoc\NotHeaders(),
|
||||||
|
ApiDoc\Param(name: "id", type: "int", require: true, desc: "id"),
|
||||||
ApiDoc\Header(name: "token", type: "string", require: true, desc: "token"),
|
ApiDoc\Header(name: "token", type: "string", require: true, desc: "token"),
|
||||||
ApiDoc\ResponseSuccess("data", type: "array"),
|
ApiDoc\ResponseSuccess("data", type: "array"),
|
||||||
]
|
]
|
||||||
@ -165,7 +169,7 @@ class StoreProductController extends BaseAdminController
|
|||||||
{
|
{
|
||||||
$params = (new StoreProductValidate())->post()->goCheck('detail');
|
$params = (new StoreProductValidate())->post()->goCheck('detail');
|
||||||
StoreBranchProductLogic::status($params);
|
StoreBranchProductLogic::status($params);
|
||||||
return $this->data([]);
|
return $this->success('操作成功', [], 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[
|
#[
|
||||||
@ -183,7 +187,7 @@ class StoreProductController extends BaseAdminController
|
|||||||
{
|
{
|
||||||
$params = (new StoreProductValidate())->post()->goCheck('stock');
|
$params = (new StoreProductValidate())->post()->goCheck('stock');
|
||||||
StoreBranchProductLogic::stock($params);
|
StoreBranchProductLogic::stock($params);
|
||||||
return $this->data([]);
|
return $this->success('操作成功', [], 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user