订单确认收货,写入计息数据

This commit is contained in:
luofei 2023-06-27 17:59:35 +08:00
parent 10d3db55ff
commit b4be5a65b4
9 changed files with 148 additions and 36 deletions

View File

@ -91,6 +91,9 @@ class StoreOrderDao extends BaseDao
->when(isset($where['activity_type']) && $where['activity_type'] != '', function ($query) use ($where) {
$query->where('activity_type', $where['activity_type']);
})
->when(isset($where['product_type']) && $where['product_type'] != '', function ($query) use ($where) {
$query->where('activity_type', $where['product_type']);
})
->when(isset($where['status']) && $where['status'] !== '', function ($query) use ($where) {
switch ($where['status']) {
case 0 :

View File

@ -177,4 +177,10 @@ class StoreOrder extends BaseModel
{
return StoreRefundOrder::where('order_id',$this->order_id)->where('status',3)->sum('refund_price');
}
public function interest()
{
return $this->hasOne(StoreOrderInterest::class, 'order_id', 'order_id');
}
}

View File

@ -0,0 +1,23 @@
<?php
namespace app\common\model\store\order;
use app\common\model\BaseModel;
class StoreOrderInterest extends BaseModel
{
const STATUS_SETTLED = 1; //已结算
const STATUS_UNSETTLED = 0; //未结算
public static function tablePk(): ?string
{
return 'id';
}
public static function tableName(): string
{
return 'store_order_interest';
}
}

View File

@ -0,0 +1,18 @@
<?php
namespace app\common\repositories\store\order;
use app\common\model\store\order\StoreOrderInterest;
use app\common\repositories\BaseRepository;
class StoreOrderInterestRepository extends BaseRepository
{
public function create($data)
{
$data['status'] = StoreOrderInterest::STATUS_UNSETTLED;
$model = new StoreOrderInterest();
return $model->insert($data);
}
}

View File

@ -1689,8 +1689,15 @@ class StoreOrderRepository extends BaseRepository
$order->presell_price = $order->pay_price;
}
}
if ($order->pay_type == StoreGroupOrder::PAY_TYPE_CREDIT_BUY && $order->interest) {
$order->interest_start_time = $order->interest->start_time;
$days = ceil((time() - strtotime($order->interest->start_time)) / 86400);
$interestMoney = bcmul($order->interest->total_price, $order->interest->rate, 2);
$order->interest_money = bcmul($days, $interestMoney, 2);
$order->interest_status = $order->interest->status;
}
$order->takeOrderCount = count($order['takeOrderList']);
unset($order['takeOrderList']);
unset($order['takeOrderList'], $order->interest);
}
return compact( 'count','list');

View File

@ -2299,4 +2299,51 @@ class ProductRepository extends BaseRepository
return true;
}
/**
* 导入商品
* @param $product_id
* @param $user
* @return bool
* @throws \Exception
*/
public function import($product_id, $user)
{
$mer_id = Db::name('store_service')->where('uid', $user['uid'])->where('status', 1)->value('mer_id');
if ($mer_id == 0) {
throw new \Exception('商户不存在');
}
$find = Db::name('store_product')->where('product_id', $product_id)->find();
if ($find) {
if ($find['product_type'] != 0) {
throw new \Exception('该商品不是普通商品');
}
$exist = Db::name('store_product')->where('old_product_id', $product_id)->where('mer_id', $mer_id)->find();
if ($exist) {
throw new \Exception('已经导入过该商品了');
}
$find['attrValue'] = Db::name('store_product_attr_value')->where('product_id', $find['product_id'])->field('image,price,cost,ot_price,svip_price,stock,bar_code,weight,volume')->select();
$find['content'] = Db::name('store_product_content')->where('product_id', $find['product_id'])->value('content');
$find['is_show'] = 0;
$find['mer_id'] = $mer_id;
$find['temp_id'] = "";
$find['give_coupon_ids'] = [];
$find['params'] = [];
$find['extend'] = [];
$find['param_temp_id'] = [];
$find['mer_labels'] = [];
$find['attr'] = [];
$find['delivery_way'] = [0 => "2"];
$find["guarantee_template_id"] = "";
$find['product_type'] = 0;
$find['mer_cate_id'] = [0 => 0];
$find['is_used'] = 1;
$find['status'] = 1;
$find['mer_status'] = 1;
$find['old_product_id'] = $product_id;
$find['slider_image'] = explode(',', $find['slider_image']);
unset($find['product_id'], $find['create_time']);
}
return $this->create($find, 0);
}
}

