BookCustomChangeClass.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace bizGhs\book\classes;
  3. use bizGhs\base\classes\BaseClass;
  4. use common\components\dict;
  5. use common\components\util;
  6. use Yii;
  7. class BookCustomChangeClass extends BaseClass
  8. {
  9. public static $baseFile = '\bizGhs\book\models\BookCustomChange';
  10. public static function getChangeList($where)
  11. {
  12. $data = self::getList('*', $where, 'addTime DESC,id DESC');
  13. return $data;
  14. }
  15. public static function delBookNum($bookCustomRes, $num, $order, $shop, $product, $params)
  16. {
  17. $mainId = $order->mainId ?? 0;
  18. $customId = $order->customId ?? 0;
  19. $customName = $order->customName ?? '';
  20. $customNamePy = $order->customNamePy ?? '';
  21. $itemId = $product->id ?? 0;
  22. $ptItemId = $product->itemId ?? 0;
  23. $name = $product->name ?? '';
  24. $py = $product->py ?? '';
  25. $bigUnit = $product->bigUnit ?? '扎';
  26. $bookSn = $shop->bookSn ?? '';
  27. $nowNum = bcsub($bookCustomRes->bookNum, $num);
  28. if ($nowNum < 0) {
  29. $cacheKey = $params['cacheKey'] ?? '';
  30. if (!empty($cacheKey)) {
  31. util::unlock($cacheKey);
  32. }
  33. util::fail($customName . '预订的' . $name . '不够减哈 bookCustom');
  34. }
  35. $bookCustomRes->bookNum = $nowNum;
  36. $bookCustomRes->save();
  37. $bookItemCustomResId = $bookCustomRes->id ?? 0;
  38. $ioRes = $params['ioRes'] ?? null;
  39. $relatedId = $ioRes->id ?? 0;
  40. //变动记录
  41. $currentCapitalType = dict::getDict('capitalType', 'delBook');
  42. $staffName = $params['staffName'] ?? '';
  43. $staffId = $params['staffId'] ?? 0;
  44. $event = $customName . '减少' . $name . $num . $bigUnit;
  45. $changeData = [
  46. 'mainId' => $mainId,
  47. 'bookSn' => $bookSn,
  48. 'name' => $name,
  49. 'py' => $py,
  50. 'itemId' => $itemId,
  51. 'ptItemId' => $ptItemId,
  52. 'customId' => $customId,
  53. 'customName' => $customName,
  54. 'customNamePy' => $customNamePy,
  55. 'relateId' => $relatedId,
  56. 'relateSecondId' => $bookItemCustomResId,
  57. 'ptStyle' => 2,
  58. 'capitalType' => $currentCapitalType,
  59. 'io' => 0,
  60. 'changeNum' => $num,
  61. 'num' => $bookCustomRes->bookNum,
  62. 'event' => $event,
  63. 'staffId' => $staffId,
  64. 'staffName' => $staffName,
  65. 'remark' => '',
  66. ];
  67. BookCustomChangeClass::add($changeData, true);
  68. return $bookCustomRes;
  69. }
  70. }