Address.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace Passport\Src;
  3. use Dever;
  4. use Passport\Lib\Base;
  5. class Address extends Base
  6. {
  7. # 获取默认地址
  8. public function getDefaultAddress($uid)
  9. {
  10. $where['uid'] = $uid;
  11. $where['type'] = 2;
  12. $data = Dever::db('passport/address')->one($where);
  13. return $data;
  14. }
  15. # 获取地址列表
  16. public function getAddress($uid)
  17. {
  18. $where['uid'] = $uid;
  19. $data = Dever::db('passport/address')->getList($where);
  20. return $data;
  21. }
  22. # 添加或者更新地址接口
  23. public function up()
  24. {
  25. $uid = $this->check();
  26. $id = Dever::input('id');
  27. $type = Dever::input('type', 2);
  28. $province = Dever::input('province');
  29. $city = Dever::input('city');
  30. $county = Dever::input('county');
  31. $address = Dever::input('address');
  32. $country = Dever::input('country');
  33. $sex = Dever::input('sex');
  34. $house_number = Dever::input('house_number');
  35. $tag = Dever::input('tag');
  36. return $this->upAddress($id, $uid, $type, $province, $city, $county, $address, $country, $sex, $house_number, $tag);
  37. }
  38. # 添加或者更新地址
  39. public function upAddress($id, $uid, $type = 2, $province = '', $city = '', $county = '', $address = '', $country = '', $sex = '', $house_number = '', $tag = '')
  40. {
  41. if ($country) {
  42. $update['country'] = $country;
  43. }
  44. if ($province && $city && $county && $address) {
  45. $update['province'] = $province;
  46. $update['city'] = $city;
  47. $update['county'] = $county;
  48. $update['area'] = $province . ',' . $city . ',' . $county;
  49. $update['address'] = $address;
  50. }
  51. $update['type'] = $type;
  52. if ($sex) {
  53. $update['sex'] = $sex;
  54. }
  55. if ($house_number) {
  56. $update['house_number'] = $house_number;
  57. }
  58. if ($tag) {
  59. $update['tag'] = $tag;
  60. }
  61. if ($id) {
  62. $update['where_id'] = $id;
  63. Dever::db('passport/address')->update($update);
  64. } else {
  65. $update['uid'] = $uid;
  66. $id = Dever::db('passport/address')->insert($update);
  67. }
  68. return $id;
  69. }
  70. }