PartController.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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\printUtil;
  9. use common\components\util;
  10. use Yii;
  11. class PartController extends BaseController
  12. {
  13. public $guestAccess = [];
  14. public function actionGetFullInfo()
  15. {
  16. $orderSn = Yii::$app->request->get('orderSn', '');
  17. $info = PartClass::getByCondition(['orderSn' => $orderSn], true);
  18. if ($info->mainId != $this->mainId) {
  19. util::fail('没有权限');
  20. }
  21. $orderSn = $info->orderSn ?? '';
  22. $orderInfo = PartItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*');
  23. $itemData = [];
  24. if (!empty($orderInfo)) {
  25. foreach ($orderInfo as $v) {
  26. $shortCover = $v['cover'] ?? '';
  27. $v['cover'] = imgUtil::groupImg($shortCover);
  28. $itemData[] = $v;
  29. }
  30. }
  31. util::success(['info' => $info, 'itemList' => $itemData]);
  32. }
  33. //列表
  34. public function actionList()
  35. {
  36. $where = [];
  37. $where['mainId'] = $this->mainId;
  38. $list = PartClass::getPartList($where);
  39. util::success($list);
  40. }
  41. //拆散花材 ssh 20230208
  42. public function actionPartItem()
  43. {
  44. $post = Yii::$app->request->post();
  45. $post['shopId'] = $this->shopId;
  46. $post['sjId'] = $this->sjId;
  47. $post['mainId'] = $this->mainId;
  48. $post['shopAdminId'] = $this->shopAdminId;
  49. $shopAdmin = $this->shopAdmin;
  50. $adminName = $shopAdmin['name'] ?? '';
  51. $post['shopAdminName'] = $adminName;
  52. $productJson = $post['product'] ?? '';
  53. if (empty($productJson)) {
  54. util::fail('请选择花材');
  55. }
  56. $productList = json_decode($productJson, true);
  57. if (empty($productList)) {
  58. util::fail('请选择花材');
  59. }
  60. //有unitType数据,说明是收银台传过来的数据,转换成和手机端结构一致
  61. $hasUnitType = array_column($productList, 'unitType');
  62. if (!empty($hasUnitType)) {
  63. $newProductList = [];
  64. foreach ($productList as $key => $val) {
  65. $unitType = $val['unitType'] ?? 0;
  66. $bigNum = 0;
  67. $smallNum = 0;
  68. $num = $val['num'] ?? 0;
  69. $id = $val['productId'] ?? 0;
  70. if ($unitType == dict::getDict('unitType', 'big')) {
  71. $bigNum = $num;
  72. } else {
  73. $smallNum = $num;
  74. util::fail('小单位不能拆散');
  75. }
  76. $newProductList[] = ['productId' => $id, 'bigNum' => $bigNum, 'smallNum' => $smallNum, 'classId' => 0, 'itemId' => 0];
  77. }
  78. $productList = $newProductList;
  79. }
  80. foreach ($productList as $v) {
  81. $bigNum = $v['bigNum'] ?? 0;
  82. $smallNum = $v['smallNum'] ?? 0;
  83. if ($bigNum <= 0 && $smallNum <= 0) {
  84. util::fail('数量不能为0');
  85. }
  86. $property = $v['property'] ?? 1;
  87. if ($property == 0) {
  88. util::fail('暂不支持成品的拆散');
  89. }
  90. }
  91. $connection = Yii::$app->db;
  92. $transaction = $connection->beginTransaction();
  93. try {
  94. ProductClass::valid($productList, $this->mainId);
  95. $post['product'] = $productList;
  96. $post['ptStyle'] = dict::getDict('ptStyle', 'ghs');
  97. $return = PartClass::addOrder($post);
  98. $transaction->commit();
  99. util::success($return, '拆散成功');
  100. } catch (\Exception $e) {
  101. $transaction->rollBack();
  102. Yii::info("拆散失败原因:" . $e->getMessage());
  103. util::fail('拆散保存失败');
  104. }
  105. }
  106. //打印拆散订单
  107. public function actionPrintOrder()
  108. {
  109. $get = Yii::$app->request->get();
  110. $orderSn = $get['orderSn'] ?? '';
  111. if (empty($orderSn)) {
  112. util::fail('参数错误');
  113. }
  114. $info = PartClass::getByCondition(['orderSn' => $orderSn], true);
  115. if (empty($info)) {
  116. util::fail('没有找到拆散单');
  117. }
  118. if ($info->mainId != $this->mainId) {
  119. util::fail('没有权限');
  120. }
  121. $itemList = PartItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*');
  122. if (empty($itemList)) {
  123. util::fail('没有花材需要打印');
  124. }
  125. $ext = $this->shopExt;
  126. $printSn = $ext->printSn ?? '';
  127. $printKey = $ext->printKey ?? '';
  128. if (empty($printSn) || empty($printKey)) {
  129. util::success(['hasNoPrint' => 1]);
  130. }
  131. $shop = $this->shop;
  132. $sj = $this->sj;
  133. $sjName = $sj->name ?? '';
  134. $shopName = $shop->shopName ?? '';
  135. $currentName = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
  136. $kindNum = 0;
  137. $totalNum = 0;
  138. $content = "<CB>{$currentName}</CB><BR>";
  139. $content .= "<CB>拆散单</CB><BR>";
  140. $content .= '商品 数量 <BR>';
  141. $content .= '--------------------------------<BR>';
  142. foreach ($itemList as $current) {
  143. $name = $current['name'] ?? '';
  144. $num = $current['itemNum'] ?? 0;
  145. $content .= '<B>' . $name . ' ' . floatval($num) . '扎' . "</B><BR>";
  146. $content .= '--------------------------------<BR>';
  147. $kindNum = bcadd($kindNum, 1);
  148. $totalNum = bcadd($totalNum, $current['itemNum']);
  149. }
  150. if (!empty($info->remark)) {
  151. $content .= '备注:' . $info->remark . '<BR>';
  152. }
  153. $content .= '<BR>';
  154. $content .= '********************************<BR>';
  155. $content .= "<CB>共{$kindNum}种,{$totalNum}扎";
  156. $content .= "</CB>";
  157. $content .= '********************************<BR>';
  158. $content .= '<BR>';
  159. $content .= "订单编号:{$orderSn}<BR>";
  160. $content .= '拆散人员:' . ($info->shopAdminName ?? '') . '<BR>';
  161. $p = new printUtil($printSn);
  162. $p->printMsg($content, $shop, $orderSn);
  163. util::complete('打印成功');
  164. }
  165. }