CommonUpdateAddress.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\models\common\admin\order;
  8. use app\models\Option;
  9. use app\models\Order;
  10. use app\utils\Validator;
  11. class CommonUpdateAddress
  12. {
  13. public $data;//更新的数据
  14. public function updateAddress()
  15. {
  16. $orderId = $this->data['orderId'];
  17. $name = $this->data['name'];
  18. $mobile = $this->data['mobile'];
  19. $address = $this->data['address'];
  20. $province = $this->data['province'];
  21. $city = $this->data['city'];
  22. $district = $this->data['district'];
  23. if (!isset($orderId)) {
  24. return [
  25. 'code' => 1,
  26. 'msg' => '请传入订单ID'
  27. ];
  28. }
  29. if (!isset($name)) {
  30. return [
  31. 'code' => 1,
  32. 'msg' => '请填写收件人姓名'
  33. ];
  34. }
  35. if (!Validator::phone($mobile)) {
  36. return [
  37. 'code' => 1,
  38. 'msg' => '请输入正确的手机号'
  39. ];
  40. }
  41. if (!isset($mobile)) {
  42. return [
  43. 'code' => 1,
  44. 'msg' => '请填写收件人手机号'
  45. ];
  46. }
  47. if (!isset($address)) {
  48. return [
  49. 'code' => 1,
  50. 'msg' => '请填写收件人地址'
  51. ];
  52. }
  53. $order = Order::findOne($orderId);
  54. $arr = [
  55. 'province' => $province,
  56. 'city' => $city,
  57. 'district' => $district,
  58. 'detail' => $address
  59. ];
  60. $order->name = $name;
  61. $order->mobile = $mobile;
  62. $order->address = $province . $city . $district . $address;
  63. $order->address_data = json_encode($arr);
  64. if ($order->save()) {
  65. return [
  66. 'code' => 0,
  67. 'msg' => '更新成功'
  68. ];
  69. }
  70. return [
  71. 'code' => 1,
  72. 'msg' => '更新失败'
  73. ];
  74. }
  75. public function updateAddress2()
  76. {
  77. $orderId = $this->data['orderId'];
  78. $name = $this->data['name'];
  79. $mobile = $this->data['mobile'];
  80. $address = $this->data['address'];
  81. $province = $this->data['province'];
  82. $city = $this->data['city'];
  83. $district = $this->data['district'];
  84. if (!isset($orderId)) {
  85. return [
  86. 'code' => 1,
  87. 'msg' => '请传入订单ID'
  88. ];
  89. }
  90. if (!isset($name)) {
  91. return [
  92. 'code' => 1,
  93. 'msg' => '请填写收件人姓名'
  94. ];
  95. }
  96. if (!Validator::phone($mobile)) {
  97. return [
  98. 'code' => 1,
  99. 'msg' => '请输入正确的手机号'
  100. ];
  101. }
  102. if (!isset($mobile)) {
  103. return [
  104. 'code' => 1,
  105. 'msg' => '请填写收件人手机号'
  106. ];
  107. }
  108. if (!isset($address)) {
  109. return [
  110. 'code' => 1,
  111. 'msg' => '请填写收件人地址'
  112. ];
  113. }
  114. $order = Order::findOne($orderId);
  115. $arr = [
  116. 'province' => $province,
  117. 'city' => $city,
  118. 'district' => $district,
  119. 'detail' => $address
  120. ];
  121. $order->name = $name;
  122. $order->mobile = $mobile;
  123. $order->address = $province . $city . $district . $address;
  124. $order->address_data = json_encode($arr);
  125. if ($order->save()) {
  126. return [
  127. 'code' => 0,
  128. 'msg' => '更新成功'
  129. ];
  130. }
  131. return [
  132. 'code' => 1,
  133. 'msg' => '更新失败'
  134. ];
  135. }
  136. }