You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
119 lines
4.0 KiB
PHP
119 lines
4.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\API\Internal;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Services\SanFangCodeService;
|
|
use App\Services\ZhongKangService;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class TransferCodeController extends Controller
|
|
{
|
|
//查询转赠码
|
|
public function GetTransferCode(Request $request)
|
|
{
|
|
$code_num = request('code_num');
|
|
$user_name = request('user_name');
|
|
$user_id_number = request('user_id_number');
|
|
$qudao = request('qudao');
|
|
|
|
$return_data = [
|
|
'code_num' => '',
|
|
'price' => 0,
|
|
'combo_id' => 0,
|
|
'status' => 0,
|
|
];
|
|
$code=DB::table('transfer_code');
|
|
if(isset($qudao)){
|
|
if($qudao==3){
|
|
$service=new ZhongKangService();
|
|
$res=$service->GetHexiaoCode($code_num,$user_name,$user_id_number);
|
|
if ($res['status'] == true && $res['data']['status'] == 1) {
|
|
//查询本地库是否有记录,进行相应的更新
|
|
$db_zk_code = DB::table('transfer_code')->where(['sanfang_qudao' => $qudao, 'code' => $code_num, 'is_del' => 0])->first();
|
|
if (!!$db_zk_code && $db_zk_code->status <> $res['data']['status']) {
|
|
return \Yz::echoError1("此转赠码状态不正确,暂不可用(中康)code:".$code_num);
|
|
}
|
|
if (!$db_zk_code) {
|
|
$data = [
|
|
'code' => $code_num,
|
|
'price' => $res['data']['price'] / 100,
|
|
'combo_id' => $res['data']['combo_id'],
|
|
'sanfang_qudao' =>$qudao,
|
|
'status' => 1,
|
|
];
|
|
$u = DB::table('transfer_code')->insert($data);
|
|
}
|
|
|
|
}else{
|
|
return \Yz::echoError1("此转赠码不可用。码号为:".$code_num."请核对后再试");
|
|
}
|
|
}
|
|
$code=$code->where('sanfang_qudao',$qudao);
|
|
}
|
|
$code=$code->where(['code'=>$code_num,'status'=>1,'is_del'=>0])->first();
|
|
if(!$code) return \Yz::echoError1("此转赠码不可用。码号为:".$code_num."请核对后再试");
|
|
$u=DB::table('transfer_code')->where(['code'=>$code_num])->update([
|
|
'user_name'=>$user_name,
|
|
'user_id_number'=>$user_id_number,
|
|
]);
|
|
$data=[
|
|
'code_num'=>$code->code,
|
|
'status'=>$code->status,
|
|
'price'=>$code->price,
|
|
'combo_id'=>$code->combo_id,
|
|
'user_name'=>$code->user_name,
|
|
'user_id_number'=>$code->user_id_number
|
|
];
|
|
return \Yz::Return(true,"查询成功",$data);
|
|
}
|
|
//操作转赠码
|
|
public function HandleTransferCode(Request $request)
|
|
{
|
|
$validatedData = $request->validate([
|
|
'type' => 'required',
|
|
'code_num' => 'required',
|
|
'qudao' => 'required'
|
|
]);
|
|
$type = $validatedData['type']; //1使用2撤销使用
|
|
$code_num = $validatedData['code_num'];
|
|
$qudao = $validatedData['qudao'];
|
|
$tj_num = request('tj_num');
|
|
$code_info=DB::table('transfer_code')->where(['code'=>$code_num,'is_del'=>0,'sanfang_qudao'=>$qudao])->first();
|
|
if(!$code_info) return \Yz::echoError1("此转赠码不存在");
|
|
$data=[];
|
|
$u=false;
|
|
$where=['code'=>$code_num,'is_del'=>0,'sanfang_qudao'=>$qudao];
|
|
if($type==1){
|
|
|
|
$data=[
|
|
'status'=>2,
|
|
'tj_num'=>isset($tj_num)?$tj_num:null,
|
|
];
|
|
$where['status']=1;
|
|
}
|
|
if($type==2){
|
|
$data=[
|
|
'status'=>1,
|
|
'tj_num'=>null,
|
|
];
|
|
$where['status']=2;
|
|
}
|
|
if($qudao==3){
|
|
$service=new ZhongKangService();
|
|
$res=$service->HandleTransferCode($type,$code_num,$code_info->user_name,$code_info->user_id_number);
|
|
if (!$res['status']) {
|
|
return \Yz::echoError1( $res['msg']);
|
|
}
|
|
}
|
|
$u=DB::table('transfer_code')->where($where)->update($data);
|
|
$cha=DB::table('transfer_code')->where(['code'=>$code_num,'sanfang_qudao'=>$qudao])->first();
|
|
if($u){
|
|
return \Yz::Return(true,"操作成功",['code_num'=>$code_num,'status'=>$cha->status]);
|
|
}else{
|
|
return \Yz::echoError1("操作失败");
|
|
}
|
|
}
|
|
}
|