AddressController.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace hd\controllers;
  3. use bizHd\admin\classes\AddressClass;
  4. use Yii;
  5. use common\components\util;
  6. class AddressController extends BaseController
  7. {
  8. //详情 ssh 20221003
  9. public function actionDetail()
  10. {
  11. $get = Yii::$app->request->get();
  12. $id = $get['id'] ?? 0;
  13. $address = AddressClass::getById($id, true);
  14. if (empty($address)) {
  15. util::fail('没有找到地址');
  16. }
  17. if ($address->mainId != $this->mainId) {
  18. util::fail('没有权限');
  19. }
  20. util::success(['info' => $address]);
  21. }
  22. //删除地址 ssh 202201003
  23. public function actionDel()
  24. {
  25. $get = Yii::$app->request->get();
  26. $id = $get['id'] ?? 0;
  27. $address = AddressClass::getById($id, true);
  28. if (empty($address)) {
  29. util::fail('没有找到地址');
  30. }
  31. if ($address->mainId != $this->mainId) {
  32. util::fail('没有权限');
  33. }
  34. $address->delete();
  35. util::complete('删除成功');
  36. }
  37. //地址列表 ssh 20221003
  38. public function actionList()
  39. {
  40. //$get = Yii::$app->request->get();
  41. $where = ['adminId' => $this->adminId];
  42. $list = AddressClass::getAddressList($where);
  43. util::success($list);
  44. }
  45. //地址列表 ssh 20221003
  46. public function actionAdd()
  47. {
  48. $post = Yii::$app->request->post();
  49. $post['sjId'] = $this->sjId;
  50. $post['mainId'] = $this->mainId;
  51. $post['shopId'] = $this->shopId;
  52. $post['adminId'] = $this->adminId;
  53. $default = $post['default'] ?? 0;
  54. if ($default == 1) {
  55. AddressClass::updateByCondition(['adminId' => $this->adminId], ['default' => 0]);
  56. }
  57. AddressClass::addData($post);
  58. util::complete('添加成功');
  59. }
  60. //修改地址 ssh 20221003
  61. public function actionUpdate()
  62. {
  63. $post = Yii::$app->request->post();
  64. $id = $post['id'] ?? 0;
  65. unset($post['id']);
  66. $address = AddressClass::getById($id, true);
  67. if (empty($address)) {
  68. util::fail('没有找到地址');
  69. }
  70. if ($address->mainId != $this->mainId) {
  71. util::fail('没有权限修改');
  72. }
  73. $default = $post['default'] ?? 0;
  74. if ($default == 1) {
  75. AddressClass::updateByCondition(['adminId' => $this->adminId], ['default' => 0]);
  76. }
  77. AddressClass::updateById($id, $post);
  78. util::complete('修改成功');
  79. }
  80. }