feat(ProductLogic): 添加新功能以计算店铺产品销售数据
This commit is contained in:
parent
15717de1d5
commit
443a50b0fe
@ -211,7 +211,8 @@ class StoreProductLogic extends BaseLogic
|
|||||||
'manufacturer_information' => $params['manufacturer_information']??'',
|
'manufacturer_information' => $params['manufacturer_information']??'',
|
||||||
'store_info' => $params['store_info']??'','cate_id'=>$params['cate_id'],
|
'store_info' => $params['store_info']??'','cate_id'=>$params['cate_id'],
|
||||||
'top_cate_id'=>$dealCate['top_cate_id'],'two_cate_id'=>$dealCate['two_cate_id'],
|
'top_cate_id'=>$dealCate['top_cate_id'],'two_cate_id'=>$dealCate['two_cate_id'],
|
||||||
'bar_code'=> $params['bar_code']
|
'bar_code'=> $params['bar_code'],
|
||||||
|
'purchase'=> $params['purchase'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Db::commit();
|
Db::commit();
|
||||||
|
105
app/api/controller/DemoOrderController.php
Normal file
105
app/api/controller/DemoOrderController.php
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\api\controller;
|
||||||
|
|
||||||
|
use app\api\logic\order\OrderLogic;
|
||||||
|
use app\common\enum\PayEnum;
|
||||||
|
use app\common\logic\PaymentLogic;
|
||||||
|
use app\common\logic\PayNotifyLogic;
|
||||||
|
use app\common\model\user\User;
|
||||||
|
|
||||||
|
class DemoOrderController extends BaseApiController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 订单校验
|
||||||
|
*/
|
||||||
|
public function checkOrder()
|
||||||
|
{
|
||||||
|
$cartId = (array)$this->request->post('cart_id', []);
|
||||||
|
$addressId = (int)$this->request->post('address_id');
|
||||||
|
// $pay_type = (int)$this->request->post('pay_type');
|
||||||
|
// $auth_code = $this->request->post('auth_code'); //微信支付条码
|
||||||
|
$params = $this->request->post();
|
||||||
|
$user = User::where('id', $this->userId)->find();
|
||||||
|
$res = OrderLogic::cartIdByOrderInfo($cartId, $addressId, $user, $params);
|
||||||
|
if ($res == false) {
|
||||||
|
$msg = OrderLogic::getError();
|
||||||
|
if ($msg == '购物车为空') {
|
||||||
|
return $this->data([]);
|
||||||
|
}
|
||||||
|
return $this->fail(OrderLogic::getError());
|
||||||
|
}
|
||||||
|
return $this->data($res);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建订单
|
||||||
|
*/
|
||||||
|
public function createOrder()
|
||||||
|
{
|
||||||
|
$cartId = (array)$this->request->post('cart_id', []);
|
||||||
|
$store_id = (array)$this->request->post('store_id', 0);
|
||||||
|
$pay_type = (int)$this->request->post('pay_type');
|
||||||
|
$addressId = (int)$this->request->post('address_id');
|
||||||
|
$auth_code = $this->request->post('auth_code'); //微信支付条码
|
||||||
|
$params = $this->request->post();
|
||||||
|
if ($store_id <= 0 && $pay_type != 9) {
|
||||||
|
return $this->fail('自提点不能为空');
|
||||||
|
}
|
||||||
|
if (count($cartId) > 100) {
|
||||||
|
return $this->fail('购物车商品不能超过100个');
|
||||||
|
}
|
||||||
|
|
||||||
|
$user = User::where('id', $this->userId)->find();
|
||||||
|
if ($pay_type == PayEnum::PURCHASE_FUNDS || $pay_type == PayEnum::BALANCE_PAY) {
|
||||||
|
if (!isset($params['password'])) {
|
||||||
|
return $this->fail('缺失参数');
|
||||||
|
}
|
||||||
|
if (empty($user['pay_password'])) {
|
||||||
|
return $this->fail('请设置密码');
|
||||||
|
}
|
||||||
|
if (!password_verify($params['password'], $user['pay_password'])) {
|
||||||
|
return $this->fail('密码错误');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$order = OrderLogic::createOrder($cartId, $addressId, $user, $params);
|
||||||
|
if ($order != false) {
|
||||||
|
if ($order['pay_price'] <= 0) {
|
||||||
|
$pay_type = 3;
|
||||||
|
}
|
||||||
|
switch ($pay_type) {
|
||||||
|
case PayEnum::PURCHASE_FUNDS:
|
||||||
|
//采购款支付
|
||||||
|
PayNotifyLogic::handle('purchase_funds', $order['order_id']);
|
||||||
|
return $this->success('采购款支付成功');
|
||||||
|
case PayEnum::BALANCE_PAY:
|
||||||
|
//余额支付
|
||||||
|
PayNotifyLogic::handle('balancePay', $order['order_id']);
|
||||||
|
return $this->success('余额支付成功');
|
||||||
|
case PayEnum::CASH_PAY:
|
||||||
|
//现金支付
|
||||||
|
PayNotifyLogic::handle('cash_pay', $order['order_id']);
|
||||||
|
return $this->success('现金支付成功');
|
||||||
|
case PayEnum::WECHAT_PAY_MINI:
|
||||||
|
//微信小程序支付
|
||||||
|
PayNotifyLogic::handle('wechat_common', $order['order_id']);
|
||||||
|
return $this->success('微信小程序支付成功');
|
||||||
|
case PayEnum::WECHAT_PAY_BARCODE:
|
||||||
|
//微信条码支付
|
||||||
|
PayNotifyLogic::handle('wechat_common', $order['order_id'], $order);
|
||||||
|
return $this->success('微信条码支付成功');
|
||||||
|
case PayEnum::ALIPAY_BARCODE:
|
||||||
|
//支付宝条码支付
|
||||||
|
PayNotifyLogic::handle('alipay_cashier', $order['order_id'], $order);
|
||||||
|
return $this->success('支付宝条码支付成功' );
|
||||||
|
default:
|
||||||
|
return $this->fail('支付方式错误');
|
||||||
|
}
|
||||||
|
// return $this->data(['order_id' => $order->id]);
|
||||||
|
} else {
|
||||||
|
return $this->fail(OrderLogic::getError());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -4,22 +4,33 @@ namespace app\statistics\logic;
|
|||||||
|
|
||||||
use app\common\logic\BaseLogic;
|
use app\common\logic\BaseLogic;
|
||||||
use app\common\model\store_branch_product\StoreBranchProduct;
|
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||||
|
use app\common\model\store_product\StoreProduct;
|
||||||
use app\common\model\system_store\SystemStore;
|
use app\common\model\system_store\SystemStore;
|
||||||
|
|
||||||
class ProductLogic extends BaseLogic
|
class ProductLogic extends BaseLogic
|
||||||
{
|
{
|
||||||
public static function Count($where, $time)
|
public static function Count($where, $time)
|
||||||
{
|
{
|
||||||
|
if (isset($where['store_id']) && $where['store_id'] > 0) {
|
||||||
$todayProductCount = StoreBranchProduct::where($where)->whereDay('create_time', $time)->count();
|
$todayProductCount = StoreBranchProduct::where($where)->whereDay('create_time', $time)->count();
|
||||||
$yestertodayProductCount = StoreBranchProduct::where($where)->where('create_time', '<', strtotime($time) - 1)->count();
|
$yestertodayProductCount = StoreBranchProduct::where($where)->where('create_time', '<', strtotime($time) - 1)->count();
|
||||||
|
$todayNewProductCount = StoreBranchProduct::where($where)->whereDay('create_time', $time)->count();
|
||||||
|
$yestertodayNewProductCount = StoreBranchProduct::where($where)->whereDay('create_time', date('Y-m-d', strtotime($time) - 1))->count();
|
||||||
|
} else {
|
||||||
|
$todayProductCount = StoreProduct::whereDay('create_time', $time)->count();
|
||||||
|
$yestertodayProductCount = StoreProduct::count();
|
||||||
|
|
||||||
|
$todayNewProductCount = StoreProduct::whereDay('create_time', $time)->count();
|
||||||
|
$yestertodayNewProductCount = StoreProduct::whereDay('create_time', date('Y-m-d', strtotime($time) - 1))->count();
|
||||||
|
}
|
||||||
|
|
||||||
if ($yestertodayProductCount == 0 || $todayProductCount == 0) {
|
if ($yestertodayProductCount == 0 || $todayProductCount == 0) {
|
||||||
$weeklyProductTotalGrowthRate = 0;
|
$weeklyProductTotalGrowthRate = 0;
|
||||||
} else {
|
} else {
|
||||||
$weeklyProductTotalGrowthRate = bcdiv(($todayProductCount - $yestertodayProductCount), $yestertodayProductCount) * 100;
|
$weeklyProductTotalGrowthRate = bcdiv(($todayProductCount - $yestertodayProductCount), $yestertodayProductCount) * 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
$todayNewProductCount=StoreBranchProduct::where($where)->whereDay('create_time',$time)->count();
|
|
||||||
$yestertodayNewProductCount=StoreBranchProduct::where($where)->whereDay('create_time', date('Y-m-d',strtotime($time)-1))->count();
|
|
||||||
if ($todayNewProductCount == 0 || $yestertodayNewProductCount == 0) {
|
if ($todayNewProductCount == 0 || $yestertodayNewProductCount == 0) {
|
||||||
$weeklyNewProductTotalGrowthRate = 0;
|
$weeklyNewProductTotalGrowthRate = 0;
|
||||||
} else {
|
} else {
|
||||||
@ -48,7 +59,8 @@ class ProductLogic extends BaseLogic
|
|||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function sales($where){
|
public static function sales($where)
|
||||||
|
{
|
||||||
$select = StoreBranchProduct::where($where)->limit(10)->order('sales desc')->field('id,store_name,image,sales')->select();
|
$select = StoreBranchProduct::where($where)->limit(10)->order('sales desc')->field('id,store_name,image,sales')->select();
|
||||||
return $select?->toArray();
|
return $select?->toArray();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user