132 lines
5.3 KiB
PHP
132 lines
5.3 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
|
||
|
|
namespace app\index\controller;
|
||
|
|
use app\common\basics\IndexBase;
|
||
|
|
use think\facade\Db;
|
||
|
|
use \weixin\Getgzopenid;
|
||
|
|
use app\common\server\JsonServer;
|
||
|
|
use app\common\model\procurement\Procurementxy;
|
||
|
|
use app\common\model\gzuser\Weixingzhuserbind;
|
||
|
|
class Weixingz extends IndexBase
|
||
|
|
{
|
||
|
|
public function getOpenid(){
|
||
|
|
$wxcode = isset($_POST['code'])?$_POST['code']:'';
|
||
|
|
if($wxcode == ""){
|
||
|
|
return JsonServer::error('code不存在');
|
||
|
|
}
|
||
|
|
$openid = "";
|
||
|
|
$open=new Getgzopenid();
|
||
|
|
$info=$open->getAcc($wxcode);
|
||
|
|
if($info) {
|
||
|
|
$openid = $info['openid'];
|
||
|
|
$data['open_id'] = $openid;
|
||
|
|
return JsonServer::success('获取成功', $data);
|
||
|
|
}else{
|
||
|
|
return JsonServer::error('用户信息获取失败');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
public function weixinLogin(){
|
||
|
|
$account = isset($_REQUEST['account'])?$_REQUEST['account']:"";
|
||
|
|
$password = isset($_REQUEST['password'])?$_REQUEST['password']:"";
|
||
|
|
$openid = isset($_REQUEST['openid'])?$_REQUEST['openid']:"";
|
||
|
|
if($password == "123456"){
|
||
|
|
$result = Db::name('goods_contact')->where('c_phone',$account)->where("gzhuser_state",1)->select();
|
||
|
|
if(count($result)>0){
|
||
|
|
if($openid != ""){
|
||
|
|
$r = Db::name('goods_contact')->where('c_phone',$account)->update(['open_id'=>$openid,'update_time'=>date("Y-m-d H:i:s")]);
|
||
|
|
if($r){
|
||
|
|
$data['user_id'] = $result[0]['c_id'];
|
||
|
|
return JsonServer::success('登录成功', $data);
|
||
|
|
}else{
|
||
|
|
return JsonServer::error('数据错误');
|
||
|
|
}
|
||
|
|
}else{
|
||
|
|
return JsonServer::error('系统错误');
|
||
|
|
}
|
||
|
|
}else{
|
||
|
|
return JsonServer::error('账号密码错误');
|
||
|
|
}
|
||
|
|
}else{
|
||
|
|
return JsonServer::error('账号密码错误');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
public function getShopList(){
|
||
|
|
$result = Db::name('shop')->field("id,name")->where('is_freeze',0)->where('del',0)->select();
|
||
|
|
if(count($result)>0){
|
||
|
|
$data['shop_list']=$result;
|
||
|
|
return JsonServer::success('查询成功', $data);
|
||
|
|
}else{
|
||
|
|
return JsonServer::error('暂无数据');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
public function bindShop(){
|
||
|
|
$user_id = isset($_REQUEST['user_id'])?$_REQUEST['user_id']:"";
|
||
|
|
$id = isset($_REQUEST['id'])?$_REQUEST['id']:"";
|
||
|
|
$result = Db::name('goods_contact')->where('c_id',$user_id)->where("gzhuser_state",1)->select();
|
||
|
|
if(count($result)>0){
|
||
|
|
if($id != ""){
|
||
|
|
$rx = Db::name('weixin_gzhuser_bind')->where('gzhuser_id',$user_id)->where("shop_id",$id)->where("bind_state",1)->select();
|
||
|
|
if(count($rx)>0){
|
||
|
|
return JsonServer::error('已绑定店铺');
|
||
|
|
}else{
|
||
|
|
$r = Weixingzhuserbind::create([
|
||
|
|
'gzhuser_id' => $user_id,
|
||
|
|
'shop_id' => $id,
|
||
|
|
'create_time' => time()
|
||
|
|
]);
|
||
|
|
if($r){
|
||
|
|
$data['bind'] = "";
|
||
|
|
return JsonServer::success('绑定成功',$data);
|
||
|
|
}else{
|
||
|
|
return JsonServer::error('绑定失败');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}else{
|
||
|
|
return JsonServer::error('请先选择绑定店铺');
|
||
|
|
}
|
||
|
|
}else{
|
||
|
|
return JsonServer::error('暂无用户或账户已被冻结');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
public function bindShopList(){
|
||
|
|
$user_id = isset($_REQUEST['user_id'])?$_REQUEST['user_id']:"";
|
||
|
|
$result =Weixingzhuserbind::alias('a')->
|
||
|
|
field("a.bind_id,a.create_time,b.name")->
|
||
|
|
leftJoin('shop b', 'a.shop_id=b.id')->
|
||
|
|
where('a.gzhuser_id',$user_id)->
|
||
|
|
where("a.bind_state",1)->
|
||
|
|
order("a.create_time desc")->
|
||
|
|
select();
|
||
|
|
$data['shop_list'] = $result;
|
||
|
|
return JsonServer::success('查询成功',$data);
|
||
|
|
|
||
|
|
}
|
||
|
|
public function relieveBind(){
|
||
|
|
$bind_id = isset($_REQUEST['bind_id'])?$_REQUEST['bind_id']:"";
|
||
|
|
$result = Db::name('weixin_gzhuser_bind')->where('bind_id',$bind_id)->update(['bind_state'=>2]);
|
||
|
|
if($result){
|
||
|
|
$data['result'] = "";
|
||
|
|
return JsonServer::success('解除绑定成功',$data);
|
||
|
|
}else{
|
||
|
|
return JsonServer::error('系统错误');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
public function limitScript(){
|
||
|
|
$result = Db::name('procurement_xy_pencil')->field("sum(pencil_price)as sums,user_id")->where('pencil_state',0)->group("user_id")->select();
|
||
|
|
foreach($result as $key=>$value){
|
||
|
|
$user = Db::name('procurement_xy')->where('user_id',$value['user_id'])->find();
|
||
|
|
if($user!=null){
|
||
|
|
Procurementxy::where('user_id', $value['user_id'])
|
||
|
|
->inc('xy_price',round($value['sums'],2))->update();
|
||
|
|
}else{
|
||
|
|
Procurementxy::create([
|
||
|
|
'xy_price' => round($value['sums'],2),
|
||
|
|
'user_id' => $value['user_id'],
|
||
|
|
'xy_use_dtime' => time()
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
Db::name('procurement_xy_pencil')->where('user_id',$value['user_id'])->update(['pencil_state'=>1]);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|