WastageController.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace hd\controllers;
  3. use bizGhs\order\classes\StockWastageOrderClass;
  4. use bizGhs\product\classes\ProductClass;
  5. use common\components\util;
  6. use Yii;
  7. //已中央化 ssh 20220319
  8. class WastageController extends BaseController
  9. {
  10. public $guestAccess = [];
  11. //新增损耗
  12. public function actionCreateOrder()
  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. }
  38. foreach ($productList as $v) {
  39. $bigNum = $v['bigNum'] ?? 0;
  40. $smallNum = $v['smallNum'] ?? 0;
  41. if ($bigNum <= 0 && $smallNum <= 0) {
  42. util::fail('花材数量不能为0');
  43. }
  44. }
  45. $connection = Yii::$app->db;//事务处理
  46. $transaction = $connection->beginTransaction();
  47. try {
  48. ProductClass::valid($productList, $this->mainId);
  49. $post['product'] = $productList;
  50. $return = StockWastageOrderClass::addOrder($post);
  51. $transaction->commit();
  52. util::success($return);
  53. } catch (\Exception $e) {
  54. $transaction->rollBack();
  55. Yii::info("报损失败原因:" . $e->getMessage());
  56. util::fail('报损保存失败');
  57. }
  58. }
  59. //列表
  60. public function actionList()
  61. {
  62. $where = [];
  63. $where['mainId'] = $this->mainId;
  64. $list = StockWastageOrderClass::getOrderList($where);
  65. util::success($list);
  66. }
  67. public function actionDetail()
  68. {
  69. $orderSn = Yii::$app->request->get('orderSn', '');
  70. $orderData = StockWastageOrderClass::getOrderDetail($orderSn, $this->mainId);
  71. util::success($orderData);
  72. }
  73. }