WlController.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * 花店物流选项管理
  4. * 用途:配送方式-物流(style=3)关联的物流名称维护,与 ghs 端 WlClass 共用主账号维度数据
  5. */
  6. namespace hd\controllers;
  7. use bizGhs\merchant\classes\WlClass;
  8. use Yii;
  9. use common\components\util;
  10. class WlController extends BaseController
  11. {
  12. /** 获取全部物流(下拉用) */
  13. public function actionGetAllWl()
  14. {
  15. $list = WlClass::getAllByCondition(['mainId' => $this->mainId, 'delStatus' => 0], 'inTurn DESC', 'id,name');
  16. util::success(['list' => $list]);
  17. }
  18. /** 物流列表(分页) */
  19. public function actionList()
  20. {
  21. $where = ['mainId' => $this->mainId, 'delStatus' => 0];
  22. $list = WlClass::getWlList($where);
  23. util::success($list);
  24. }
  25. /** 删除物流 */
  26. public function actionDelWl()
  27. {
  28. $id = Yii::$app->request->get('id', 0);
  29. $wl = WlClass::getById($id, true);
  30. if (empty($wl)) {
  31. util::fail('没有物流信息');
  32. }
  33. if ($wl->mainId != $this->mainId) {
  34. util::fail('无法操作');
  35. }
  36. $wl->delStatus = 1;
  37. $wl->save();
  38. util::complete();
  39. }
  40. /** 添加物流 */
  41. public function actionAdd()
  42. {
  43. $post = Yii::$app->request->post();
  44. $post['mainId'] = $this->mainId ?? 0;
  45. $name = trim($post['name'] ?? '');
  46. if (empty($name)) {
  47. util::fail('请填写名称');
  48. }
  49. $has = WlClass::getByCondition(['mainId' => $this->mainId, 'name' => $name], true);
  50. if (!empty($has)) {
  51. $has->delStatus = 0;
  52. $has->save();
  53. } else {
  54. WlClass::add($post);
  55. }
  56. util::complete('添加成功');
  57. }
  58. /** 更新物流 */
  59. public function actionUpdate()
  60. {
  61. $post = Yii::$app->request->post();
  62. $name = trim($post['name'] ?? '');
  63. $inTurn = $post['inTurn'] ?? 100;
  64. $id = $post['id'] ?? 0;
  65. $pre = WlClass::getById($id, true);
  66. if (empty($pre)) {
  67. util::fail('修改失败');
  68. }
  69. if ($pre->mainId != $this->mainId) {
  70. util::fail('没有权限修改');
  71. }
  72. if ($name != $pre->name) {
  73. $repeat = WlClass::getByCondition(['mainId' => $this->mainId, 'name' => $name], true);
  74. if (!empty($repeat)) {
  75. util::fail('名称已经存在');
  76. }
  77. }
  78. $pre->name = $name;
  79. $pre->inTurn = $inTurn;
  80. $pre->save();
  81. util::complete();
  82. }
  83. }