WlController.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace ghs\controllers;
  3. use bizGhs\merchant\classes\WlClass;
  4. use Yii;
  5. use common\components\util;
  6. class WlController extends BaseController
  7. {
  8. //获取所有物流 ssh 20230104
  9. public function actionGetAllWl()
  10. {
  11. $list = WlClass::getAllByCondition(['mainId' => $this->mainId, 'delStatus' => 0], 'inTurn DESC', 'id,name');
  12. util::success(['list' => $list]);
  13. }
  14. public function actionList()
  15. {
  16. $where = ['mainId' => $this->mainId, 'delStatus' => 0];
  17. $list = WlClass::getWlList($where);
  18. util::success($list);
  19. }
  20. //删除物流 ssh 20230105
  21. public function actionDelWl()
  22. {
  23. $id = Yii::$app->request->get('id', 0);
  24. $wl = WlClass::getById($id, true);
  25. if (empty($wl)) {
  26. util::fail('没有物流信息');
  27. }
  28. if ($wl->mainId != $this->mainId) {
  29. util::fail('无法操作');
  30. }
  31. $wl->delStatus = 1;
  32. $wl->save();
  33. util::complete();
  34. }
  35. //添加物流 ssh 20230105
  36. public function actionAdd()
  37. {
  38. $post = Yii::$app->request->post();
  39. $post['mainId'] = $this->mainId ?? 0;
  40. $name = $post['name'] ?? '';
  41. $name = trim($name);
  42. if (empty($name)) {
  43. util::fail('请填写名称');
  44. }
  45. $has = WlClass::getByCondition(['mainId' => $this->mainId, 'name' => $name], true);
  46. if (!empty($has)) {
  47. $has->delStatus = 0;
  48. $has->save();
  49. } else {
  50. WlClass::add($post);
  51. }
  52. util::complete('添加成功');
  53. }
  54. public function actionUpdate()
  55. {
  56. $post = Yii::$app->request->post();
  57. $name = $post['name'] ?? '';
  58. $name = trim($name);
  59. $inTurn = $post['inTurn'] ?? 100;
  60. $id = $post['id'] ?? 0;
  61. unset($post['id']);
  62. $pre = WlClass::getById($id, true);
  63. if (empty($pre)) {
  64. util::fail('修改失败');
  65. }
  66. if ($pre->mainId != $this->mainId) {
  67. util::fail('没有权限修改');
  68. }
  69. if ($name != $pre->name) {
  70. $repeat = WlClass::getByCondition(['mainId' => $this->mainId, 'name' => $name], true);
  71. if (!empty($repeat)) {
  72. util::fail('名称已经存在');
  73. }
  74. }
  75. $pre->name = $name;
  76. $pre->inTurn = $inTurn;
  77. $pre->save();
  78. util::complete();
  79. }
  80. }