| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- <?php
- namespace ghs\controllers;
- use bizGhs\book\classes\BookItemClass;
- use bizGhs\book\classes\BookItemCustomClass;
- use bizGhs\order\classes\OrderClass;
- use bizGhs\product\classes\ProductClass;
- use common\components\util;
- use Yii;
- class BookItemCustomController extends BaseController
- {
- //获取对象资源 ssh 20240829
- public function actionGetInfo()
- {
- $get = Yii::$app->request->get();
- $orderId = $get['orderId'] ?? 0;
- $productId = $get['productId'] ?? 0;
- $shop = $this->shop;
- $order = OrderClass::getById($orderId, true);
- if (empty($order)) {
- util::fail('没有找到订单');
- }
- $bookSn = $shop->bookSn ?? 0;
- if (empty($bookSn)) {
- util::fail('当前不是在预订活动中');
- }
- $customId = $order->customId ?? 0;
- $res = BookItemCustomClass::getByCondition(['bookSn' => $bookSn, 'customId' => $customId, 'itemId' => $productId], true);
- if (empty($res)) {
- util::fail('数据有问题');
- }
- util::success(['res' => $res]);
- }
- //下架 ssh 20240721
- public function actionGoOff()
- {
- $staff = $this->shopAdmin;
- if (isset($staff->identity) && $staff->identity == 2) {
- util::fail('不能操作');
- }
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $num = $get['num'] ?? 0;
- if (empty($num)) {
- util::fail('请填写下架数量');
- }
- $shop = $this->shop;
- $bookSn = $shop->bookSn ?? 0;
- if (empty($bookSn)) {
- util::fail('预订没有开户');
- }
- $book = BookItemCustomClass::getById($id, true);
- if (empty($book) || $book->bookSn != $bookSn) {
- util::fail('当前无法操作');
- }
- $staff = $this->shopAdmin;
- $staffId = $staff->id ?? 0;
- $staffName = $staff->name ?? '';
- $params = ['staffId' => $staffId, 'staffName' => $staffName, 'staff' => $staff];
- BookItemCustomClass::goOff($book, $shop, $params, $num);
- util::complete('操作成功');
- }
- //标记装箱 ssh 20240721
- public function actionToBox()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $shop = $this->shop;
- $bookSn = $shop->bookSn ?? 0;
- if (empty($bookSn)) {
- util::fail('预订没有开户');
- }
- $book = BookItemCustomClass::getById($id, true);
- if (empty($book) || $book->bookSn != $bookSn) {
- util::fail('当前无法操作');
- }
- BookItemCustomClass::toBox($book);
- util::complete('操作成功');
- }
- //取消装箱 ssh 20240721
- public function actionCancelBox()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $shop = $this->shop;
- $bookSn = $shop->bookSn ?? 0;
- if (empty($bookSn)) {
- util::fail('预订没有开户');
- }
- $book = BookItemCustomClass::getById($id, true);
- if (empty($book) || $book->bookSn != $bookSn) {
- util::fail('当前无法操作');
- }
- BookItemCustomClass::cancelBox($book);
- util::complete('操作成功');
- }
- //仓库有货上架和上齐 ssh 20240721
- public function actionGoOn()
- {
- $staff = $this->shopAdmin;
- if (isset($staff->identity) && $staff->identity == 2) {
- util::fail('不能操作');
- }
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $num = $get['num'] ?? 0;
- $shop = $this->shop;
- $bookSn = $shop->bookSn ?? 0;
- if (empty($bookSn)) {
- util::fail('预订没有开启');
- }
- $book = BookItemCustomClass::getById($id, true);
- if (empty($book) || $book->bookSn != $bookSn) {
- util::fail('当前无法操作');
- }
- $staff = $this->shopAdmin;
- $staffId = $staff->id ?? 0;
- $staffName = $staff->name ?? '';
- $params = ['staffId' => $staffId, 'staffName' => $staffName, 'staff' => $staff];
- BookItemCustomClass::goOn($book, $shop, $params, $num);
- util::complete('操作成功');
- }
- //批量上齐 ssh 20240812
- public function actionBatchGoOn()
- {
- $post = Yii::$app->request->post();
- $ids = $post['ids'] ?? '';
- $staff = $this->shopAdmin;
- if (isset($staff->identity) && $staff->identity == 2) {
- util::fail('不能操作');
- }
- $shop = $this->shop;
- $bookSn = $shop->bookSn ?? 0;
- if (empty($bookSn)) {
- util::fail('预订没有开启');
- }
- if (empty($ids)) {
- util::fail('请选择要上齐的项');
- }
- $arr = json_decode($ids, true);
- if (empty($arr)) {
- util::fail('请选择项');
- }
- $staff = $this->shopAdmin;
- $staffId = $staff->id ?? 0;
- $staffName = $staff->name ?? '';
- $params = ['staffId' => $staffId, 'staffName' => $staffName, 'staff' => $staff];
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- foreach ($arr as $id) {
- $num = 0;
- $book = BookItemCustomClass::getById($id, true);
- if (empty($book)) {
- util::fail('有选择项没有找到');
- }
- if ($book->bookSn != $bookSn) {
- util::fail('有选择的项不是当前预订活动');
- }
- BookItemCustomClass::goOn($book, $shop, $params, $num);
- }
- $transaction->commit();
- util::complete();
- } catch (\Exception $e) {
- Yii::info("操作失败原因:" . $e->getMessage());
- $transaction->rollBack();
- util::fail('操作失败');
- }
- }
- //预订客户列表 ssh 20240616
- public function actionList()
- {
- $get = Yii::$app->request->get();
- $where = [];
- $where['mainId'] = $this->mainId;
- $bookSn = $get['bookSn'] ?? '';
- if (empty($bookSn)) {
- $shop = $this->shop;
- $bookSn = $shop->bookSn ?? 0;
- if (empty($bookSn)) {
- util::success(['list' => [], 'hint' => 'no bookSn']);
- }
- }
- $where['bookSn'] = $bookSn;
- $customId = $get['customId'] ?? 0;
- if (!empty($customId)) {
- $where['customId'] = $customId;
- }
- $itemId = $get['itemId'] ?? 0;
- $remainNum = 0;
- $remainName = '';
- if (!empty($itemId)) {
- $where['itemId'] = $itemId;
- //显示剩余数量
- $product = ProductClass::getById($itemId, true);
- $booItem = BookItemClass::getByCondition(['bookSn' => $bookSn, 'itemId' => $itemId], true);
- if (!empty($booItem)) {
- $stock = $product->stock ?? 0;
- $onNum = $booItem->onNum ?? 0;
- $remainNum = bcsub($stock, $onNum);
- $remainName = $product->name ?? '';
- }
- }
- $list = BookItemCustomClass::getAllByCondition($where, '(bookNum-onNum) DESC', '*');
- util::success(['list' => $list, 'remainNum' => $remainNum, 'remainName' => $remainName]);
- }
- }
|