123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <?php
- namespace app\api\controller;
- use think\facade\Db;
- class Chain extends MobileMall
- {
- public function initialize()
- {
- parent::initialize();
- }
-
- public function chain_list()
- {
-
- $condition = array();
- $condition[] = array('chain_state', '=', 1);
- if (!empty(input('post.keyword'))) {
- $condition[] = array('chain_addressname', 'like', '%' . input('post.keyword') . '%');
- }
- $lat = input('post.latitude', 0);
- $lng = input('post.longitude', 0);
- if (!is_numeric($lat) || !is_numeric($lng)) {
- ds_json_encode(10001, lang('param_error'));
- }
- $order = 'distance asc';
- $chain_object = Db::name('chain')->where($condition)
- ->where('(2 * 6378.137* ASIN(SQRT(POW(SIN(PI()*(' . $lat . '-chain_latitude)/360),2)+COS(PI()*' . $lat . '/180)* COS(chain_latitude * PI()/180)*POW(SIN(PI()*(' . $lng . '-chain_longitude)/360),2)))) < 100000')
- ->fieldRaw('chain_id,store_id,chain_addressname,chain_area_info,chain_address,(2 * 6378.137* ASIN(SQRT(POW(SIN(PI()*(' . $lat . '-chain_latitude)/360),2)+COS(PI()*' . $lat . '/180)* COS(chain_latitude * PI()/180)*POW(SIN(PI()*(' . $lng . '-chain_longitude)/360),2)))) as distance')
- ->order($order)
- ->paginate(['list_rows' => $this->pagesize, 'query' => request()->param()], false);
- $chain = $chain_object->items();
- $store_model = model('store');
- $goods_model = model('goods');
- foreach ($chain as $key => $value) {
- $store_info = $store_model->getStoreInfoByID($value['store_id']);
- $chain[$key]['distance'] = round($value['distance'], 2);
- $chain[$key]['chain_avatar'] = get_store_logo($store_info['store_avatar'], 'store_avatar');
- $condition = array();
- $condition[] = array('chain_id', '=', $value['chain_id']);
- $condition[] = array('goods_storage', '>', 0);
- $chain_goods_commonid = Db::name('chain_goods')->where($condition)->column('goods_commonid');
- if (!empty($chain_goods_commonid)) {
- $chain[$key]['goods_list'] = $goods_model->getGoodsListByColorDistinct(array(array('store_id', '=', $value['store_id']), array('goods_commend', '=', 1), array('goods_commonid', 'in', $chain_goods_commonid)), 'goods_image,goods_id,goods_price', 'goods_id desc', 0, 4);
- foreach ($chain[$key]['goods_list'] as $k => $v) {
- $chain[$key]['goods_list'][$k]['goods_image_url'] = goods_cthumb($v['goods_image'], 480, $value['chain_id']);
- }
- } else {
- $chain[$key]['goods_list'] = array();
- }
- }
- $result = array_merge(array('chain_list' => $chain), mobile_page($chain_object));
- ds_json_encode(10000, '', $result);
- }
- }
|