dlh_test_server/app/api/controller/LocalStore.php

338 lines
12 KiB
PHP
Raw Normal View History

2024-08-03 10:04:14 +08:00
<?php
namespace app\api\controller;
use app\common\basics\Api;
use app\common\enum\NoticeEnum;
2024-08-03 10:04:14 +08:00
use app\common\model\user\User;
use app\common\server\ConfigServer;
2024-08-03 10:04:14 +08:00
use app\common\server\JsonServer;
use app\common\server\WeChatServer;
use app\api\logic\LocalStoreLogic;
2024-08-03 10:04:14 +08:00
use EasyWeChat\Factory;
use think\facade\Db;
use think\facade\Config as FileConfig;
2024-08-22 09:18:07 +08:00
use app\api\validate\LocalStoreGoodsValidate;
2024-08-03 10:04:14 +08:00
class LocalStore extends Api
{
public $like_not_need_login = ['makeMyPayImage', 'getLocalShopById', 'getLocalList', 'getLocation'];
2024-09-02 16:47:29 +08:00
2024-08-03 10:04:14 +08:00
public function getLocalStore()
{
2024-09-05 22:10:46 +08:00
$lstore_id = $this->request->post('lstore_id');
2024-08-03 10:04:14 +08:00
$user_id = $this->user_id;
2024-09-05 22:10:46 +08:00
if ($lstore_id) {
$result = Db::name("local_store")->where(['lstore_id' => $lstore_id, "user_id" => $user_id])->find();
} else {
$result = Db::name("local_store")->where("user_id", $user_id)->select()->toArray();
}
2024-08-03 10:04:14 +08:00
$data['local'] = $result;
$data['set_state'] = 1;
return JsonServer::success('查询成功',$data);
}
// 查询本地商家
public function getLocalList(){
$model = new LocalStoreLogic;
$data = $this->request->param();
$result = $model->getLocalList($data);
return JsonServer::success('查询成功',$result);
}
2024-08-11 16:58:13 +08:00
// 查询本地商户订单
public function getLocalOrderList(){
$model = new LocalStoreLogic;
$data = $this->request->param();
$result = $model->getLocalOrderList($data);
return JsonServer::success('查询成功',$result);
}
2024-08-12 10:31:55 +08:00
// 查询本地商户用户订单
public function getLocalUserOrderList(){
$model = new LocalStoreLogic;
$data = $this->request->param();
$user_id = $this->user_id;
$data['user_id'] = $user_id;
$result = $model->getLocalUserOrderList($data);
return JsonServer::success('查询成功',$result);
}
2024-08-03 10:04:14 +08:00
public function addLocalStore()
{
$user_id = $this->user_id;
$data = $this->request->param();
if(isset($data['lstore_id']) && $data['lstore_id'] != 0){
$data['store_state'] = 0;
$data['update_time'] = date("Y-m-d H:i:s");
$result = Db::name("local_store")->where("lstore_id",$data['lstore_id'])->save($data);
}else {
$data['user_id'] = $user_id;
$data['create_time'] = date("Y-m-d H:i:s");
$result = Db::name("local_store")->save($data);
2024-08-03 10:04:14 +08:00
}
2024-08-03 10:04:14 +08:00
if($result){
event('Notice', [
'scene' => NoticeEnum::LOCAL_SHOP_SETTLED_NOTICE,
'mobile' => 18436015360, // 张慧娟的手机号码
'params' => [
'user_id' => $this->user_id,
'shopName' => $data['shopName'],
]
]);
2024-08-03 10:04:14 +08:00
return JsonServer::success('上传成功');
}else{
return JsonServer::error('上传失败');
}
}
// 查询协议
public function checkTreaty()
{
$result = Db::name("procurement_treaty")->where("id",1)->find();
return JsonServer::success('查询成功',$result);
}
// 获取本地生活商家列表
public function getLocalStoreList()
{
$page = $this->request->get('page_no', $this->page_no);
$size = $this->request->get('page_size', $this->page_size);
$lists = Db::name('local_store')
2024-09-05 23:23:46 +08:00
->where(['user_id' => $this->user_id, 'store_state' => 1, 'is_delete' => 0])
2024-08-03 10:04:14 +08:00
->order('create_time', 'desc')
->page($page,$size)
->select()
->toArray();
$count = Db::name('local_store')
2024-09-05 23:23:46 +08:00
->where(['user_id' => $this->user_id, 'store_state' => 1 , 'is_delete' => 0])
2024-08-03 10:04:14 +08:00
->count();
$more = is_more($count, $page, $size); //是否有下一页
$data = [
'list' => $lists,
'page_no' => $page,
'page_size' => $size,
'count' => $count,
'more' => $more,
];
return JsonServer::success('查询成功', $data);
}
2024-08-07 09:17:18 +08:00
// 获取本地生活商家列表
public function getLocalAllStoreList()
{
$page = $this->request->get('page_no', $this->page_no);
$size = $this->request->get('page_size', $this->page_size);
$lists = Db::name('local_store')
->where(['store_state' => 1])
->order('create_time', 'desc')
->page($page,$size)
2024-08-07 09:17:18 +08:00
->select()
->toArray();
foreach ($lists as &$v) {
if (!empty($v['header_image'])) {
$v['header_image'] = FileConfig::get('aliyunoss.domain') . 'local_life_shop/' . $v['header_image'];
}
}
$count = Db::name('local_store')
->where(['user_id' => $this->user_id, 'store_state' => 1])
->count();
$more = is_more($count, $page, $size); //是否有下一页
$data = [
'list' => $lists,
'page_no' => $page,
'page_size' => $size,
'count' => $count,
'more' => $more,
];
return JsonServer::success('查询成功', $data);
}
2024-08-03 10:04:14 +08:00
/**
*生成本地商家支付二维码
*/
public function makeMyPayImage(){
// $user_id = 2;
$user_id = $this->user_id;
$lstore_id = $this->request->post('lstore_id');
$user_msg = User::where("id",$user_id)->where("del",0)->where("disable",0)->find();
if($user_msg==null){
return JsonServer::error('暂无用户');
}
$user_local_msg = Db::name("local_store")->where("user_id",$user_id)->where("store_state",1)->find();
if ($user_local_msg!= null) {
if($user_local_msg['pay_image'] != null){
$data['pay_image'] = $user_local_msg['pay_image'];
return JsonServer::success('查询成功',$data);
}else{
$url = "bundle_b/pages/local_shop/local_pay";
$save_dir = ROOT_PATH .'/uploads/localpay/';
$scene = 'lid='.$lstore_id;
$a = time().$scene;
$qr_src = $a . '.jpg';
}
}else{
$url = "bundle_b/pages/local_shop/local_pay";
$save_dir = ROOT_PATH .'/uploads/localpay/';
$scene = 'lid='.$lstore_id;
$a = time().$scene;
$qr_src = $a . '.jpg';
}
try {
$config = WeChatServer::getMnpConfig();
$app = Factory::miniProgram($config);
$response = $app->app_code->getUnlimit($scene, [
2024-08-10 14:52:26 +08:00
'page' => $url
2024-08-03 10:04:14 +08:00
// 'env_version' => 'trial',
2024-08-10 14:52:26 +08:00
// 'env_version' => 'develop'
2024-08-03 10:04:14 +08:00
]);
// print_r("<pre>");
// var_dump($response);die;
if ($response instanceof \EasyWeChat\Kernel\Http\StreamResponse) {
$response->saveAs($save_dir, $a);
$us = \think\facade\Request::instance()->domain();
$data['pay_image'] = $us.'/uploads/localpay/'.$qr_src;
$user_msg = Db::name("local_store")->where("lstore_id",$lstore_id)->update($data);
if($user_msg){
return JsonServer::success('查询成功',$data);
}else{
return JsonServer::error('查询失败');
}
}
if(isset($response['errcode']) && 41030 === $response['errcode']){
return '商城小程序未上线或商城小程序页面发布';
}
return $response['errmsg'];
} catch (\EasyWeChat\Kernel\Exceptions\Exception $e){
return $e->getMessage();
}
}
public function getLocalShopById()
{
$id = $this->request->post('id');
2024-08-13 09:28:28 +08:00
$latitude = $this->request->post('latitude',0);
$longitude = $this->request->post('longitude',0);
2024-08-13 10:22:57 +08:00
$type = $this->request->post('type',0);
2024-08-13 09:28:28 +08:00
$user_id = $this->user_id;
$u = "";
2024-08-13 10:22:57 +08:00
if($type == 0){
2024-08-13 09:28:28 +08:00
$u = "user_id = $user_id";
}
2024-08-03 10:04:14 +08:00
$result = Db::name('local_store')
2024-08-13 09:41:33 +08:00
->where('lstore_id',$id)
->where('store_state',1)
2024-08-13 09:28:28 +08:00
->where($u)
2024-08-13 09:41:33 +08:00
->order('create_time desc')
2024-08-03 10:04:14 +08:00
->find();
2024-08-13 09:24:30 +08:00
if ($result) {
$model = new LocalStoreLogic;
$result['distance']=round($model->distance($result['latitude'],$result['longitude'],$latitude,$longitude)/1000,2)."公里";
$result['header_image'] = FileConfig::get('aliyunoss.domain') . 'local_life_shop/' . $result['header_image'] ;
2024-08-03 10:04:14 +08:00
return JsonServer::success('成功获取', $result);
}
return JsonServer::error('获取失败');
}
public function editLocaShopInfo()
{
$id = $this->request->post('id');
$header_image = $this->request->post('header_image');
$store_name = $this->request->post('store_name');
$result = false;
if ($id && $header_image) {
$result = Db::name('local_store')
->where(['lstore_id' => $id, 'user_id' => $this->user_id])
2024-08-23 17:44:07 +08:00
->update(['shopLogo' => $header_image, 'update_time' => date('Y-m-d H:i:s')]);
2024-08-03 10:04:14 +08:00
}
if ($id && $store_name) {
$result = Db::name('local_store')
->where(['lstore_id' => $id, 'user_id' => $this->user_id])
2024-08-23 17:34:50 +08:00
->update(['shopName' => $store_name, 'update_time' => date('Y-m-d H:i:s')]);
2024-08-03 10:04:14 +08:00
}
if ($result) {
return JsonServer::success('修改成功');
}
return JsonServer::error('修改失败');
}
2024-09-05 16:31:02 +08:00
// 本地商家提交记录
public function record()
{
$page = $this->request->get('page_no', $this->page_no);
$size = $this->request->get('page_size', $this->page_size);
$data = LocalStoreLogic::record($page, $size, $this->user_id);
return JsonServer::success('查询成功', $data);
}
2024-09-16 15:40:03 +08:00
//下单购买商品
public function submitLocalOrder(){
$post = $this->request->post();
$user_id = $this->user_id;
$data = LocalStoreLogic::submitOrder($post,$user_id);
if($data === -1){
2024-09-16 15:50:39 +08:00
return JsonServer::error('库存不足');
2024-09-16 15:40:03 +08:00
}
return JsonServer::success('下单成功', $data);
}
2024-09-16 15:40:03 +08:00
// 订单详情
public function localOrderDetails(){
$post = $this->request->post();
$data = LocalStoreLogic::orderDetails($post);
return JsonServer::success('查询成功', $data);
}
2024-09-16 17:21:05 +08:00
// 取消订单
public function cancelLocalOrder(){
$post = $this->request->post();
$data = LocalStoreLogic::cancelOrder($post);
if($data){
return JsonServer::success('取消成功');
}else{
return JsonServer::error('取消失败');
}
}
// 我的订单
2024-09-16 21:53:19 +08:00
public function localMyOrderList(){
$post = $this->request->post();
$user_id = $this->user_id;
$post['user_id'] = $user_id;
$data = LocalStoreLogic::myOrderList($post);
return JsonServer::success('查询成功', $data);
}
2024-09-16 21:53:19 +08:00
// 店铺订单列表
public function localOrderList(){
$post = $this->request->post();
$data = LocalStoreLogic::orderList($post);
return JsonServer::success('查询成功', $data);
}
// 腾讯地图逆编码
public function getLocation()
{
2024-09-29 14:11:38 +08:00
try {
$post = $this->request->post();
$url = 'https://apis.map.qq.com/ws/geocoder/v1?key=' . ConfigServer::get('map', 'tx_map_key') . '&address=' . $post['address'];
$result = file_get_contents($url);
$data = json_decode($result, true);
if ($data['message'] == 'Success') {
return JsonServer::success('', $data['result']['location']);
}
} catch(\Exception $e) {
return JsonServer::error($e->getMessage());
}
}
2024-08-03 10:04:14 +08:00
}