| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?php
- namespace ghs\controllers;
- use bizGhs\custom\classes\CustomClass;
- use bizGhs\order\classes\OrderClearClass;
- use bizHd\purchase\classes\PurchaseClearClass;
- use common\components\dateUtil;
- use Yii;
- use common\components\util;
- class OrderClearController extends BaseController
- {
- //收款 ssh 2021.2.4
- public function actionClear()
- {
- $post = Yii::$app->request->post();
- $shopAdmin = $this->shopAdmin;
- if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
- util::fail('超管才能结帐');
- }
- $id = Yii::$app->request->post('id');
- $customId = Yii::$app->request->post('customId', 0);
- if (empty($id)) {
- util::fail('请选择交易记录');
- }
- //抹零之后的价格
- $modifyPrice = Yii::$app->request->post('modifyPrice', 0.00);
- if (is_numeric($modifyPrice) == false || $modifyPrice <= 0) {
- util::fail('金额填错了哦');
- }
- $custom = CustomClass::getById($customId, true);
- CustomClass::valid($custom, $this->shopId);
- $current = time();
- $where = ['customId' => $customId, 'status' => PurchaseClearClass::STATUS_AWAIT_PAY];
- $searchTime = $post['searchTime'] ?? '';
- //结账记录太多数据库会报错,所以必须选月份才能结账!!!!!
- if (empty($searchTime)) {
- util::fail('请选择月份');
- }
- $startTime = $post['startTime'] ?? '';
- $endTime = $post['endTime'] ?? '';
- $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
- $startDate = $period['startTime'];
- $endDate = $period['endTime'];
- $where['addTime'] = ['between', [$startDate, $endDate]];
- if (bcdiv(bcsub(strtotime($endDate), strtotime($startDate)), 86400) > 50) {
- util::fail('超过30天,请按月结账');
- }
- //查找有没结帐订单还没有过期
- $list = OrderClearClass::getAllByCondition($where, null, '*', null, true);
- if (!empty($list)) {
- foreach ($list as $item) {
- $deadline = $item->deadline;
- $deadTime = strtotime($deadline);
- if ($current > $deadTime) {
- $item->status = PurchaseClearClass::STATUS_EXPIRE;
- $item->save();
- } else {
- util::fail('客户是否也在结账?请几分钟后再试');
- }
- }
- }
- $payWay = Yii::$app->request->post('payWay', 0);
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- $name = $this->shopAdmin['name'] ?? '';
- $data = [
- 'customId' => $customId,
- 'ghsShopAdminId' => $this->shopAdminId,
- 'ghsShopAdminName' => $name,
- 'modifyPrice' => $modifyPrice,
- 'payWay' => $payWay,
- ];
- try {
- OrderClearClass::clear($data, $id, $this->sjId, $this->shopId);
- $transaction->commit();
- } catch (\Exception $exception) {
- $transaction->rollBack();
- Yii::info("批量收款失败:" . $exception->getMessage());
- util::fail('操作失败');
- }
- util::complete();
- }
- }
|