BookItemCustomController.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace ghs\controllers;
  3. use bizGhs\book\classes\BookItemClass;
  4. use bizGhs\book\classes\BookItemCustomClass;
  5. use bizGhs\product\classes\ProductClass;
  6. use common\components\util;
  7. use Yii;
  8. class BookItemCustomController extends BaseController
  9. {
  10. //预订客户列表 ssh 20240616
  11. public function actionList()
  12. {
  13. $get = Yii::$app->request->get();
  14. $where = [];
  15. $where['mainId'] = $this->mainId;
  16. $bookSn = $get['bookSn'] ?? '';
  17. if (empty($bookSn)) {
  18. $shop = $this->shop;
  19. $bookSn = $shop->bookSn ?? 0;
  20. if (empty($bookSn)) {
  21. util::success(['list' => [], 'hint' => 'no bookSn']);
  22. }
  23. }
  24. $where['bookSn'] = $bookSn;
  25. $customId = $get['customId'] ?? 0;
  26. if (!empty($customId)) {
  27. $where['customId'] = $customId;
  28. }
  29. $itemId = $get['itemId'] ?? 0;
  30. $remainNum = 0;
  31. $remainName = '';
  32. if (!empty($itemId)) {
  33. $where['itemId'] = $itemId;
  34. //显示剩余数量
  35. $product = ProductClass::getById($itemId, true);
  36. $booItem = BookItemClass::getByCondition(['bookSn' => $bookSn, 'itemId' => $itemId], true);
  37. if (!empty($booItem)) {
  38. $stock = $product->stock ?? 0;
  39. $onNum = $booItem->onNum ?? 0;
  40. $remainNum = bcsub($stock, $onNum);
  41. $remainName = $product->name ?? '';
  42. }
  43. }
  44. $list = BookItemCustomClass::getAllByCondition($where, '(bookNum-onNum) DESC', '*');
  45. util::success(['list' => $list, 'remainNum' => $remainNum, 'remainName' => $remainName]);
  46. }
  47. }