Merge pull request 'dev' (#145) from dev into master

Reviewed-on: #145
This commit is contained in:
mkm 2024-01-28 17:51:15 +08:00
commit 0a4bacb5d2
14 changed files with 166 additions and 68 deletions

View File

@ -23,6 +23,7 @@ use app\common\repositories\store\product\SpuRepository;
use think\db\Query;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\Log;
/**
*
@ -147,18 +148,19 @@ class StoreActivityDao extends BaseDao
if (empty($productIds)) {
return;
}
$find = StoreActivityOrderProduct::where('user_id', $order['uid'])->where('status', 1)->find();
// $find = StoreActivityOrderProduct::where('user_id', $order['uid'])->where('status', 1)->find();
foreach ($productIds as $productId) {
if (!empty($find['product_id']) && $find['product_id'] == $productId && $activityId == 2) {
throw new ValidateException('活动商品限购1个');
}
// if (!empty($find['product_id']) && $find['product_id'] == $productId && $activityId == 2) {
// throw new ValidateException('活动商品限购1个');
// }
$model = new StoreActivityOrderProduct();
$model->user_id = $order['uid'];
$model->activity_id = $activityId;
$model->product_id = $productId;
$model->number = 1;
if (!$model->save()) {
throw new ValidateException('活动商品数据保存失败');
Log::error('活动商品数据保存失败productId'.$productId);
// throw new ValidateException('活动商品数据保存失败');
}
}
}

View File

@ -16,8 +16,30 @@ use think\facade\Db;
class StoreConsumptionUserDao extends BaseDao
{
/** @var float $maxAmount 单笔订单计算红包的最大有效金额 */
public $maxAmount = 20000;
/** @var float $orderTotalPrice 订单总金额 */
public $orderTotalPrice;
/** @var float $orderPayPrice 订单实付金额 */
public $orderPayPrice;
/** @var float $orderProductPrice 当前商品金额 */
public $orderProductPrice;
/** @var float $realPriceTotal 扣除红包后实际支付金额 */
public $realPriceTotal = 0;
/** @var float $isLast 是否最后一条数据 */
public $isLast = false;
/** @var float $groupOrderTotalPrice 订单组总金额 */
public $groupOrderTotalPrice;
/** @var float $consumptionTotalAmount 红包总金额 */
public $consumptionTotalAmount;
protected function getModel(): string
{
return StoreConsumptionUser::class;
@ -281,4 +303,59 @@ class StoreConsumptionUserDao extends BaseDao
}
}
/**
* 根据订单商品计算实际金额和红包金额
* @return array
*/
public function calculate()
{
// 把所有金额转换成分,避免红包金额产生误差
$orderTotalPrice = $this->orderTotalPrice * 100;
$orderPayPrice = $this->orderPayPrice * 100;
$productPrice = $this->orderProductPrice * 100;
$realPriceTotal = $this->realPriceTotal * 100;
$consumptionAmount = 0;
if ($orderTotalPrice == $orderPayPrice) {
$realPrice = $productPrice;
} else {
$rate = bcdiv($productPrice, $orderTotalPrice, 5);
$realPrice = $this->isLast ? bcsub($orderPayPrice, $realPriceTotal, 2) : ceil(bcmul($orderPayPrice, $rate, 5));
$consumptionAmount = $productPrice - $realPrice;
$realPriceTotal += $realPrice;
}
$realPrice = bcdiv($realPrice, 100, 2);
$consumptionAmount = bcdiv($consumptionAmount, 100, 2);
$realPriceTotal = bcdiv($realPriceTotal, 100, 2);
/** $realPrice实际支付的金额$realPriceTotal实际支付金额总计$consumptionAmount红包金额总计 */
return [$realPrice, $realPriceTotal, $consumptionAmount];
}
/**
* 根据订单计算实际金额和红包金额
* @return array
*/
public function calculateByOrder()
{
// 把所有金额转换成分,避免红包金额产生误差
$orderTotalPrice = $this->orderTotalPrice * 100;
$groupOrderTotalPrice = $this->groupOrderTotalPrice * 100;
$consumptionBalance = $this->consumptionTotalAmount * 100;
$rate = bcdiv($orderTotalPrice, $groupOrderTotalPrice, 5);
if ($consumptionBalance >= $orderTotalPrice) {
$useAmount = $orderTotalPrice;
} else {
$useAmount = $this->isLast ? $consumptionBalance : ceil(bcmul($consumptionBalance, $rate, 5));
}
$consumptionBalance -= $useAmount;
$payPrice = $orderTotalPrice - $useAmount;
$groupOrderTotalPrice -= $useAmount;
$payPrice = bcdiv($payPrice, 100, 2);
$useAmount = bcdiv($useAmount, 100, 2);
$consumptionBalance = bcdiv($consumptionBalance, 100, 2);
$groupOrderTotalPrice = bcdiv($groupOrderTotalPrice, 100, 2);
/** $payPrice实际支付的金额$groupOrderTotalPrice实际支付金额总计$useAmount红包金额总计$consumptionAmount红包余额总计 */
return [$payPrice, $groupOrderTotalPrice, $useAmount, $consumptionBalance];
}
}

