PdGoodsController.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace hd\controllers;
  3. use bizHd\pd\classes\PdGoodsClass;
  4. use bizHd\pd\classes\PdGoodsDetailClass;
  5. use Yii;
  6. use common\components\util;
  7. class PdGoodsController extends BaseController
  8. {
  9. //订单列表 ssh 20230302
  10. public function actionList()
  11. {
  12. $get = Yii::$app->request->get();
  13. $orderStatus = isset($get['status']) ? $get['status'] : '';
  14. $where = [];
  15. $where['shopId'] = $this->shopId;
  16. if (!empty($orderStatus)) {
  17. $where['status'] = $orderStatus;
  18. }
  19. $list = PdGoodsClass::getPdList($where);
  20. util::success($list);
  21. }
  22. //订单详情
  23. public function actionGetInfo()
  24. {
  25. $get = Yii::$app->request->get();
  26. $orderSn = $get['orderSn'] ?? '';
  27. $info = PdGoodsClass::getByCondition(['orderSn' => $orderSn], true);
  28. if (empty($info) || $info->mainId != $this->mainId) {
  29. util::fail('没有找到盘点记录');
  30. }
  31. $detail = PdGoodsDetailClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
  32. $data = ['info' => $info, 'goodsList' => $detail];
  33. util::success($data);
  34. }
  35. //创建盘点 ssh 20230302
  36. public function actionCreateOrder()
  37. {
  38. $post = Yii::$app->request->post();
  39. $post['sjId'] = $this->sjId;
  40. $post['shopId'] = $this->shopId;
  41. $staff = $this->shopAdmin;
  42. $post['adminId'] = $this->adminId;
  43. $post['staffName'] = $staff->name ?? '';
  44. $post['mainId'] = $this->mainId;
  45. $goodsItemInfo = $post['goodsInfo'] ?? '';
  46. if (empty($goodsItemInfo)) {
  47. util::fail('请选择花材');
  48. }
  49. $goodsItemInfo = json_decode($goodsItemInfo, true);
  50. if (!is_array($goodsItemInfo)) {
  51. util::fail('商品格式错误');
  52. }
  53. foreach ($goodsItemInfo as $key => $item) {
  54. //如果盘点数是99999则转为0
  55. if (isset($item['num']) && $item['num'] == 99999) {
  56. $goodsItemInfo[$key]['num'] = 0;
  57. }
  58. }
  59. $post['goodsInfo'] = $goodsItemInfo;
  60. $connection = Yii::$app->db;
  61. $transaction = $connection->beginTransaction();
  62. try {
  63. PdGoodsClass::createPd($post);
  64. $transaction->commit();
  65. util::complete();
  66. } catch (\Exception $e) {
  67. $transaction->rollBack();
  68. Yii::info("操作原因:" . $e->getMessage());
  69. util::fail('操作失败');
  70. }
  71. }
  72. }