PartController.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. namespace ghs\controllers;
  3. use bizGhs\part\classes\PartClass;
  4. use bizGhs\part\classes\PartItemClass;
  5. use common\components\dict;
  6. use common\components\imgUtil;
  7. use common\components\util;
  8. use Yii;
  9. class PartController extends BaseController
  10. {
  11. public $guestAccess = [];
  12. public function actionGetFullInfo()
  13. {
  14. $orderSn = Yii::$app->request->get('orderSn', '');
  15. $info = PartClass::getByCondition(['orderSn' => $orderSn], true);
  16. if ($info->mainId != $this->mainId) {
  17. util::fail('没有权限');
  18. }
  19. $orderSn = $info->orderSn ?? '';
  20. $orderInfo = PartItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*');
  21. $itemData = [];
  22. if (!empty($orderInfo)) {
  23. foreach ($orderInfo as $v) {
  24. $shortCover = $v['cover'] ?? '';
  25. $v['cover'] = imgUtil::groupImg($shortCover);
  26. $itemData[] = $v;
  27. }
  28. }
  29. util::success(['info' => $info, 'itemList' => $itemData]);
  30. }
  31. //列表
  32. public function actionList()
  33. {
  34. $where = [];
  35. $where['mainId'] = $this->mainId;
  36. $list = PartClass::getPartList($where);
  37. util::success($list);
  38. }
  39. //拆散花材 ssh 20230208
  40. public function actionPartItem()
  41. {
  42. $post = Yii::$app->request->post();
  43. $post['shopId'] = $this->shopId;
  44. $post['sjId'] = $this->sjId;
  45. $post['mainId'] = $this->mainId;
  46. $post['shopAdminId'] = $this->shopAdminId;
  47. $shopAdmin = $this->shopAdmin;
  48. $adminName = $shopAdmin['name'] ?? '';
  49. $post['shopAdminName'] = $adminName;
  50. $productJson = $post['product'] ?? '';
  51. if (empty($productJson)) {
  52. util::fail('请选择花材');
  53. }
  54. $productList = json_decode($productJson, true);
  55. if (empty($productList)) {
  56. util::fail('请选择花材');
  57. }
  58. //有unitType数据,说明是收银台传过来的数据,转换成和手机端结构一致
  59. $hasUnitType = array_column($productList, 'unitType');
  60. if (!empty($hasUnitType)) {
  61. $newProductList = [];
  62. foreach ($productList as $key => $val) {
  63. $unitType = $val['unitType'] ?? 0;
  64. $bigNum = 0;
  65. $smallNum = 0;
  66. $num = $val['num'] ?? 0;
  67. $id = $val['productId'] ?? 0;
  68. if ($unitType == dict::getDict('unitType', 'big')) {
  69. $bigNum = $num;
  70. } else {
  71. $smallNum = $num;
  72. util::fail('小单位不能拆散');
  73. }
  74. $newProductList[] = ['productId' => $id, 'bigNum' => $bigNum, 'smallNum' => $smallNum, 'classId' => 0, 'itemId' => 0];
  75. }
  76. $productList = $newProductList;
  77. }
  78. foreach ($productList as $v) {
  79. $bigNum = $v['bigNum'] ?? 0;
  80. $smallNum = $v['smallNum'] ?? 0;
  81. if ($bigNum <= 0) {
  82. util::fail('数量不能为0');
  83. }
  84. if ($smallNum > 0) {
  85. util::fail('仅支持整扎的拆散');
  86. }
  87. $property = $v['property'] ?? 1;
  88. if ($property == 0) {
  89. util::fail('暂不支持成品的拆散');
  90. }
  91. }
  92. $connection = Yii::$app->db;
  93. $transaction = $connection->beginTransaction();
  94. try {
  95. ProductClass::valid($productList, $this->mainId);
  96. $post['product'] = $productList;
  97. $post['ptStyle'] = dict::getDict('ptStyle', 'hd');
  98. $return = PartClass::addOrder($post);
  99. $transaction->commit();
  100. util::success($return);
  101. } catch (\Exception $e) {
  102. $transaction->rollBack();
  103. Yii::info("拆散失败原因:" . $e->getMessage());
  104. util::fail('拆散保存失败');
  105. }
  106. }
  107. }