PurchaseOrderController.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\admin\classes\AdminRoleClass;
  4. use biz\ghs\classes\GhsClass;
  5. use bizGhs\order\classes\PurchaseOrderClass;
  6. use bizGhs\order\classes\PurchaseOrderItemClass;
  7. use bizGhs\product\classes\ProductClass;
  8. use common\components\noticeUtil;
  9. use common\components\printUtil;
  10. use common\components\util;
  11. use Yii;
  12. class PurchaseOrderController extends BaseController
  13. {
  14. //打印全部 ssh 20220602
  15. public function actionPrintAll()
  16. {
  17. $get = Yii::$app->request->get();
  18. $orderSn = $get['orderSn'] ?? 0;
  19. $itemList = PurchaseOrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
  20. if (empty($itemList)) {
  21. util::fail('没有商品');
  22. }
  23. $order = PurchaseOrderClass::getByCondition(['orderSn' => $orderSn], true);
  24. $mainId = $order->mainId ?? 0;
  25. $ext = $this->shopExt;
  26. $printLabelSn = $ext->printLabelSn ?? '';
  27. if (empty($printLabelSn)) {
  28. util::fail('请设置标签打印机');
  29. }
  30. $p = new printUtil($printLabelSn);
  31. foreach ($itemList as $key => $item) {
  32. $name = $item->name ?? '';
  33. $num = !empty($item->itemNum) ? floatval($item->itemNum) : 0;
  34. if (empty($num)) {
  35. util::fail('没有花材数量');
  36. }
  37. $ptItemId = $item->itemId ?? '';
  38. $productId = $item->productId ?? 0;
  39. $p->times = $num;
  40. $smallUnit = $item->smallUnit ?? '';
  41. $bigUnit = $item->bigUnit ?? '';
  42. $ratio = $item->ratio ?? 0;
  43. $unit = $ratio . $smallUnit . '/' . $bigUnit;
  44. $content = '<TEXT x="360" y="30" font="12" w="2" h="2" r="90">' . $name . '</TEXT>';
  45. $content .= '<BC128 x="260" y="30" h="80" s="1" r="90" n="5" w="12">' . $ptItemId . '</BC128>';
  46. if ($key % 2 == 1) {
  47. $content .= '<TEXT x="415" y="20" font="12" w="2" h="2" r="90">.</TEXT>';
  48. }
  49. if (in_array($mainId, [52, 1459])) {
  50. $content .= '<TEXT x="80" y="30" font="12" w="2" h="2" r="90">惠雅鲜花</TEXT>';
  51. } else {
  52. $content .= '<TEXT x="80" y="30" font="12" w="2" h="2" r="90">' . $unit . '</TEXT>';
  53. }
  54. //$content .= '<QR x="30" y="390" e="L" w="5">' . Yii::$app->params['mallHost'] . "/item/show-info?id=" . $productId . '</QR>';
  55. //$content .= '<TEXT x="220" y="400" font="12" w="1" h="1" r="90">扫码看价格</TEXT>';
  56. $p->printLabelMsg($content);
  57. }
  58. util::complete();
  59. }
  60. //打印全部 ssh 20220
  61. public function actionPrintItem()
  62. {
  63. $get = Yii::$app->request->get();
  64. $id = $get['id'] ?? 0;
  65. $item = PurchaseOrderItemClass::getById($id, true);
  66. if (empty($item)) {
  67. util::fail('没有找到花材');
  68. }
  69. $name = $item->name ?? '';
  70. $num = !empty($item->itemNum) ? floatval($item->itemNum) : 0;
  71. if (empty($num)) {
  72. util::fail('没有花材数量');
  73. }
  74. $orderSn = $item->orderSn ?? '';
  75. $order = PurchaseOrderClass::getByCondition(['orderSn' => $orderSn], true);
  76. $mainId = $order->mainId ?? 0;
  77. $ext = $this->shopExt;
  78. $printLabelSn = $ext->printLabelSn ?? '';
  79. if (empty($printLabelSn)) {
  80. util::fail('请设置标签打印机');
  81. }
  82. $p = new printUtil($printLabelSn);
  83. $smallUnit = $item->smallUnit ?? '';
  84. $bigUnit = $item->bigUnit ?? '';
  85. $unit = $smallUnit . '/' . $bigUnit;
  86. $ptItemId = $item->itemId ?? '';
  87. $productId = $item->productId ?? 0;
  88. $p->times = $num;
  89. $content = '<TEXT x="360" y="30" font="12" w="2" h="2" r="90">' . $name . '</TEXT>';
  90. $content .= '<BC128 x="260" y="30" h="80" s="1" r="90" n="5" w="12">' . $ptItemId . '</BC128>';
  91. if (in_array($mainId, [52, 1459])) {
  92. $content .= '<TEXT x="80" y="30" font="12" w="2" h="2" r="90">惠雅鲜花</TEXT>';
  93. } else {
  94. $content .= '<TEXT x="80" y="30" font="12" w="2" h="2" r="90">' . $unit . '</TEXT>';
  95. }
  96. //$content .= '<QR x="30" y="390" e="L" w="5">' . Yii::$app->params['mallHost'] . "/item/show-info?id=" . $productId . '</QR>';
  97. //$content .= '<TEXT x="220" y="400" font="12" w="1" h="1" r="90">扫码看价格</TEXT>';
  98. $p->printLabelMsg($content);
  99. util::complete();
  100. }
  101. //新增采购订单
  102. public function actionCreateOrder()
  103. {
  104. ini_set('memory_limit', '2045M');
  105. set_time_limit(0);
  106. $post = Yii::$app->request->post();
  107. $post['sjId'] = $this->sjId;
  108. $post['shopId'] = $this->shopId;
  109. $post['adminId'] = $this->adminId;
  110. $post['mainId'] = $this->mainId;
  111. $shopAdmin = $this->shopAdmin;
  112. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  113. util::fail('超管才能修改');
  114. }
  115. $shop = $this->shop;
  116. $carSale = $shop->carSale ?? 0;
  117. if ($carSale == 1) {
  118. util::fail('车销不能采购');
  119. }
  120. $connection = Yii::$app->db;
  121. $transaction = $connection->beginTransaction();
  122. try {
  123. // [{productId:0,itemPrice:1,bigNum:1,smallNum:0}]
  124. $ghsItemInfo = $post['itemInfo'] ?? '';
  125. if (empty($ghsItemInfo)) {
  126. util::fail('请选择花材');
  127. }
  128. $ghsItemInfo = json_decode($ghsItemInfo, true);
  129. if (!is_array($ghsItemInfo)) {
  130. util::fail('花材格式不正确');
  131. }
  132. //合并
  133. $ghsItemInfo = PurchaseOrderClass::mergeItemInfo($ghsItemInfo);
  134. //判断花材格式,是否属于当前门店
  135. ProductClass::valid($ghsItemInfo, $this->mainId);
  136. //获取供货商信息
  137. $ghsId = $post['ghsId'];
  138. // if (getenv('YII_ENV') == 'production') {
  139. // if ($this->shopId == 763) {
  140. // $ghsId = 832;
  141. // $post['ghsId'] = 832;
  142. // }
  143. // }
  144. if (empty($ghsId)) {
  145. util::fail("请选择供货商");
  146. }
  147. $ghsInfo = GhsClass::getGhsInfo($ghsId);
  148. GhsClass::valid($ghsInfo, $this->shopId);
  149. $post['ghsInfo'] = json_encode($ghsInfo);
  150. $post['ghsName'] = $ghsInfo['name'] ?? '';
  151. $post['ghsAvatar'] = $ghsInfo['shortAvatar'] ?? '';
  152. //判断花材里的信息
  153. foreach ($ghsItemInfo as $v) {
  154. $bigNum = $v['bigNum'] ?? 0;
  155. $productId = $v['productId'] ?? 0;
  156. $smallNum = $v['smallNum'] ?? 0;
  157. if (!isset($v['itemPrice'])) {
  158. util::fail('采购价格不能为空');
  159. }
  160. if (!$productId) {
  161. util::fail('花材不存在');
  162. }
  163. if ($bigNum <= 0 && $smallNum <= 0) {
  164. util::fail('花材数量不能为0');
  165. }
  166. }
  167. $post['itemInfo'] = $ghsItemInfo;
  168. $post['debt'] = PurchaseOrderClass::DEBT_YES;
  169. $order = PurchaseOrderClass::addOrder($post);
  170. $transaction->commit();
  171. util::success($order);
  172. } catch (\Exception $e) {
  173. $transaction->rollBack();
  174. noticeUtil::push('批发店采购入库失败,原因:' . $e->getMessage(), '15280215347');
  175. Yii::error("操作失败原因:" . $e->getMessage());
  176. util::fail('操作失败');
  177. }
  178. }
  179. //订单列表
  180. public function actionList()
  181. {
  182. if (getenv('YII_ENV') == 'production') {
  183. //阿东的创始人才能查看采购单
  184. if (in_array($this->mainId, [742])) {
  185. $staff = $this->shopAdmin;
  186. if ($staff->founder != 2 && in_array($staff->id, [126647]) == false) {
  187. util::fail('没有权限');
  188. }
  189. }
  190. }
  191. $get = Yii::$app->request->get();
  192. $orderStatus = $get['status'] ?? '';
  193. if ($orderStatus) {
  194. $where['status'] = $orderStatus;
  195. }
  196. $ghsId = $get['ghsId'] ?? 0;
  197. if (!empty($ghsId)) {
  198. $where['ghsId'] = $ghsId;
  199. }
  200. $where['sjId'] = $this->sjId;
  201. $where['shopId'] = $this->shopId;
  202. $data = PurchaseOrderClass::getOrderList($where);
  203. //状态统计,很慢,暂时隐藏
  204. //$statData = PurchaseOrderClass::statNum($this->shopId);
  205. $statData = [
  206. 'allNum' => 0,
  207. 'unPayNum' => 0,
  208. 'unSendNum' => 0,
  209. 'sendingNum' => 0,
  210. 'finishNum' => 0,
  211. ];
  212. $data = array_merge($data, $statData);
  213. util::success($data);
  214. }
  215. //订单详情
  216. public function actionDetail()
  217. {
  218. if (getenv('YII_ENV') == 'production') {
  219. //阿东的创始人才能查看采购单
  220. if (in_array($this->mainId, [742])) {
  221. $staff = $this->shopAdmin;
  222. if ($staff->founder != 2 && in_array($staff->id, [126647]) == false) {
  223. util::fail('没有权限');
  224. }
  225. }
  226. }
  227. $orderSn = Yii::$app->request->get('orderSn', '');
  228. $orderData = PurchaseOrderClass::getOrderDetail($orderSn, $this->shopId);
  229. util::success($orderData);
  230. }
  231. //修改备注
  232. public function actionUpdateRemark()
  233. {
  234. $remark = Yii::$app->request->post('remark', '');
  235. $id = Yii::$app->request->post('id', '');
  236. $cg = PurchaseOrderClass::getById($id, true);
  237. if (empty($cg)) {
  238. util::fail('没有找到订单');
  239. }
  240. if ($cg->shopId != $this->shopId) {
  241. util::fail('没有权限修改');
  242. }
  243. $cg->remark = $remark;
  244. $cg->save();
  245. util::complete('修改成功');
  246. }
  247. }