首页统计

This commit is contained in:
2024-11-05 15:08:35 +08:00
parent 972bf2496f
commit 2a42a9518c

View File

@@ -11,7 +11,9 @@ use common\models\CashAccount;
use common\models\Drug;
use common\models\DrugStoreDrug;
use common\models\DrugStoreRelations;
use common\models\PrescripOrderRefund;
use common\models\ProductOrder;
use common\models\ProductOrderRefund;
use common\models\Reconciliation;
use common\models\Store;
use common\services\PlatformService;
@@ -35,13 +37,15 @@ class HomeController extends BaseAdminController
$totalPrice = Reconciliation::find()->where(['status' => 1]);
$drugCount = Drug::find();
$inventoryWarning = DrugStoreDrug::find()->where(['<', 'stock', 100]);
$inventoryWarningByStore = DrugStoreRelations::find()->where(['<', 'stock', 100]);
return [
'store' => intval($storeCount->count()),
'user' => intval($userCount->count()),
'order' => intval($orderCount->count()),
'drug' => intval($drugCount->count()),
'total_price' => intval($totalPrice->sum('total_price')),
'inventory_warning' => intval($inventoryWarning->count())
'inventory_warning' => intval($inventoryWarning->count()),
'inventory_warning_store' => intval($inventoryWarningByStore->count())
];
}
@@ -206,6 +210,7 @@ class HomeController extends BaseAdminController
*/
public function storeLowStock()
{
$selectStore = $this->request->get('store_id');
$query = DrugStoreRelations::find()
->with(['drug' => function ($query) {
$query->select(['id', 'drug_name', 'drug_number', 'type', 'image']);
@@ -226,14 +231,18 @@ class HomeController extends BaseAdminController
case UserRoleEnum::PROVINCE_DAI:
// 省代
if (empty($admin->province_id)) throw new Exception('省区经理信息获取失败' . $admin->province_id);
if (empty($selectStore)) throw new Exception('需要选择诊所');
$store_id = Store::find()->select(['id'])->where(['province_id' => $admin->province_id])->column();
$where = ['in', 'store_id', $store_id];
if (!in_array($selectStore, $store_id)) throw new Exception('没有权限');
$where = ['store_id' => $selectStore];
break;
case UserRoleEnum::CITY_DAI:
// 市代
if (empty($admin->city_id)) throw new Exception('市区经理信息获取失败' . $admin->city_id);
if (empty($selectStore)) throw new Exception('需要选择诊所');
$store_id = Store::find()->select(['id'])->where(['city_id' => $admin->city_id])->column();
$where = ['in', 'store_id', $store_id];
if (!in_array($selectStore, $store_id)) throw new Exception('没有权限');
$where = ['store_id' => $selectStore];
break;
case UserRoleEnum::SUPPLY:
// 业务员
@@ -280,14 +289,18 @@ class HomeController extends BaseAdminController
*/
public function actionOrderRefund()
{
// refund_time
// yii_product_order_refund
// ['between', 'created_at', strtotime('-90 day'), time()]
$query = ProductOrder::find()
->with(['orderItems', 'productOrderRefund' => function ($query) {
$query->where(['between', 'created_at', strtotime('-7 day'), time()]);
}])
->where(['status' => 1])
$query = ProductOrderRefund::find()->alias('por')->with([
'order' => function ($query) {
$query->select(['id', 'order_no', 'items_price', 'cancel_remark']);
},
'order.orderItems' => function ($query) {
$query->select(['id', 'product_order_id', 'drug_id', 'drug_name']);
},
])
// ->where(['between', 'por.created_at', strtotime('-7 day'), time()])
// ->andWhere(['status' => 0])
->where(['por.status' => 0])
->orderBy(['id' => SORT_DESC])
->asArray();
@@ -327,11 +340,14 @@ class HomeController extends BaseAdminController
break;
}
if (!empty($where)) {
$query->andWhere($where);
$query->joinWith('order', function ($query) use ($where) {
$query->where($where);
});
}
$list = $query->all();
foreach ($list as &$v) {
$v['order_names'] = implode(',', array_column($v['orderItems'], 'drug_name'));
$v['order_names'] = implode(',', array_column($v['order']['orderItems'], 'drug_name'));
$v['created_at'] = date('Y-m-d H:i:s', $v['created_at']);
}
return $list;