fisrt
This commit is contained in:
12
app/Api/Controllers/Controller.php
Normal file
12
app/Api/Controllers/Controller.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Api\Controllers;
|
||||
|
||||
use Jason\Api\Traits\ApiResponse;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
|
||||
use ApiResponse;
|
||||
}
|
||||
159
app/Api/Controllers/Data/IndexController.php
Normal file
159
app/Api/Controllers/Data/IndexController.php
Normal file
@@ -0,0 +1,159 @@
|
||||
<?php
|
||||
|
||||
namespace App\Api\Controllers\Data;
|
||||
|
||||
use App\Api\Controllers\Controller;
|
||||
use App\Api\Resources\Order\OrderDataCollection;
|
||||
use App\Api\Resources\User\UserDataCollection;
|
||||
use App\Api\Resources\User\UserDataResource;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Coupon\Http\Resources\User\UserBaseResource;
|
||||
use Modules\Mall\Models\Order;
|
||||
use Modules\User\Models\User;
|
||||
|
||||
class IndexController extends Controller
|
||||
{
|
||||
|
||||
public function index()
|
||||
{
|
||||
$all = 1000;
|
||||
$sold = Order::query()
|
||||
->whereIn('state', [
|
||||
Order::STATUS_PAID,
|
||||
Order::STATUS_DELIVERED,
|
||||
Order::STATUS_SIGNED,
|
||||
Order::STATUS_COMPLETED,
|
||||
])
|
||||
->count();
|
||||
$donate = (new User())->getALlJzCount();
|
||||
|
||||
$orderQuery = Order::query()->where('type', Order::TYPE_NORMAL);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
$amount = (clone $orderQuery)->whereIn('state', [
|
||||
Order::STATUS_PAID,
|
||||
Order::STATUS_DELIVERED,
|
||||
Order::STATUS_SIGNED,
|
||||
Order::STATUS_COMPLETED,
|
||||
])->sum('amount');
|
||||
|
||||
$data = [
|
||||
'activities' => [
|
||||
'all' => $all,
|
||||
'donate' => $donate,
|
||||
'residue' => bcsub($all, $donate),
|
||||
],
|
||||
'orders' => [
|
||||
'users' => User::query()->whereHas('orders', function ($q) {
|
||||
$q->whereIn('state', [
|
||||
Order::STATUS_PAID,
|
||||
Order::STATUS_DELIVERED,
|
||||
Order::STATUS_SIGNED,
|
||||
Order::STATUS_COMPLETED,
|
||||
])->where('type', Order::TYPE_NORMAL);
|
||||
})->count(),
|
||||
|
||||
'all' => (clone $orderQuery)
|
||||
->whereIn('state', [
|
||||
Order::STATUS_PAID,
|
||||
Order::STATUS_DELIVERED,
|
||||
Order::STATUS_SIGNED,
|
||||
Order::STATUS_COMPLETED,
|
||||
])->count(),
|
||||
'paid' => (clone $orderQuery)->where('state', Order::STATUS_PAID)->count(),
|
||||
'delivered' => (clone $orderQuery)->where('state', Order::STATUS_DELIVERED)->count(),
|
||||
'signed' => (clone $orderQuery)->where('state', Order::STATUS_SIGNED)->count(),
|
||||
'completed' => (clone $orderQuery)->where('state', Order::STATUS_COMPLETED)->count(),
|
||||
'amount' => floatval($amount),
|
||||
],
|
||||
'users' => [
|
||||
'all' => User::count(),
|
||||
'yk' => User::query()
|
||||
->whereHas('identities', function ($q) {
|
||||
$q->where('id', 2);
|
||||
})->count(),
|
||||
'jk' => User::query()
|
||||
->whereHas('identities', function ($q) {
|
||||
$q->where('id', 3);
|
||||
})->count(),
|
||||
'nk' => User::query()
|
||||
->whereHas('identities', function ($q) {
|
||||
$q->where('id', 4);
|
||||
})->count(),
|
||||
]
|
||||
];
|
||||
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: description
|
||||
*
|
||||
* @Author: 玄尘
|
||||
* @Date: 2023/1/5 13:50
|
||||
*/
|
||||
public function orders(Request $request)
|
||||
{
|
||||
$status = $request->status ?? 'all';
|
||||
|
||||
$orders = Order::query()
|
||||
->where('type', Order::TYPE_NORMAL)
|
||||
->when($status !== 'all', function ($q) use ($status) {
|
||||
$q->where('state', $status);
|
||||
}, function ($q) {
|
||||
$q->whereIn('state', [
|
||||
Order::STATUS_PAID,
|
||||
Order::STATUS_DELIVERED,
|
||||
Order::STATUS_SIGNED,
|
||||
Order::STATUS_COMPLETED,
|
||||
]);
|
||||
})
|
||||
->paginate();
|
||||
|
||||
return $this->success(new OrderDataCollection($orders));
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: description
|
||||
*
|
||||
* @Author: 玄尘
|
||||
* @Date: 2023/1/5 14:13
|
||||
*/
|
||||
public function users()
|
||||
{
|
||||
$users = User::query()
|
||||
->withCount([
|
||||
'orders' => function ($q) {
|
||||
$q->whereIn('state', [
|
||||
Order::STATUS_PAID,
|
||||
Order::STATUS_DELIVERED,
|
||||
Order::STATUS_SIGNED,
|
||||
Order::STATUS_COMPLETED,
|
||||
]);
|
||||
}
|
||||
])
|
||||
->withSum([
|
||||
'orders' => function ($q) {
|
||||
$q->whereIn('state', [
|
||||
Order::STATUS_PAID,
|
||||
Order::STATUS_DELIVERED,
|
||||
Order::STATUS_SIGNED,
|
||||
Order::STATUS_COMPLETED,
|
||||
]);
|
||||
}
|
||||
], 'amount')
|
||||
->whereHas('orders', function ($q) {
|
||||
$q->whereIn('state', [
|
||||
Order::STATUS_PAID,
|
||||
Order::STATUS_DELIVERED,
|
||||
Order::STATUS_SIGNED,
|
||||
Order::STATUS_COMPLETED,
|
||||
])->where('type', Order::TYPE_NORMAL);
|
||||
})
|
||||
->paginate();
|
||||
return $this->success(new UserDataCollection($users));
|
||||
|
||||
}
|
||||
}
|
||||
12
app/Api/Controllers/IndexController.php
Normal file
12
app/Api/Controllers/IndexController.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Api\Controllers;
|
||||
|
||||
class IndexController extends Controller
|
||||
{
|
||||
|
||||
public function index()
|
||||
{
|
||||
return $this->success('Json Api is ready');
|
||||
}
|
||||
}
|
||||
63
app/Api/Controllers/Wechat/IndexController.php
Normal file
63
app/Api/Controllers/Wechat/IndexController.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Api\Controllers\Wechat;
|
||||
|
||||
use App\Api\WechatHandlers\EventMessageHandler;
|
||||
use App\Api\WechatHandlers\FileMessageHandler;
|
||||
use App\Api\WechatHandlers\ImageMessageHandler;
|
||||
use App\Api\WechatHandlers\LinkMessageHandler;
|
||||
use App\Api\WechatHandlers\LocationMessageHandler;
|
||||
use App\Api\WechatHandlers\ShortVideoMessageHandler;
|
||||
use App\Api\WechatHandlers\TextMessageHandler;
|
||||
use App\Api\WechatHandlers\TransferMessageHandler;
|
||||
use App\Api\WechatHandlers\VideoMessageHandler;
|
||||
use App\Api\WechatHandlers\VoiceMessageHandler;
|
||||
use EasyWeChat\Kernel\Messages\Message;
|
||||
use Overtrue\LaravelWeChat\Controllers\Controller;
|
||||
|
||||
class IndexController extends Controller
|
||||
{
|
||||
|
||||
public function serve()
|
||||
{
|
||||
$app = app('wechat.official_account');
|
||||
|
||||
$app->server->push(function ($message) {
|
||||
switch ($message['MsgType']) {
|
||||
case 'event':
|
||||
return '收到事件消息';
|
||||
break;
|
||||
case 'text':
|
||||
return '收到文字消息';
|
||||
break;
|
||||
case 'image':
|
||||
return '收到图片消息';
|
||||
break;
|
||||
case 'voice':
|
||||
return '收到语音消息';
|
||||
break;
|
||||
case 'video':
|
||||
return '收到视频消息';
|
||||
break;
|
||||
case 'location':
|
||||
return '收到坐标消息';
|
||||
break;
|
||||
case 'link':
|
||||
return '收到链接消息';
|
||||
break;
|
||||
case 'file':
|
||||
return '收到文件消息';
|
||||
// ... 其它消息
|
||||
default:
|
||||
return '收到其它消息';
|
||||
break;
|
||||
}
|
||||
|
||||
// ...
|
||||
});
|
||||
|
||||
$app->server->push(EventMessageHandler::class, Message::EVENT);
|
||||
|
||||
return $app->server->serve();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user