初始化项目
This commit is contained in:
58
app/Http/Controllers/Controller.php
Normal file
58
app/Http/Controllers/Controller.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
|
||||
|
||||
/**
|
||||
* 验证
|
||||
*
|
||||
* @param array $rules
|
||||
* @param array $messages
|
||||
* @param array $customAttributes
|
||||
* @param bool|array $only
|
||||
* @return array
|
||||
*/
|
||||
public function toValidator(array $rules, array $messages = [], array $customAttributes = [], bool|array $only = []): array
|
||||
{
|
||||
$input = request()->all();
|
||||
$validator = Validator::make($input, $rules, $messages, $customAttributes)->stopOnFirstFailure();
|
||||
if ($validator->fails()) {
|
||||
$messages = $validator->messages()->getMessages();
|
||||
json_error(Arr::first($messages)[0]);
|
||||
}
|
||||
if ($only === true) {
|
||||
return Arr::only($input, array_keys($rules));
|
||||
}
|
||||
if (count($only)) {
|
||||
return Arr::only($input, $only);
|
||||
}
|
||||
return $input;
|
||||
}
|
||||
|
||||
/**
|
||||
* ID验证
|
||||
*
|
||||
* @param string $idField
|
||||
* @return int
|
||||
*/
|
||||
public function getId(string $idField = 'id'): int
|
||||
{
|
||||
$id = request()->input($idField);
|
||||
$validator = Validator::make(['id' => $id], ['id' => 'required|integer|min:1'], ['id' => '数据传参错误'])->stopOnFirstFailure();
|
||||
if ($validator->fails()) {
|
||||
$messages = $validator->messages()->getMessages();
|
||||
json_error(Arr::first($messages)[0]);
|
||||
}
|
||||
return $id;
|
||||
}
|
||||
}
|
||||
90
app/Http/Controllers/InternalService/ApiController.php
Normal file
90
app/Http/Controllers/InternalService/ApiController.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\InternalService;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Jobs\ProductOrderCancelJob;
|
||||
use App\Models\YiiModels\Platform;
|
||||
use App\Models\YiiModels\ProductOrder;
|
||||
use Exception;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
/**
|
||||
* 内部通讯API
|
||||
*/
|
||||
class ApiController extends Controller
|
||||
{
|
||||
private ?Platform $platform = null;
|
||||
|
||||
/**
|
||||
* 内部服务
|
||||
*
|
||||
* @param Request $request
|
||||
* @return void
|
||||
*/
|
||||
public function handle(Request $request)
|
||||
{
|
||||
$token = $request->input('token');
|
||||
log_i($token, 'token', 'internal_services');
|
||||
if ($token != config('services.internal_service.api_token')) {
|
||||
json_error('通讯错误');
|
||||
}
|
||||
|
||||
$type = $request->input('type');
|
||||
if (method_exists($this, $type)) {
|
||||
log_i(' 开始执行:' . $type, 'token', 'internal_services');
|
||||
log_i(json_encode(request()->all()), $type, 'internal_services');
|
||||
$this->{$type}();
|
||||
} else {
|
||||
log_i('内部服务数据错误 ' . $type, 'token', 'internal_services');
|
||||
json_error('内部服务数据错误 ' . $type);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建订单自动取消任务
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function createOrderAutoCancel()
|
||||
{
|
||||
$product_order_id = request()->input('product_order_id');
|
||||
$minutes = request()->input('minutes');
|
||||
|
||||
ProductOrderCancelJob::dispatch($product_order_id)->delay(now()->addMinutes($minutes));
|
||||
|
||||
json_success('自动取消队列启动成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建退款请求
|
||||
*
|
||||
* @return void
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function createOrderRefundHandle()
|
||||
{
|
||||
$product_order_id = request()->input('product_order_id');
|
||||
$refund_no = request()->input('refund_no');
|
||||
|
||||
$productOrder = ProductOrder::where('id', $product_order_id)->first();
|
||||
if (!$productOrder) {
|
||||
json_error('订单信息不存在');
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
$refundResult = [];
|
||||
try {
|
||||
$refundResult = $productOrder->toRefund($productOrder->total_pay_price, $refund_no);
|
||||
|
||||
DB::commit();
|
||||
} catch (Exception $exception) {
|
||||
DB::rollBack();
|
||||
log_s('申请错误:' . var_export(request()->all(), true) . $exception->getMessage() . $exception->getTraceAsString(), 'order', 'error');
|
||||
json_error('申请错误,请重试');
|
||||
}
|
||||
|
||||
response()->json($refundResult)->throwResponse();
|
||||
}
|
||||
}
|
||||
151
app/Http/Controllers/Member/CartController.php
Normal file
151
app/Http/Controllers/Member/CartController.php
Normal file
@@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Member;
|
||||
|
||||
use App\Models\Cart;
|
||||
use App\Models\YiiModels\Drug;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||
|
||||
/**
|
||||
* 购物车
|
||||
*/
|
||||
class CartController extends MemberBaseController
|
||||
{
|
||||
/**
|
||||
* 添加购物车
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function cartAdd()
|
||||
{
|
||||
$input = $this->toValidator([
|
||||
'drug_id' => 'required|integer',
|
||||
'change_qty' => 'nullable|integer',
|
||||
'true_qty' => 'nullable|integer',
|
||||
], [], [
|
||||
'drug_id' => '商品',
|
||||
'change_qty' => '数量',
|
||||
'true_qty' => '数量',
|
||||
], true);
|
||||
|
||||
if (!$input['change_qty'] && !$input['true_qty']) {
|
||||
json_error('商品数量不正确');
|
||||
}
|
||||
|
||||
/* @var Drug $drug */
|
||||
$drug = Drug::with([
|
||||
'drugStoreRelation' => function (Relation $relation) {
|
||||
$relation->select(['drug_id', 'total_sales_volume', 'status'])
|
||||
->where('store_id', $this->getStoreId());
|
||||
},
|
||||
'drugstoreDrug' => function (Relation $relation) {
|
||||
$relation->select(['drug_id', 'price', 'stock'])
|
||||
->where('drugstore_id', $this->getDrugstoreId());
|
||||
},
|
||||
])
|
||||
->select([
|
||||
'id', 'status',
|
||||
])
|
||||
->whereHasIn('drugStoreRelation', function (Builder $builder) {
|
||||
$builder->where('store_id', $this->getStoreId());
|
||||
})
|
||||
->where('id', $input['drug_id'])
|
||||
->first();
|
||||
if (!$drug && !$drug->drugStoreRelation && !$drug->drugstoreDrug) {
|
||||
json_error('商品不存在');
|
||||
}
|
||||
if ($drug->status != Drug::STATUS_ON || $drug->drugStoreRelation->status != Drug::STATUS_ON) {
|
||||
json_error('商品已下架');
|
||||
}
|
||||
$cart = $this->user()->carts()->firstOrCreate([
|
||||
'drug_id' => $input['drug_id'],
|
||||
'store_id' => $this->getStoreId(),
|
||||
]);
|
||||
if ($input['change_qty']) {
|
||||
if ($input['change_qty'] > $drug->drugstoreDrug->stock) {
|
||||
json_error("库存不足,最多可加入{$drug->drugstoreDrug->stock}个");
|
||||
}
|
||||
$cart->increment('qty', $input['change_qty'], ['join_at' => now()]);
|
||||
if ($cart->qty <= 0) {
|
||||
$cart->delete();
|
||||
json_success('购物车商品已删除');
|
||||
}
|
||||
} else {
|
||||
if (($input['true_qty'] - $cart['qty']) > $drug->drugstoreDrug->stock) {
|
||||
json_error("库存不足,最多可加入{$drug->drugstoreDrug->stock}个");
|
||||
}
|
||||
$cart->update([
|
||||
'qty' => $input['true_qty'],
|
||||
'join_at' => now(),
|
||||
]);
|
||||
if ($cart->qty <= 0) {
|
||||
$cart->delete();
|
||||
json_success('购物车商品已删除');
|
||||
}
|
||||
}
|
||||
json_success('已加入购物车');
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空购物车
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function clearAll()
|
||||
{
|
||||
Cart::where('store_id', $this->getStoreId())
|
||||
->where('user_id', $this->userId())
|
||||
->delete();
|
||||
json_success('已清空购物车');
|
||||
}
|
||||
|
||||
/**
|
||||
* 购物车列表
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function cartLists()
|
||||
{
|
||||
$carts = Cart::with([
|
||||
'drug' => function (Relation $relation) {
|
||||
$relation->with([
|
||||
'drugStoreRelation' => function (Relation $relation) {
|
||||
$relation->select(['drug_id', 'total_sales_volume', 'status'])
|
||||
->where('store_id', $this->getStoreId());
|
||||
},
|
||||
'drugstoreDrug' => function (Relation $relation) {
|
||||
$relation->select(['drug_id', 'price', 'stock'])
|
||||
->where('drugstore_id', $this->getDrugstoreId());
|
||||
},
|
||||
])
|
||||
->select(['id', 'drug_name', 'source', 'type', 'is_otc', 'small_info', 'usage', 'specification', 'image', 'status']);
|
||||
}
|
||||
])
|
||||
->whereHasIn('drug')
|
||||
->where('store_id', $this->getStoreId())
|
||||
->where('user_id', $this->userId())
|
||||
->orderByDesc('join_at')
|
||||
->get();
|
||||
|
||||
$valid = $invalid = [];
|
||||
/* @var Cart $cart */
|
||||
foreach ($carts as $cart) {
|
||||
if (!$cart->drug || !$cart->drug->drugStoreRelation || !$cart->drug->drugstoreDrug) {
|
||||
$invalid[] = $cart;
|
||||
continue;
|
||||
}
|
||||
if ($cart->drug->status != Drug::STATUS_ON || $cart->drug->drugStoreRelation->status != Drug::STATUS_ON) {
|
||||
$invalid[] = $cart;
|
||||
continue;
|
||||
}
|
||||
$valid[] = $cart;
|
||||
}
|
||||
|
||||
json_success([
|
||||
'store_name' => $this->getStore()->name,
|
||||
'valid' => $valid,
|
||||
'invalid' => $invalid,
|
||||
]);
|
||||
}
|
||||
}
|
||||
110
app/Http/Controllers/Member/DrugController.php
Normal file
110
app/Http/Controllers/Member/DrugController.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Member;
|
||||
|
||||
use App\Models\DrugCategory;
|
||||
use App\Models\DrugStoreRelation;
|
||||
use App\Models\YiiModels\Drug;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||
|
||||
/**
|
||||
* 药品
|
||||
*/
|
||||
class DrugController extends MemberBaseController
|
||||
{
|
||||
/**
|
||||
* 药品分类
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function drugCategory()
|
||||
{
|
||||
json_success(DrugCategory::getCategory());
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品列表(带库存)
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function drugLists()
|
||||
{
|
||||
$category_first = request('category_first');
|
||||
$category_second = request('category_second');
|
||||
$keyword = request('keyword');
|
||||
// $this->toValidator([
|
||||
// 'category_first' => 'required|integer',
|
||||
// 'category_second' => 'required|integer',
|
||||
// ], [], [
|
||||
// 'category_first' => '一级分类',
|
||||
// 'category_second' => '二级分类',
|
||||
// ]);
|
||||
|
||||
$drugs = Drug::with([
|
||||
'drugstoreDrug' => function (Relation $relation) {
|
||||
$relation->select(['drug_id', 'price', 'stock'])
|
||||
->where('drugstore_id', $this->getDrugstoreId());
|
||||
},
|
||||
])
|
||||
->select([
|
||||
'id', 'drug_name', 'source', 'type', 'is_otc', 'category_first', 'category_second',
|
||||
'usage', 'small_info', 'specification', 'image',
|
||||
])
|
||||
->whereHasIn('drugStoreRelation', function (Builder $builder) {
|
||||
$builder->where('status', DrugStoreRelation::STATUS_ON)
|
||||
->where('store_id', $this->getStoreId());
|
||||
})
|
||||
->when($keyword, function (Builder $builder) use ($keyword) {
|
||||
$builder->where('drug_name', 'like', "%$keyword%");
|
||||
})
|
||||
->where('status', Drug::STATUS_ON)
|
||||
->where('type_id', [Drug::TYPE_CHINESE_DRUG, Drug::TYPE_PELLET_PATENT])
|
||||
->where('is_otc', Drug::IS_OTC_FALSE)
|
||||
->where('category_first', $category_first)
|
||||
->where('category_second', $category_second)
|
||||
->get();
|
||||
|
||||
json_success($drugs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品详情
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function drugDetail()
|
||||
{
|
||||
$id = $this->getId();
|
||||
|
||||
/* @var Drug $drug */
|
||||
$drug = Drug::with([
|
||||
'drugStoreRelation' => function (Relation $relation) {
|
||||
$relation->select(['store_id', 'drug_id', 'total_sales_volume', 'status'])
|
||||
->with(['store:id,name'])
|
||||
->where('store_id', $this->getStoreId());
|
||||
},
|
||||
'drugstoreDrug' => function (Relation $relation) {
|
||||
$relation->select(['drugstore_id', 'drug_id', 'price', 'stock'])
|
||||
->where('drugstore_id', $this->getDrugstoreId());
|
||||
},
|
||||
])
|
||||
->select([
|
||||
'id', 'drug_name', 'source', 'type', 'is_otc', 'category_first', 'category_second',
|
||||
'usage', 'specification', 'image', 'small_info', 'info', 'content', 'status',
|
||||
])
|
||||
->whereHasIn('drugStoreRelation', function (Builder $builder) {
|
||||
$builder->where('store_id', $this->getStoreId());
|
||||
})
|
||||
->where('id', $id)
|
||||
->first();
|
||||
if (!$drug || !$drug->drugStoreRelation || !$drug->drugstoreDrug) {
|
||||
json_error('商品不存在');
|
||||
}
|
||||
if ($drug->status != Drug::STATUS_ON || $drug->drugStoreRelation->status != Drug::STATUS_ON) {
|
||||
json_error('商品已下架');
|
||||
}
|
||||
|
||||
json_success($drug);
|
||||
}
|
||||
}
|
||||
20
app/Http/Controllers/Member/ExpressController.php
Normal file
20
app/Http/Controllers/Member/ExpressController.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Member;
|
||||
|
||||
use App\Models\ExpressFee;
|
||||
|
||||
/**
|
||||
* 物流
|
||||
*/
|
||||
class ExpressController extends MemberBaseController
|
||||
{
|
||||
public function feeInfo()
|
||||
{
|
||||
$expressFeeInfo = ExpressFee::getDefaultExpressFee();
|
||||
if (!$expressFeeInfo) {
|
||||
json_error('运费信息错误');
|
||||
}
|
||||
json_success($expressFeeInfo);
|
||||
}
|
||||
}
|
||||
92
app/Http/Controllers/Member/MemberBaseController.php
Normal file
92
app/Http/Controllers/Member/MemberBaseController.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Member;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\YiiModels\Drugstore;
|
||||
use App\Models\YiiModels\Store;
|
||||
use App\Models\YiiModels\User;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
/**
|
||||
* 用户端基类
|
||||
*/
|
||||
class MemberBaseController extends Controller
|
||||
{
|
||||
protected ?Store $store = null;
|
||||
protected ?Drugstore $drugstore = null;
|
||||
protected ?int $store_id = 0;
|
||||
protected ?int $drugstore_id = 0;
|
||||
|
||||
/**
|
||||
* @comment 用户
|
||||
* @return \App\Models\YiiModels\User|\Illuminate\Contracts\Auth\Authenticatable|null
|
||||
*/
|
||||
public function user()
|
||||
{
|
||||
return Auth::guard(User::GUARD)->user();
|
||||
}
|
||||
|
||||
/**
|
||||
* @comment 用户id
|
||||
* @return int
|
||||
*/
|
||||
public function userId(): int
|
||||
{
|
||||
return $this->user()->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前仓库ID
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getDrugstoreId(): int
|
||||
{
|
||||
if (!$this->drugstore_id) {
|
||||
$this->drugstore_id = $this->getStore()->drugstore_id;
|
||||
}
|
||||
return $this->drugstore_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前仓库
|
||||
*
|
||||
* @return Drugstore
|
||||
*/
|
||||
public function getDrugstore(): Drugstore
|
||||
{
|
||||
$this->drugstore = Drugstore::where('id', $this->getDrugstoreId())->first();
|
||||
if (!$this->drugstore) {
|
||||
json_error('药房信息获取失败');
|
||||
}
|
||||
return $this->drugstore;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取门店ID
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getStoreId(): int
|
||||
{
|
||||
if (!$this->store_id) {
|
||||
$this->store_id = (int)request()->input('store_id');
|
||||
}
|
||||
return $this->store_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取门店
|
||||
*
|
||||
* @return Store
|
||||
*/
|
||||
public function getStore(): Store
|
||||
{
|
||||
$this->store = Store::where('id', $this->getStoreId())->first();
|
||||
if (!$this->store) {
|
||||
json_error('门店信息获取失败');
|
||||
}
|
||||
return $this->store;
|
||||
}
|
||||
}
|
||||
23
app/Http/Controllers/Member/TestController.php
Normal file
23
app/Http/Controllers/Member/TestController.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Member;
|
||||
|
||||
use App\Models\YiiModels\User;
|
||||
|
||||
/**
|
||||
* @deprecated fixme delete 测试接口
|
||||
*/
|
||||
class TestController extends MemberBaseController
|
||||
{
|
||||
public function testLogin()
|
||||
{
|
||||
if (app()->isLocal() && file_exists(base_path('./../dev.ini'))) {
|
||||
/* @var User $user */
|
||||
$user = User::where('mobile', request('mobile'))->first();
|
||||
if ($user) {
|
||||
json_success('登陆成功', ['token' => $user->token, 'user_id' => $user->id]);
|
||||
}
|
||||
}
|
||||
json_error('错误示例');
|
||||
}
|
||||
}
|
||||
100
app/Http/Controllers/Pay/NotifyController.php
Normal file
100
app/Http/Controllers/Pay/NotifyController.php
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Pay;
|
||||
|
||||
use App\Models\Pay\Bill;
|
||||
use App\Models\Pay\RefundBill;
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Yansongda\LaravelPay\Facades\Pay;
|
||||
|
||||
class NotifyController
|
||||
{
|
||||
/**
|
||||
* 微信异步通知入口
|
||||
*
|
||||
* @param $config_name
|
||||
* @return \Psr\Http\Message\ResponseInterface|void
|
||||
* @throws \Throwable
|
||||
* @throws \Yansongda\Pay\Exception\ContainerException
|
||||
* @throws \Yansongda\Pay\Exception\InvalidParamsException
|
||||
*/
|
||||
public function payWechat($config_name)
|
||||
{
|
||||
$result = Pay::wechat()->callback(null, ['_config' => $config_name]);
|
||||
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
switch ($result['event_type']) {
|
||||
case 'TRANSACTION.SUCCESS': // 支付成功
|
||||
$payData = $result['resource']['ciphertext'];
|
||||
if ($payData['trade_state'] == 'SUCCESS') {
|
||||
$data = [
|
||||
'mchid' => $payData['mchid'],
|
||||
'appid' => $payData['appid'],
|
||||
'pay_no' => $payData['out_trade_no'],
|
||||
'pay_service_no' => $payData['transaction_id'],
|
||||
'pay_amount' => $payData['amount']['total'] / 100,
|
||||
'pay_at' => Carbon::parseFromLocale($payData['success_time'])->toDateTimeString(),
|
||||
];
|
||||
$handleResult = Bill::handleNotify($data, Bill::PAY_WAY_WECHAT);
|
||||
if ($handleResult === true) {
|
||||
DB::commit();
|
||||
return Pay::wechat()->success();
|
||||
} else {
|
||||
log_i('支付成功处理失败-' . $handleResult . "\n" . var_export($result, true), 'pay-handle-error', 'wechat');
|
||||
}
|
||||
} else {
|
||||
log_i('支付通知失败' . "\n" . var_export($result, true), 'pay-notify-error', 'wechat');
|
||||
}
|
||||
break;
|
||||
|
||||
case 'REFUND.SUCCESS': // 退款成功
|
||||
$payData = $result['resource']['ciphertext'];
|
||||
if ($payData['refund_status'] == 'SUCCESS') {
|
||||
$data = [
|
||||
'refund_no' => $payData['out_refund_no'],
|
||||
'refund_service_no' => $payData['refund_id'],
|
||||
'pay_no' => $payData['out_trade_no'],
|
||||
'pay_service_no' => $payData['transaction_id'],
|
||||
'refund_amount' => $payData['amount']['refund'] / 100,
|
||||
'refund_at' => Carbon::parseFromLocale($payData['success_time'])->toDateTimeString(),
|
||||
];
|
||||
$handleResult = RefundBill::handleNotify($data);
|
||||
if ($handleResult === true) {
|
||||
DB::commit();
|
||||
return Pay::wechat()->success();
|
||||
} else {
|
||||
log_i('退款成功处理失败-' . $handleResult . "\n" . var_export($result, true), 'refund-handle-error', 'wechat');
|
||||
}
|
||||
} else {
|
||||
log_i('退款通知失败' . "\n" . var_export($result, true), 'refund-notify-error', 'wechat');
|
||||
}
|
||||
break;
|
||||
|
||||
default: // 其他情况
|
||||
log_i('其他通知失败' . "\n" . var_export($result, true), 'other-notify-error', 'wechat');
|
||||
break;
|
||||
}
|
||||
} catch (Exception $exception) {
|
||||
log_i('通知处理失败-程序出错' . $exception->getMessage() . "\n" . $exception->getTraceAsString() . "\n" . var_export($result, true), 'all-handle-exception', 'wechat');
|
||||
}
|
||||
|
||||
DB::rollBack();
|
||||
return new Response(
|
||||
500,
|
||||
['Content-Type' => 'application/json'],
|
||||
json_encode(['code' => 'FAIL', 'message' => '失败']),
|
||||
);
|
||||
}
|
||||
|
||||
public function messageWechatMini($config_name)
|
||||
{
|
||||
$server = app('easywechat.official_account.' . $config_name)->getServer();
|
||||
$message = $server->getDecryptedMessage();
|
||||
log_s($message);
|
||||
return $server->serve();
|
||||
}
|
||||
}
|
||||
51
app/Http/Controllers/Platform/PlatformApi.php
Normal file
51
app/Http/Controllers/Platform/PlatformApi.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Platform;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\YiiModels\Platform;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/**
|
||||
* 平台通讯API
|
||||
*/
|
||||
class PlatformApi extends Controller
|
||||
{
|
||||
private ?Platform $platform = null;
|
||||
|
||||
/**
|
||||
* 同步
|
||||
*
|
||||
* @param Request $request
|
||||
* @return void
|
||||
*/
|
||||
public function handle(Request $request)
|
||||
{
|
||||
$platform_token = $request->input('platform_token');
|
||||
$this->platform = Platform::where('token', $platform_token)->first();
|
||||
log_i($platform_token, 'token', 'sync');
|
||||
if (!$this->platform) {
|
||||
log_i($platform_token . ' 未找到', 'token', 'sync');
|
||||
json_error('通讯错误');
|
||||
}
|
||||
if ($this->platform->status != Platform::STATUS_PASS) {
|
||||
log_i($platform_token . ' 无权限', 'token', 'sync');
|
||||
json_error('无权限');
|
||||
}
|
||||
|
||||
$type = $request->input('type');
|
||||
if (method_exists($this, $type)) {
|
||||
log_i($platform_token . ' 开始执行:' . $type, 'token', 'sync');
|
||||
log_i(json_encode(request()->all()), $type, 'sync');
|
||||
$this->{$type}();
|
||||
} else {
|
||||
log_i($platform_token . '同步数据错误 ' . $type, 'token', 'sync');
|
||||
json_error('同步数据错误 ' . $type);
|
||||
}
|
||||
}
|
||||
|
||||
private function prescriptionSync()
|
||||
{
|
||||
$data = request('data');
|
||||
}
|
||||
}
|
||||
53
app/Http/Controllers/Service/ServiceBaseController.php
Normal file
53
app/Http/Controllers/Service/ServiceBaseController.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Service;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\YiiModels\ServiceUser;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
/**
|
||||
* 用户端基类
|
||||
*/
|
||||
class ServiceBaseController extends Controller
|
||||
{
|
||||
/**
|
||||
* @comment 用户
|
||||
* @return \App\Models\YiiModels\ServiceUser|\Illuminate\Contracts\Auth\Authenticatable|null
|
||||
*/
|
||||
public function user()
|
||||
{
|
||||
return Auth::guard(ServiceUser::GUARD)->user();
|
||||
}
|
||||
|
||||
/**
|
||||
* @comment 用户id
|
||||
* @return int
|
||||
*/
|
||||
public function userId()
|
||||
{
|
||||
return $this->user()->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @comment 当前仓库id
|
||||
* @return int
|
||||
*/
|
||||
public function currentDrugstoreId()
|
||||
{
|
||||
$serviceUser = $this->user();
|
||||
$serviceUser->loadMissing(['storeDoctorOnline.store']);
|
||||
return $serviceUser->storeDoctorOnline->store->drugstore_id ?? 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @comment 当前门店id
|
||||
* @return int
|
||||
*/
|
||||
public function currentStoreId()
|
||||
{
|
||||
$serviceUser = $this->user();
|
||||
$serviceUser->loadMissing(['storeDoctorOnline']);
|
||||
return $serviceUser->storeDoctorOnline->store_id ?? 0;
|
||||
}
|
||||
}
|
||||
26
app/Http/Controllers/Service/TestController.php
Normal file
26
app/Http/Controllers/Service/TestController.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Service;
|
||||
|
||||
use App\Models\YiiModels\ServiceUserToken;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
/**
|
||||
* @deprecated fixme delete 测试接口
|
||||
*/
|
||||
class TestController extends ServiceBaseController
|
||||
{
|
||||
public function testLogin()
|
||||
{
|
||||
if (app()->isLocal() && file_exists(base_path('./../dev.ini'))) {
|
||||
/* @var ServiceUserToken $token */
|
||||
$token = ServiceUserToken::whereHasIn('serviceUser', fn(Builder $builder) => $builder->where('mobile', request('mobile')))
|
||||
->where('is_disable', ServiceUserToken::IS_DISABLE_IS_ABLE)
|
||||
->first();
|
||||
if ($token) {
|
||||
json_success('登陆成功', ['token' => $token->token, 'user_id' => $token->su_id]);
|
||||
}
|
||||
}
|
||||
json_error('错误示例');
|
||||
}
|
||||
}
|
||||
76
app/Http/Controllers/Tests/TestController.php
Normal file
76
app/Http/Controllers/Tests/TestController.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Tests;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ExpressNo;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
class TestController extends Controller
|
||||
{
|
||||
|
||||
public const ALLOW_LISTS = [
|
||||
'express',
|
||||
'express_update',
|
||||
];
|
||||
|
||||
/**
|
||||
* TestController constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
if (!app()->isLocal() && in_array(__FUNCTION__, self::ALLOW_LISTS)) {
|
||||
abort(404);
|
||||
}
|
||||
}
|
||||
|
||||
public function t($fun = '')
|
||||
{
|
||||
if (0 == strlen($fun)) {
|
||||
$fun = 'a';
|
||||
}
|
||||
$result = $this->$fun();
|
||||
if (!empty($result)) {
|
||||
return $result;
|
||||
}
|
||||
dd('结束运行方法:' . $fun);
|
||||
}
|
||||
|
||||
public function express()
|
||||
{
|
||||
$expressNo = ExpressNo::where('express_no', request('no'))->first();
|
||||
if (!$expressNo) {
|
||||
dda('单号对应数据库不存在');
|
||||
}
|
||||
$response = app('express')->track($expressNo->express_no, $expressNo->express_company_code, ['phone' => $expressNo->mobile]);
|
||||
$result = json_decode($response, true);
|
||||
dda($expressNo, $result);
|
||||
}
|
||||
|
||||
public function express_update()
|
||||
{
|
||||
$id = request('id');
|
||||
$parameters = [
|
||||
'type' => 'update',
|
||||
];
|
||||
if ($id) {
|
||||
$parameters['--id'] = $id;
|
||||
$expressNo = ExpressNo::where('id', $id)->first();
|
||||
if (!$expressNo) {
|
||||
json_error("{$id}数据不存在");
|
||||
}
|
||||
}
|
||||
Artisan::call('express', $parameters);
|
||||
json_success("{$id}更新完成");
|
||||
}
|
||||
|
||||
// public function a()
|
||||
// {
|
||||
// //
|
||||
// }
|
||||
|
||||
public function a()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user