WastageController.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. $post = Yii::$app->request->post();
  14. $post['shopId'] = $this->shopId;
  15. $post['sjId'] = $this->sjId;
  16. $post['shopAdminId'] = $this->shopAdminId;
  17. $shopAdmin = $this->shopAdmin;
  18. $adminName = $shopAdmin['name'] ?? '';
  19. $post['shopAdminName'] = $adminName;
  20. $productJson = $post['product'] ?? '';
  21. if (empty($productJson)) {
  22. util::fail('请选择花材');
  23. }
  24. $productList = json_decode($productJson, true);
  25. if (empty($productList)) {
  26. util::fail('请选择花材');
  27. }
  28. //判断花材里的信息
  29. foreach ($productList as $v) {
  30. $bigNum = $v['bigNum'] ?? 0;
  31. $smallNum = $v['smallNum'] ?? 0;
  32. if ($bigNum <= 0 && $smallNum <= 0) {
  33. util::fail('花材数量不能为0');
  34. }
  35. }
  36. $connection = Yii::$app->db;//事务处理
  37. $transaction = $connection->beginTransaction();
  38. try {
  39. //判断花材有效性
  40. ProductClass::valid($productList, $this->shopId);
  41. $post['product'] = $productList;
  42. $return = StockWastageOrderClass::addOrder($post);
  43. $transaction->commit();
  44. util::success($return);
  45. } catch (\Exception $e) {
  46. $transaction->rollBack();
  47. Yii::info("报损失败原因:" . $e->getMessage());
  48. util::fail('报损保存失败');
  49. }
  50. }
  51. //列表
  52. public function actionList()
  53. {
  54. $get = Yii::$app->request->get();
  55. $where = [];
  56. $where['shopId'] = $this->shopId;
  57. $list = StockWastageOrderClass::getOrderList($where);
  58. util::success($list);
  59. }
  60. public function actionDetail()
  61. {
  62. $orderSn = Yii::$app->request->get('orderSn', '');
  63. $orderData = StockWastageOrderClass::getOrderDetail($orderSn, $this->shopId);
  64. util::success($orderData);
  65. }
  66. }