PartController.php 6.4 KB

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