View File

@ -241,7 +241,7 @@ class ProductDao extends BaseDao
}
app()->make(SpuRepository::class)->getSearch(['product_id' => $id])->update(['is_del' => 1, 'status' => 0]);
event('product.delete',compact('id'));
event('product.sell', ['product_id' => [$id]]);
event('product.sell', ['product_id' => [$id], 'status' => 0]);
}
/**

View File

@ -2,6 +2,7 @@
namespace app\common\repositories\store\order;
use app\common\dao\store\consumption\StoreConsumptionUserDao;
use app\common\dao\store\order\StoreCartDao;
use app\common\dao\store\StoreActivityDao;
use app\common\model\store\order\StoreGroupOrder;
@ -589,13 +590,6 @@ class StoreOrderCreateRepository extends StoreOrderRepository
} else {
$pay_price = $org_price;
}
//计算总红包金额
if ($source == 105) {
$this->consumption_money = bcsub($pay_price, 2, 2);
$pay_price =2; ;
$this->balance = 0;
$consumption_coupon_id=100;
}
$giveIntegralFlag = $sysIntegralConfig['integral_status'] && $sysIntegralConfig['integral_order_rate'] > 0;
@ -638,30 +632,38 @@ class StoreOrderCreateRepository extends StoreOrderRepository
}
$consumptionTotal = min($consumptionTotal, $this->balance);
}
$groupOrderPayPrice = $order_total_price;
foreach ($merchantCartList as $k => &$merchantCart) {
$isLast = count($merchantCartList) == $k + 1;
$merchantPrice = 0;
foreach ($merchantCart['list'] as &$cart) {
$cart['total_price'] = bcadd($cart['total_price'], $cart['svip_discount'], 2);
}
$orderPayPrice = $merchantCart['order']['total_price'];
if ($consumptionTotal) {
// 按当前店铺的商品金额计算使用的红包金额
$rate = bcdiv($merchantCart['order']['total_price'], $order_total_price, 6);
if ($consumptionTotal >= $order_total_price) {
$useAmount = $merchantCart['order']['total_price'];
} else {
$useAmount = $isLast ? bcsub($consumptionTotal, $this->consumption_money, 2) : bcmul($consumptionTotal, $rate, 2);
}
$merchantProductPrice = bcsub($merchantCart['order']['total_price'], $useAmount, 2);
$merchantPrice = bcadd($merchantPrice, $merchantProductPrice, 2);
$storeConsumptionUserDao = new StoreConsumptionUserDao();
$storeConsumptionUserDao->groupOrderTotalPrice = $groupOrderPayPrice;
$storeConsumptionUserDao->orderTotalPrice = $orderPayPrice;
$storeConsumptionUserDao->consumptionTotalAmount = $consumptionTotal;
$storeConsumptionUserDao->isLast = $isLast;
[$orderPayPrice, $groupOrderPayPrice, $useAmount, $consumptionTotal] = $storeConsumptionUserDao->calculateByOrder();
$this->consumption_money = bcadd($this->consumption_money, $useAmount, 2);
$this->balance = bcsub($this->balance, $useAmount, 2);
}
if ($source == 105) {
$this->consumption_money = bcsub($orderPayPrice, 2, 2);
$useAmount = $this->consumption_money;
$orderPayPrice = '2.00';
$groupOrderPayPrice = $orderPayPrice;
$order_total_price = $orderPayPrice;
$this->balance = 0;
$consumption_coupon_id = 100;
}
unset($cart);
$merchantCart['order']['consumption_money'] = $useAmount ?? '0.00';
$merchantCart['order']['real_price'] = $merchantPrice;
$merchantCart['order']['pay_price'] = $orderPayPrice;
$merchantCart['order']['total_price'] = bcadd($merchantCart['order']['total_price'], $merchantCart['order']['svip_discount'], 2);
$order_total_price = bcadd($order_total_price, $merchantCart['order']['svip_discount'], 2);
}
@ -669,8 +671,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
$status = ($address || $order_model || $allow_no_address) ? ($noDeliver ? 'noDeliver' : 'finish') : 'noAddress';
$order = $merchantCartList;
$consumption_money = $this->consumption_money;
$order_total_price = bcsub($order_total_price, $this->consumption_money, 2);
$order_price = $order_total_price;
$order_price = $groupOrderPayPrice;
$total_price = $order_total_price;
$openIntegral = $merIntegralFlag && !$order_type && $sysIntegralConfig['integral_status'] && $sysIntegralConfig['integral_money'] > 0;
$total_coupon = bcadd($order_svip_discount, bcadd(bcadd($total_platform_coupon_price, $order_coupon_price, 2), $order_total_integral_price, 2), 2);

View File

@ -164,8 +164,7 @@ class StoreOrderRepository extends BaseRepository
Db::commit();
} catch (Exception $e) {
Db::rollback();
halt($e);
throw new ValidateException('余额支付失败');
throw new ValidateException('余额支付失败'.$e->getMessage());
}
return app('json')->status('success', '余额支付成功', ['order_id' => $groupOrder['group_order_id']]);

View File

@ -14,6 +14,7 @@
namespace app\common\repositories\store\order;
use app\common\dao\store\consumption\StoreConsumptionUserDao;
use app\common\dao\store\order\StoreRefundOrderDao;
use app\common\model\store\order\StoreGroupOrder;
use app\common\model\store\order\StoreOrder;
@ -230,7 +231,7 @@ class StoreRefundOrderRepository extends BaseRepository
* 按订单实付金额退款
* @param $order
* @param $products
* @return string
* @return array
*/
public function getOrderRefundPrice($order, $products)
{
@ -238,9 +239,17 @@ class StoreRefundOrderRepository extends BaseRepository
$totalPostage = 0;
$totalRefundPrice = 0;
$realPriceTotal = 0;
$consumptionTotal = 0;
foreach ($products as $k => $product) {
$isLast = count($products->toArray()) == ($k + 1);
[$realPrice, $realPriceTotal] = $this->calculate($order['total_price'], $order['pay_price'], $product['product_price'], $realPriceTotal, $isLast);
$storeConsumptionUserDao = new StoreConsumptionUserDao();
$storeConsumptionUserDao->orderTotalPrice = $order['total_price'];
$storeConsumptionUserDao->orderPayPrice = $order['pay_price'];
$storeConsumptionUserDao->orderProductPrice = $product['product_price'];
$storeConsumptionUserDao->realPriceTotal = $realPriceTotal;
$storeConsumptionUserDao->isLast = $isLast;
[$realPrice, $realPriceTotal, $consumptionPrice] = $storeConsumptionUserDao->calculate();
$consumptionTotal = bcadd($consumptionTotal, $consumptionPrice, 2);
$productRefundPrice = $productRefundPrices[$product['order_product_id']] ?? [];
$postagePrice = (!$order->status || $order->status == 9) ? bcsub($product['postage_price'], $productRefundPrice['refund_postage'] ?? 0, 2) : 0;
$refundPrice = 0;
@ -250,7 +259,7 @@ class StoreRefundOrderRepository extends BaseRepository
$totalPostage = bcadd($totalPostage, $postagePrice, 2);
$totalRefundPrice = bcadd($totalRefundPrice, $refundPrice, 2);
}
return bcadd($totalPostage, $totalRefundPrice, 2);
return [bcadd($totalPostage, $totalRefundPrice, 2), $consumptionTotal];
}
public function getRefundsTotalPrice($order, $products)
@ -276,28 +285,15 @@ class StoreRefundOrderRepository extends BaseRepository
$productRefundPrices = app()->make(StoreRefundProductRepository::class)->userRefundPrice($products->column('order_product_id'));
$product = $products[0];
$productRefundPrice = $productRefundPrices[$product['order_product_id']] ?? [];
[$realPrice, $realPriceTotal] = $this->calculate($order['total_price'], $order['pay_price'], $product['product_price'], 0);
$storeConsumptionUserDao = new StoreConsumptionUserDao();
$storeConsumptionUserDao->orderTotalPrice = $order['total_price'];
$storeConsumptionUserDao->orderPayPrice = $order['pay_price'];
$storeConsumptionUserDao->orderProductPrice = $product['product_price'];
[$realPrice, $realPriceTotal, $consumptionPrice] = $storeConsumptionUserDao->calculate();
$total_refund_price = bcsub($realPrice, bcsub($productRefundPrice['refund_price'] ?? 0, $productRefundPrice['refund_postage'] ?? 0, 2), 2);
$postage_price = (!$order->status || $order->status == 9) ? bcsub($product['postage_price'], $productRefundPrice['refund_postage'] ?? 0, 2) : 0;
return compact('total_refund_price', 'postage_price');
}
/**
* 计算退款金额
* @param float $orderTotalPrice 订单总金额
* @param float $orderPayPrice 订单实付金额
* @param float $productPrice 商品总金额
* @param float $realPriceTotal 实付金额合计
* @param bool $isLast 是否最后一条
* @return array
*/
public function calculate($orderTotalPrice, $orderPayPrice, $productPrice, $realPriceTotal, $isLast = false)
{
$rate = bcdiv($productPrice, $orderTotalPrice, 5);
$realPrice = $isLast ? bcsub($orderPayPrice, $realPriceTotal, 2) : bcmul($orderPayPrice, $rate, 2);
$realPriceTotal = bcadd($realPriceTotal, $realPrice, 2);
return [$realPrice, $realPriceTotal];
return compact('total_refund_price', 'postage_price', 'consumptionPrice');
}
/**
@ -331,7 +327,8 @@ class StoreRefundOrderRepository extends BaseRepository
$totalPostage = 0;
$refundProduct = [];
$refund_order_id = 0;
foreach ($products as $product) {
$consumptionTotal = 0;
foreach ($products as $k => $product) {
$productRefundPrice = $productRefundPrices[$product['order_product_id']] ?? [];
if ($product['extension_one'] > 0)
$total_extension_one = bcadd($total_extension_one, bcmul($product['refund_num'], $product['extension_one'], 2), 2);
@ -341,9 +338,18 @@ class StoreRefundOrderRepository extends BaseRepository
$totalRefundNum += $product['refund_num'];
$refundPrice = 0;
//计算可退金额
if ($product['product_price'] > 0) {
$refundPrice = bcsub($product['product_price'], bcsub($productRefundPrice['refund_price'] ?? 0, $productRefundPrice['refund_postage'] ?? 0, 2), 2);
if ($order['total_price'] > 0) {
$isLast = count($products->toArray()) == ($k + 1);
$storeConsumptionUserDao = new StoreConsumptionUserDao();
$storeConsumptionUserDao->orderTotalPrice = $order['total_price'];
$storeConsumptionUserDao->orderPayPrice = $order['pay_price'];
$storeConsumptionUserDao->orderProductPrice = $product['product_price'];
$storeConsumptionUserDao->realPriceTotal = $totalRefundPrice;
$storeConsumptionUserDao->isLast = $isLast;
[$refundPrice, $totalRefundPrice, $consumptionPrice] = $storeConsumptionUserDao->calculate();
$consumptionTotal = bcadd($consumptionTotal, $consumptionPrice, 2);
}
$platform_refund_price = 0;
//计算退的平台优惠券金额
if ($product['platform_coupon_price'] > 0) {
@ -355,7 +361,6 @@ class StoreRefundOrderRepository extends BaseRepository
}
$totalPostage = bcadd($totalPostage, $postagePrice, 2);
$totalRefundPrice = bcadd($totalRefundPrice, $refundPrice, 2);
$totalPlatformRefundPrice = bcadd($totalPlatformRefundPrice, $platform_refund_price, 2);
$totalIntegral = bcadd($totalIntegral, $integral, 2);
@ -366,6 +371,7 @@ class StoreRefundOrderRepository extends BaseRepository
'platform_refund_price' => $platform_refund_price,
'refund_integral' => $integral,
'refund_price' => $refundPrice,
'refund_consumption' => $consumptionPrice,
'refund_postage' => $postagePrice,
];
}
@ -377,6 +383,7 @@ class StoreRefundOrderRepository extends BaseRepository
$data['extension_one'] = $total_extension_one;
$data['extension_two'] = $total_extension_two;
$data['refund_price'] = bcadd($totalPostage, $totalRefundPrice, 2);
$data['refund_consumption'] = $consumptionTotal;
$data['integral'] = $totalIntegral;
$data['platform_refund_price'] = $totalPlatformRefundPrice;
$data['refund_postage'] = $totalPostage;

View File

@ -319,14 +319,14 @@ class ProductRepository extends BaseRepository
app()->make(SpuRepository::class)->baseUpdate($spuData, $id, 0, $productType);
event('product.update', compact('id'));
if ($data['status'] == 0) {
event('product.sell', ['product_id' => [$id]]);
event('product.sell', ['product_id' => [$id],'status'=>$data['status']]);
}
app()->make(SpuRepository::class)->changeStatus($id, $productType);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
return false;
return $e->getMessage();
}
}
@ -1746,7 +1746,6 @@ class ProductRepository extends BaseRepository
*/
public function switchStatus($id, $data)
{
halt($data);
$product = $this->getSearch([])->find($id);
if(!$product) throw new ValidateException('商品不存在');
$this->dao->update($id, $data);

View File

@ -32,8 +32,6 @@ class FinancialRecordTransfer extends BaseController
public function lst()
{
halt(1);
[$page, $limit] = $this->getPage();
$where = $this->request->params(['keyword', 'date', 'mer_id']);
$merId = $this->request->merId();

View File

@ -734,7 +734,10 @@ class Auth extends BaseController
if (!$sms_code && !env('APP_DEBUG')) return app('json')->fail('验证码不正确');
$user = $repository->accountByUser($data['phone']);
$auth = $this->parseAuthToken($data['auth_token']);
if (!$user) $user = $repository->registr($data['phone'], null, $data['user_type']);
if (!$user) {
$isNewUser = true;
$user = $repository->registr($data['phone'], null, $data['user_type']);
}
if ($auth && !$user['wechat_user_id']) {
$repository->syncBaseAuth($auth, $user);
}
@ -744,7 +747,7 @@ class Auth extends BaseController
$tokenInfo = $repository->createToken($user);
$repository->loginAfter($user);
return app('json')->success($repository->returnToken($user, $tokenInfo));
return app('json')->success(array_merge(['is_new_user' => $isNewUser ?? false], $repository->returnToken($user, $tokenInfo)));
}
public function changePassword(ChangePasswordValidate $validate, UserRepository $repository)

View File

@ -21,6 +21,7 @@ use Exception;
use ZipArchive;
use think\facade\Queue;
use crmeb\jobs\ProductCopyJob;
use app\controller\api\store\order\StoreProcessing;
/**
* Class Auth
@ -32,7 +33,11 @@ class Demo extends BaseController
{
public function index()
{
return app('json')->success('修改成功');
return app('json')->success('修改成功');
$find= Db::name('store_order')->where('order_id',78)->find();
$StoreProcessing= app()->make(StoreProcessing::class);
$a= $StoreProcessing->AutomaticallyCreateOrders($find);
halt($a);
//[31,32,118,39,167,236,237,238,239]
// return app('json')->success('修改成功');>whereIn('mer_id',[110,116,149,227,226,35,117,148,156,104,137,151,136,183,140,229,79,133,235])->
// $merchant = Db::name('merchant')->where('mer_id', 31)->find();

View File

@ -23,10 +23,11 @@ class StoreProcessing extends BaseController
$merchant_two = Db::name('merchant')->where('mer_id', $order['mer_id'])->find();
$store_group_order = Db::name('store_group_order')->where('group_order_id', $order['group_order_id'])->find();
$store_group_order_other = Db::name('store_group_order_other')->where('group_order_sn', $order['order_sn'])->find();
if (!$store_group_order_other) {
unset($store_group_order['group_order_id']);
$group_order_id = Db::name('store_group_order_other')->strict(false)->insertGetId($store_group_order);
}else{
$group_order_id=$store_group_order_other['group_order_id'];
}
$select = Db::name('store_order_product')->where('order_id', $order['order_id'])->select();
if ($order['source'] == 103 ||$order['source'] == 105 && $select) {
@ -54,6 +55,7 @@ class StoreProcessing extends BaseController
}
// $financialRecordRepository->insertAll($finance);
Db::name('store_order_product_other')->strict(false)->insertAll($arr);
return $order_id;
}
}
}

View File

@ -91,16 +91,17 @@ class StoreRefundOrder extends BaseController
if (count($product) != count($ids))
return app('json')->fail('请选择正确的退款商品');
if ($type == 2) {
$total_refund_price = $this->repository->getOrderRefundPrice($order, $product);
[$total_refund_price, $consumptionPrice] = $this->repository->getOrderRefundPrice($order, $product);
$postage_price = 0;
} else {
$data = $this->repository->getRefundTotalPrice($order, $product);
$total_refund_price = (float)$data['total_refund_price'];
$postage_price = (float)$data['postage_price'];
$consumptionPrice = (float)$data['consumptionPrice'];
}
$status = (!$order->status || $order->status == 9) ? 0 : $order->status;
$activity_type = $order->activity_type;
return app('json')->success(compact('activity_type', 'total_refund_price', 'product', 'postage_price', 'status'));
return app('json')->success(compact('activity_type', 'total_refund_price', 'product', 'postage_price', 'status', 'consumptionPrice'));
}
/**

View File

@ -145,7 +145,7 @@ class StoreOrderBehalf extends BaseController
// $find = Db::name('store_order_other')->where('uid', $uid)->where('order_id', $id)->find();
// $find_two = Db::name('store_order')->where('order_sn', $find['order_sn'])->find();
if($res){
$order = StoreOrder::where('order_sn', $orderOther['order_sn'])->field('user_phone,order_type,logistics_code,logistics_phone')->find()->toArray();
$order = StoreOrder::where('order_sn', $orderOther['order_sn'])->find()->toArray();
if($status==3 && $order['order_type'] == 1){
SmsService::create()->send($order['user_phone'], 'RECEIVE_NOTICE', ['code' => $order['logistics_code'], 'name' => $merchant['mer_name']]);
} elseif($status==3 && $order['order_type'] != 1){

View File

@ -132,8 +132,12 @@ class Product extends BaseController
$data['update_time'] = date('Y-m-d H:i:s');
$typeSupplyChainId = Db::name('MerchantType')->where('type_code', Merchant::TypeCode['TypeSupplyChain'])->value('mer_type_id');
$productType = $this->request->merchant()->type_id == $typeSupplyChainId ? 98 : 0;
$this->repository->edit($id, $data, $this->request->merId(), $productType, 1);
return app('json')->success('编辑成功');
$res=$this->repository->edit($id, $data, $this->request->merId(), $productType, 1);
if($res===true){
return app('json')->success('编辑成功');
}else{
return app('json')->fail('编辑失败'.$res);
}
}
/**