[ 'id' => 1, 'name' => '商品添加', 'path' => '/bundle_b/pages/local_shop/local_shop_add', 'image' => 'uniapp/bundle_b/local_shop/local_add.png' ], 2 => [ 'id' => 2, 'name' => '商品管理', 'path' => '/bundle_b/pages/local_shop/local_shop_manager', 'image' => 'uniapp/bundle_b/local_shop/local_shop.png' ], 3 => [ 'id' => 3, 'name' => '订单管理', 'path' => '/bundle_b/pages/local_shop/local_shop_order', 'image' => 'uniapp/bundle_b/local_shop/local_bill.png' ], 4 => [ 'id' => 4, 'name' => '站点设置', 'path' => '/bundle_b/pages/local_map/index', 'image' => 'uniapp/bundle_b/local_shop/local_map.png' ] ); public function getLocalList($data) { $model = new LocalStore; $distance = ""; $s = $s1 = ""; $keyword = $keyword1 = ""; $city_where = []; if (isset($data['c_name'])) { if ($data['c_name'] != "") { $s1 = "address like '%" . $data['c_name'] . "%'"; $s = "and address like '%" . $data['c_name'] . "%'"; } // if ($data['c_name'] == '嘉兴市') { // $city_where[] = ['lstore_id', '=', 138]; // } } // 搜索商家名称 if (isset($data['keyword']) && $data['keyword'] != '') { $keyword1 = "shopName like '%" . $data['keyword'] . "%'"; $keyword = "and shopName like '%" . $data['keyword'] . "%'"; } $count = $model->where('is_delete', 0) ->where($city_where) ->where($s1) ->where($keyword1) ->where("store_state", 1) ->where("shopLogo is not null") ->count(); // $lists = $model->where('is_delete',0) // ->where($s) // ->page($data['page'], $data['size']) // ->order('lstore_id desc') // ->select(); $size = $data['page_size']; $page = ($data['page_no'] - 1) * $data['page_size']; // $sql = "SELECT *, ST_Distance_Sphere(POINT(".$data['longitude'].",".$data['latitude']."),POINT(longitude, latitude)) AS distance // FROM ls_local_store where is_delete = 0 $s // ORDER BY distance limit $page,$size"; // if (isset($data['c_name']) && $data['c_name'] == '嘉兴市') { // $sql = "SELECT * FROM ls_local_store where lstore_id = 138 and is_delete = 0 and store_state = 1 and shopLogo is not null $s ORDER BY lstore_id asc limit " . $page . "," . $size; // } else { $sql = "SELECT * FROM ls_local_store where is_delete = 0 and store_state = 1 and shopLogo is not null $s $keyword ORDER BY sort desc limit " . $page . "," . $size; // } // var_dump($sql); $lists = Db::query($sql); foreach ($lists as $key => $value) { $lists[$key]['distance'] = round($this->distance($data['latitude'], $data['longitude'], $value['latitude'], $value['longitude']) / 1000, 2) . "公里"; $lists[$key]['store_nickname'] = $value["shopName"]; } $data = [ 'list' => $lists, 'page' => $data['page_no'], 'size' => $data['page_size'], 'count' => $count, 'more' => is_more($count, $data['page_no'], $data['page_size']) ]; // var_dump($data); return $data; } public function getLocalLists($data) { $where = []; // 城市搜索 if (isset($data['c_name']) && $data['c_name'] != "") { $where[] = ['ls.address', 'like', '%' . $data['c_name'] . '%']; } // 搜索商家名称 if (isset($data['keyword']) && $data['keyword'] != '') { $where[] = ['ls.shopName|lsg.title', 'like', '%' . $data['keyword'] . '%']; } // 价格排序 $order = ['lsg.id' => 'desc']; if (isset($data['money_sort'])) { $order = ['lsg.price' => $data['money_sort']]; } // 经纬度排序 if (isset($data['distance_sort'])) { $order = ['distance' => $data['distance_sort']]; } // 经纬度排序 $distance_sql = "6371 * acos(cos(radians(" . $data['latitude'] . ")) * cos(radians(latitude)) * cos(radians(longitude) - radians(" . $data['longitude'] . ")) + sin(radians(" . $data['latitude'] . ")) * sin(radians(latitude))) AS distance"; // 数量统计 $count = LocalStore::alias('ls') ->join('local_store_goods lsg', 'ls.lstore_id = lsg.lstore_id') ->where(['ls.store_state' => 1, 'ls.is_delete' => 0, 'lsg.state' => 1, 'lsg.audit_status' => 1, 'lsg.delete_time' => 0]) ->where($where) ->whereNotNull('ls.shopLogo') ->count(); // 列表 $lists = LocalStore::alias('ls') ->join('local_store_goods lsg', 'ls.lstore_id = lsg.lstore_id') ->where(['ls.store_state' => 1, 'ls.is_delete' => 0, 'lsg.state' => 1, 'lsg.audit_status' => 1, 'lsg.delete_time' => 0]) ->where($where) ->whereNotNull('ls.shopLogo') ->order($order) ->page($data['page_no'], $data['page_size']) ->field('ls.shopName, ls.longitude, ls.latitude, lsg.id, lsg.lstore_id, lsg.title, lsg.price, ' . $distance_sql) ->select(); foreach ($lists as $key => &$value) { // 东龙汇超时价格 *88折 if ($value['lstore_id'] == Config::get('localstore.dlh_lstore_id')) { $lists[$key]['original_price'] = $value['price']; $lists[$key]['price'] = round($value['price'] * LocalStoreGoodsLogic::$sale, 2); } $pic = LocalStoreGoodsPic::where('lsg_id', $value['id'])->field('url')->find(); $lists[$key]['url'] = $pic['url']; if ($value['distance'] <= 0.5) { $lists[$key]['distance'] = '<500m'; } else { $lists[$key]['distance'] = number_format($value['distance'], 2, '.', '') . "km"; } // $lists[$key]['distance'] = round($this->distance($data['latitude'], $data['longitude'], $value['latitude'], $value['longitude']) / 1000, 2) . "km"; $lists[$key]['store_nickname'] = $value["shopName"]; } $data = [ 'list' => $lists, 'page' => $data['page_no'], 'size' => $data['page_size'], 'count' => $count, 'more' => is_more($count, $data['page_no'], $data['page_size']) ]; return $data; } public function getStreetlList($data) { $where = []; // 城市搜索 if (isset($data['c_name']) && $data['c_name'] != "") { $where[] = ['address', 'like', '%' . $data['c_name'] . '%']; } // 搜索商家名称 $keyword = ''; if (isset($data['keyword']) && $data['keyword'] != '') { $where[] = ['shopName', 'like', '%' . $data['keyword'] . '%']; } $order = ['distance' => 'asc']; // 经纬度排序 if (isset($data['distance_sort'])) { $order = ['distance' => $data['distance_sort']]; } // 经纬度排序 $distance_sql = "6371 * acos(cos(radians(" . $data['latitude'] . ")) * cos(radians(latitude)) * cos(radians(longitude) - radians(" . $data['longitude'] . ")) + sin(radians(" . $data['latitude'] . ")) * sin(radians(latitude))) AS distance"; // 数量统计 $count = LocalStore::where($where) ->where(['is_delete' => 0, 'store_state' => 1]) ->whereNotNull('shopLogo') ->count(); // 这里的Join只是为了配合with获取指定的字段 $lists = LocalStore::alias('ls') ->with(['street_goods' => function ($query) { $query->where(['state' => 1, 'audit_status' => 1, 'delete_time' => 0]) ->withLimit(10); }]) ->leftJoin('local_store_goods lsg', 'lsg.lstore_id = ls.lstore_id') ->where($where) ->where(['ls.is_delete' => 0, 'ls.store_state' => 1]) ->whereNotNull('ls.shopLogo') ->field('ls.lstore_id as ls_id, ls.shopLogo, ls.shopName, ls.longitude, ls.latitude, ls.latitude, ls.address, ' . $distance_sql . ', lsg.id, lsg.lstore_id') ->order($order) ->page($data['page_no'], $data['page_size']) ->group('ls.lstore_id') ->select()->toArray(); foreach ($lists as $key => &$value) { // 获取商品图片 if (isset($value['street_goods'])) { foreach ($value['street_goods'] as $k1 => $v1) { $field = LocalStoreGoodsPic::where('lsg_id', $v1['id'])->field('url')->find(); $value['street_goods'][$k1]['url'] = $field['url']; } } // 东龙汇超时价格 *88折 if ($value['lstore_id'] == Config::get('localstore.dlh_lstore_id')) { foreach ($value['street_goods'] as $k1 => &$v1) { $value['street_goods'][$k1]['original_price'] = $v1['price']; $v1['price'] = round($v1['price'] * LocalStoreGoodsLogic::$sale, 2); } } // 店铺下面的商品数量 $lists[$key]['goods_count'] = LocalStoreGoods::where(['lstore_id' => $value['ls_id'], 'state' => 1, 'audit_status' => 1, 'delete_time' => 0])->count(); // 店铺距离 if ($value['distance'] <= 0.5) { $lists[$key]['distance'] = '<500m'; } else { $lists[$key]['distance'] = number_format($value['distance'], 2, '.', '') . "km"; } } $data = [ 'list' => $lists, 'page' => $data['page_no'], 'size' => $data['page_size'], 'count' => $count, 'more' => is_more($count, $data['page_no'], $data['page_size']) ]; return $data; } public function getLocalOrderList($data) { $count = LocalStoreOrder::where(['lstore_id' => $data['lstore_id'], 'pay_shop_type' => 1, 'state' => 1])->count(); // $count = Db::name("local_store_order") // ->where("lstore_id",$data['lstore_id']) // ->where("pay_shop_type",1) // ->where('state',1) // ->count(); // $lists = $model->where('is_delete',0) // ->where($s) // ->page($data['page'], $data['size']) // ->order('lstore_id desc') // ->select(); // $size = $data['page_size']; // $page = ($data['page_no']-1)*$data['page_size']; // $sql = "SELECT *, ST_Distance_Sphere(POINT(".$data['longitude'].",".$data['latitude']."),POINT(longitude, latitude)) AS distance // FROM ls_local_store where is_delete = 0 $s // ORDER BY distance limit $page,$size"; // $sql = "SELECT * FROM ls_local_store_order where state = 1 and // pay_shop_type = 1 and lstore_id = ".$data['lstore_id']." // ORDER BY create_time desc limit ".$page.",".$size; // $lists = Db::query($sql); $lists = LocalStoreOrder::alias('lso') ->field('lso.*, u.id, u.nickname') ->join('user u', 'lso.user_id = u.id') ->where(['lso.state' => 1, 'lso.pay_shop_type' => 1, 'lso.lstore_id' => $data['lstore_id']]) ->order('lso.create_time desc') ->page($data['page_no'], $data['page_size']) ->select(); $data = [ 'list' => $lists, 'page' => $data['page_no'], 'size' => $data['page_size'], 'count' => $count, 'more' => is_more($count, $data['page_no'], $data['page_size']) ]; // var_dump($data); return $data; } public function getLocalUserOrderList($data) { $count = Db::name("local_store_order") ->where("user_id", $data['user_id']) ->where("pay_shop_type", 1) ->where('state', 1) ->count(); $size = $data['page_size']; $page = ($data['page_no'] - 1) * $data['page_size']; $sql = "SELECT * FROM ls_local_store_order where state = 1 and pay_shop_type = 1 and user_id = " . $data['user_id'] . " ORDER BY lstore_id desc limit " . $page . "," . $size; $lists = Db::query($sql); $data = [ 'list' => $lists, 'page' => $data['page_no'], 'size' => $data['page_size'], 'count' => $count, 'more' => is_more($count, $data['page_no'], $data['page_size']) ]; return $data; } function distance($lat1, $lon1, $lat2, $lon2) { $earthRadius = 6371000; // 地球平均半径,单位为米 // 将经纬度转换为弧度 $lat1 = deg2rad($lat1); $lon1 = deg2rad($lon1); $lat2 = deg2rad($lat2); $lon2 = deg2rad($lon2); // 使用haversine公式计算距离 $diffLat = $lat2 - $lat1; $diffLon = $lon2 - $lon1; $a = sin($diffLat / 2) * sin($diffLat / 2) + cos($lat1) * cos($lat2) * sin($diffLon / 2) * sin($diffLon / 2); $c = 2 * atan2(sqrt($a), sqrt(1 - $a)); $distance = $earthRadius * $c; return $distance; } public static function record($page, $size, $user_id) { $list = LocalStore::where(['user_id' => $user_id, 'is_delete' => 0])->page($page, $size)->order('lstore_id desc')->select()->toArray(); $count = LocalStore::where(['user_id' => $user_id, 'is_delete' => 0])->count(); $more = is_more($count, $page, $size); //是否有下一页 return [ 'list' => $list, 'page_no' => $page, 'page_size' => $size, 'count' => $count, 'more' => $more, ]; } public static function submitOrder($post, $user_id) { $goods_msg = Db::name("local_store_goods")->where("id", $post['goods_id'])->find(); if ($post['item_id'] > 0) { if ($goods_msg['is_multiple_spec'] > 0) { $goods_sku_msg = Db::name("local_store_goods_item")->where("id", $post['item_id'])->find(); if ($goods_sku_msg['stock'] < $post['goods_num']) { return -1; } $data['goods_total_price'] = round($goods_sku_msg['price'] * $post['goods_num'], 2); Db::name("local_store_goods_item") ->where("id", $post['item_id']) ->dec("stock", $post['goods_num']) ->update(); } else { $data['goods_total_price'] = round($goods_msg['price'] * $post['goods_num'], 2); } } else { $data['goods_total_price'] = round($goods_msg['price'] * $post['goods_num'], 2); } if ($post['lstore_id'] == Config::get('localstore.dlh_lstore_id')) { $data['goods_total_price'] = number_format($data['goods_total_price'] * LocalStoreGoodsLogic::$sale, 2, '.', ''); } $data['order_no'] = createSn('local_goods_order', 'order_no'); $data['lstore_id'] = $post['lstore_id']; $data['item_id'] = $post['item_id']; $data['goods_id'] = $post['goods_id']; $data['goods_num'] = $post['goods_num']; $data['user_id'] = $user_id; $data['dtime'] = date("Y-m-d H:i:s"); $res = Db::name("local_goods_order")->insertGetId($data); $result['lsg_order_id'] = $res; return $result; } public static function orderDetails($post) { $result = Db::name("local_goods_order")->where("lsg_order_id", $post['lsg_order_id'])->find(); $goods = Db::name("local_store_goods")->where("id", $result['goods_id'])->find(); $result['goods_msg'] = $goods; $image = Db::name("local_store_goods_pic")->where("lsg_id", $result['goods_id'])->select()->toArray(); foreach ($image as $k => $v) { $image[$k]['url'] = Config::get('aliyunoss.domain') . $v['url']; } $result['goods_image'] = $image; $item = Db::name("local_store_goods_item")->where("id", $result['item_id'])->find(); if ($item != null) { $item['image'] = Config::get('aliyunoss.domain') . $item['image']; } $result['sku_msg'] = $item; $local = Db::name("local_store")->field("shopName,shopLogo")->where("lstore_id", $result['lstore_id'])->find(); $result['local_msg'] = $local; return $result; } public static function cancelOrder($post) { $result = Db::name("local_goods_order") ->where("lsg_order_id", $post['lsg_order_id']) ->find(); if ($result['item_id'] > 0) { Db::name("local_store_goods_item") ->where("id", $result['item_id']) ->inc("stock", $result['goods_num']) ->update(); } $res = Db::name("local_goods_order") ->where("lsg_order_id", $post['lsg_order_id']) ->update(["state" => 2]); return $res; } public static function myOrderList($post) { $s = ""; if (isset($post['state'])) { $s = "state= " . $post['state'] . ""; } $list = LocalGoodsStore::where('user_id', $post['user_id']) ->where($s) ->where("state <> 3") ->page($post['page_no'], $post['page_size']) ->order('dtime desc') ->select() ->toArray(); foreach ($list as $key => $value) { $goods = Db::name("local_store_goods")->where("id", $value['goods_id'])->find(); $image = Db::name("local_store_goods_pic")->where("lsg_id", $value['goods_id'])->select()->toArray(); foreach ($image as $k => $v) { $image[$k]['url'] = Config::get('aliyunoss.domain') . $v['url']; } $sku_msg = Db::name("local_store_goods_item") ->field("image,spec_value_str") ->where("id", $value['item_id']) ->find(); if ($sku_msg != null) { $sku_msg['image'] = Config::get('aliyunoss.domain') . $sku_msg['image']; } $list[$key]['sku_msg'] = $sku_msg; $list[$key]['goods_msg'] = $goods; $list[$key]['goods_image'] = $image; $local = Db::name("local_store")->field("shopName,shopLogo")->where("lstore_id", $value['lstore_id'])->find(); $post_station = Db::name('local_store_post_station')->where('id', $value['post_station_id'])->find(); $list[$key]['post_station'] = $post_station; $list[$key]['local_msg'] = $local; $list[$key]['post_station_time'] = date("m-d", $value['post_station_time']); } $count = LocalGoodsStore::where('user_id', $post['user_id']) ->where($s) ->where("state <> 3") ->count(); $all_count = LocalGoodsStore::where('user_id', $post['user_id']) ->where("state <> 3") ->count(); $wait_count = LocalGoodsStore::where('user_id', $post['user_id']) ->where("state", 0) ->where("state <> 3") ->count(); $already_count = LocalGoodsStore::where('user_id', $post['user_id']) ->where("state", 1) ->where("state <> 3") ->count(); $cancel_count = LocalGoodsStore::where('user_id', $post['user_id']) ->where("state", 2) ->where("state <> 3") ->count(); $more = is_more($count, $post['page_no'], $post['page_size']); //是否有下一页 return [ 'list' => $list, 'page_no' => $post['page_no'], 'page_size' => $post['page_size'], 'count' => $count, 'all_count' => $all_count, 'wait_count' => $wait_count, 'already_count' => $already_count, 'cancel_count' => $cancel_count, 'more' => $more, ]; } public static function orderList($post) { $where = []; if (isset($post['state'])) { $where[] = ['state', '=', $post['state']]; } if (isset($post['keyword'])) { $where[] = ['order_no', 'like', '%'. $post['keyword'] . '%']; } $list = LocalGoodsStore::where('lstore_id', $post['lstore_id']) ->where($where) ->where("state <> 3") ->page($post['page_no'], $post['page_size']) ->order('dtime desc') ->select() ->toArray(); foreach ($list as $key => $value) { $goods = Db::name("local_store_goods")->where("id", $value['goods_id'])->find(); $image = Db::name("local_store_goods_pic")->where("lsg_id", $value['goods_id'])->select()->toArray(); foreach ($image as $k => $v) { $image[$k]['url'] = Config::get('aliyunoss.domain') . $v['url']; } $sku_msg = Db::name("local_store_goods_item") ->field("image,spec_value_str") ->where("id", $value['item_id']) ->find(); if ($sku_msg != null) { $sku_msg['image'] = Config::get('aliyunoss.domain') . $sku_msg['image']; } $list[$key]['sku_msg'] = $sku_msg; $list[$key]['goods_msg'] = $goods; $list[$key]['goods_image'] = $image; $local = Db::name("local_store")->field("shopName,shopLogo")->where("lstore_id", $value['lstore_id'])->find(); $list[$key]['local_msg'] = $local; } $count = LocalGoodsStore::where('lstore_id', $post['lstore_id']) ->where($where) ->where("state <> 3") ->count(); $all_count = LocalGoodsStore::where('lstore_id', $post['lstore_id']) ->where("state <> 3") ->count(); $wait_count = LocalGoodsStore::where('lstore_id', $post['lstore_id']) ->where("state", 0) ->where("state <> 3") ->count(); $already_count = LocalGoodsStore::where('lstore_id', $post['lstore_id']) ->where("state", 1) ->where("state <> 3") ->count(); $cancel_count = LocalGoodsStore::where('lstore_id', $post['lstore_id']) ->where("state", 2) ->where("state <> 3") ->count(); $more = is_more($count, $post['page_no'], $post['page_size']); //是否有下一页 return [ 'list' => $list, 'page_no' => $post['page_no'], 'page_size' => $post['page_size'], 'count' => $count, 'all_count' => $all_count, 'wait_count' => $wait_count, 'already_count' => $already_count, 'cancel_count' => $cancel_count, 'more' => $more, ]; } public static function addPostStation($post, $user_id) { if (!$post['province'] && !$post['city'] && !$post['area'] && !$post['address']) { throw new \Exception('未选择区域'); } if (!$post['lat'] && !$post['lng']) { throw new \Exception('经纬度不能为空'); } if (!$post['phone']) { throw new \Exception('自提点联系电话不能为空'); } $post['user_id'] = $user_id; $result = LocalStorePostStation::insert($post); if ($result) { return true; } throw new \Exception('更新失败'); } // 修改自提站点联系电话 public static function editPostStationPhone($post) { if (!$post['id']) { throw new \Exception('参数不能为空'); } if (!$post['phone']) { throw new \Exception('自提点联系电话不能为空'); } LocalStorePostStation::where([ 'id' => $post['id'], ])->update(['phone' => $post['phone']]); } // 删除自提点 public static function delPostStation($post) { if (!$post['id']) { throw new \Exception('参数不能为空'); } $result = LocalStorePostStation::where([ 'id' => $post['id'] ])->update(['is_delete' => 1, 'delete_time' => time()]); if ($result) { return true; } throw new \Exception('删除失败'); } public static function searchSn($post) { if ($post['keyword']) { $userInfo = User::where(['sn' => $post['keyword'], 'del' => 0])->field('id, nickname, avatar as abs_avatar')->find(); if ($userInfo) { $userInfo = $userInfo->toArray(); $userInfo['rule'] = self::$local_menu; } else { $userInfo = []; } return $userInfo; } return false; } public static function bindList($post) { $list = LocalStoreBind::alias('lsb') ->join('user u', 'lsb.bind_user_id = u.id') ->where(['lstore_id' => $post['lstore_id'], 'is_unbind' => 0]) ->field('lsb.*, u.nickname, u.avatar') ->order('id desc') ->page($post['page_no'], $post['page_size']) ->select(); $count = LocalStoreBind::where(['lstore_id' => $post['lstore_id'], 'is_unbind' => 0])->count(); $more = is_more($count, $post['page_no'], $post['page_size']); //是否有下一页 if ($list) { foreach ($list as &$v) { $v['avatar'] = UrlServer::getFileUrl($v['avatar']); } } return [ 'lists' => $list, 'page_no' => $post['page_no'], 'page_size' => $post['page_size'], 'count' => $count, 'more' => $more, ]; } public static function bindUser($post) { if ($post['user']['id'] <= 0) { throw new \Exception('缺少用户ID'); } if (empty($post['user']['rule'])) { throw new \Exception('请为用户分配权限'); } $model = new LocalStoreBind(); $in = $model->where(['lstore_id' => $post['lstore_id'], 'bind_user_id' => $post['user']['id'], 'is_unbind' => 0])->find(); if (!empty($in)) { throw new \Exception('已绑定该用户'); } $data = array(); $data['lstore_id'] = $post['lstore_id']; $data['bind_user_id'] = $post['user']['id']; $data['rule'] = implode(',', $post['user']['rule']); $data['bind_time'] = time(); $result = $model->insert($data); if ($result) { return true; } throw new \Exception('添加失败'); } public static function unbindUser($post) { if ($post['id'] <= 0) { throw new \Exception('缺少ID'); } $result = LocalStoreBind::where('id', $post['id'])->update([ 'is_unbind' => 1, 'unbind_time' => time() ]); if ($result) { return true; } throw new \Exception('解绑失败'); } public static function inBindList($user_id, $page, $size) { $list = LocalStoreBind::alias('lsb') ->join('local_store ls', 'lsb.lstore_id = ls.lstore_id') ->where(['lsb.bind_user_id' => $user_id, 'lsb.is_unbind' => 0]) ->field('lsb.*, ls.shopName, ls.shopLogo') ->page($page, $size) ->select(); $count = LocalStoreBind::where(['bind_user_id' => $user_id, 'is_unbind' => 0])->count(); if ($list) { foreach ($list as &$v) { $v['rule'] = self::crate_bind_menu($v['rule']); } } $data = [ 'list' => $list, 'page' => $page, 'size' => $size, 'count' => $count, 'more' => is_more($count, $page, $size) ]; return $data; } public static function countData($post, $user_id) { $where = [ ['lstore_id', '=', $post['lstore_id']], ['user_id', '=', $user_id], ['state', '=', 1] ]; $model = new LocalGoodsOrder(); // 历史订单总和 $history_total_amount = $model->where($where)->sum('goods_total_price'); // 本月业绩总和 $current_month_start = date('Y-m-01 00:00:00'); // 当月开始日期 $current_month_end = date('Y-m-t 23:59:59'); // 当月结束日期 $current_month_total_amount = $model ->where($where) ->where([ ['dtime', '>=', $current_month_start], ['dtime', '<=', $current_month_end] ])->sum('goods_total_price'); // 上月业绩总和 $last_month_start = date('Y-m-01 00:00:00', strtotime('-1 month')); // 上月开始日期 $last_month_end = date('Y-m-t 23:59:59', strtotime('-1 month')); // 上月结束日期 $last_month_total_amount = $model ->where($where) ->where([ ['dtime', '>=', $last_month_start], ['dtime', '<=', $last_month_end] ])->sum('goods_total_price'); // 当日营业额 $current_day_start = date('Y-m-d 00:00:00'); $current_day_end = date('Y-m-d 23:59:59'); $current_day_total_amount = $model ->where($where) ->where([ ['dtime', '>=', $current_day_start], ['dtime', '<=', $current_day_end] ])->sum('goods_total_price'); // 统计当日数据: 总共支付交易笔数 report = 1(日报) report = 2(月报) $trade_where = $where; $time_where = []; $filter_month_total_amount = 0; if (empty($filter_day)) { if ($post['report'] == 1) { unset($trade_where[2]); } $time_where['start'] = $post['report'] == 1 ? $current_day_start : $current_month_start; $time_where['end'] = $post['report'] == 1 ? $current_day_end : $current_month_end; } else { // 日期筛选 $time_where['start'] = $post['filter_day']['startDate']; $time_where['end'] = $post['filter_day']['endDate']; $filter_month_total_amount = $model ->where($where) ->where([ ['dtime', '>=', $time_where['start']], ['dtime', '<=', $time_where['end']] ])->sum('goods_total_price'); } // 总共交易笔数 $count_trade = $model ->where($trade_where) ->where([ ['dtime', '>=', $time_where['start']], ['dtime', '<=', $time_where['end']] ])->count(); // 支付成功交易笔数 $trade_where[] = ['state', '=', 1]; $success_trade = $model ->where($trade_where) ->where([ ['dtime', '>=', $time_where['start']], ['dtime', '<=', $time_where['end']] ])->count(); // 单笔均价 if (empty($filter_day)) { if ($post['report'] == 1) { $average_price = $success_trade > 0 ? $current_day_total_amount / $success_trade : 0; } else if ($post['report'] == 2) { $average_price = $success_trade > 0 ? $current_month_total_amount / $success_trade : 0; } } else { $average_price = $success_trade > 0 ? $filter_month_total_amount / $success_trade : 0; } return [ 'history_total_amount' => number_format($history_total_amount, 2, '.', ''), 'current_month_total_amount' => number_format($current_month_total_amount, 2, '.', ''), 'last_month_total_amount' => number_format($last_month_total_amount, 2, '.', ''), 'current_day_total_amount' => number_format($current_day_total_amount, 2, '.', ''), 'count_trade' => $count_trade, 'success_trade' => $success_trade, 'average_price' => $average_price ]; } private static function crate_bind_menu($rule) { $menu = []; $r = explode(',', $rule); sort($r); foreach ($r as &$v) { $menu[] = self::$local_menu[$v]; } return $menu; } }