2024-08-10 10:18:04 +08:00
< ? php
namespace app\api\logic ;
use app\common\basics\Logic ;
use app\common\model\LocalStore ;
2024-09-16 21:53:19 +08:00
use app\common\model\localstore\LocalGoodsStore ;
2024-10-08 14:15:35 +08:00
use app\common\model\localstore\LocalStoreBind ;
2024-10-16 15:12:40 +08:00
use app\common\model\localstore\LocalStoreGoodsPic ;
2024-09-01 09:53:16 +08:00
use app\common\model\LocalStoreOrder ;
2024-09-29 17:14:43 +08:00
use app\common\model\LocalStorePostStation ;
2024-10-08 12:03:33 +08:00
use app\common\model\user\User ;
2024-10-08 15:10:13 +08:00
use app\common\server\UrlServer ;
2024-09-16 23:23:40 +08:00
use think\facade\Config ;
2024-10-08 15:36:48 +08:00
use think\facade\Db ;
2024-09-29 17:14:43 +08:00
2024-08-10 10:18:04 +08:00
class LocalStoreLogic extends Logic
{
2024-10-08 16:02:40 +08:00
private static $local_menu = array (
1 => [
'id' => 1 ,
'name' => '商品添加' ,
2024-10-08 16:07:04 +08:00
'path' => '/bundle_b/pages/local_shop/local_shop_add' ,
2024-10-08 16:02:40 +08:00
'image' => 'uniapp/bundle_b/local_shop/local_add.png'
],
2 => [
'id' => 2 ,
'name' => '商品管理' ,
2024-10-08 16:07:04 +08:00
'path' => '/bundle_b/pages/local_shop/local_shop_manager' ,
2024-10-08 16:02:40 +08:00
'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' => '站点设置' ,
2024-10-08 16:07:04 +08:00
'path' => '/bundle_b/pages/local_map/index' ,
2024-10-08 16:02:40 +08:00
'image' => 'uniapp/bundle_b/local_shop/local_map.png'
]
);
2024-09-05 16:31:02 +08:00
public function getLocalList ( $data )
{
2024-08-10 10:18:04 +08:00
$model = new LocalStore ;
$distance = " " ;
2024-09-05 16:31:02 +08:00
$s = $s1 = " " ;
2024-10-05 14:14:47 +08:00
$keyword = $keyword1 = " " ;
2024-09-29 23:27:52 +08:00
$city_where = [];
2024-09-05 16:31:02 +08:00
if ( isset ( $data [ 'c_name' ])) {
if ( $data [ 'c_name' ] != " " ) {
$s1 = " address like '% " . $data [ 'c_name' ] . " %' " ;
$s = " and address like '% " . $data [ 'c_name' ] . " %' " ;
2024-08-10 10:34:18 +08:00
}
2024-09-29 23:27:52 +08:00
2024-10-04 10:18:47 +08:00
// if ($data['c_name'] == '嘉兴市') {
// $city_where[] = ['lstore_id', '=', 138];
// }
2024-08-10 10:34:18 +08:00
}
2024-10-05 14:14:47 +08:00
// 搜索商家名称
if ( isset ( $data [ 'keyword' ]) && $data [ 'keyword' ] != '' ) {
$keyword1 = " shopName like '% " . $data [ 'keyword' ] . " %' " ;
$keyword = " and shopName like '% " . $data [ 'keyword' ] . " %' " ;
}
2024-09-05 16:31:02 +08:00
$count = $model -> where ( 'is_delete' , 0 )
2024-09-29 23:27:52 +08:00
-> where ( $city_where )
2024-08-10 10:38:31 +08:00
-> where ( $s1 )
2024-10-05 14:14:47 +08:00
-> where ( $keyword1 )
2024-09-05 16:31:02 +08:00
-> where ( " store_state " , 1 )
2024-08-10 15:55:35 +08:00
-> where ( " shopLogo is not null " )
2024-08-10 10:37:16 +08:00
-> count ();
2024-08-10 10:18:04 +08:00
// $lists = $model->where('is_delete',0)
// ->where($s)
// ->page($data['page'], $data['size'])
// ->order('lstore_id desc')
// ->select();
2024-08-10 10:40:10 +08:00
$size = $data [ 'page_size' ];
2024-09-05 16:31:02 +08:00
$page = ( $data [ 'page_no' ] - 1 ) * $data [ 'page_size' ];
2024-08-10 14:58:01 +08:00
// $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";
2024-09-29 23:27:52 +08:00
2024-10-04 10:19:35 +08:00
// 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 {
2024-10-10 10:31:36 +08:00
$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 ;
2024-10-04 10:19:35 +08:00
// }
2024-09-29 23:27:52 +08:00
2024-08-10 16:01:35 +08:00
// var_dump($sql);
2024-08-10 10:18:04 +08:00
$lists = Db :: query ( $sql );
2024-09-29 20:09:20 +08:00
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 " ];
}
2024-08-10 10:18:04 +08:00
$data = [
'list' => $lists ,
2024-08-10 10:23:02 +08:00
'page' => $data [ 'page_no' ],
'size' => $data [ 'page_size' ],
2024-08-10 10:18:04 +08:00
'count' => $count ,
2024-08-10 10:23:02 +08:00
'more' => is_more ( $count , $data [ 'page_no' ], $data [ 'page_size' ])
2024-08-10 10:18:04 +08:00
];
2024-08-10 16:01:35 +08:00
// var_dump($data);
2024-08-10 10:18:04 +08:00
return $data ;
2024-09-30 09:50:50 +08:00
}
2024-10-16 14:06:14 +08:00
public function getLocalLists ( $data )
{
$where = [];
2024-10-16 14:43:11 +08:00
// 城市搜索
2024-10-16 14:06:14 +08:00
if ( isset ( $data [ 'c_name' ]) && $data [ 'c_name' ] != " " ) {
2024-10-16 15:12:40 +08:00
$where [] = [ 'ls.address' , 'like' , '%' . $data [ 'c_name' ] . '%' ];
2024-10-16 14:06:14 +08:00
}
// 搜索商家名称
if ( isset ( $data [ 'keyword' ]) && $data [ 'keyword' ] != '' ) {
2024-10-16 15:12:40 +08:00
$where [] = [ 'ls.shopName|lsg.title' , 'like' , '%' . $data [ 'keyword' ] . '%' ];
2024-10-16 14:06:14 +08:00
}
2024-10-16 14:43:11 +08:00
// 数量统计
2024-10-16 15:12:40 +08:00
$count = LocalStore :: alias ( 'ls' )
-> join ( 'local_store_goods lsg' , 'ls.lstore_id = lsg.lstore_id' )
-> where ([ 'ls.is_delete' => 0 , 'ls.store_state' => 1 ])
2024-10-16 14:43:11 +08:00
-> where ( $where )
2024-10-16 15:12:40 +08:00
-> whereNotNull ( 'ls.shopLogo' )
2024-10-16 14:43:11 +08:00
-> count ();
2024-10-16 14:06:14 +08:00
2024-10-16 14:43:11 +08:00
// 列表
2024-10-16 15:12:40 +08:00
$lists = LocalStore :: alias ( 'ls' )
-> join ( 'local_store_goods lsg' , 'ls.lstore_id = lsg.lstore_id' )
-> where ([ 'ls.is_delete' => 0 , 'ls.store_state' => 1 ])
2024-10-16 14:06:14 +08:00
-> where ( $where )
2024-10-16 15:12:40 +08:00
-> whereNotNull ( 'ls.shopLogo' )
-> order ( 'lsg.id desc' )
2024-10-16 14:06:14 +08:00
-> page ( $data [ 'page_no' ], $data [ 'page_size' ])
2024-10-16 15:12:40 +08:00
-> field ( 'ls.lstore_id as ls_id, ls.shopName, ls.longitude, ls.latitude, lsg.id, lsg.lstore_id, lsg.title, lsg.price' )
-> select () -> toArray ();
2024-10-16 14:43:11 +08:00
2024-10-16 14:06:14 +08:00
foreach ( $lists as $key => & $value ) {
2024-10-16 15:12:40 +08:00
$pic = LocalStoreGoodsPic :: where ( 'lsg_id' , $value [ 'id' ]) -> field ( 'url' ) -> find ();
$lists [ $key ][ 'url' ] = UrlServer :: getFileUrl ( $pic [ 'url' ]);
2024-10-16 14:06:14 +08:00
$lists [ $key ][ 'distance' ] = round ( $this -> distance ( $data [ 'latitude' ], $data [ 'longitude' ], $value [ 'latitude' ], $value [ 'longitude' ]) / 1000 , 2 ) . " 公里 " ;
$lists [ $key ][ 'store_nickname' ] = $value [ " shopName " ];
}
2024-10-16 14:43:11 +08:00
2024-10-16 14:06:14 +08:00
$data = [
'list' => $lists ,
'page' => $data [ 'page_no' ],
'size' => $data [ 'page_size' ],
'count' => $count ,
'more' => is_more ( $count , $data [ 'page_no' ], $data [ 'page_size' ])
];
2024-10-16 14:43:11 +08:00
2024-10-16 14:06:14 +08:00
return $data ;
}
2024-09-30 09:50:50 +08:00
public function getStreetlList ( $data )
{
$model = new LocalStore ;
$distance = " " ;
$s = $s1 = " " ;
$city_where = [];
if ( isset ( $data [ 'c_name' ])) {
if ( $data [ 'c_name' ] != " " ) {
$s1 = " address like '% " . $data [ 'c_name' ] . " %' " ;
$s = " and address like '% " . $data [ 'c_name' ] . " %' " ;
}
}
$count = $model -> where ( 'is_delete' , 0 )
-> where ( $city_where )
-> where ( $s1 )
-> where ( " store_state " , 1 )
-> where ( " shopLogo is not null " )
-> count ();
$size = $data [ 'page_size' ];
$page = ( $data [ 'page_no' ] - 1 ) * $data [ 'page_size' ];
$sql = " SELECT * FROM ls_local_store where is_delete = 0 and store_state = 1 and shopLogo is not null $s ORDER BY lstore_id asc limit " . $page . " , " . $size ;
$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' ])
];
return $data ;
2024-08-10 10:18:04 +08:00
}
2024-08-11 16:58:13 +08:00
2024-09-05 16:31:02 +08:00
public function getLocalOrderList ( $data )
{
2024-09-01 09:53:16 +08:00
$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();
2024-08-11 16:58:13 +08:00
// $lists = $model->where('is_delete',0)
// ->where($s)
// ->page($data['page'], $data['size'])
// ->order('lstore_id desc')
// ->select();
2024-09-01 09:53:16 +08:00
// $size = $data['page_size'];
// $page = ($data['page_no']-1)*$data['page_size'];
2024-08-11 16:58:13 +08:00
// $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";
2024-09-01 09:53:16 +08:00
// $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' )
2024-09-01 22:31:16 +08:00
-> where ([ 'lso.state' => 1 , 'lso.pay_shop_type' => 1 , 'lso.lstore_id' => $data [ 'lstore_id' ]])
2024-09-01 09:53:16 +08:00
-> order ( 'lso.create_time desc' )
-> page ( $data [ 'page_no' ], $data [ 'page_size' ])
-> select ();
2024-08-11 16:58:13 +08:00
$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 ;
}
2024-08-12 10:31:55 +08:00
2024-09-05 16:31:02 +08:00
public function getLocalUserOrderList ( $data )
{
2024-08-12 10:31:55 +08:00
$count = Db :: name ( " local_store_order " )
2024-09-05 16:31:02 +08:00
-> where ( " user_id " , $data [ 'user_id' ])
-> where ( " pay_shop_type " , 1 )
-> where ( 'state' , 1 )
2024-08-12 10:31:55 +08:00
-> count ();
$size = $data [ 'page_size' ];
2024-09-05 16:31:02 +08:00
$page = ( $data [ 'page_no' ] - 1 ) * $data [ 'page_size' ];
2024-08-12 10:31:55 +08:00
$sql = " SELECT * FROM ls_local_store_order where state = 1 and
2024-09-05 16:31:02 +08:00
pay_shop_type = 1 and user_id = " . $data['user_id'] . "
ORDER BY lstore_id desc limit " . $page . " , " . $size ;
2024-08-12 10:31:55 +08:00
$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 ;
}
2024-09-05 16:31:02 +08:00
function distance ( $lat1 , $lon1 , $lat2 , $lon2 )
{
2024-08-10 10:18:04 +08:00
$earthRadius = 6371000 ; // 地球平均半径,单位为米
// 将经纬度转换为弧度
$lat1 = deg2rad ( $lat1 );
$lon1 = deg2rad ( $lon1 );
$lat2 = deg2rad ( $lat2 );
$lon2 = deg2rad ( $lon2 );
// 使用haversine公式计算距离
2024-09-05 16:31:02 +08:00
$diffLat = $lat2 - $lat1 ;
$diffLon = $lon2 - $lon1 ;
2024-08-10 10:18:04 +08:00
$a = sin ( $diffLat / 2 ) * sin ( $diffLat / 2 ) + cos ( $lat1 ) * cos ( $lat2 ) * sin ( $diffLon / 2 ) * sin ( $diffLon / 2 );
2024-09-05 16:31:02 +08:00
$c = 2 * atan2 ( sqrt ( $a ), sqrt ( 1 - $a ));
2024-08-10 10:18:04 +08:00
$distance = $earthRadius * $c ;
return $distance ;
}
2024-09-05 16:31:02 +08:00
public static function record ( $page , $size , $user_id )
{
2024-09-05 16:41:42 +08:00
$list = LocalStore :: where ([ 'user_id' => $user_id , 'is_delete' => 0 ]) -> page ( $page , $size ) -> order ( 'lstore_id desc' ) -> select () -> toArray ();
2024-09-05 16:31:02 +08:00
$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 ,
];
}
2024-09-16 15:40:03 +08:00
2024-10-08 15:36:48 +08:00
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' ]) {
2024-09-16 15:54:31 +08:00
return - 1 ;
}
2024-10-08 15:36:48 +08:00
$data [ 'goods_total_price' ] = round ( $goods_sku_msg [ 'price' ] * $post [ 'goods_num' ], 2 );
2024-09-16 15:54:31 +08:00
Db :: name ( " local_store_goods_item " )
2024-10-08 15:36:48 +08:00
-> where ( " id " , $post [ 'item_id' ])
-> dec ( " stock " , $post [ 'goods_num' ])
2024-09-16 15:54:31 +08:00
-> update ();
2024-10-08 15:36:48 +08:00
} else {
$data [ 'goods_total_price' ] = round ( $goods_msg [ 'price' ] * $post [ 'goods_num' ], 2 );
2024-09-16 15:40:03 +08:00
}
2024-10-08 15:36:48 +08:00
} else {
$data [ 'goods_total_price' ] = round ( $goods_msg [ 'price' ] * $post [ 'goods_num' ], 2 );
2024-09-16 15:54:31 +08:00
2024-09-16 15:40:03 +08:00
}
2024-10-08 15:36:48 +08:00
$data [ 'order_no' ] = createSn ( 'local_goods_order' , 'order_no' );
2024-09-16 15:40:03 +08:00
$data [ 'lstore_id' ] = $post [ 'lstore_id' ];
2024-09-16 15:54:31 +08:00
$data [ 'item_id' ] = $post [ 'item_id' ];
2024-09-16 15:40:03 +08:00
$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 ;
}
2024-10-08 15:36:48 +08:00
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 ();
2024-09-16 15:40:03 +08:00
$result [ 'goods_msg' ] = $goods ;
2024-10-08 15:36:48 +08:00
$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' ];
2024-09-17 00:40:35 +08:00
}
$result [ 'goods_image' ] = $image ;
2024-10-08 15:36:48 +08:00
$item = Db :: name ( " local_store_goods_item " ) -> where ( " id " , $result [ 'item_id' ]) -> find ();
if ( $item != null ) {
$item [ 'image' ] = Config :: get ( 'aliyunoss.domain' ) . $item [ 'image' ];
2024-09-17 00:41:53 +08:00
}
2024-09-16 15:40:03 +08:00
$result [ 'sku_msg' ] = $item ;
2024-10-08 15:36:48 +08:00
$local = Db :: name ( " local_store " ) -> field ( " shopName,shopLogo " ) -> where ( " lstore_id " , $result [ 'lstore_id' ]) -> find ();
2024-09-16 15:40:03 +08:00
$result [ 'local_msg' ] = $local ;
return $result ;
}
2024-10-08 15:36:48 +08:00
public static function cancelOrder ( $post )
{
2024-09-16 17:21:05 +08:00
$result = Db :: name ( " local_goods_order " )
2024-10-08 15:36:48 +08:00
-> where ( " lsg_order_id " , $post [ 'lsg_order_id' ])
2024-09-16 17:21:05 +08:00
-> find ();
2024-10-08 15:36:48 +08:00
if ( $result [ 'item_id' ] > 0 ) {
2024-09-16 17:21:05 +08:00
Db :: name ( " local_store_goods_item " )
2024-10-08 15:36:48 +08:00
-> where ( " id " , $result [ 'item_id' ])
-> inc ( " stock " , $result [ 'goods_num' ])
2024-09-16 17:21:05 +08:00
-> update ();
}
2024-10-08 15:36:48 +08:00
$res = Db :: name ( " local_goods_order " )
-> where ( " lsg_order_id " , $post [ 'lsg_order_id' ])
-> update ([ " state " => 2 ]);
2024-09-16 17:21:05 +08:00
return $res ;
}
2024-09-16 21:53:19 +08:00
public static function myOrderList ( $post )
2024-09-16 23:37:43 +08:00
{
2024-09-16 21:53:19 +08:00
$s = " " ;
2024-10-08 15:36:48 +08:00
if ( isset ( $post [ 'state' ])) {
$s = " state= " . $post [ 'state' ] . " " ;
2024-09-17 00:26:05 +08:00
}
2024-10-08 15:36:48 +08:00
$list = LocalGoodsStore :: where ( 'user_id' , $post [ 'user_id' ])
2024-09-16 21:53:19 +08:00
-> where ( $s )
2024-09-16 22:53:23 +08:00
-> where ( " state <> 3 " )
2024-09-16 21:53:19 +08:00
-> page ( $post [ 'page_no' ], $post [ 'page_size' ])
2024-09-16 22:53:23 +08:00
-> order ( 'dtime desc' )
2024-09-16 21:53:19 +08:00
-> select ()
-> toArray ();
2024-10-08 15:36:48 +08:00
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' ];
2024-09-16 23:23:40 +08:00
}
2024-10-08 15:36:48 +08:00
$sku_msg = Db :: name ( " local_store_goods_item " )
2024-09-18 14:27:40 +08:00
-> field ( " image,spec_value_str " )
2024-10-08 15:36:48 +08:00
-> where ( " id " , $value [ 'item_id' ])
2024-09-18 14:27:40 +08:00
-> find ();
2024-10-08 15:36:48 +08:00
if ( $sku_msg != null ) {
$sku_msg [ 'image' ] = Config :: get ( 'aliyunoss.domain' ) . $sku_msg [ 'image' ];
2024-09-18 14:29:31 +08:00
}
2024-09-18 14:27:40 +08:00
$list [ $key ][ 'sku_msg' ] = $sku_msg ;
2024-09-16 21:53:19 +08:00
$list [ $key ][ 'goods_msg' ] = $goods ;
2024-09-16 23:23:40 +08:00
$list [ $key ][ 'goods_image' ] = $image ;
2024-10-08 15:36:48 +08:00
$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 ();
2024-10-03 14:39:55 +08:00
$list [ $key ][ 'post_station' ] = $post_station ;
2024-09-16 22:58:50 +08:00
$list [ $key ][ 'local_msg' ] = $local ;
2024-10-03 14:41:57 +08:00
$list [ $key ][ 'post_station_time' ] = date ( " m-d " , $value [ 'post_station_time' ]);
2024-09-16 21:53:19 +08:00
}
2024-10-08 15:36:48 +08:00
$count = LocalGoodsStore :: where ( 'user_id' , $post [ 'user_id' ])
2024-09-17 00:10:49 +08:00
-> where ( $s )
2024-09-16 22:55:33 +08:00
-> where ( " state <> 3 " )
-> count ();
2024-10-08 15:36:48 +08:00
$all_count = LocalGoodsStore :: where ( 'user_id' , $post [ 'user_id' ])
2024-09-18 11:42:03 +08:00
-> where ( " state <> 3 " )
-> count ();
2024-10-08 15:36:48 +08:00
$wait_count = LocalGoodsStore :: where ( 'user_id' , $post [ 'user_id' ])
-> where ( " state " , 0 )
2024-09-18 11:42:03 +08:00
-> where ( " state <> 3 " )
-> count ();
2024-10-08 15:36:48 +08:00
$already_count = LocalGoodsStore :: where ( 'user_id' , $post [ 'user_id' ])
-> where ( " state " , 1 )
2024-09-18 11:42:03 +08:00
-> where ( " state <> 3 " )
-> count ();
2024-10-08 15:36:48 +08:00
$cancel_count = LocalGoodsStore :: where ( 'user_id' , $post [ 'user_id' ])
-> where ( " state " , 2 )
2024-09-18 11:42:03 +08:00
-> where ( " state <> 3 " )
-> count ();
2024-09-16 21:53:19 +08:00
$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 ,
2024-10-08 15:36:48 +08:00
'all_count' => $all_count ,
2024-09-18 11:42:03 +08:00
'wait_count' => $wait_count ,
'already_count' => $already_count ,
'cancel_count' => $cancel_count ,
2024-09-16 21:53:19 +08:00
'more' => $more ,
];
}
public static function orderList ( $post )
{
$s = " " ;
2024-10-08 15:36:48 +08:00
if ( isset ( $post [ 'state' ])) {
$s = " state= " . $post [ 'state' ] . " " ;
2024-09-16 21:53:19 +08:00
}
2024-10-08 15:36:48 +08:00
$list = LocalGoodsStore :: where ( 'lstore_id' , $post [ 'lstore_id' ])
2024-09-16 21:53:19 +08:00
-> where ( $s )
2024-09-16 22:53:23 +08:00
-> where ( " state <> 3 " )
2024-09-16 21:53:19 +08:00
-> page ( $post [ 'page_no' ], $post [ 'page_size' ])
2024-09-16 22:53:23 +08:00
-> order ( 'dtime desc' )
2024-09-16 21:53:19 +08:00
-> select ()
-> toArray ();
2024-10-08 15:36:48 +08:00
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' ];
2024-09-16 23:23:40 +08:00
}
2024-10-08 15:36:48 +08:00
$sku_msg = Db :: name ( " local_store_goods_item " )
2024-09-18 14:27:40 +08:00
-> field ( " image,spec_value_str " )
2024-10-08 15:36:48 +08:00
-> where ( " id " , $value [ 'item_id' ])
2024-09-18 14:27:40 +08:00
-> find ();
2024-10-08 15:36:48 +08:00
if ( $sku_msg != null ) {
$sku_msg [ 'image' ] = Config :: get ( 'aliyunoss.domain' ) . $sku_msg [ 'image' ];
2024-09-18 14:29:31 +08:00
}
2024-09-18 14:27:40 +08:00
$list [ $key ][ 'sku_msg' ] = $sku_msg ;
2024-09-16 21:53:19 +08:00
$list [ $key ][ 'goods_msg' ] = $goods ;
2024-09-16 23:23:40 +08:00
$list [ $key ][ 'goods_image' ] = $image ;
2024-10-08 15:36:48 +08:00
$local = Db :: name ( " local_store " ) -> field ( " shopName,shopLogo " ) -> where ( " lstore_id " , $value [ 'lstore_id' ]) -> find ();
2024-09-16 22:58:50 +08:00
$list [ $key ][ 'local_msg' ] = $local ;
2024-09-16 21:53:19 +08:00
}
2024-10-08 15:36:48 +08:00
$count = LocalGoodsStore :: where ( 'lstore_id' , $post [ 'lstore_id' ])
2024-09-17 00:10:49 +08:00
-> where ( $s )
2024-09-16 22:55:33 +08:00
-> where ( " state <> 3 " )
-> count ();
2024-10-08 15:36:48 +08:00
$all_count = LocalGoodsStore :: where ( 'lstore_id' , $post [ 'lstore_id' ])
2024-09-18 11:42:03 +08:00
-> where ( " state <> 3 " )
-> count ();
2024-10-08 15:36:48 +08:00
$wait_count = LocalGoodsStore :: where ( 'lstore_id' , $post [ 'lstore_id' ])
-> where ( " state " , 0 )
2024-09-18 11:42:03 +08:00
-> where ( " state <> 3 " )
-> count ();
2024-10-08 15:36:48 +08:00
$already_count = LocalGoodsStore :: where ( 'lstore_id' , $post [ 'lstore_id' ])
-> where ( " state " , 1 )
2024-09-18 11:42:03 +08:00
-> where ( " state <> 3 " )
-> count ();
2024-10-08 15:36:48 +08:00
$cancel_count = LocalGoodsStore :: where ( 'lstore_id' , $post [ 'lstore_id' ])
-> where ( " state " , 2 )
2024-09-18 11:42:03 +08:00
-> where ( " state <> 3 " )
-> count ();
2024-09-16 21:53:19 +08:00
$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 ,
2024-10-08 15:36:48 +08:00
'all_count' => $all_count ,
2024-09-18 11:42:03 +08:00
'wait_count' => $wait_count ,
'already_count' => $already_count ,
'cancel_count' => $cancel_count ,
2024-09-16 21:53:19 +08:00
'more' => $more ,
];
}
2024-09-29 15:14:04 +08:00
2024-09-29 17:14:43 +08:00
public static function addPostStation ( $post , $user_id )
2024-09-29 15:14:04 +08:00
{
if ( ! $post [ 'province' ] && ! $post [ 'city' ] && ! $post [ 'area' ] && ! $post [ 'address' ]) {
throw new \Exception ( '未选择区域' );
}
2024-09-29 15:22:11 +08:00
if ( ! $post [ 'lat' ] && ! $post [ 'lng' ]) {
2024-09-29 15:14:04 +08:00
throw new \Exception ( '经纬度不能为空' );
}
2024-10-09 15:17:57 +08:00
if ( ! $post [ 'phone' ]) {
throw new \Exception ( '自提点联系电话不能为空' );
}
2024-09-29 17:23:43 +08:00
$post [ 'user_id' ] = $user_id ;
$result = LocalStorePostStation :: insert ( $post );
2024-09-29 15:14:04 +08:00
if ( $result ) {
return true ;
}
throw new \Exception ( '更新失败' );
}
2024-09-29 17:53:43 +08:00
2024-10-09 15:17:57 +08:00
// 修改自提站点联系电话
public static function editPostStationPhone ( $post )
2024-09-29 17:53:43 +08:00
{
if ( ! $post [ 'id' ]) {
throw new \Exception ( '参数不能为空' );
}
2024-10-09 15:17:57 +08:00
if ( ! $post [ 'phone' ]) {
throw new \Exception ( '自提点联系电话不能为空' );
}
2024-10-09 15:34:46 +08:00
LocalStorePostStation :: where ([
2024-09-29 17:53:43 +08:00
'id' => $post [ 'id' ],
2024-10-09 15:17:57 +08:00
]) -> 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 ()]);
2024-09-29 17:53:43 +08:00
if ( $result ) {
return true ;
}
throw new \Exception ( '删除失败' );
}
2024-10-08 12:03:33 +08:00
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 ();
2024-10-08 16:02:40 +08:00
$userInfo [ 'rule' ] = self :: $local_menu ;
2024-10-08 12:03:33 +08:00
} else {
$userInfo = [];
}
return $userInfo ;
}
return false ;
}
2024-10-08 14:15:35 +08:00
2024-10-08 14:40:18 +08:00
public static function bindList ( $post )
{
2024-10-08 15:07:50 +08:00
$list = LocalStoreBind :: alias ( 'lsb' )
-> join ( 'user u' , 'lsb.bind_user_id = u.id' )
-> where ([ 'lstore_id' => $post [ 'lstore_id' ], 'is_unbind' => 0 ])
2024-10-08 15:10:13 +08:00
-> field ( 'lsb.*, u.nickname, u.avatar' )
2024-10-08 15:04:22 +08:00
-> order ( 'id desc' )
-> page ( $post [ 'page_no' ], $post [ 'page_size' ])
-> select ();
2024-10-08 14:57:48 +08:00
$count = LocalStoreBind :: where ([ 'lstore_id' => $post [ 'lstore_id' ], 'is_unbind' => 0 ]) -> count ();
$more = is_more ( $count , $post [ 'page_no' ], $post [ 'page_size' ]); //是否有下一页
2024-10-08 15:10:13 +08:00
if ( $list ) {
foreach ( $list as & $v ) {
$v [ 'avatar' ] = UrlServer :: getFileUrl ( $v [ 'avatar' ]);
}
}
2024-10-08 14:57:48 +08:00
return [
'lists' => $list ,
'page_no' => $post [ 'page_no' ],
'page_size' => $post [ 'page_size' ],
'count' => $count ,
'more' => $more ,
];
2024-10-08 14:40:18 +08:00
}
2024-10-08 14:15:35 +08:00
public static function bindUser ( $post )
{
2024-10-08 15:36:48 +08:00
if ( $post [ 'user' ][ 'id' ] <= 0 ) {
2024-10-08 14:15:35 +08:00
throw new \Exception ( '缺少用户ID' );
}
if ( empty ( $post [ 'user' ][ 'rule' ])) {
throw new \Exception ( '请为用户分配权限' );
}
2024-10-08 14:19:00 +08:00
$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 ( '已绑定该用户' );
}
2024-10-08 14:15:35 +08:00
$data = array ();
2024-10-08 14:48:01 +08:00
$data [ 'lstore_id' ] = $post [ 'lstore_id' ];
$data [ 'bind_user_id' ] = $post [ 'user' ][ 'id' ];
2024-10-08 14:48:27 +08:00
$data [ 'rule' ] = implode ( ',' , $post [ 'user' ][ 'rule' ]);
2024-10-08 14:48:01 +08:00
$data [ 'bind_time' ] = time ();
2024-10-08 14:15:35 +08:00
2024-10-08 14:48:01 +08:00
$result = $model -> insert ( $data );
2024-10-08 14:15:35 +08:00
if ( $result ) {
return true ;
}
throw new \Exception ( '添加失败' );
}
public static function unbindUser ( $post )
{
2024-10-08 15:36:48 +08:00
if ( $post [ 'id' ] <= 0 ) {
2024-10-08 15:14:11 +08:00
throw new \Exception ( '缺少ID' );
}
$result = LocalStoreBind :: where ( 'id' , $post [ 'id' ]) -> update ([
'is_unbind' => 1 ,
'unbind_time' => time ()
]);
if ( $result ) {
2024-10-08 15:36:48 +08:00
return true ;
2024-10-08 15:14:11 +08:00
}
throw new \Exception ( '解绑失败' );
2024-10-08 14:15:35 +08:00
}
2024-10-08 15:36:48 +08:00
public static function inBindList ( $user_id , $page , $size )
{
$list = LocalStoreBind :: alias ( 'lsb' )
-> join ( 'local_store ls' , 'lsb.lstore_id = ls.lstore_id' )
2024-10-08 15:44:38 +08:00
-> where ([ 'lsb.bind_user_id' => $user_id , 'lsb.is_unbind' => 0 ])
2024-10-08 15:36:48 +08:00
-> field ( 'lsb.*, ls.shopName, ls.shopLogo' )
-> page ( $page , $size )
-> select ();
$count = LocalStoreBind :: where ([ 'bind_user_id' => $user_id , 'is_unbind' => 0 ]) -> count ();
2024-10-08 15:48:29 +08:00
if ( $list ) {
foreach ( $list as & $v ) {
2024-10-08 16:02:40 +08:00
$v [ 'rule' ] = self :: crate_bind_menu ( $v [ 'rule' ]);
2024-10-08 15:48:29 +08:00
}
}
2024-10-08 15:36:48 +08:00
$data = [
'list' => $list ,
'page' => $page ,
'size' => $size ,
'count' => $count ,
'more' => is_more ( $count , $page , $size )
];
return $data ;
}
2024-10-08 16:02:40 +08:00
private static function crate_bind_menu ( $rule )
{
$menu = [];
$r = explode ( ',' , $rule );
2024-10-08 16:23:49 +08:00
sort ( $r );
2024-10-08 16:02:40 +08:00
foreach ( $r as & $v ) {
$menu [] = self :: $local_menu [ $v ];
}
return $menu ;
}
2024-08-10 10:18:04 +08:00
}