| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- <?php
- namespace mall\controllers;
- use bizHd\order\classes\SettleClass;
- use bizHd\recharge\classes\RechargeClass;
- use bizHd\wx\classes\WxOpenClass;
- use bizMall\order\classes\OrderClass;
- use common\components\dict;
- use common\components\lakala\Lakala;
- use common\components\noticeUtil;
- use common\components\orderSn;
- use common\components\util;
- use Yii;
- class SettleController extends BaseController
- {
- public $guestAccess = [];
- public function actionGetDetail()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $settle = SettleClass::getById($id);
- if ($settle['customUserId'] != $this->userId) {
- util::fail('不是你的账单');
- }
- $respond = SettleClass::getMyDetail($settle);
- util::success($respond);
- }
- public function actionCancelSettle()
- {
- util::fail('开发中');
- }
- public function actionGetList()
- {
- $get = Yii::$app->request->get();
- $where = [];
- if (isset($get['status']) && is_numeric($get['status'])) {
- $where['status'] = $get['status'];
- }
- $hdId = $get['hdId'] ?? 0;
- if (!empty($hdId)) {
- //BaseController文件有判断是否本人花店,这里不需要再判断
- $where['hdId'] = $hdId;
- }
- $where['shopId'] = $this->shopId;
- $list = \bizMall\settle\classes\SettleClass::getSettleList($where);
- $totalAmount = SettleClass::sum(['shopId' => $this->shopId, 'status' => 2, 'hdId' => $hdId], 'actPrice');
- $list['totalAmount'] = floatval($totalAmount);
- util::success($list);
- }
- //创建结账和充值单 ssh 20250709
- public function actionCreateOrder()
- {
- $post = Yii::$app->request->post();
- $shop = $this->shop;
- if (empty($shop)) {
- util::fail('没有门店信息');
- }
- $hd = $this->hd;
- if (empty($hd)) {
- util::fail('没有花店信息呢');
- }
- $custom = $this->custom;
- if (empty($custom)) {
- util::fail('花店信息缺失,编号88611');
- }
- $idList = $post['ids'] ?? '';
- $idList = trim($idList);
- if (empty($idList)) {
- util::fail('请选择订单');
- }
- $ids = explode(',', $idList);
- if (empty($ids)) {
- util::fail('请选择订单哦');
- }
- $mayClearAmount = 0;
- $orderList = OrderClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
- if (empty($orderList)) {
- util::fail('没有选订单');
- }
- $myClearData = [];
- foreach ($orderList as $order) {
- if ($order->mainId != $this->mainId) {
- util::fail('不是你的订单呢');
- }
- $orderId = $order->id;
- $orderSn = $order->orderSn ?? '';
- $remainDebtPrice = $order->remainDebtPrice ?? 0;
- $mayClearAmount = bcadd($mayClearAmount, $remainDebtPrice, 2);
- $myClearData[] = ['orderId' => $orderId, 'clearAmount' => $remainDebtPrice, 'orderSn' => $orderSn];
- }
- if ($mayClearAmount <= 0) {
- util::fail('不需要销账');
- }
- $orderSn = orderSn::getRechargeSn();
- $payWay = 0;
- $shopId = $this->shopId;
- $mainId = $this->mainId;
- $hdId = $hd->id;
- $hdName = $hd->name;
- $staffId = 0;
- $staffName = '';
- $customId = $custom->id;
- $customName = $custom->name;
- $userId = $this->userId;
- $staff = [];
- //避免重复提交
- util::checkRepeatCommit($userId, 6);
- $createData = [
- 'customId' => $customId,
- 'customName' => $customName,
- 'userId' => $userId,
- 'orderSn' => $orderSn,
- 'modPrice' => 1,
- 'payWay' => $payWay,
- 'style' => 1,
- 'shopId' => $shopId,
- 'mainId' => $mainId,
- 'hdId' => $hdId,
- 'hdName' => $hdName,
- 'onlinePay' => 1,
- 'amount' => $mayClearAmount,
- 'staffId' => $staffId,
- 'staffName' => $staffName,
- 'payStatus' => 0,
- 'payTime' => '0000-00-00 00:00:00',
- 'status' => 0,
- 'remark' => '',
- ];
- $respond = RechargeClass::addRecharge($createData);
- //创建待账单
- $settle = SettleClass::addSettle($myClearData, $shop, $custom, $hd, $staff);
- $settleId = $settle->id;
- $settleAmount = $settle->actPrice;
- $settleNo = $settle->orderSn ?? '';
- $respond->settleId = $settleId;
- $respond->settleAmount = $settleAmount;
- $respond->settleNo = $settleNo;
- $respond->save();
- util::success($respond);
- }
- }
|