PartController.php 3.8 KB

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