PartController.php 3.3 KB

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