初始化项目
This commit is contained in:
@@ -0,0 +1,401 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\api\model\Goods as GoodsModel;
|
||||
use app\api\model\Order as OrderModel;
|
||||
use app\api\model\OrderGoods as OrderGoodsModel;
|
||||
use app\api\model\Code as CodeModel;
|
||||
use app\api\model\Merchant as MerchantModel;
|
||||
use app\api\model\Setting as SettingModel;
|
||||
use app\common\service\SybOil;
|
||||
use app\common\service\IdingjuOil;
|
||||
use app\store\model\Company as CompanyModel;
|
||||
use app\store\model\Express as ExpressModel;
|
||||
use app\common\enum\order\PayType as OrderPayTypeEnum;
|
||||
use app\store\model\order\QrCode as QrCodeModel;
|
||||
use cores\exception\BaseException;
|
||||
use think\facade\Request;
|
||||
use think\response\Json;
|
||||
use think\cache\driver\Redis;
|
||||
use GatewayWorker\Lib\Gateway;
|
||||
|
||||
/**
|
||||
* 我的订单控制器
|
||||
* Class Order
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class Order extends Controller
|
||||
{
|
||||
private $redis = null;
|
||||
/**
|
||||
* 获取当前用户待处理的订单数量
|
||||
* @return Json
|
||||
* @throws BaseException
|
||||
*/
|
||||
public function todoCounts(): Json
|
||||
{
|
||||
$model = new OrderModel;
|
||||
$counts = $model->getTodoCounts();
|
||||
return $this->renderSuccess(compact('counts'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 我的订单列表
|
||||
* @param string $dataType 订单类型 (all全部 payment待付款 received待发货 deliver待收货 comment待评价)
|
||||
* @return Json
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws BaseException
|
||||
*/
|
||||
public function list(string $dataType): Json
|
||||
{
|
||||
$model = new OrderModel;
|
||||
$list = $model->getList($dataType);
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单详情信息
|
||||
* @param int $orderId 订单ID
|
||||
* @return Json
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws BaseException
|
||||
*/
|
||||
public function detail(int $orderId): Json
|
||||
{
|
||||
// 订单详情
|
||||
$model = OrderModel::getUserOrderDetail($orderId);
|
||||
return $this->renderSuccess([
|
||||
'order' => $model, // 订单详情
|
||||
'setting' => [
|
||||
// 积分名称
|
||||
'points_name' => SettingModel::getPointsName(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取物流信息
|
||||
* @param int $orderId 订单ID
|
||||
* @return Json
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws BaseException
|
||||
*/
|
||||
public function express(int $orderId): Json
|
||||
{
|
||||
// 订单信息
|
||||
$order = OrderModel::getDetail($orderId);
|
||||
if (!$order['express_no']) {
|
||||
return $this->renderError('没有物流信息');
|
||||
}
|
||||
// 获取物流信息
|
||||
$model = ExpressModel::detail($order['express_id']);
|
||||
$express = $model->dynamic($model['express_name'], $model['kuaidi100_code'], $order['express_no']);
|
||||
if ($express === false) {
|
||||
return $this->renderError($model->getError());
|
||||
}
|
||||
return $this->renderSuccess(compact('express'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消订单
|
||||
* @param int $orderId
|
||||
* @return Json
|
||||
* @throws BaseException
|
||||
*/
|
||||
public function cancel(int $orderId): Json
|
||||
{
|
||||
$model = OrderModel::getDetail($orderId);
|
||||
if ($model->cancel()) {
|
||||
return $this->renderSuccess('订单取消成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '订单取消失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 确认收货
|
||||
* @param int $orderId
|
||||
* @return Json
|
||||
* @throws BaseException
|
||||
*/
|
||||
public function receipt(int $orderId): Json
|
||||
{
|
||||
$model = OrderModel::getDetail($orderId);
|
||||
if ($model->receipt()) {
|
||||
return $this->renderSuccess('确认收货成功');
|
||||
}
|
||||
return $this->renderError($model->getError());
|
||||
}
|
||||
|
||||
/**
|
||||
* 立即支付
|
||||
* @param int $orderId 订单ID
|
||||
* @param int $payType 支付方式
|
||||
* @return Json
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws BaseException
|
||||
*/
|
||||
public function pay(int $orderId, int $payType = OrderPayTypeEnum::WECHAT): Json
|
||||
{
|
||||
// 获取订单详情
|
||||
$model = OrderModel::getUserOrderDetail($orderId);
|
||||
// 订单支付事件
|
||||
if (!$model->onPay($payType)) {
|
||||
return $this->renderError($model->getError() ?: '订单支付失败');
|
||||
}
|
||||
// 构建微信支付请求
|
||||
$payment = $model->onOrderPayment($model, $payType);
|
||||
// 支付状态提醒
|
||||
return $this->renderSuccess([
|
||||
'order_id' => $model['order_id'], // 订单id
|
||||
'pay_type' => $payType, // 支付方式
|
||||
'payment' => $payment // 微信支付参数
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交订单
|
||||
* @return Json
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws BaseException
|
||||
*/
|
||||
public function submitOrder(): Json
|
||||
{
|
||||
$data = $this->postData();
|
||||
$verify = $this->verifySign($data);
|
||||
if($verify['code'] > 0){
|
||||
return $this->renderError($verify['msg']);
|
||||
}else {
|
||||
$data['merchant_id'] = $verify['merchant_id'];
|
||||
$data['callback'] = $verify['callback'];
|
||||
$model = new OrderModel;
|
||||
$data['order_no'] = $this->insertNo($data['order_no']);
|
||||
$data['ip'] = Request::instance()->ip();
|
||||
if(!$bool = $model->putInto($data)) {
|
||||
$this->saveLog("提交订单,订单:" . $data['order_no'] . ",数据:".json_encode($data,320).",结果:" . $bool);
|
||||
return $this->renderError('插入订单失败');
|
||||
}
|
||||
$domain = Request::instance()->domain();
|
||||
|
||||
$qrcode = $domain.'/pay?passageway='.$data['passageway'].'&orderId='.$model->order_id;
|
||||
$res = [
|
||||
'qrcode'=>$qrcode,
|
||||
];
|
||||
return $this->renderSuccess($res, '提交成功');
|
||||
}
|
||||
}
|
||||
|
||||
public function generateRandomString($length = 10, $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') {
|
||||
$charactersLength = strlen($characters);
|
||||
$randomString = '';
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$randomString .= $characters[rand(0, $charactersLength - 1)];
|
||||
}
|
||||
return $randomString;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询订单
|
||||
* @return Json
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws BaseException
|
||||
*/
|
||||
public function searchOrder(): Json
|
||||
{
|
||||
$data = $this->postData();
|
||||
$verify = $this->verifySign($data);
|
||||
if($verify['code'] > 0){
|
||||
return $this->renderError($verify['msg']);
|
||||
}else {
|
||||
$order = OrderModel::detail(['order_no'=>$data['order_no']]);
|
||||
if(empty($order['order_id'])){
|
||||
return $this->renderError('订单错误');
|
||||
}
|
||||
$res = [
|
||||
'order_no'=>$order['order_no'],
|
||||
'pay_status'=>$order['pay_status'],
|
||||
'pay_time'=>$order['pay_time']
|
||||
];
|
||||
return $this->renderSuccess($res, '提交成功');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交订单
|
||||
* @return
|
||||
* @throws \app\common\exception\BaseException
|
||||
* @throws \think\exception\DbException
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function testOrder()
|
||||
{
|
||||
$data = $this->request->get();
|
||||
$money = isset($data['money'])?$data['money']:299;
|
||||
$passageway = isset($data['passageway'])?$data['passageway']:'WX';
|
||||
$shop_id = isset($data['shop_id'])?$data['shop_id']:'';
|
||||
$merchant = MerchantModel::detail($shop_id);
|
||||
if(empty($merchant['merchant_id'])){
|
||||
return $this->renderError('商户不存在');
|
||||
}
|
||||
$domain = Request::instance()->domain();
|
||||
$ip = Request::instance()->ip();
|
||||
|
||||
$data = [
|
||||
'appid'=>$merchant['appId'],
|
||||
'name'=>'系统订单',
|
||||
'money'=>$money,
|
||||
'order_no'=> 'XT'.$this->generateRandomString(10),
|
||||
'timestamp'=>time(),
|
||||
'passageway'=>$passageway,
|
||||
'notifyUrl'=>$domain.'/index.php?s=/api/notify/received',
|
||||
'ip'=>$ip,
|
||||
];
|
||||
|
||||
$data['merchant_id'] = $merchant['merchant_id'];
|
||||
$data['shop_id'] = 10033;
|
||||
|
||||
$model = new OrderModel;
|
||||
$data['order_no'] = $this->insertNo($data['order_no']);
|
||||
|
||||
if(!$bool = $model->putInto($data)) {
|
||||
$this->saveLog("提交订单,订单:" . $data['order_no'] . ",数据:".json_encode($data,320).",结果:" . $bool);
|
||||
return $this->renderError('插入系统订单失败');
|
||||
}
|
||||
$domain = Request::instance()->domain();
|
||||
$qrcode = $domain.'/pay?passageway='.$data['passageway'].'&orderId='.$model->order_id;
|
||||
/*$qrcode = $domain.'/index.php?s=/store/passport/detail&orderId='.$model->order_id;
|
||||
return $qrcode;*/
|
||||
header('location: '.$qrcode.'');
|
||||
exit();
|
||||
}
|
||||
|
||||
/** 测试发送数据
|
||||
*/
|
||||
public function send()
|
||||
{
|
||||
//Gateway::sendToClient("7f00000107d00000001b", json_encode(['type' => 'test_send']));
|
||||
var_export(Gateway::getAllUidList());
|
||||
//Gateway::sendToClient('c0a8008a07d000000002',json_encode(['type' => 'test_send']));
|
||||
if(Gateway::isUidOnline(10001))
|
||||
{
|
||||
// 在线就转发消息给对应的uid
|
||||
Gateway::sendToUid(10001, json_encode(['type' => 'test_send']));
|
||||
}
|
||||
var_export(Gateway::isUidOnline(10001));
|
||||
//Gateway::sendToUid('10001', json_encode(['type' => 'test_send']));
|
||||
//return $this->renderSuccess([], '提交成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取支付二维码
|
||||
* @return Json
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function qrCode(): Json
|
||||
{
|
||||
$IdingjuOil = new IdingjuOil();
|
||||
$postData = $this->request->param();
|
||||
$postData['order_goods_id'] = $this->request->param('orderGoodsId');
|
||||
|
||||
$orderGoods = OrderGoodsModel::detail($postData['order_goods_id']);
|
||||
if($orderGoods['use_status'] != 0){
|
||||
return $this->renderError('油券已核销');
|
||||
}else {
|
||||
$company = CompanyModel::detail($orderGoods['company_id']);
|
||||
// 对接平台接口
|
||||
$res = $IdingjuOil->payQrCodeRequest(['order_no'=>$orderGoods['oilCardNo']], $company);
|
||||
if($res['code'] == '1' && isset($res['data']['useQrCodeUrl'])){
|
||||
// 插入支付码记录
|
||||
$QrCodeModel = new QrCodeModel();
|
||||
$QrCodeModel->add([
|
||||
'oilCardNo'=>$orderGoods['oilCardNo'],
|
||||
'qrCode'=>$res['data']['useQrCodeUrl'],
|
||||
'amount'=>$orderGoods['goods_price'],
|
||||
'order_id'=>$orderGoods['order_id'],
|
||||
'user_id'=>$orderGoods['user_id'],
|
||||
'store_id'=>$orderGoods['store_id'],
|
||||
]);
|
||||
$res = [
|
||||
'qrCode'=>$res['data']['useQrCodeUrl']
|
||||
];
|
||||
return $this->renderSuccess($res, '提交成功');
|
||||
}else{
|
||||
return $this->renderError('平台创建用户失败【'.($res['errMessage'] ?? $res['message']).'】');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取支付二维码图片
|
||||
* @return Json
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function qrCodeImg(): Json
|
||||
{
|
||||
// $res = [
|
||||
// 'base64'=> 'data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8gQLCBDsIAMwQIyBAvIECwgQ7CADMECMgQLyBAsIEOwgAzBAjIEC8gQLCBDsICM17X9HYB/44YFZAgWkCFYQIZgARmCBWQIFpAhWECGYAEZggVkCBaQIVhAhmABGYIFZAgWkCFYQIZgARmCBWQIFpAhWECGYAEZggVkCBaQIVhAhmABGYIFZAgWkCFYQIZgARmCBWQIFpAhWEDGP+OBJg1/1F6rAAAAAElFTkSuQmCC'
|
||||
//// 'base64'=> ''
|
||||
// ];
|
||||
// return $this->renderSuccess($res, '提交成功');
|
||||
$IdingjuOil = new IdingjuOil();
|
||||
$postData = $this->request->param();
|
||||
$postData['order_goods_id'] = $this->request->param('orderGoodsId');
|
||||
|
||||
$orderGoods = OrderGoodsModel::detail($postData['order_goods_id']);
|
||||
if($orderGoods['use_status'] != 0){
|
||||
return $this->renderError('油券已核销');
|
||||
}else {
|
||||
/*$res = [
|
||||
'base64'=> $this->getBase64($orderGoods['qrCode'])
|
||||
];
|
||||
return $this->renderSuccess($res, '提交成功');*/
|
||||
$company = CompanyModel::detail($orderGoods['company_id']);
|
||||
// 对接平台接口
|
||||
$res = $IdingjuOil->payQrCodeRequest(['order_no'=>$orderGoods['oilCardNo']], $company);
|
||||
//$res = $IdingjuOil->payQrCodeRequest(['oilCardNo'=>$orderGoods['oilCardNo'],'shareNo'=>$orderGoods['shareNo'],'mobile'=>$orderGoods['mobile'],'oilCardType'=>$orderGoods['oilCardType']], $company);
|
||||
//if($res['code'] == '00' && isset($res['data']['qrCode'])){
|
||||
if($res['code'] == '1' && isset($res['data']['useQrCodeUrl'])){
|
||||
// 插入支付码记录
|
||||
$QrCodeModel = new QrCodeModel();
|
||||
$QrCodeModel->add([
|
||||
'oilCardNo'=>$orderGoods['oilCardNo'],
|
||||
'qrCode'=>$res['data']['useQrCodeUrl'],
|
||||
'amount'=>$orderGoods['goods_price'],
|
||||
'order_id'=>$orderGoods['order_id'],
|
||||
'user_id'=>$orderGoods['user_id'],
|
||||
'store_id'=>$orderGoods['store_id'],
|
||||
]);
|
||||
$res = [
|
||||
'base64'=> $this->getBase64($res['data']['useQrCodeUrl'])
|
||||
];
|
||||
return $this->renderSuccess($res, '提交成功');
|
||||
}else{
|
||||
return $this->renderError('平台创建用户失败【'.($res['errMessage'] ?? $res['message']).'】');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getBase64($url){
|
||||
$publicPath = app()->getRootPath() . 'public/';
|
||||
$escaped_url = escapeshellarg($url);
|
||||
$command = "node {$publicPath}myscript.js {$escaped_url} 2>&1";
|
||||
$content = shell_exec($command);
|
||||
return (string)$content;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user