Merge branch 'main' of https://gitea.lihaink.cn/mkm/multi-store
This commit is contained in:
commit
601aa01ab8
@ -226,6 +226,7 @@ class WorkbenchController extends BaseAdminController
|
||||
return $this->data($data);
|
||||
}
|
||||
//-------------------------------商品统计---------------------------------------//
|
||||
|
||||
/**
|
||||
* 商品概况
|
||||
*/
|
||||
@ -536,6 +537,7 @@ class WorkbenchController extends BaseAdminController
|
||||
}
|
||||
|
||||
//-------------------------------用户统计---------------------------------------//
|
||||
|
||||
/**
|
||||
* 获取用户概况
|
||||
*/
|
||||
|
@ -316,7 +316,7 @@ class OrderController extends BaseApiController
|
||||
StoreOrder::where(['id' => $order_id, 'uid' => Request()->userId])->update($_order);
|
||||
}
|
||||
}
|
||||
$result = PaymentLogic::pay($pay_type, 'wechat_common', $order, $this->userInfo['terminal'], $redirectUrl);
|
||||
$result = PaymentLogic::pay($pay_type, 'wechat_common', $order, $this->userInfo['terminal']??1, $redirectUrl);
|
||||
if (PaymentLogic::hasError()) {
|
||||
return $this->fail(PaymentLogic::getError());
|
||||
}
|
||||
@ -405,7 +405,7 @@ class OrderController extends BaseApiController
|
||||
];
|
||||
$order = StoreOrder::where($where)->find();
|
||||
if ($order) {
|
||||
$data = ['data' => $value, 'delete_time' => time()];
|
||||
$data = ['cancle_reason' => $value, 'delete_time' => time()];
|
||||
StoreOrder::where($where)->update($data);
|
||||
return $this->success('取消成功');
|
||||
}
|
||||
|
@ -39,6 +39,8 @@ use Yansongda\Pay\Event\PayEnd;
|
||||
class OrderLogic extends BaseLogic
|
||||
{
|
||||
public static $total;
|
||||
public static $cost;
|
||||
public static $profit;
|
||||
|
||||
/**
|
||||
* @notes 获取购物车商品信息
|
||||
@ -56,6 +58,9 @@ class OrderLogic extends BaseLogic
|
||||
}
|
||||
try {
|
||||
self::$total = 0;
|
||||
self::$cost = 0;//成本
|
||||
self::$profit = 0;//利润
|
||||
|
||||
/** 计算价格 */
|
||||
$check = DictType::where('type', 'activities')->find();
|
||||
foreach ($cart_select as $k => $v) {
|
||||
@ -63,9 +68,14 @@ class OrderLogic extends BaseLogic
|
||||
if (!$find) {
|
||||
continue;
|
||||
}
|
||||
$productBase = StoreProduct::where('id', $find['product_id'])->withTrashed()->field('price,ot_price,cost')->find();
|
||||
if (isset($check) && $check['status'] == 1) {
|
||||
$find['price'] = StoreProduct::where('id',$find['product_id'])->withTrashed()->value('ot_price');
|
||||
$find['price'] = $productBase['ot_price'];
|
||||
}
|
||||
//利润
|
||||
$onePrice = bcsub($productBase['price'], $productBase['ot_price'], 2);
|
||||
$cart_select[$k]['profit'] = bcmul($v['cart_num'], $onePrice, 2);//利润
|
||||
$cart_select[$k]['cost'] = bcmul($v['cart_num'], $productBase['cost'], 2) ?? 0;
|
||||
$cart_select[$k]['total'] = bcmul($v['cart_num'], $find['price'], 2);//钱
|
||||
$cart_select[$k]['price'] = $find['price'];
|
||||
$cart_select[$k]['product_id'] = $v['goods'];
|
||||
@ -87,6 +97,8 @@ class OrderLogic extends BaseLogic
|
||||
$cart_select[$k]['imgs'] = $find['image'];
|
||||
$cart_select[$k]['unit_name'] = StoreProductUnit::where(['id' => $find['unit']])->value('name');
|
||||
self::$total = bcadd(self::$total, $cart_select[$k]['total'], 2);
|
||||
self::$cost = bcadd(self::$cost, $cart_select[$k]['cost'], 2);
|
||||
self::$profit = bcadd(self::$profit, $cart_select[$k]['profit'], 2);
|
||||
}
|
||||
//TODO 收单打9.9折 会员按照比例打折 等级按照充值去升级
|
||||
$pay_price = self::$total;
|
||||
@ -128,10 +140,14 @@ class OrderLogic extends BaseLogic
|
||||
bcscale(2);
|
||||
$vipPrice = bcsub(self::$total, $pay_price, 2);
|
||||
}
|
||||
|
||||
//成本价 收益
|
||||
$order = [
|
||||
'create_time' => time(),
|
||||
'order_id' => getNewOrderId('PF'),
|
||||
'total_price' => self::$total,//总价
|
||||
'cost' => self::$cost,//成本价
|
||||
'profit' => self::$profit,//利润
|
||||
'pay_price' => $pay_price,//后期可能有降价抵扣
|
||||
'vip_price' => $vipPrice,
|
||||
'total_num' => count($cart_select),//总数
|
||||
@ -141,6 +157,10 @@ class OrderLogic extends BaseLogic
|
||||
'store_id' => $params['store_id'] ?? 0,
|
||||
'shipping_type' => $params['shipping_type'] ?? 1//配送方式 1=快递 ,2=门店自提
|
||||
];
|
||||
$order['default_delivery'] = 0;
|
||||
if($params['store_id']){
|
||||
$order['default_delivery'] = SystemStore::where('id',$params['store_id'])->value('is_store');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
@ -168,6 +188,7 @@ class OrderLogic extends BaseLogic
|
||||
$_order['mobile'] = $user['mobile'];
|
||||
$_order['pay_type'] = $orderInfo['order']['pay_type'];
|
||||
$_order['verify_code'] = $verify_code;
|
||||
$_order['reservation_time'] = null;
|
||||
if (isset($params['reservation_time'])) {
|
||||
$_order['reservation_time'] = $params['reservation_time'];
|
||||
$_order['reservation'] = YesNoEnum::YES;
|
||||
@ -618,11 +639,13 @@ class OrderLogic extends BaseLogic
|
||||
//todo 单子不是完成的不允许退款
|
||||
//单笔不拆单子直接修改状态
|
||||
$order = StoreOrder::where('id', $params['id'])->withTrashed()->findOrEmpty();
|
||||
$params['refund_num'] = 1;//todo 拿实际数量
|
||||
if (count($params['old_cart_id']) == 1) {
|
||||
$order->refund_status = OrderEnum::REFUND_STATUS_YES;
|
||||
$order->status = OrderEnum::ALREADY_REFUND;
|
||||
$order->refund_reason_wap_explain = $params['refund_message'] ?? '';
|
||||
$order->refund_num = $params['refund_num'];
|
||||
$order->mark = $params['mark'] ?? '';
|
||||
$order->refund_num = $params['refund_num'] ?? 1;
|
||||
$refund_price_cart = StoreOrderCartInfo::where('oid', $params['id'])
|
||||
->field('id,oid,cart_info')
|
||||
->find()->toArray();
|
||||
@ -685,7 +708,6 @@ class OrderLogic extends BaseLogic
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static function dealCreateLeftOrder($order, $cart_info, $params)
|
||||
{
|
||||
//查出不在这个退货中的数据
|
||||
@ -726,7 +748,6 @@ class OrderLogic extends BaseLogic
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static function dealCreateRefundOrder($order, $params)
|
||||
{
|
||||
$order['order_id'] = $order['order_id'] . '-1';
|
||||
@ -738,6 +759,7 @@ class OrderLogic extends BaseLogic
|
||||
$order['status'] = OrderEnum::ALREADY_REFUND;
|
||||
$order['refund_num'] = $params['refund_num'];//按数量整单退剩余的
|
||||
$order['refund_reason_wap_explain'] = $params['refund_message'] ?? '';
|
||||
$order['mark'] = $params['mark'] ?? '';
|
||||
$order['total_num'] = count($params['old_cart_id']);
|
||||
$refund_price_cart = StoreOrderCartInfo::whereIn('old_cart_id', $params['old_cart_id'])
|
||||
->field('id,oid,cart_info')
|
||||
|
@ -18,6 +18,7 @@ class OrderEnum
|
||||
* @SUPPLIER_ORDER_OBTAINS 供应链订单获得
|
||||
* @PLATFORM_ORDER_PAY 平台订单支付
|
||||
* @SYSTEM_SET 系统设置
|
||||
* @OWN_GET 平台收入
|
||||
*/
|
||||
const USER_ORDER_PAY = 1;
|
||||
const MERCHANT_ORDER_OBTAINS = 2;
|
||||
@ -30,6 +31,8 @@ class OrderEnum
|
||||
const CASHIER_ORDER_PAY = 9;
|
||||
const CASHIER_CASH_ORDER_PAY = 10;
|
||||
|
||||
const OWN_GET = 3;
|
||||
|
||||
|
||||
/**
|
||||
* 收入支出类型
|
||||
|
@ -242,8 +242,16 @@ class PayNotifyLogic extends BaseLogic
|
||||
$financeLogic->order = $order;
|
||||
$financeLogic->user = ['uid' => $order['uid']];
|
||||
if ($order->pay_type != 9 || $order->pay_type != 10) {
|
||||
$financeLogic->in($transaction_id,$order['pay_price'], OrderEnum::USER_ORDER_PAY);
|
||||
$financeLogic->out($transaction_id,$order['pay_price'], OrderEnum::MERCHANT_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0);
|
||||
//手续费
|
||||
$fees = bcdiv(bcmul($order->pay_price, '0.02', 2), 1, 2);
|
||||
$financeLogic->in($transaction_id,$order->pay_price, OrderEnum::USER_ORDER_PAY); //用户单入账
|
||||
$financeLogic->in($transaction_id,$fees, OrderEnum::OWN_GET); //手续费入账
|
||||
//商户应该获得的钱 每个商品的price-ot_price 利润
|
||||
if($order->profit !== "0.00"){ //要测下写入没
|
||||
$financeLogic->out($transaction_id,$order->pay_price, OrderEnum::MERCHANT_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0);//商户获得的
|
||||
}
|
||||
// $financeLogic->in($transaction_id,$order['pay_price'], OrderEnum::USER_ORDER_PAY);
|
||||
// $financeLogic->out($transaction_id,$order['pay_price'], OrderEnum::MERCHANT_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0);
|
||||
$financeLogic->save();
|
||||
}
|
||||
}
|
||||
|
@ -4,16 +4,13 @@ namespace app\common\logic\store_order;
|
||||
|
||||
use app\common\enum\OrderEnum;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\enum\PayEnum;
|
||||
use app\common\enum\YesNoEnum;
|
||||
use app\common\model\dict\DictType;
|
||||
use app\common\model\order\Cart;
|
||||
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||
use app\common\model\store_order\StoreOrder;
|
||||
use app\common\model\store_order_cart_info\StoreOrderCartInfo;
|
||||
use app\common\model\store_product\StoreProduct;
|
||||
use app\common\model\store_product_unit\StoreProductUnit;
|
||||
use app\common\model\user\UserAddress;
|
||||
use app\common\service\pay\PayService;
|
||||
use Exception;
|
||||
use support\Cache;
|
||||
@ -81,7 +78,7 @@ class StoreOrderLogic extends BaseLogic
|
||||
$pay_price = bcdiv(bcmul($pay_price, $discountRate, 4), '1', 2);
|
||||
} else {
|
||||
|
||||
$discountRate = bcdiv(100, '100', 2);
|
||||
$discountRate = bcdiv(1, '100', 2);
|
||||
$pay_price = bcdiv(bcmul($pay_price, $discountRate, 4), '1', 2);
|
||||
}
|
||||
if (!empty(self::$total) && !empty($pay_price)) {
|
||||
@ -106,6 +103,7 @@ class StoreOrderLogic extends BaseLogic
|
||||
}
|
||||
return ['order' => $order, 'cart_list' => $cart_select];
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建新订单
|
||||
* @return Object|bool|array
|
||||
@ -209,9 +207,9 @@ class StoreOrderLogic extends BaseLogic
|
||||
* @param $extra
|
||||
* @return float|\think\db\Query
|
||||
*/
|
||||
public function storeOrderSumByDate($storeId, $start, $end, $extra = [])
|
||||
public function storeOrderSumByDate($storeId, $start, $end, $extra = [], $field = 'pay_price')
|
||||
{
|
||||
return StoreOrder::where('store_id', $storeId)->where('paid', 1)->where($extra)->whereBetweenTime('create_time', $start, $end)->sum('pay_price');
|
||||
return StoreOrder::where('store_id', $storeId)->where('paid', 1)->where($extra)->whereBetweenTime('pay_time', $start, $end)->sum($field);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -30,7 +30,7 @@ class WorkbenchController extends BaseAdminController
|
||||
}
|
||||
|
||||
#[
|
||||
ApiDoc\Title('商品统计'),
|
||||
ApiDoc\Title('商品统计(暂时不用)'),
|
||||
ApiDoc\url('/store/workbench/product'),
|
||||
ApiDoc\Method('GET'),
|
||||
ApiDoc\NotHeaders(),
|
||||
@ -42,13 +42,14 @@ class WorkbenchController extends BaseAdminController
|
||||
]
|
||||
public function product()
|
||||
{
|
||||
$storeId = $this->request->adminInfo['store_id'];
|
||||
$result = WorkbenchLogic::index($storeId);
|
||||
$params = $this->request->get();
|
||||
$params['store_id'] = $this->request->adminInfo['store_id'];
|
||||
$result = WorkbenchLogic::product($params);
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
#[
|
||||
ApiDoc\Title('配送统计'),
|
||||
ApiDoc\Title('配送统计(暂时不用)'),
|
||||
ApiDoc\url('/store/workbench/delivery'),
|
||||
ApiDoc\Method('GET'),
|
||||
ApiDoc\NotHeaders(),
|
||||
@ -61,8 +62,98 @@ class WorkbenchController extends BaseAdminController
|
||||
public function delivery()
|
||||
{
|
||||
$storeId = $this->request->adminInfo['store_id'];
|
||||
$result = WorkbenchLogic::index($storeId);
|
||||
$result = WorkbenchLogic::delivery($storeId);
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
#[
|
||||
ApiDoc\Title('商品统计-概况'),
|
||||
ApiDoc\url('/store/workbench/get_basic'),
|
||||
ApiDoc\Method('GET'),
|
||||
ApiDoc\NotHeaders(),
|
||||
ApiDoc\Author('中国队长'),
|
||||
ApiDoc\Query(name: 'start_time', type: 'string', require: true, desc: '开始时间'),
|
||||
ApiDoc\Query(name: 'end_time', type: 'string', require: true, desc: '结束时间'),
|
||||
ApiDoc\Header(ref: [Definitions::class, "token"]),
|
||||
ApiDoc\ResponseSuccess("data", type: "array"),
|
||||
]
|
||||
public function get_basic(\app\admin\controller\WorkbenchController $workbench)
|
||||
{
|
||||
$params = $this->request->get();
|
||||
$params['store_id'] = $this->request->adminInfo['store_id'];
|
||||
return $workbench->get_basic();
|
||||
}
|
||||
|
||||
#[
|
||||
ApiDoc\Title('商品统计-图表'),
|
||||
ApiDoc\url('/store/workbench/get_trend'),
|
||||
ApiDoc\Method('GET'),
|
||||
ApiDoc\NotHeaders(),
|
||||
ApiDoc\Author('中国队长'),
|
||||
ApiDoc\Query(name: 'start_time', type: 'string', require: true, desc: '开始时间'),
|
||||
ApiDoc\Query(name: 'end_time', type: 'string', require: true, desc: '结束时间'),
|
||||
ApiDoc\Header(ref: [Definitions::class, "token"]),
|
||||
ApiDoc\ResponseSuccess("data", type: "array"),
|
||||
]
|
||||
public function get_trend(\app\admin\controller\WorkbenchController $workbench)
|
||||
{
|
||||
$params = $this->request->get();
|
||||
$params['store_id'] = $this->request->adminInfo['store_id'];
|
||||
return $workbench->get_trend();
|
||||
}
|
||||
|
||||
#[
|
||||
ApiDoc\Title('商品统计-排行'),
|
||||
ApiDoc\url('/store/workbench/get_product_ranking'),
|
||||
ApiDoc\Method('GET'),
|
||||
ApiDoc\NotHeaders(),
|
||||
ApiDoc\Author('中国队长'),
|
||||
ApiDoc\Query(name: 'start_time', type: 'string', require: true, desc: '开始时间'),
|
||||
ApiDoc\Query(name: 'end_time', type: 'string', require: true, desc: '结束时间'),
|
||||
ApiDoc\Header(ref: [Definitions::class, "token"]),
|
||||
ApiDoc\ResponseSuccess("data", type: "array"),
|
||||
]
|
||||
public function get_product_ranking(\app\admin\controller\WorkbenchController $workbench)
|
||||
{
|
||||
$params = $this->request->get();
|
||||
$params['store_id'] = $this->request->adminInfo['store_id'];
|
||||
return $workbench->get_product_ranking();
|
||||
}
|
||||
|
||||
#[
|
||||
ApiDoc\Title('用户统计-概况'),
|
||||
ApiDoc\url('/store/workbench/get_user_basic'),
|
||||
ApiDoc\Method('GET'),
|
||||
ApiDoc\NotHeaders(),
|
||||
ApiDoc\Author('中国队长'),
|
||||
ApiDoc\Query(name: 'start_time', type: 'string', require: true, desc: '开始时间'),
|
||||
ApiDoc\Query(name: 'end_time', type: 'string', require: true, desc: '结束时间'),
|
||||
ApiDoc\Header(ref: [Definitions::class, "token"]),
|
||||
ApiDoc\ResponseSuccess("data", type: "array"),
|
||||
]
|
||||
public function get_user_basic(\app\admin\controller\WorkbenchController $workbench)
|
||||
{
|
||||
$params = $this->request->get();
|
||||
$params['store_id'] = $this->request->adminInfo['store_id'];
|
||||
return $workbench->get_user_basic();
|
||||
}
|
||||
|
||||
#[
|
||||
ApiDoc\Title('用户统计-图表'),
|
||||
ApiDoc\url('/store/workbench/get_user_trend'),
|
||||
ApiDoc\Method('GET'),
|
||||
ApiDoc\NotHeaders(),
|
||||
ApiDoc\Author('中国队长'),
|
||||
ApiDoc\Query(name: 'start_time', type: 'string', require: true, desc: '开始时间'),
|
||||
ApiDoc\Query(name: 'end_time', type: 'string', require: true, desc: '结束时间'),
|
||||
ApiDoc\Header(ref: [Definitions::class, "token"]),
|
||||
ApiDoc\ResponseSuccess("data", type: "array"),
|
||||
]
|
||||
public function get_user_trend(\app\admin\controller\WorkbenchController $workbench)
|
||||
{
|
||||
$params = $this->request->get();
|
||||
$params['store_id'] = $this->request->adminInfo['store_id'];
|
||||
return $workbench->get_user_trend();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,8 +18,11 @@ namespace app\store\logic;
|
||||
use app\common\enum\PayEnum;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\logic\store_order\StoreOrderLogic;
|
||||
use app\common\model\order\Cart;
|
||||
use app\common\model\store_cash_finance_flow\StoreCashFinanceFlow;
|
||||
use app\common\model\store_order\StoreOrder;
|
||||
use app\common\model\store_order_cart_info\StoreOrderCartInfo;
|
||||
use app\common\model\store_visit\StoreVisit;
|
||||
use app\common\service\ConfigService;
|
||||
use app\common\service\FileService;
|
||||
|
||||
@ -50,10 +53,12 @@ class WorkbenchLogic extends BaseLogic
|
||||
$data['cash_amount'] = StoreCashFinanceFlow::where('store_id', $params['store_id'])->whereBetweenTime('create_time', $startTime, $endTime)->sum('cash_price');
|
||||
//核销订单金额
|
||||
$data['verify_amount'] = $orderLogic->storeOrderSumByDate($params['store_id'], $startTime, $endTime, ['shipping_type' => 2]);
|
||||
//门店收益金额
|
||||
$data['income_amount'] = $orderLogic->storeOrderSumByDate($params['store_id'], $startTime, $endTime, [], 'profit');
|
||||
//门店成交用户数
|
||||
$data['user_number'] = StoreOrder::where('store_id', $params['store_id'])
|
||||
->where('paid', 1)
|
||||
->whereBetweenTime('create_time', $startTime, $endTime)
|
||||
->whereBetweenTime('pay_time', $startTime, $endTime)
|
||||
->group('uid')
|
||||
->count();
|
||||
if ($dateDiff->days == 1) {
|
||||
@ -132,8 +137,8 @@ class WorkbenchLogic extends BaseLogic
|
||||
];
|
||||
$data['order_list'] = StoreOrder::with('user')->where('store_id', $params['store_id'])
|
||||
->where('paid', 1)
|
||||
->whereBetweenTime('create_time', $startTime, $endTime)
|
||||
->order('create_time', 'desc')
|
||||
->whereBetweenTime('pay_time', $startTime, $endTime)
|
||||
->order('pay_time', 'desc')
|
||||
->limit(10)
|
||||
->select()->toArray();
|
||||
$data['pay_type'] = [
|
||||
@ -289,4 +294,141 @@ class WorkbenchLogic extends BaseLogic
|
||||
];
|
||||
}
|
||||
|
||||
public static function product($params)
|
||||
{
|
||||
$data = [];
|
||||
$storeId = $params['store_id'];
|
||||
$startTime = $params['start_time'];
|
||||
$endTime = $params['end_time'];
|
||||
$endTime = date('Y-m-d', strtotime($endTime) + 86400);
|
||||
$dateDiff = (new \DateTime($endTime))->diff(new \DateTime($startTime));
|
||||
$data['visit_count'] = StoreVisit::where('store_id', $storeId)->whereBetweenTime('create_time', $startTime, $endTime)->count();
|
||||
$data['visit_user_count'] = StoreVisit::where('store_id', $storeId)->whereBetweenTime('create_time', $startTime, $endTime)->group('uid')->count();
|
||||
$data['add_cart_count'] = Cart::where('store_id', $storeId)->whereBetweenTime('create_time', $startTime, $endTime)->withTrashed()->group('product_id')->count();
|
||||
$data['add_order_count'] = StoreOrderCartInfo::where('store_id', $storeId)->whereBetweenTime('create_time', $startTime, $endTime)->withTrashed()->group('product_id')->count();
|
||||
$data['pay_count'] = StoreOrder::alias('t1')
|
||||
->join('store_order_cart_info t2', 't1.id = t2.oid')
|
||||
->where('t1.store_id', $storeId)
|
||||
->where('paid', 1)
|
||||
->whereBetweenTime('pay_time', $startTime, $endTime)
|
||||
->group('product_id')
|
||||
->count();
|
||||
$data['pay_amount'] = StoreOrder::where('store_id', $storeId)
|
||||
->where('paid', 1)
|
||||
->whereBetweenTime('pay_time', $startTime, $endTime)
|
||||
->sum('pay_price');
|
||||
$data['cost_amount'] = StoreOrder::where('store_id', $storeId)
|
||||
->where('paid', 1)
|
||||
->whereBetweenTime('pay_time', $startTime, $endTime)
|
||||
->sum('cost');
|
||||
$data['refund_amount'] = StoreOrder::where('store_id', $storeId)
|
||||
->where('paid', 1)
|
||||
->where('refund_status', '>', 0)
|
||||
->whereBetweenTime('pay_time', $startTime, $endTime)
|
||||
->sum('pay_price');
|
||||
$data['refund_count'] = StoreOrder::alias('t1')
|
||||
->join('store_order_cart_info t2', 't1.id = t2.oid')
|
||||
->where('t1.store_id', $storeId)
|
||||
->where('paid', 1)
|
||||
->where('refund_status', '>', 0)
|
||||
->whereBetweenTime('pay_time', $startTime, $endTime)
|
||||
->group('product_id')
|
||||
->count();
|
||||
$payUserCount = StoreOrder::where('store_id', $storeId)
|
||||
->where('paid', 1)
|
||||
->whereBetweenTime('pay_time', $startTime, $endTime)
|
||||
->group('uid')
|
||||
->count();
|
||||
if ($data['visit_user_count'] == 0) {
|
||||
$data['trans_rate'] = 0;
|
||||
} else {
|
||||
$data['trans_rate'] = bcdiv($payUserCount * 100, $data['visit_user_count'], 2);
|
||||
}
|
||||
//商品图表统计开始,未完成
|
||||
if ($dateDiff->days == 1) {
|
||||
$group = 'HOUR(pay_time)';
|
||||
$i = 0;
|
||||
while ($i < 24) {
|
||||
$timeRange[] = date('H', strtotime("+$i hours", strtotime($startTime)));
|
||||
$i++;
|
||||
}
|
||||
$field = 'from_unixtime(pay_time,"%H") as pay_time,sum(pay_price) as pay_price';
|
||||
} elseif ($dateDiff->days <= 31) {
|
||||
$group = 'DAY(pay_time)';
|
||||
$i = 0;
|
||||
while ($i < $dateDiff->days) {
|
||||
$timeRange[] = date('m-d', strtotime("+$i days", strtotime($startTime)));
|
||||
$i++;
|
||||
}
|
||||
$field = 'from_unixtime(pay_time,"%m-%d") as pay_time,sum(pay_price) as pay_price';
|
||||
} else {
|
||||
$group = 'MONTH(pay_time)';
|
||||
$i = 0;
|
||||
$month = 0;
|
||||
if ($dateDiff->y > 0) {
|
||||
$month = $dateDiff->y * 12;
|
||||
}
|
||||
if ($dateDiff->m > 0) {
|
||||
$month += $dateDiff->m;
|
||||
}
|
||||
if ($dateDiff->d > 0) {
|
||||
$month += 1;
|
||||
}
|
||||
while ($i < $month) {
|
||||
$timeRange[] = date('Y-m', strtotime("+$i months", strtotime($startTime)));
|
||||
$i++;
|
||||
}
|
||||
$field = 'from_unixtime(pay_time,"%Y-%m") as pay_time,sum(pay_price) as pay_price';
|
||||
}
|
||||
$orderList = StoreOrder::field($field)
|
||||
->where('store_id', $params['store_id'])
|
||||
->where('paid', 1)
|
||||
->whereBetweenTime('pay_time', $startTime, $endTime)
|
||||
->group($group)
|
||||
->select()
|
||||
->toArray();
|
||||
$userList = StoreOrder::field($field . ',count(uid) as user_num')
|
||||
->where('store_id', $params['store_id'])
|
||||
->where('paid', 1)
|
||||
->whereBetweenTime('pay_time', $startTime, $endTime)
|
||||
->group($group . ',uid')
|
||||
->select()
|
||||
->toArray();
|
||||
$orderList = reset_index($orderList, 'pay_time');
|
||||
$userList = reset_index($userList, 'pay_time');
|
||||
$orderListTmp = [];
|
||||
$userListTmp = [];
|
||||
$range = [];
|
||||
foreach ($timeRange as $item) {
|
||||
$range[] = $item;
|
||||
if (!isset($orderList[$item])) {
|
||||
$orderListTmp[$item] = 0;
|
||||
} else {
|
||||
$orderListTmp[$item] = $orderList[$item]['pay_price'];
|
||||
}
|
||||
if (!isset($userList[$item])) {
|
||||
$userListTmp[$item] = 0;
|
||||
} else {
|
||||
$userListTmp[$item] = $userList[$item]['user_num'];
|
||||
}
|
||||
}
|
||||
$data['statistics'] = [
|
||||
'range' => $range,
|
||||
'data' => [
|
||||
'order_amount' => array_values($orderListTmp),
|
||||
'user_number' => array_values($userListTmp)
|
||||
]
|
||||
];
|
||||
//商品图表统计结束
|
||||
|
||||
// 商品排行榜,未完成
|
||||
$data['rank_list'] = StoreOrder::with('user')->where('store_id', $params['store_id'])
|
||||
->where('paid', 1)
|
||||
->whereBetweenTime('create_time', $startTime, $endTime)
|
||||
->order('create_time', 'desc')
|
||||
->limit(10)
|
||||
->select()->toArray();
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user