200 lines
7.0 KiB
PHP
Executable File
200 lines
7.0 KiB
PHP
Executable File
<?php
|
|
|
|
namespace app\api\controller;
|
|
|
|
use app\common\basics\Api;
|
|
use app\common\model\Config;
|
|
use app\common\model\user\User;
|
|
use app\common\server\JsonServer;
|
|
use app\common\server\UrlServer;
|
|
use app\common\server\WeChatServer;
|
|
use EasyWeChat\Factory;
|
|
use think\facade\Db;
|
|
use think\facade\Config as FileConfig;
|
|
|
|
class LocalStore extends Api
|
|
{
|
|
// public $like_not_need_login = ['makeMyPayImage'];
|
|
public function getLocalStore()
|
|
{
|
|
$id = $this->request->post('id');
|
|
$user_id = $this->user_id;
|
|
$result = Db::name("local_store")->where("user_id",$user_id)->find();
|
|
$data['local'] = $result;
|
|
// $data['local'] = [];
|
|
$data['set_state'] = 1;
|
|
return JsonServer::success('查询成功',$data);
|
|
}
|
|
|
|
public function addLocalStore()
|
|
{
|
|
$user_id = $this->user_id;
|
|
$data = $this->request->param();
|
|
if(isset($data['lstore_id'])){
|
|
if($data['lstore_id'] != 0){
|
|
$data['store_state'] = 0;
|
|
$result = Db::name("local_store")->where("lstore_id",$data['lstore_id'])->save($data);
|
|
if($result){
|
|
return JsonServer::success('上传成功');
|
|
}else{
|
|
return JsonServer::error('上传失败');
|
|
}
|
|
}
|
|
}
|
|
unset($data['lstore_id']);
|
|
|
|
$data['user_id'] = $user_id;
|
|
$data['create_time'] = date("Y-m-d H:i:s");
|
|
$result = Db::name("local_store")->save($data);
|
|
if($result){
|
|
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')
|
|
->where(['user_id' => $this->user_id, 'store_state' => 1])
|
|
->order('create_time', 'desc')
|
|
->page($page,$size)
|
|
->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);
|
|
}
|
|
|
|
/**
|
|
*生成本地商家支付二维码
|
|
*/
|
|
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, [
|
|
'page' => $url,
|
|
// 'env_version' => 'trial',
|
|
'env_version' => 'develop'
|
|
]);
|
|
// 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');
|
|
$result = Db::name('local_store')
|
|
->where(['lstore_id' => $id, 'user_id' => $this->user_id, 'store_state' => 1])
|
|
->order('create_time', 'desc')
|
|
->field('lstore_id, store_state, header_image, store_nickname, pay_image')
|
|
->find();
|
|
if ($result) {
|
|
$result['header_image'] = FileConfig::get('aliyunoss.domain') . 'local_life_shop/' . $result['header_image'] ;
|
|
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])
|
|
->update(['header_image' => 'local_life_shop/' . basename($header_image), 'update_time' => date('Y-m-d H:i:s')]);
|
|
}
|
|
|
|
if ($id && $store_name) {
|
|
$result = Db::name('local_store')
|
|
->where(['lstore_id' => $id, 'user_id' => $this->user_id])
|
|
->update(['store_nickname' => $store_name, 'update_time' => date('Y-m-d H:i:s')]);
|
|
}
|
|
|
|
if ($result) {
|
|
return JsonServer::success('修改成功');
|
|
}
|
|
|
|
return JsonServer::error('修改失败');
|
|
}
|
|
} |