支付方式修改

This commit is contained in:
2025-03-14 16:49:08 +08:00
parent 79852501a6
commit e92607d14d
2 changed files with 126 additions and 0 deletions

View File

@@ -7,6 +7,7 @@ use admin\models\Admin;
use common\enums\UserRoleEnum;
use common\forms\ProductRefundForm;
use common\helpers\FuncHelper;
use common\models\newDb\MonthlyPaymentModel;
use common\models\oldDb\CashApply;
use common\models\oldDb\FundWater;
use common\models\oldDb\Ledger;
@@ -891,4 +892,119 @@ class FinanceController extends BaseAdminController
}
return $weeks;
}
/**
* 月度付款列表 - 店铺
* @return array
*/
public function actionMonthlyPaymentByStore()
{
$results = MonthlyPaymentModel::find()->with([
'order' => function ($query) {
$query->select(['id', 'order_no']);
},
'store' => function ($query) {
$query->select(['id', 'name']);
},
])->where(['store_id' => \Yii::$app->user->identity->store_id])->all();
$results = array_map(function ($item) {
$item['created_at'] = date('Y-m-d H:i:s', $item['created_at']);
return $item;
}, $results);
return [
'data' => $results,
'count' => $this->actionCountStoreMonthlyPayment(\Yii::$app->user->identity->store_id),
];
}
/**
* 月度付款列表 - 平台
* @return array
*/
public function actionMonthlyPayment()
{
$params = \Yii::$app->request->get();
$query = MonthlyPaymentModel::find()->with([
'order' => function ($query) {
$query->select(['id', 'order_no']);
},
'store' => function ($query) {
$query->select(['id', 'name']);
},
]);
// 使用andWhere来追加条件避免覆盖
if (!empty($params['store_id'])) {
$query->andWhere(['store_id' => $params['store_id']]);
}
if (!empty($params['status'])) {
$query->andWhere(['status' => $params['status']]);
}
if (!empty($params['start_time']) && !empty($params['end_time'])) {
$query->andWhere(['between', 'created_at', strtotime($params['start_time']), strtotime($params['end_time'])]);
}
// 执行查询并返回结果数组
$results = $query->asArray()->all();
$results = array_map(function ($item) {
$item['created_at'] = date('Y-m-d H:i:s', $item['created_at']);
return $item;
}, $results);
return [
'data' => $results,
'count' => $this->actionCountStoreMonthlyPayment(!empty($params['store_id'])? $params['store_id']: 0, $params['start_time'], $params['end_time'])
];
}
/**
* 统计店铺月度付款总额
* @param $storeId
* @return array
*/
public function actionCountStoreMonthlyPayment($storeId = 0, $startTime = '', $endTime = '')
{
$model = MonthlyPaymentModel::find()->andWhere(['status' => 0]);
if (!empty($storeId)) {
$model->andWhere(['store_id' => $storeId])->all();
}
if (!empty($startTime) && !empty($endTime)) {
$model->andWhere(['between', 'created_at', strtotime($startTime), strtotime($endTime)]);
}
return [
'count' => $model->count(),
'sum' => $model->sum('amount')?? 0,
];
}
/**
* 结算
* @return array
*/
public function actionSettlement()
{
$params = \Yii::$app->request->post();
$storeId = $params['store_id'];
$startTime = $params['start_time'];
$endTime = $params['end_time'];
if (empty($storeId)) {
return ['请选择诊所'];
}
// 批量修改MonthlyPaymentModel
$model = MonthlyPaymentModel::updateAll(['status' => 1,'updated_at' => time()], [
'and',
['store_id' => $storeId],
['status' => 0],
['between', 'created_at', strtotime($startTime), strtotime($endTime)]
]);
if ($model) {
return ['结算成功'];
}
return ['结算失败'];
}
}

View File

@@ -2,6 +2,8 @@
namespace common\models\newDb;
use common\models\oldDb\ProductOrder;
use common\models\oldDb\Store;
use yii\behaviors\TimestampBehavior;
class MonthlyPaymentModel extends \common\modelsgii\newDb\MonthlyPaymentModelGii
@@ -16,4 +18,12 @@ class MonthlyPaymentModel extends \common\modelsgii\newDb\MonthlyPaymentModelGii
],
];
}
public function getOrder()
{
return $this->hasOne(ProductOrder::class, ['id' => 'order_id']);
}
public function getStore()
{
return $this->hasOne(Store::class, ['id' => 'store_id']);
}
}