WastageController.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. //损耗
  3. namespace ghs\controllers;
  4. use Yii;
  5. use bizGhs\order\classes\StockWastageOrderClass;
  6. use common\components\util;
  7. use bizGhs\product\classes\ProductClass;
  8. class WastageController extends BaseController
  9. {
  10. //新增损耗
  11. public function actionCreateOrder()
  12. {
  13. $shopAdmin = $this->shopAdmin;
  14. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  15. util::fail('超管才能报损');
  16. }
  17. $post = Yii::$app->request->post();
  18. $post['shopId'] = $this->shopId;
  19. $post['sjId'] = $this->sjId;
  20. $post['shopAdminId'] = $this->shopAdminId;
  21. $shopAdmin = $this->shopAdmin;
  22. $adminName = $shopAdmin['name'] ?? '';
  23. $post['shopAdminName'] = $adminName;
  24. $productJson = $post['product'] ?? '';
  25. if (empty($productJson)) {
  26. util::fail('请选择花材');
  27. }
  28. $productList = json_decode($productJson, true);
  29. if (empty($productList)) {
  30. util::fail('请选择花材');
  31. }
  32. //判断花材里的信息
  33. foreach ($productList as $v) {
  34. $bigNum = $v['bigNum'] ?? 0;
  35. $smallNum = $v['smallNum'] ?? 0;
  36. if ($bigNum <= 0 && $smallNum <= 0) {
  37. util::fail('花材数量不能为0');
  38. }
  39. }
  40. $connection = Yii::$app->db;//事务处理
  41. $transaction = $connection->beginTransaction();
  42. try {
  43. //判断花材有效性
  44. ProductClass::valid($productList, $this->shopId);
  45. $post['product'] = $productList;
  46. $return = StockWastageOrderClass::addOrder($post);
  47. $transaction->commit();
  48. util::success($return);
  49. } catch (\Exception $e) {
  50. $transaction->rollBack();
  51. Yii::info("报损失败原因:" . $e->getMessage());
  52. util::fail('报损保存失败');
  53. }
  54. }
  55. //列表
  56. public function actionList()
  57. {
  58. $get = Yii::$app->request->get();
  59. $where = [];
  60. $where['shopId'] = $this->shopId;
  61. $list = StockWastageOrderClass::getOrderList($where);
  62. util::success($list);
  63. }
  64. public function actionDetail()
  65. {
  66. $orderSn = Yii::$app->request->get('orderSn', '');
  67. $orderData = StockWastageOrderClass::getOrderDetail($orderSn, $this->shopId);
  68. util::success($orderData);
  69. }
  70. }