123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- <?php
- namespace app\common\model;
- use think\facade\Db;
- class Address extends BaseModel
- {
-
- public function getDefaultAddressInfo($condition = array(), $order = 'address_is_default desc,chain_id asc,address_id desc')
- {
- return $this->getAddressInfo($condition, $order);
- }
-
- public function getAddressInfo($condition, $order = '')
- {
- $addr_info = Db::name('address')->where($condition)->order($order)->find();
- if ($addr_info['chain_id']) {
- if (config('ds_config.chain_isuse')) {
- $chain_model = model('chain');
- $chain_info = $chain_model->getChainOpenInfo(array(array('chain_id', '=', $addr_info['chain_id'])));
- if (!empty($chain_info)) {
- if ($addr_info['city_id'] !== $chain_info['chain_area_2'] || $addr_info['area_id'] !== $chain_info['chain_area_3']) {
- $addr_info['cityerror'] = true;
- } else {
- $addr_info['cityerror'] = false;
- }
- $addr_info['chain_if_pickup'] = $chain_info['chain_if_pickup'];
- $addr_info['chain_if_collect'] = $chain_info['chain_if_collect'];
- $addr_info['chain_mobile'] = $chain_info['chain_mobile'];
- $addr_info['chain_telephony'] = $chain_info['chain_telephony'];
- $addr_info['chain_addressname'] = $chain_info['chain_addressname'];
- $addr_info['chain_area_info'] = $chain_info['chain_area_info'];
- $addr_info['chain_address'] = $chain_info['chain_address'];
- $addr_info['chain_mobile'] = $chain_info['chain_mobile'];
- $addr_info['area_id'] = $chain_info['chain_area_3'];
- $addr_info['area_info'] = $chain_info['chain_area_info'];
- $addr_info['address_detail'] = '(' . $chain_info['chain_addressname'] . ') ' . $chain_info['chain_address']
- . ',电话:' . trim($chain_info['chain_mobile'] . ',' . $chain_info['chain_telephony'], ',');
- } else {
- $addr_info = false;
- }
- } else {
- $addr_info = false;
- }
- }
- if (!empty($addr_info && $addr_info['chain_id'] == 0)) {
- $addr_info['cityerror'] = false;
- }
- return $addr_info;
- }
-
- public function getAddressList($condition, $order = 'address_id desc')
- {
- $address_list = Db::name('address')->where($condition)->order($order)->select()->toArray();
- if (empty($address_list))
- return array();
- if (config('ds_config.chain_isuse')) {
- $chain_ids = array();
- $chain_new_list = array();
- foreach ($address_list as $k => $v) {
- if ($v['chain_id']) {
- $chain_ids[] = $v['chain_id'];
- }
- }
- if (!empty($chain_ids)) {
- $chain_model = model('chain');
- $condition = array();
- $condition[] = array('chain_id', 'in', $chain_ids);
- $chain_list = $chain_model->getChainOpenList($condition);
- foreach ($chain_list as $k => $v) {
- $chain_new_list[$v['chain_id']] = $v;
- }
- }
- if (!empty($chain_new_list)) {
- foreach ($address_list as $k => $v) {
- if (!$v['chain_id'])
- continue;
- if ($v['chain_id'] && !isset($chain_new_list[$v['chain_id']])) {
- unset($address_list[$k]);
- continue;
- }
- $chain_info = $chain_new_list[$v['chain_id']];
- $address_list[$k]['area_info'] = $chain_info['chain_area_info'];
- $address_list[$k]['address_detail'] = '(' . $chain_info['chain_addressname'] . ') ' . $chain_info['chain_address']
- . ',电话:' . trim($chain_info['chain_mobile'] . ',' . $chain_info['chain_telephony'], ',');
- }
- }
- }
- $address_list = array_values($address_list);
- return $address_list;
- }
-
- public function getAddressCount($condition = array())
- {
- return Db::name('address')->where($condition)->count();
- }
-
- public function addAddress($data)
- {
-
- if ($data['address_is_default'] == 1) {
- Db::name('address')->where('member_id', $data['member_id'])->update(array('address_is_default' => 0));
- }
- return Db::name('address')->insertGetId($data);
- }
-
- public function getOneAddress($id)
- {
- if (intval($id) > 0) {
- $result = Db::name('address')->where('address_id', intval($id))->find();
- return $result;
- } else {
- return false;
- }
- }
-
- public function editAddress($update, $condition)
- {
- return Db::name('address')->where($condition)->update($update);
- }
-
- public function checkAddress($member_id, $address_id)
- {
-
- $check_array = self::getOneAddress($address_id);
- if ($check_array['member_id'] == $member_id) {
- unset($check_array);
- return true;
- }
- unset($check_array);
- return false;
- }
-
- public function delAddress($condition)
- {
- return Db::name('address')->where($condition)->delete();
- }
- }
|