作者 郭文星

123

... ... @@ -203,5 +203,76 @@ class Car extends Backend
$this->success();
}
function getAccessToken() {
$appId = "wx58ceff4e93cfc523";
$appSecret = "baf744d21875280a5e98611f66adaf91";
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appId}&secret={$appSecret}";
$result = json_decode(file_get_contents($url), true);
return $result["access_token"] ?? null;
}
function createMiniProgramQRCode($accessToken, $path, $width = 430) {
$url = "https://api.weixin.qq.com/wxa/getwxacode?access_token={$accessToken}";
$data = json_encode([
'path' => $path,
'width' => $width
]);
$options = [
'http' => [
'method' => 'POST',
'header' => 'Content-type:application/json',
'content' => $data,
],
];
//POST参数
$result = $this->httpRequest($url,$data,"POST");
$filename= './uploads/store_qrcode/' . time() . '.png';
$ret = file_put_contents($filename, $result, true);
return $filename;
}
//把请求发送到微信服务器换取二维码
public function httpRequest($url,$data='',$method='GET'){
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL,$url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_USERAGENT,$_SERVER['HTTP_USER_AGENT']);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_AUTOREFERER, 1);
if($method=='POST')
{
curl_setopt($curl, CURLOPT_POST, 1);
if ($data !='')
{
curl_setopt($curl, CURLOPT_POSTFIELDS,$data);
}
}
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
curl_close($curl);
return $result;
}
public function test(){
$accessToken = $this->getAccessToken();
if ($accessToken) {
$path = 'pages/index/index'; // 小程序内的页面路径
$qrCodeData = $this->createMiniProgramQRCode($accessToken, $path);
if ($qrCodeData) {
echo '图像文件保存成功!';
// 验证图像文件是否成功保存
} else {
echo '图像文件保存失败!';
}
header('Content-Type: image/png');
} else {
echo "Failed to generate QR code.";
}
}
}
\ No newline at end of file
... ...
... ... @@ -58,7 +58,7 @@ class Driver extends Backend
->paginate($limit);
foreach ($list as $row) {
$row->visible(['id','name','car_fleet','phone','scheduling_type']);
$row->visible(['id','name','car_fleet','offline_payment','phone','scheduling_type']);
$row->visible(['user']);
$row->getRelation('user')->visible(['username']);
}
... ...
... ... @@ -4,6 +4,8 @@ namespace app\admin\controller;
use app\common\controller\Backend;
use think\Db;
use think\exception\PDOException;
use think\exception\ValidateException;
/**
* 订单管理
... ... @@ -52,19 +54,19 @@ class Order extends Backend
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$list = $this->model
->with(['driver','car','user'])
->where($where)
->order($sort, $order)
->paginate($limit);
->with(['driver', 'car', 'user'])
->where($where)
->order($sort, $order)
->paginate($limit);
foreach ($list as $row) {
$row->visible(['id','order_no','type','pay_type','price','is_pay','user_name','driver_name','pay_time','refund_time','create_time']);
$row->visible(['id', 'order_no', 'type','intended_driver_id', 'pay_type', 'price', 'is_pay', 'user_name', 'driver_name', 'pay_time', 'refund_time', 'create_time']);
$row->visible(['driver']);
$row->getRelation('driver')->visible(['name']);
$row->visible(['car']);
$row->getRelation('car')->visible(['license_plate']);
$row->visible(['user']);
$row->getRelation('user')->visible(['username']);
$row->getRelation('driver')->visible(['name']);
$row->visible(['car']);
$row->getRelation('car')->visible(['license_plate']);
$row->visible(['user']);
$row->getRelation('user')->visible(['username']);
}
$result = array("total" => $list->total(), "rows" => $list->items());
... ... @@ -74,10 +76,11 @@ class Order extends Backend
return $this->view->fetch();
}
public function refund($id){
public function refund($id)
{
//查询订单
$order=Db::name("order")->where("id",$id)->find();
if($order['is_pay']!=1){
$order = Db::name("order")->where("id", $id)->find();
if ($order['is_pay'] != 1) {
$this->error("该订单无法退款");
}
//拼接退款参数
... ... @@ -102,8 +105,60 @@ class Order extends Backend
->where(['id' => $order['id']])
->update($relogs);
} else {
$this->error('退款失败');
$this->error('退款失败');
}
$this->success("退款成功");
}
/**
* 编辑
*
* @param $ids
* @return string
* @throws DbException
* @throws \think\Exception
*/
public function selectiondriver($ids = null)
{
$row = $this->model->get($ids);
if (!$row) {
$this->error(__('No Results were found'));
}
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
$this->error(__('You have no permission'));
}
if (false === $this->request->isPost()) {
$this->view->assign('row', $row);
return $this->view->fetch();
}
$params = $this->request->post('row/a');
if (empty($params)) {
$this->error(__('Parameter %s can not be empty', ''));
}
$params = $this->preExcludeFields($params);
$result = false;
Db::startTrans();
try {
//是否采用模型验证
if ($this->modelValidate) {
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
$row->validateFailException()->validate($validate);
}
$result = $row->allowField(true)->save($params);
Db::commit();
} catch (ValidateException|PDOException|Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if (false === $result) {
$this->error(__('No rows were updated'));
}
$this->success();
}
}
... ...
... ... @@ -5,9 +5,9 @@ return [
'User_id' => '用户id',
'Name' => '司机名称',
'Phone' => '手机号',
'Is_work' => '是否上班',
'Is_work 1' => '上班',
'Is_work 2' => '下班',
'Offline_payment' => '是否线下支付',
'Offline_payment 0' => '否',
'Offline_payment 1' => '是',
'Scheduling_type' => '排班类型',
'Scheduling_type 1' => '滚动排班',
'Scheduling_type 2' => '自主排班',
... ...
... ... @@ -6,6 +6,12 @@
<input id="c-user_id" data-rule="required" data-source="user/user/index" data-field="username" class="form-control selectpage" name="row[user_id]" type="text" value="">
</div>
</div>
<div class="form-group" id="kevin_company_type">
<label class="control-label col-xs-12 col-sm-2">{:__('Offline_payment')}:</label>
<div class="col-xs-12 col-sm-8">
{:build_radios("row[offline_payment]",["0"=>"否","1"=>"是"])}
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Name')}:</label>
<div class="col-xs-12 col-sm-8">
... ...
... ... @@ -6,6 +6,12 @@
<input id="c-user_id" data-rule="required" data-source="user/user/index" data-field="username" class="form-control selectpage" name="row[user_id]" type="text" value="{$row.user_id|htmlentities}">
</div>
</div>
<div class="form-group" id="kevin_company_type">
<label class="control-label col-xs-12 col-sm-2">{:__('Offline_payment')}:</label>
<div class="col-xs-12 col-sm-8">
{:build_radios("row[offline_payment]",["0"=>"否","1"=>"是"],$row['offline_payment'])}
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Name')}:</label>
<div class="col-xs-12 col-sm-8">
... ...
<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<div class="form-group layer-footer">
<label class="control-label col-xs-12 col-sm-2"></label>
<div class="col-xs-12 col-sm-8">
<button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
<button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
</div>
</div>
</form>
... ...
... ... @@ -1094,10 +1094,6 @@ class Car extends Base
$phone = $this->request->param("phone");//联系电话
$intended_driver_id = $this->request->param("intended_driver_id");//意向司机
$remarks = $this->request->param("remarks");//备注
$driver = Db::name("driver")->where("id", $intended_driver_id)->find();
$car = Db::name("car")->where("driver_id", $driver['id'])->find();
$carmodel = Db::name("carmodel")->where("id", $car['carmodel_id'])->find();
$route = Db::name("route")->where("id", $car['route_id'])->find();
$price = 0;
$specificaddress = Db::name("specificaddress")->where("id", $specificaddress_id)->find();
if ($specificaddress) {
... ... @@ -1105,6 +1101,12 @@ class Car extends Base
} else {
$this->error("价格计算错误");
}
if ($intended_driver_id){
$driver = Db::name("driver")->where("id", $intended_driver_id)->find();
$car = Db::name("car")->where("driver_id", $driver['id'])->find();
$carmodel = Db::name("carmodel")->where("id", $car['carmodel_id'])->find();
$route = Db::name("route")->where("id", $car['route_id'])->find();
//判断总表
$time = strtotime(date("Y-m-d", time()));
$order_review = Db::name("order_review")
... ... @@ -1138,7 +1140,6 @@ class Car extends Base
"is_pay" => "2",//未支付
"route_id" => $route_id,
"user_id" => $this->auth->id,
"driver_id" => $driver['id'],
"phone" => $phone,
"create_time" => time(),
"reservation_time" => time(),
... ... @@ -1147,6 +1148,25 @@ class Car extends Base
"remarks" => $remarks,
"intended_driver_id" => $intended_driver_id,
];
}else{
$data = [
"order_no" => getOrderSn(),
"price" => $price,
"is_qrcode" => $is_qrcode,
"specificaddress_id" => $specificaddress_id,
"reservation_time" => $reservation_time,
"is_pay" => "2",//未支付
"route_id" => $route_id,
"user_id" => $this->auth->id,
"phone" => $phone,
"create_time" => time(),
"reservation_time" => time(),
"type" => 2,
"number" => $number,
"remarks" => $remarks,
"intended_driver_id" => $intended_driver_id,
];
}
$res = Db::name("order")->insertGetId($data);
$userinfo = Db::name('user')
->where(['id' => $this->auth->id])
... ... @@ -1467,6 +1487,15 @@ class Car extends Base
}
}
/**
* 查询订单详情
* @return void
*/
public function orderinfo(){
$order_id = $this->request->param("order_id");
$res=Db::name("order")->where('id',$order_id)->find();
$this->success("请求成功",$res);
}
public function test(){
$res=SendMessage(117);
$this->success("123",$res);
... ...
... ... @@ -2,6 +2,7 @@
namespace app\api\controller;
use app\api\controller\inspection\Task;
use app\common\controller\Api;
/**
... ... @@ -29,9 +30,8 @@ class Index extends Api
$result = json_decode(file_get_contents($url), true);
return $result["access_token"] ?? null;
}
function createMiniProgramQRCode($accessToken, $path, $width = 430) {
$url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token={$accessToken}";
$url = "https://api.weixin.qq.com/wxa/getwxacode?access_token={$accessToken}";
$data = json_encode([
'path' => $path,
... ... @@ -44,13 +44,38 @@ class Index extends Api
'content' => $data,
],
];
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
print_r($result);return;
if ($result === false) {
return false;
//POST参数
$result = $this->httpRequest($url,$data,"POST");
$file_name=md5(rand(1000,9999).time()). '.png';
$filename= 'uploads/' . $file_name ;
$ret = file_put_contents($filename, $result, true);
$task=new Task();
$res=$task->fileUpload($file_name);
return $res;
}
//把请求发送到微信服务器换取二维码
public function httpRequest($url,$data='',$method='GET'){
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL,$url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_USERAGENT,$_SERVER['HTTP_USER_AGENT']);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_AUTOREFERER, 1);
if($method=='POST')
{
curl_setopt($curl, CURLOPT_POST, 1);
if ($data !='')
{
curl_setopt($curl, CURLOPT_POSTFIELDS,$data);
}
}
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
curl_close($curl);
return $result;
}
public function test(){
... ... @@ -58,15 +83,8 @@ class Index extends Api
if ($accessToken) {
$path = 'pages/index/index'; // 小程序内的页面路径
$qrCodeData = $this->createMiniProgramQRCode($accessToken, $path);
if ($qrCodeData) {
header('Content-Type: image/png');
echo $qrCodeData;
} else {
echo "Failed to generate QR code.";
}
} else {
echo "Failed to get access token.";
print_r($qrCodeData);return;
return $qrCodeData;
}
}
}
... ...
... ... @@ -82,7 +82,7 @@ class Task extends Api
$data['filepath'] = $domain . $ret['key'];
$data['fileurl'] = $ret['key'];
$path = '../public' . $data['fileurl'];
is_file($path) && unlink($path);//删除服务器上文件
is_file($filepath) && unlink($filepath);//删除服务器上文件
return $data;
} else {
//上传失败获取错误信息
... ...
... ... @@ -30,6 +30,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
{field: 'phone', title: __('Phone'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
{field: 'car_fleet', title: __('Car_fleet'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
{field: 'scheduling_type', title: __('Scheduling_type'), searchList: {"1":__('Scheduling_type 1'),"2":__('Scheduling_type 2')}, formatter: Table.api.formatter.normal},
{field: 'offline_payment', title: __('Offline_payment'), searchList: {"0":__('Offline_payment 0'),"1":__('Offline_payment 1')}, formatter: Table.api.formatter.normal},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
]
]
... ...
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function ($, undefined, Backend, Table, Form, Template) {
var Controller = {
index: function () {
... ... @@ -28,21 +28,74 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
[
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'order_no', title: __('Order_no'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
{field: 'price', title: __('Price'), operate:'BETWEEN'},
{field: 'is_pay', title: __('Is_pay'), searchList: {"1":__('Is_pay 1'),"2":__('Is_pay 2'),"3":__('Is_pay 3'),"4":__('Is_pay 4')}, formatter: Table.api.formatter.normal},
{field: 'type', title: __('Type'), searchList: {"1":__('Type 1'),"2":__('Type 2'),"3":__('Type 3')}, formatter: Table.api.formatter.normal},
{field: 'pay_type', title: __('Pay_type'), searchList: {"Wxpay":__('Pay_type wxpay'),"offlinepay":__('Pay_type offlinepay')}, formatter: Table.api.formatter.normal},
{field: 'pay_time', title: __('Pay_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
{field: 'refund_time', title: __('Refund_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
{field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
{
field: 'order_no',
title: __('Order_no'),
operate: 'LIKE',
table: table,
class: 'autocontent',
formatter: Table.api.formatter.content
},
{field: 'price', title: __('Price'), operate: 'BETWEEN'},
{
field: 'is_pay',
title: __('Is_pay'),
searchList: {
"1": __('Is_pay 1'),
"2": __('Is_pay 2'),
"3": __('Is_pay 3'),
"4": __('Is_pay 4')
},
formatter: Table.api.formatter.normal
},
{
field: 'type',
title: __('Type'),
searchList: {"1": __('Type 1'), "2": __('Type 2'), "3": __('Type 3')},
formatter: Table.api.formatter.normal
},
{
field: 'pay_type',
title: __('Pay_type'),
searchList: {"Wxpay": __('Pay_type wxpay'), "offlinepay": __('Pay_type offlinepay')},
formatter: Table.api.formatter.normal
},
{
field: 'pay_time',
title: __('Pay_time'),
operate: 'RANGE',
addclass: 'datetimerange',
autocomplete: false,
formatter: Table.api.formatter.datetime
},
{
field: 'refund_time',
title: __('Refund_time'),
operate: 'RANGE',
addclass: 'datetimerange',
autocomplete: false,
formatter: Table.api.formatter.datetime
},
{
field: 'create_time',
title: __('Create_time'),
operate: 'RANGE',
addclass: 'datetimerange',
autocomplete: false,
formatter: Table.api.formatter.datetime
},
{field: 'user.username', title: __('User.username'), operate: 'LIKE'},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
buttons:[
{
field: 'operate',
title: __('Operate'),
table: table,
events: Table.api.events.operate,
formatter: Table.api.formatter.operate,
buttons: [
{
name: 'ajax',
title: "退款",
text:"退款",
title: "退款",
text: "退款",
classname: 'btn btn-xs btn-warning btn-magic btn-ajax',
icon: 'fa fa-paper-plane',
confirm: function (row) {
... ... @@ -50,22 +103,17 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
},
url: 'order/refund?id={id}',
success: function (data, ret) {
// Layer.alert(ret.msg + ",返回数据:" + JSON.stringify(data));
// 如果需要阻止成功提示,则必须使用return false;
console.log(data, ret);
Layer.alert(ret.msg);
$("#myTabContent .btn-refresh").trigger("click");
return false;
},
error: function (data, ret) {
console.log(data, ret);
Layer.alert(ret.msg);
$("#myTabContent .btn-refresh").trigger("click");
return false;
}
},
{
name: 'selectiondriver',
text:"选择司机",
title: "选择司机",
extend:'data-area=["94%","94%"]',
classname: 'btn btn-xs btn-primary btn-dialog',
icon: 'fa fa-recipt',
url: 'order/selectiondriver?id={id}',
}
]
}]
]
... ...