Merge pull request 'feat: 修改订单逻辑以支持生鲜产品,并添加新的统计功能到数据分析模块。' (#40) from dev into main
Reviewed-on: #40
This commit is contained in:
commit
6701f31b07
@ -57,7 +57,7 @@ class OrderLogic extends BaseLogic
|
|||||||
public static $activity_price;
|
public static $activity_price;
|
||||||
public static $deduction_price;
|
public static $deduction_price;
|
||||||
public static $frozen_money; //返还金额
|
public static $frozen_money; //返还金额
|
||||||
|
public static $fresh_price; //生鲜金额
|
||||||
/**
|
/**
|
||||||
* @notes 获取购物车商品信息
|
* @notes 获取购物车商品信息
|
||||||
* @param $params
|
* @param $params
|
||||||
@ -81,7 +81,7 @@ class OrderLogic extends BaseLogic
|
|||||||
self::$deduction_price = 0;
|
self::$deduction_price = 0;
|
||||||
self::$frozen_money = 0; //返还金额
|
self::$frozen_money = 0; //返还金额
|
||||||
$deduction_price = 0; //抵扣金额
|
$deduction_price = 0; //抵扣金额
|
||||||
$fresh_price = 0; //生鲜金额
|
self::$fresh_price = 0; //生鲜金额
|
||||||
/** 计算价格 */
|
/** 计算价格 */
|
||||||
$off_activity = Config::where('name', 'off_activity')->value('value');
|
$off_activity = Config::where('name', 'off_activity')->value('value');
|
||||||
$field = 'id branch_product_id,store_name,image,unit,price,vip_price,cost,purchase,product_id,top_cate_id';
|
$field = 'id branch_product_id,store_name,image,unit,price,vip_price,cost,purchase,product_id,top_cate_id';
|
||||||
@ -108,7 +108,7 @@ class OrderLogic extends BaseLogic
|
|||||||
}
|
}
|
||||||
unset($cart_select[$k]['id']);
|
unset($cart_select[$k]['id']);
|
||||||
$cart_select[$k]['total_price'] = bcmul($v['cart_num'], $find['price'], 2); //订单总价
|
$cart_select[$k]['total_price'] = bcmul($v['cart_num'], $find['price'], 2); //订单总价
|
||||||
if ($off_activity == 1 || ($user!=null &&in_array($user['user_ship'], [4, 5, 6, 7]))) {
|
if ($off_activity == 1 || ($user != null && in_array($user['user_ship'], [4, 5, 6, 7]))) {
|
||||||
$price = $find['cost'];
|
$price = $find['cost'];
|
||||||
} else {
|
} else {
|
||||||
$price = $find['price'];
|
$price = $find['price'];
|
||||||
@ -128,10 +128,6 @@ class OrderLogic extends BaseLogic
|
|||||||
$deduction_price = bcsub($cart_select[$k]['total_price'], $cart_select[$k]['pay_price'], 2);
|
$deduction_price = bcsub($cart_select[$k]['total_price'], $cart_select[$k]['pay_price'], 2);
|
||||||
$cart_select[$k]['deduction_price'] = $deduction_price; //抵扣金额
|
$cart_select[$k]['deduction_price'] = $deduction_price; //抵扣金额
|
||||||
}
|
}
|
||||||
//计算生鲜
|
|
||||||
if ($createOrder == 1 && $find['top_cate_id'] == 15201) {
|
|
||||||
$fresh_price = bcadd($fresh_price, $cart_select[$k]['pay_price']);
|
|
||||||
}
|
|
||||||
$cart_select[$k]['product_id'] = $find['product_id'];
|
$cart_select[$k]['product_id'] = $find['product_id'];
|
||||||
$cart_select[$k]['old_cart_id'] = $v['id'];
|
$cart_select[$k]['old_cart_id'] = $v['id'];
|
||||||
$cart_select[$k]['cart_num'] = $v['cart_num'];
|
$cart_select[$k]['cart_num'] = $v['cart_num'];
|
||||||
@ -164,6 +160,10 @@ class OrderLogic extends BaseLogic
|
|||||||
self::$store_price = bcadd(self::$store_price, $cart_select[$k]['store_price'], 2); //商户价
|
self::$store_price = bcadd(self::$store_price, $cart_select[$k]['store_price'], 2); //商户价
|
||||||
self::$deduction_price = bcadd(self::$deduction_price, $deduction_price, 2); //抵扣金额
|
self::$deduction_price = bcadd(self::$deduction_price, $deduction_price, 2); //抵扣金额
|
||||||
self::$frozen_money = bcadd(self::$frozen_money, $cart_select[$k]['vip_frozen_price'], 2); //返还金额
|
self::$frozen_money = bcadd(self::$frozen_money, $cart_select[$k]['vip_frozen_price'], 2); //返还金额
|
||||||
|
//计算生鲜
|
||||||
|
if ($createOrder == 1 && $find['top_cate_id'] == 15201) {
|
||||||
|
self::$fresh_price = bcadd(self::$fresh_price, $cart_select[$k]['pay_price'], 2);
|
||||||
|
}
|
||||||
// self::$profit = bcadd(self::$profit, $cart_select[$k]['profit'], 2);
|
// self::$profit = bcadd(self::$profit, $cart_select[$k]['profit'], 2);
|
||||||
}
|
}
|
||||||
//加支付方式限制
|
//加支付方式限制
|
||||||
@ -175,8 +175,8 @@ class OrderLogic extends BaseLogic
|
|||||||
|
|
||||||
$pay_price = bcsub(self::$pay_price, self::$activity_price, 2); //减去活动优惠金额
|
$pay_price = bcsub(self::$pay_price, self::$activity_price, 2); //减去活动优惠金额
|
||||||
//判断生鲜是否大于200
|
//判断生鲜是否大于200
|
||||||
if ($createOrder == 1 && $fresh_price > 0) {
|
if ($createOrder == 1 && self::$fresh_price > 0) {
|
||||||
if ($pay_price < 200) {
|
if (self::$pay_price < 200) {
|
||||||
self::setError('订单包含生鲜产品,订单金额必须大于200元,才能下单');
|
self::setError('订单包含生鲜产品,订单金额必须大于200元,才能下单');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,9 @@ namespace app\statistics\controller;
|
|||||||
|
|
||||||
use app\admin\logic\statistic\TradeStatisticLogic;
|
use app\admin\logic\statistic\TradeStatisticLogic;
|
||||||
use app\common\controller\BaseLikeController;
|
use app\common\controller\BaseLikeController;
|
||||||
|
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||||
|
use app\common\model\store_order_cart_info\StoreOrderCartInfo;
|
||||||
|
use app\common\model\store_product\StoreProduct;
|
||||||
use app\common\model\user\User;
|
use app\common\model\user\User;
|
||||||
use app\common\model\user_recharge\UserRecharge;
|
use app\common\model\user_recharge\UserRecharge;
|
||||||
use app\statistics\logic\OrderLogic;
|
use app\statistics\logic\OrderLogic;
|
||||||
@ -14,12 +17,12 @@ use DateTime;
|
|||||||
class IndexController extends BaseLikeController
|
class IndexController extends BaseLikeController
|
||||||
{
|
{
|
||||||
|
|
||||||
public $store_id = 0;
|
// public $store_id = 0;
|
||||||
|
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
$time = $this->request->get('date', date('Y-m-d'));
|
$time = $this->request->get('date', date('Y-m-d'));
|
||||||
$store_id = $this->store_id;
|
$store_id = $this->request->get('store_id', 0);
|
||||||
if ($store_id) {
|
if ($store_id) {
|
||||||
$where['store_id'] = $store_id;
|
$where['store_id'] = $store_id;
|
||||||
}
|
}
|
||||||
@ -28,11 +31,72 @@ class IndexController extends BaseLikeController
|
|||||||
if (OrderLogic::hasError()) {
|
if (OrderLogic::hasError()) {
|
||||||
return $this->fail(OrderLogic::getError()); //获取错误信息并返回错误信息
|
return $this->fail(OrderLogic::getError()); //获取错误信息并返回错误信息
|
||||||
}
|
}
|
||||||
return $this->success('ok', ['dayPayPrice' => $res, 'title' => '百合镇农(特)产品交易大数据']);
|
switch ($store_id) {
|
||||||
|
case 1:
|
||||||
|
$title = '喻寺镇农(特)产品交易大数据';
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
$title = '立石镇农(特)产品交易大数据';
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
$title = '百和镇农(特)产品交易大数据';
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
$title = '得胜镇农(特)产品交易大数据';
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
$title = '玄滩镇农(特)产品交易大数据';
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
$title = '牛滩镇农(特)产品交易大数据';
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
$title = '云锦镇农(特)产品交易大数据';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$title = '百合镇农(特)产品交易大数据';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return $this->success('ok', ['dayPayPrice' => $res, 'title' => $title]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 门店统计
|
||||||
|
*/
|
||||||
|
public function sotre_count(){
|
||||||
|
$data=[
|
||||||
|
['street_name'=>'喻寺镇','merchant_count'=>1],
|
||||||
|
['street_name'=>'立石镇','merchant_count'=>1],
|
||||||
|
['street_name'=>'百和镇','merchant_count'=>1],
|
||||||
|
['street_name'=>'得胜镇','merchant_count'=>1],
|
||||||
|
['street_name'=>'玄滩镇','merchant_count'=>1],
|
||||||
|
['street_name'=>'云锦镇','merchant_count'=>1],
|
||||||
|
];
|
||||||
|
return $this->success('ok', ['merchatCountList'=>$data,'merchantTotalCount'=>count($data)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function product_count_sotre_count(){
|
||||||
|
$data=[
|
||||||
|
['street_name'=>'喻寺镇','product_count'=>1],
|
||||||
|
['street_name'=>'立石镇','product_count'=>1],
|
||||||
|
['street_name'=>'百和镇','product_count'=>1],
|
||||||
|
['street_name'=>'得胜镇','product_count'=>1],
|
||||||
|
['street_name'=>'玄滩镇','product_count'=>1],
|
||||||
|
['street_name'=>'云锦镇','product_count'=>1],
|
||||||
|
];
|
||||||
|
$townProductCount=StoreProduct::count();
|
||||||
|
$product_count=StoreBranchProduct::group('product_id')->order('total_sales desc')->limit(20)->field('image,product_id,store_name,sum(sales) as total_sales')->select();
|
||||||
|
$productRankingTotal=0;
|
||||||
|
foreach($product_count as $item){
|
||||||
|
$productRankingTotal+=$item['total_sales'];
|
||||||
|
}
|
||||||
|
return $this->success('ok', ['townProductCountList'=>$data,'productRankingList'=>$product_count,'townProductCount'=>$townProductCount,'productRankingTotal'=>$productRankingTotal]);
|
||||||
|
|
||||||
}
|
}
|
||||||
public function user()
|
public function user()
|
||||||
{
|
{
|
||||||
$time = $this->request->get('date', date('Y-m-d'));
|
$time = $this->request->get('date', date('Y-m-d'));
|
||||||
|
$store_id = $this->request->get('store_id', 0);
|
||||||
$today = strtotime($time);
|
$today = strtotime($time);
|
||||||
$dates = [];
|
$dates = [];
|
||||||
// 循环输出前5天的日期
|
// 循环输出前5天的日期
|
||||||
@ -44,7 +108,6 @@ class IndexController extends BaseLikeController
|
|||||||
$date = date('Y-m-d', $timestamp);
|
$date = date('Y-m-d', $timestamp);
|
||||||
$dates[] = $date;
|
$dates[] = $date;
|
||||||
}
|
}
|
||||||
$store_id = $this->store_id;
|
|
||||||
$where = [];
|
$where = [];
|
||||||
if ($store_id) {
|
if ($store_id) {
|
||||||
$where['store_id'] = $store_id;
|
$where['store_id'] = $store_id;
|
||||||
@ -62,7 +125,7 @@ class IndexController extends BaseLikeController
|
|||||||
public function product_count()
|
public function product_count()
|
||||||
{
|
{
|
||||||
$time = $this->request->get('date', date('Y-m-d'));
|
$time = $this->request->get('date', date('Y-m-d'));
|
||||||
$store_id = $this->store_id;
|
$store_id = $this->request->get('store_id', 0);
|
||||||
$where = [];
|
$where = [];
|
||||||
if ($store_id) {
|
if ($store_id) {
|
||||||
$where['store_id'] = $store_id;
|
$where['store_id'] = $store_id;
|
||||||
@ -79,23 +142,23 @@ class IndexController extends BaseLikeController
|
|||||||
public function order_user_num_count()
|
public function order_user_num_count()
|
||||||
{
|
{
|
||||||
$time = $this->request->get('date', date('Y-m-d'));
|
$time = $this->request->get('date', date('Y-m-d'));
|
||||||
$store_id = $this->store_id;
|
$store_id = $this->request->get('store_id', 0);
|
||||||
$where = [];
|
$where = [];
|
||||||
if ($store_id) {
|
if ($store_id) {
|
||||||
$where['store_id'] = $store_id;
|
$where['store_id'] = $store_id;
|
||||||
}
|
}
|
||||||
$where['recharge_type']='INDUSTRYMEMBERS';
|
$where['recharge_type'] = 'INDUSTRYMEMBERS';
|
||||||
$where['status']=1;
|
$where['status'] = 1;
|
||||||
$where['paid']=1;
|
$where['paid'] = 1;
|
||||||
// $res = OrderLogic::Count($where,$time);
|
// $res = OrderLogic::Count($where,$time);
|
||||||
// if (ProductLogic::hasError()) {
|
// if (ProductLogic::hasError()) {
|
||||||
// return $this->fail(ProductLogic::getError()); //获取错误信息并返回错误信息
|
// return $this->fail(ProductLogic::getError()); //获取错误信息并返回错误信息
|
||||||
// }
|
// }
|
||||||
$res = UserRecharge::where($where)->whereTime('create_time', $time)->select()->each(function ($item) {
|
$res = UserRecharge::where($where)->whereTime('create_time', $time)->select()->each(function ($item) {
|
||||||
if($item['uid']){
|
if ($item['uid']) {
|
||||||
$item['nickname']=User::where('id',$item['uid'])->value('nickname');
|
$item['nickname'] = User::where('id', $item['uid'])->value('nickname');
|
||||||
}else{
|
} else {
|
||||||
$item['nickname']='';
|
$item['nickname'] = '';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return $this->success('ok', $res?->toArray());
|
return $this->success('ok', $res?->toArray());
|
||||||
@ -106,7 +169,7 @@ class IndexController extends BaseLikeController
|
|||||||
public function sales_ranking()
|
public function sales_ranking()
|
||||||
{
|
{
|
||||||
$time = $this->request->get('date');
|
$time = $this->request->get('date');
|
||||||
$store_id = $this->store_id;
|
$store_id = $this->request->get('store_id', 0);
|
||||||
$where = [];
|
$where = [];
|
||||||
if ($store_id) {
|
if ($store_id) {
|
||||||
$where['store_id'] = $store_id;
|
$where['store_id'] = $store_id;
|
||||||
@ -122,9 +185,16 @@ class IndexController extends BaseLikeController
|
|||||||
*/
|
*/
|
||||||
public function user_trade_count()
|
public function user_trade_count()
|
||||||
{
|
{
|
||||||
|
$store_id = $this->request->get('store_id', 0);
|
||||||
|
$where = ['create_time' => 'today'];
|
||||||
|
$where2 = ['create_time' => 'yestoday'];
|
||||||
|
if ($store_id) {
|
||||||
|
$where['store_id'] = $store_id;
|
||||||
|
$where2['store_id'] = $store_id;
|
||||||
|
}
|
||||||
$logic = (new TradeStatisticLogic());
|
$logic = (new TradeStatisticLogic());
|
||||||
$leftToday = $logic->getTopLeftTrade(['create_time' => 'today']);
|
$leftToday = $logic->getTopLeftTrade($where);
|
||||||
$leftyestoday = $logic->getTopLeftTrade(['create_time' => 'yestoday']);
|
$leftyestoday = $logic->getTopLeftTrade($where2);
|
||||||
$totalleft = [$leftToday, $leftyestoday];
|
$totalleft = [$leftToday, $leftyestoday];
|
||||||
foreach ($totalleft as $k => $v) {
|
foreach ($totalleft as $k => $v) {
|
||||||
$left['name'] = "当日订单金额";
|
$left['name'] = "当日订单金额";
|
||||||
@ -141,7 +211,7 @@ class IndexController extends BaseLikeController
|
|||||||
public function street_currday_order_count()
|
public function street_currday_order_count()
|
||||||
{
|
{
|
||||||
$time = $this->request->get('date', date('Y-m-d'));
|
$time = $this->request->get('date', date('Y-m-d'));
|
||||||
$store_id = $this->store_id;
|
$store_id = $this->request->get('store_id', 0);
|
||||||
$where = [];
|
$where = [];
|
||||||
if ($store_id) {
|
if ($store_id) {
|
||||||
$where['store_id'] = $store_id;
|
$where['store_id'] = $store_id;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user