修复bug
This commit is contained in:
@@ -33,17 +33,19 @@ class HomeController extends BaseAdminController
|
||||
*/
|
||||
public function actionHomeCount()
|
||||
{
|
||||
$storeCount = Store::find()->where(['is_delete' => 0]);
|
||||
$userCount = User::find();
|
||||
$orderCount = ProductOrder::find()->where(['is_pay' => 1]);
|
||||
$totalPrice = Reconciliation::find()->where(['status' => 1]);
|
||||
$drugCount = Drug::find();
|
||||
$inventoryWarning = DrugStoreDrug::find()->where(['<', 'stock', 100]);
|
||||
$inventoryWarningByStore = DrugStoreRelations::find()->where(['<', 'stock', 100]);
|
||||
$get = \Yii::$app->request->get();
|
||||
$whereTime = $this->getWhereTime($get['start_time'], $get['end_time']);
|
||||
$storeCount = Store::find()->where(['is_delete' => 0])->andWhere($whereTime);
|
||||
$userCount = \common\models\User::find()->where($whereTime);
|
||||
$orderCount = ProductOrder::find()->where(['is_pay' => 1])->andWhere($whereTime);
|
||||
$totalPrice = Reconciliation::find()->where(['status' => 1])->andWhere($whereTime);
|
||||
$drugCount = Drug::find()->where($whereTime);
|
||||
$inventoryWarning = DrugStoreDrug::find()->where(['<', 'stock', 100])->andWhere($whereTime);
|
||||
$inventoryWarningByStore = DrugStoreRelations::find()->where(['<', 'stock', 100])->andWhere($whereTime);
|
||||
// 处方订单
|
||||
$prescriptionCount = Prescription::find()->where(['status' => 1]);
|
||||
$prescriptionCount = Prescription::find()->where(['status' => 1])->andWhere($whereTime);
|
||||
// 挂号人数
|
||||
$registerCount = Register::find()->where(['in', 'status', [2,3]]);
|
||||
$registerCount = Register::find()->where(['in', 'status', [2,3]])->andWhere($whereTime);
|
||||
return [
|
||||
'store' => intval($storeCount->count()),
|
||||
'user' => intval($userCount->count()),
|
||||
@@ -66,6 +68,8 @@ class HomeController extends BaseAdminController
|
||||
*/
|
||||
public function actionHomeCountByStore()
|
||||
{
|
||||
$get = \Yii::$app->request->get();
|
||||
$whereTime = $this->getWhereTime($get['start_time'], $get['end_time']);
|
||||
$admin = \Yii::$app->user->identity;
|
||||
$orderCount = ProductOrder::find()->where(['is_pay' => 1]);
|
||||
$totalPrice = Reconciliation::find()->where(['status' => 1]);
|
||||
@@ -105,12 +109,12 @@ class HomeController extends BaseAdminController
|
||||
break;
|
||||
}
|
||||
if (!empty($where)) {
|
||||
$orderCount->andWhere($where);
|
||||
$totalPrice->andWhere($where);
|
||||
$inventoryWarning->andWhere($where);
|
||||
$drug->where($where);
|
||||
$registerCount->andWhere($where);
|
||||
$prescriptionCount->andWhere($where);
|
||||
$orderCount->andWhere($where)->andWhere($whereTime);
|
||||
$totalPrice->andWhere($where)->andWhere($whereTime);
|
||||
$inventoryWarning->andWhere($where)->andWhere($whereTime);
|
||||
$drug->where($where)->andWhere($whereTime);
|
||||
$registerCount->andWhere($where)->andWhere($whereTime);
|
||||
$prescriptionCount->andWhere($where)->andWhere($whereTime);
|
||||
}
|
||||
$totalPriceArr = 0;
|
||||
$totalPriceSum = $totalPrice->select(['total_price'])->asArray()->all();
|
||||
@@ -129,6 +133,24 @@ class HomeController extends BaseAdminController
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取时间筛选条件
|
||||
* @param $startTime
|
||||
* @param $endTime
|
||||
* @return array
|
||||
*/
|
||||
public function getWhereTime($startTime, $endTime, $field = 'created_at')
|
||||
{
|
||||
if (!empty($startTime) && !empty($endTime)) {
|
||||
$where = ['between', $field, strtotime(date('Y-m-d 00:00:00', strtotime($startTime))), strtotime(date('Y-m-d 23:59:59', strtotime($endTime)))];
|
||||
} else {
|
||||
$time = time();
|
||||
$where = ['between', $field, $time - 86400 * 7, $time];
|
||||
}
|
||||
return $where;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取销售量Top10的药品
|
||||
* @return array|ActiveRecord[]
|
||||
@@ -136,11 +158,15 @@ class HomeController extends BaseAdminController
|
||||
*/
|
||||
public function actionTopDrugs()
|
||||
{
|
||||
$get = \Yii::$app->request->get();
|
||||
$whereTime = $this->getWhereTime($get['start_time'], $get['end_time'], 'rec.created_at');
|
||||
// 通过yii_reconciliation表统计出前10的药品
|
||||
$query = Reconciliation::find()
|
||||
->alias('rec')
|
||||
->with(['drug' => function ($query) {
|
||||
$query->select(['id', 'drug_name', 'drug_number', 'type', 'image']);
|
||||
}])
|
||||
->where($whereTime)
|
||||
->select(['drug_id', 'sum(number) as number', 'sum(total_price) as total_price'])
|
||||
->groupBy('drug_id')
|
||||
->orderBy(['total_price' => SORT_DESC])
|
||||
@@ -234,6 +260,7 @@ class HomeController extends BaseAdminController
|
||||
*/
|
||||
public function storeLowStock()
|
||||
{
|
||||
return [];
|
||||
$selectStore = $this->request->get('store_id');
|
||||
$query = DrugStoreRelations::find()
|
||||
->with(['drug' => function ($query) {
|
||||
@@ -294,11 +321,14 @@ class HomeController extends BaseAdminController
|
||||
*/
|
||||
public function actionTopStore()
|
||||
{
|
||||
$get = \Yii::$app->request->get();
|
||||
$whereTime = $this->getWhereTime($get['start_time'], $get['end_time']);
|
||||
return CashAccount::find()
|
||||
->with(['store' => function ($query) {
|
||||
$query->select(['id', 'name']);
|
||||
}])
|
||||
->where(['user_type' => 1])
|
||||
->andWhere($whereTime)
|
||||
->select(['user_id', 'total_cash'])
|
||||
->orderBy(['total_cash' => SORT_DESC])
|
||||
->limit(5)
|
||||
@@ -323,7 +353,7 @@ class HomeController extends BaseAdminController
|
||||
},
|
||||
])
|
||||
->where(['between', 'por.created_at', strtotime('-7 day'), time()])
|
||||
->andWhere(['status' => 0])
|
||||
->andWhere(['por.status' => 0])
|
||||
// ->where(['por.status' => 0])
|
||||
->orderBy(['id' => SORT_DESC])
|
||||
->asArray();
|
||||
|
||||
Reference in New Issue
Block a user