Chain.php 4.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Db;
  4. /**
  5. * ============================================================================
  6. *
  7. * ============================================================================
  8. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  9. * 网站地址: https://www.valimart.net/
  10. * ----------------------------------------------------------------------------
  11. *
  12. * ============================================================================
  13. * 附件店铺控制器
  14. */
  15. class Chain extends MobileMall {
  16. public function initialize() {
  17. parent::initialize();
  18. }
  19. /**
  20. * @api {POST} api/Chain/chain_list 门店列表
  21. * @apiVersion 1.0.0
  22. * @apiGroup Chain
  23. *
  24. * @apiParam {Int} brand 所属品牌id
  25. * @apiParam {Int} category 所属分类id
  26. * @apiParam {String} keyword 关键字
  27. * @apiParam {String} longitude 经度
  28. * @apiParam {String} latitude 纬度
  29. * @apiParam {String} sort_key 键
  30. * @apiParam {String} sort_value 值
  31. * @apiParam {Int} page 当前第几页
  32. * @apiParam {Int} per_page 每页多少
  33. *
  34. * @apiSuccess {String} code 返回码,10000为成功
  35. * @apiSuccess {String} message 返回消息
  36. * @apiSuccess {Object} result 返回数据
  37. * @apiSuccess {Object[]} result.chain 店铺列表 (返回字段参考chain)
  38. * @apiSuccess {Float} result.chain.distance 距离
  39. * @apiSuccess {Float} result.chain.chain_credit_percent 店铺信用评分
  40. * @apiSuccess {Int} result.page_total 总页数
  41. * @apiSuccess {Boolean} result.hasmore 是否有更多 true是false否
  42. */
  43. public function chain_list() {
  44. //查询条件
  45. $condition = array();
  46. $condition[] = array('chain_state', '=', 1);
  47. if (!empty(input('post.keyword'))) {
  48. $condition[] = array('chain_addressname', 'like', '%' . input('post.keyword') . '%');
  49. }
  50. $lat = input('post.latitude', 0);
  51. $lng = input('post.longitude', 0);
  52. if (!is_numeric($lat) || !is_numeric($lng)) {
  53. ds_json_encode(10001, lang('param_error'));
  54. }
  55. $order = 'distance asc';
  56. $chain_object = Db::name('chain')->where($condition)
  57. ->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')
  58. ->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')
  59. ->order($order)
  60. ->paginate(['list_rows' => $this->pagesize, 'query' => request()->param()], false);
  61. $chain = $chain_object->items();
  62. $store_model = model('store');
  63. $goods_model = model('goods');
  64. foreach ($chain as $key => $value) {
  65. $store_info = $store_model->getStoreInfoByID($value['store_id']);
  66. $chain[$key]['distance'] = round($value['distance'], 2);
  67. $chain[$key]['chain_avatar'] = get_store_logo($store_info['store_avatar'], 'store_avatar');
  68. $condition = array();
  69. $condition[] = array('chain_id', '=', $value['chain_id']);
  70. $condition[] = array('goods_storage', '>', 0);
  71. $chain_goods_commonid = Db::name('chain_goods')->where($condition)->column('goods_commonid');
  72. if (!empty($chain_goods_commonid)) {
  73. $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);
  74. foreach ($chain[$key]['goods_list'] as $k => $v) {
  75. $chain[$key]['goods_list'][$k]['goods_image_url'] = goods_cthumb($v['goods_image'], 480, $value['chain_id']);
  76. }
  77. } else {
  78. $chain[$key]['goods_list'] = array();
  79. }
  80. }
  81. $result = array_merge(array('chain_list' => $chain), mobile_page($chain_object));
  82. ds_json_encode(10000, '', $result);
  83. }
  84. }