View File

@ -50,42 +50,13 @@ class StoreMicro extends BaseController
public function ProductImport(){
$product_id = $this->request->param('id', 0);
$user = $this->request->userInfo();
$mer_id =Db::name('store_service')->where('uid',$user['uid'])->where('status',1)->value('mer_id');
if ($mer_id==0) return app('json')->fail('商户id不能为空');
$find=Db::name('store_product')->where('product_id',$product_id)->find();
if($find){
if($find['product_type']!=0){
return app('json')->fail('该商品不是普通商品');
}
$exist = Db::name('store_product')->where('old_product_id', $product_id)->where('mer_id', $mer_id)->find();
if($exist){
return app('json')->fail('已经导入过该商品了');
}
$find['attrValue']=Db::name('store_product_attr_value')->where('product_id',$find['product_id'])->field('image,price,cost,ot_price,svip_price,stock,bar_code,weight,volume')->select();
$find['content']=Db::name('store_product_content')->where('product_id',$find['product_id'])->value('content');
$find['is_show']=0;
$find['mer_id']=$mer_id;
$find['temp_id']="";
$find['give_coupon_ids']=[];
$find['params']=[];
$find['extend']=[];
$find['param_temp_id']=[];
$find['mer_labels']=[];
$find['attr']=[];
$find['delivery_way']=[ 0 => "2"];
$find["guarantee_template_id"] = "";
$find['product_type']=0;
$find['mer_cate_id']=[0 => 0];
$find['is_used']=1;
$find['status']=1;
$find['mer_status']=1;
$find['old_product_id']=$product_id;
$find['slider_image']=explode(',',$find['slider_image']);
unset($find['product_id'],$find['create_time']);
try {
/** @var ProductRepository $productRepository */
$productRepository = app()->make(ProductRepository::class);
$a = $productRepository->import($product_id, $user);
} catch (\Exception $e) {
return app('json')->fail($e->getMessage());
}
/** @var ProductRepository $make */
$make = app()->make(ProductRepository::class);
$a=$make->create($find,0);
if($a){
return app('json')->success(['data'=>$a,'msg'=>'导入成功']);
}else{

View File

@ -67,6 +67,7 @@ return [
'product.create'=>[\app\listener\ProductCreate::class],
'product.sell'=>[\app\listener\CloudProduct::class], //商品上下架
'refund.after'=>[\app\listener\AfterRefund::class],
'order.take'=>[\app\listener\OrderTake::class],
],
'subscribe' => [],

View File

@ -0,0 +1,36 @@
<?php
declare (strict_types=1);
namespace app\listener;
use app\common\model\system\merchant\Merchant;
use app\common\repositories\store\order\StoreOrderInterestRepository;
/**
* 订单确认收货后置事件
*/
class OrderTake
{
public function handle($event)
{
$order = $event['order'];
if ($order['merchant']['interest_rate'] <= 0) {
return true;
}
/** @var StoreOrderInterestRepository $storeOrderInterestRepository */
$storeOrderInterestRepository = app()->make(StoreOrderInterestRepository::class);
$merchantId = Merchant::where('uid', $order['uid'])->value('mer_id');
$data = [
'order_id' => $order['order_id'],
'mer_id' => $merchantId,
'to_mer_id' => $order['mer_id'],
'total_price' => $order['total_price'],
'rate' => $order['merchant']['interest_rate'],
'start_time' => date('Y-m-d H:i:s', strtotime("+{$order['merchant']['settle_cycle']} days")),
];
return $storeOrderInterestRepository->create($data);
}
}