| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- <?php
- namespace ghs\controllers;
- use biz\ghs\classes\GhsClass;
- use bizGhs\custom\classes\CustomClass;
- use bizGhs\order\classes\OrderClearClass;
- use bizHd\purchase\classes\PurchaseClearClass;
- use common\components\dateUtil;
- use common\components\dict;
- 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 (count((array)$id) > 120) {
- util::fail('提交订单数超过120单');
- }
- $startTime = $post['startTime'] ?? '';
- $endTime = $post['endTime'] ?? '';
- $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
- $startDate = $period['startTime'];
- $endDate = $period['endTime'];
- 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::success(['hasUnComplete' => 1], '此客户还有待完成结账单');
- }
- }
- }
- $payWay = Yii::$app->request->post('payWay', 0);
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- $name = $this->shopAdmin['name'] ?? '';
- $complete = $post['complete'] ?? 0;
- $data = [
- 'customId' => $customId,
- 'ghsShopAdminId' => $this->shopAdminId ?? 0,
- 'ghsShopId' => $this->shopId ?? 0,
- 'ghsShopAdminName' => $name,
- 'modifyPrice' => $modifyPrice,
- 'payWay' => $payWay,
- 'complete' => $complete,
- ];
- try {
- $respond = OrderClearClass::clear($data, $id, $this->sjId, $this->shopId);
- $transaction->commit();
- util::success($respond);
- } catch (\Exception $exception) {
- $transaction->rollBack();
- Yii::info("批量收款失败:" . $exception->getMessage());
- util::fail('操作失败');
- }
- util::complete();
- }
- //确认结账 ssh 20220510
- public function actionConfirmClear()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $payWay = $get['payWay'] ?? dict::getDict('payWay', 'wxPay');
- $clear = OrderClearClass::getById($id, true);
- if (empty($clear)) {
- util::fail('没有找到结账单');
- }
- $ghsId = $clear->ghsId ?? 0;
- $ghs = GhsClass::getById($ghsId, true);
- if ($ghs->shopId != $this->shopId) {
- util::fail('没有权限');
- }
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- OrderClearClass::confirmClear($clear, $payWay);
- $transaction->commit();
- util::complete();
- } catch (\Exception $exception) {
- $transaction->rollBack();
- Yii::info("失败:" . $exception->getMessage());
- util::fail('操作失败');
- }
- }
- }
|