| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265 |
- <?php
- namespace ghs\controllers;
- use biz\ghs\classes\GhsClass;
- use biz\wx\classes\WxMessageClass;
- use bizGhs\custom\classes\CustomClass;
- use bizGhs\order\classes\OrderClearClass;
- use bizGhs\shop\classes\ShopClass;
- 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);
- $info = OrderClearClass::getByCondition(['customId' => $customId, 'status' => 1], true);
- if (!empty($info)) {
- util::fail('已有待结账单,请先取消或提醒客户付款');
- }
- $where = ['customId' => $customId, 'status' => PurchaseClearClass::STATUS_AWAIT_PAY];
- $searchTime = $post['searchTime'] ?? '';
- //结账记录太多数据库会报错,所以必须选月份才能结账!!!!!
- //订单详情里可以单个结账
- if (count((array)$id) > 135) {
- util::fail('提交订单数超过135单');
- }
- $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) {
- //只要新建账单,老账单就取消掉
- $item->status = PurchaseClearClass::STATUS_EXPIRE;
- $item->save();
- }
- }
- $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 {
- $clearInfo = OrderClearClass::clear($data, $id, $this->sjId, $this->shopId);
- $transaction->commit();
- if (!empty($clearInfo)) {
- //结账单通知客户
- $customShopId = $custom->shopId ?? 0;
- $customShop = ShopClass::getById($customShopId, true);
- if (!empty($customShop)) {
- $noticeRespond = \bizHd\notice\classes\NoticeClass::newClearNotice($customShop, $clearInfo);
- if (isset($noticeRespond['hasNotice']) && $noticeRespond['hasNotice'] == 1) {
- $clearInfo->hasNoticeCustom = 1;
- $clearInfo->save();
- }
- }
- }
- util::success($clearInfo);
- } 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');
- $payRemark = $get['payRemark'] ?? '';
- $clear = OrderClearClass::getById($id, true);
- if (empty($clear)) {
- util::fail('没有找到结账单');
- }
- $ghsId = $clear->ghsId ?? 0;
- $ghs = GhsClass::getLockById($ghsId);
- if ($ghs->shopId != $this->shopId) {
- util::fail('没有获得授权');
- }
- if ($ghs->balance > 0) {
- util::mistake('客户有余额,不能通过订单销账,请走充值。有疑问请联系技术员', false, 'none', 3000);
- }
- $staff = $this->shopAdmin;
- if (!isset($staff->finance) || $staff->finance == 0) {
- $speShopList = [4608];
- //杭州斗南鲜花员工,没有财务权限也要能销单
- if (!in_array($this->shopId, $speShopList)) {
- util::fail('没有财务权限,不能销单哦');
- }
- }
- //避免网络延迟,造成重复操作
- $cacheKey = 'ghs_custom_confirm_clear_' . $id;
- $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
- if (!empty($has)) {
- util::fail('6秒之后再操作');
- }
- Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 6, 'has']);
- //多个地方需要同步修改clear_order_power
- if (getenv('YII_ENV') == 'production') {
- //小向花卉
- if (in_array($this->shopId, [23580, 24713])) {
- if (!in_array($this->adminId, [24043, 23960])) {
- util::fail('不能销单哈!');
- }
- }
- //花样年华只有总控才能结账
- if (in_array($this->shopId, [1585, 1596])) {
- if ($this->adminId != 2876) {
- util::fail('不能销单。。。');
- }
- }
- //花大苪 洋桔梗,只有叶荷姐才能销账,多处请搜索关键词hdb_clear_control
- if (in_array($this->shopId, [16070])) {
- if (!in_array($this->adminId, [9303, 4])) {
- util::fail('不能销单。');
- }
- }
- //中山淘花里,销账权限控制,多处请搜索 thl_clear_control
- if (in_array($this->shopId, [17118])) {
- if (!in_array($this->adminId, [55494, 55445, 17908, 55459, 55707, 55709])) {
- util::fail('你不能销单那。。');
- }
- }
- //小齐鲜花总店和出车,多处请搜索关键词 xq_clear_control
- if (in_array($this->shopId, [41467, 42946])) {
- if (!in_array($this->adminId, [40144,42912,42023])) {
- util::fail('不能销单。');
- }
- }
- //恋善好多花控制销账权限
- if (in_array($this->shopId, [55238, 56609, 56611])) {
- if (!in_array($this->adminId, [43856, 54620])) {
- util::fail('暂无权限,请联系老板或财务');
- }
- }
- //天天鲜花 陈江店
- if (in_array($this->shopId, [763, 1405, 795])) {
- if (!in_array($this->adminId, [2094, 5959])) {
- util::fail('不能销单哦');
- }
- }
- //花儿好仙
- if (in_array($this->shopId, [22666])) {
- if (!in_array($this->adminId, [12869, 23174])) {
- util::fail('不能充值销单哈');
- }
- }
- //小丽鲜花
- if (in_array($this->shopId, [11094])) {
- if (!in_array($this->adminId, [12073, 12296])) {
- util::fail('您不能充值销单哦');
- }
- }
- //源花汇
- if (in_array($this->shopId, [10649])) {
- if (!in_array($this->adminId, [11641, 11648, 4])) {
- util::fail('请闵总或小周操作');
- }
- }
- //昱成
- if (in_array($this->shopId, [8596])) {
- if (!in_array($this->adminId, [9303, 9601])) {
- util::fail('只能叶荷和财务操作');
- }
- }
- //花大苪
- if (in_array($this->shopId, [8249])) {
- if (!in_array($this->adminId, [9303])) {
- util::fail('只能叶荷操作');
- }
- }
- } else {
- if (in_array($this->shopId, [36523])) {
- if ($this->adminId != 919) {
- util::fail('不能销单哈');
- }
- }
- }
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $clear->payRemark = $payRemark;
- $clear->save();
- $amount = $clear->actPrice ?? 0;
- $customId = $clear->customId ?? 0;
- $custom = CustomClass::getLockById($customId);
- $shop = $this->shop;
- $staff = $this->shopAdmin;
- //充值
- $return = CustomClass::rechargeBalance($custom, $amount, $shop, $staff, $payWay);
- $custom = $return['custom'];
- $ghs = $return['ghs'];
- $customRecharge = $return['customRecharge'];
- //结账
- OrderClearClass::confirmClear($clear, $payWay);
- $clearInfo = OrderClearClass::getLockById($id);
- //结账消余额
- CustomClass::clearConsumeBalance($amount, $custom, $ghs, $shop, $staff, $clearInfo);
- $transaction->commit();
- //充值销账通知
- WxMessageClass::customRechargeClearInform($shop, $customRecharge);
- util::complete();
- } catch (\Exception $exception) {
- $transaction->rollBack();
- Yii::info("失败:" . $exception->getMessage());
- util::fail('操作失败');
- }
- }
- }
|