Merge branch 'develop' of gitee.com:zi-chunsheng-e-commerce/mall-server into develop
commit
b9d68c2db6
|
|
@ -18,7 +18,7 @@ class HomeController extends Controller
|
|||
{
|
||||
return $content
|
||||
->header('首页')
|
||||
->description('开发中...')
|
||||
->description('首页')
|
||||
->body(function (Row $row) {
|
||||
$row->column(6, function (Column $column) {
|
||||
$column->row(Dashboard::title());
|
||||
|
|
|
|||
|
|
@ -119,6 +119,7 @@ class UserController extends AdminController
|
|||
$grid->filter(function (Grid\Filter $filter) {
|
||||
$filter->panel();
|
||||
$filter->like('phone')->width(3);
|
||||
$filter->like('userInfo.nickname')->width(3);
|
||||
$filter->equal('userInfo.agent_level')->select(UserInfo::$agentLevelTexts)->width(3);
|
||||
$filter->between('created_at')->dateTime()->width(7);
|
||||
// $filter->between('userInfo.growth_value')->width(6);
|
||||
|
|
@ -147,6 +148,8 @@ class UserController extends AdminController
|
|||
$show->field('id');
|
||||
$show->field('phone');
|
||||
$show->field('user_info.nickname');
|
||||
$show->field('user_info.gender')->using(UserInfo::$genderTexts)->label();
|
||||
$show->field('user_info.birthday');
|
||||
$show->field('user_info.agent_level')->as(function ($value) {
|
||||
return $this->userInfo?->agent_level_name??'未知';
|
||||
})->label();
|
||||
|
|
@ -162,6 +165,9 @@ class UserController extends AdminController
|
|||
$value = bcdiv($value, 100, 2);
|
||||
return $value;
|
||||
})->prepend('¥');
|
||||
$show->field('user_info.quota_v2');
|
||||
$show->field('user_info.quota_v1');
|
||||
$show->field('user_info.points');
|
||||
|
||||
$show->field('last_login_ip');
|
||||
$show->field('last_login_at');
|
||||
|
|
|
|||
|
|
@ -39,9 +39,9 @@ class Unipush extends Form
|
|||
|
||||
$this->switch('is_use', '是否启用')->value($appSettings['is_use'] ?? 0);
|
||||
$this->text('mall_app_id', '商城APP_ID')->value($appSettings['mall_app_id'] ?? '');
|
||||
$this->text('mall_app_key', '商城APP_KEY')->value($appSettings['mall_app_id'] ?? '');
|
||||
$this->text('mall_app_secret', '商城APP_SECRET')->value($appSettings['mall_app_id'] ?? '');
|
||||
$this->text('mall_master_secret', '商城APP_MASTER_SECRET')->value($appSettings['mall_app_id'] ?? '');
|
||||
$this->text('mall_app_key', '商城APP_KEY')->value($appSettings['mall_app_key'] ?? '');
|
||||
$this->text('mall_app_secret', '商城APP_SECRET')->value($appSettings['mall_app_secret'] ?? '');
|
||||
$this->text('mall_master_secret', '商城APP_MASTER_SECRET')->value($appSettings['mall_master_secret'] ?? '');
|
||||
|
||||
$this->divider();
|
||||
$this->switch('merchant_is_use', '是否启用')->value($appSettings['merchant_is_use'] ?? 0);
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ class StatisticsTotal extends RadialBar
|
|||
parent::init();
|
||||
|
||||
$this->title('统计预览');
|
||||
$this->height(320);
|
||||
$this->height(300);
|
||||
$this->contentWidth(12, 0);
|
||||
}
|
||||
|
||||
|
|
@ -57,29 +57,29 @@ class StatisticsTotal extends RadialBar
|
|||
<div class="d-flex row text-center align-items-center justify-content-center" >
|
||||
|
||||
<div class="col-sm-4">
|
||||
<h1 class="font-lg-2 mt-2 mb-0">{$content['total_distribution']}</h1>
|
||||
<h1 class="font-lg-1 mt-2 mb-0">{$content['total_distribution']}</h1>
|
||||
当前预收益
|
||||
</div>
|
||||
<div class="col-sm-4">
|
||||
<h1 class="font-lg-2 mt-2 mb-0">{$content['total_wallet']}</h1>
|
||||
<h1 class="font-lg-1 mt-2 mb-0">{$content['total_wallet']}</h1>
|
||||
总可提
|
||||
</div>
|
||||
<div class="col-sm-4">
|
||||
<h1 class="font-lg-2 mt-2 mb-0">{$content['total_balance']}</h1>
|
||||
<h1 class="font-lg-1 mt-2 mb-0">{$content['total_balance']}</h1>
|
||||
总余额
|
||||
</div>
|
||||
</div>
|
||||
<div class="d-flex row text-center align-items-center justify-content-center" >
|
||||
<div class="col-sm-4">
|
||||
<h1 class="font-lg-2 mt-2 mb-0">{$content['total_points']}</h1>
|
||||
<h1 class="font-lg-1 mt-2 mb-0">{$content['total_points']}</h1>
|
||||
总积分
|
||||
</div>
|
||||
<div class="col-sm-4">
|
||||
<h1 class="font-lg-2 mt-2 mb-0">{$content['total_quota_v2']}</h1>
|
||||
<h1 class="font-lg-1 mt-2 mb-0">{$content['total_quota_v2']}</h1>
|
||||
新配额
|
||||
</div>
|
||||
<div class="col-sm-4">
|
||||
<h1 class="font-lg-2 mt-2 mb-0">{$content['total_quota_v1']}</h1>
|
||||
<h1 class="font-lg-1 mt-2 mb-0">{$content['total_quota_v1']}</h1>
|
||||
老配额
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -3,7 +3,10 @@
|
|||
namespace App\Console\Commands\Distribution;
|
||||
|
||||
use App\Exceptions\BizException;
|
||||
use App\Models\DistributionPreIncome;
|
||||
use App\Models\DistributionPreIncomeJob;
|
||||
use App\Models\MerchantMessage;
|
||||
use App\Models\Order;
|
||||
use App\Services\DistributionPreIncomeJobService;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
|
@ -53,6 +56,30 @@ class PreIncomeJobCommand extends Command
|
|||
]);
|
||||
}
|
||||
}
|
||||
|
||||
//发送商家端预收益进帐消息
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
switch (get_class($job->jobable)) {
|
||||
case Order::class://如果是订单类型,则发送预收益消息
|
||||
$order = $job->jobable;
|
||||
$incomesLogs = DistributionPreIncome::where('order_id', $order->id)->get();
|
||||
foreach ($incomesLogs as $log) {
|
||||
MerchantMessage::createDistributionMessage($log->user_id, [
|
||||
'title'=>'恭喜收入'.$log->total_revenue.'元',
|
||||
'content'=>'您有新的预收益产生,共'.$log->total_revenue.'元。',
|
||||
]);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
DB::commit();
|
||||
} catch (Throwable $e) {
|
||||
DB::rollBack();
|
||||
|
||||
report($e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,9 +2,11 @@
|
|||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\MerchantMessage;
|
||||
use App\Models\Message;
|
||||
use App\Models\PushMessageTask;
|
||||
use App\Services\Push\MallUnipushService;
|
||||
use App\Services\Push\MerchantUnipushService;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Throwable;
|
||||
|
|
@ -34,6 +36,7 @@ class PushMessageCommand extends Command
|
|||
{
|
||||
PushMessageTask::with('message')->where('is_pushed', 0)->chunkById(100, function ($tasks) {
|
||||
$mallPushService = new MallUnipushService();
|
||||
$merchantPushService = new MerchantUnipushService();
|
||||
foreach ($tasks as $task) {
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
|
@ -43,6 +46,10 @@ class PushMessageCommand extends Command
|
|||
if ((bool) app_settings('unipush.is_use')) {//如果开启了推送
|
||||
$status = $mallPushService->push($task->sn, $task->message) ? 1 : 2;
|
||||
}
|
||||
} elseif ($task->message instanceof MerchantMessage) {
|
||||
if ((bool) app_settings('unipush.merchant_is_use')) {//如果开启了推送
|
||||
$status = $merchantPushService->push($task->sn, $task->message) ? 1 : 2;
|
||||
}
|
||||
}
|
||||
|
||||
$task->update([
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace App\Endpoint\Api\Http\Controllers\Merchant;
|
||||
|
||||
use App\Endpoint\Api\Http\Controllers\Controller;
|
||||
use App\Endpoint\Api\Http\Resources\Merchant\MessageResource;
|
||||
use App\Helpers\Paginator as PaginatorHelper;
|
||||
use App\Models\MerchantMessage as Message;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class MessageController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$list = Message::userMessages($request->user())
|
||||
->orderBy('created_at', 'desc')
|
||||
->simplePaginate(PaginatorHelper::resolvePerPage('per_page', 20, 50));
|
||||
return MessageResource::collection($list);
|
||||
}
|
||||
}
|
||||
|
|
@ -6,6 +6,7 @@ use App\Exceptions\BizException;
|
|||
use App\Models\UserCid;
|
||||
use App\Services\Push\MallUnipushService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Throwable;
|
||||
|
||||
|
|
@ -25,16 +26,19 @@ class PushController extends Controller
|
|||
|
||||
$input = $request->validate([
|
||||
'cid' => ['bail', 'required', 'string', 'max:64'],
|
||||
'type' => ['bail', 'string', 'max:1'],
|
||||
]);
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
$filed = Arr::get($input, 'type', 'u').'_cid';
|
||||
//查询目前有没有人已绑定这个cid, 有就解绑
|
||||
UserCid::where('u_cid', $input['cid'])->where('user_id', '<>', $request->user()->id)->update([
|
||||
'u_cid' => null,
|
||||
UserCid::where($filed, $input['cid'])->where('user_id', '<>', $request->user()->id)->update([
|
||||
$filed => null,
|
||||
]);
|
||||
$request->user()->cid()->updateOrCreate([
|
||||
'u_cid'=>$input['cid'],
|
||||
'user_id' => $request->user()->id,
|
||||
], [
|
||||
$filed=>$input['cid'],
|
||||
]);
|
||||
DB::commit();
|
||||
} catch (Throwable $th) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace App\Endpoint\Api\Http\Resources\Merchant;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class MessageResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'title' => $this->title,
|
||||
'content' => $this->content,
|
||||
'type' => $this->type,
|
||||
'ext' => $this->ext,
|
||||
'jump_type' => $this->jump_type,
|
||||
'jump_link' => (string) $this->jump_link,
|
||||
'created_at'=> $this->created_at->toDateTimeString(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -200,5 +200,7 @@ Route::group([
|
|||
Route::get('agent-upgrade-conditions', [Merchant\AgentController::class, 'upgradeConditions']);
|
||||
// 代理统计
|
||||
Route::get('agent-statistics', [Merchant\AgentController::class, 'statistics']);
|
||||
// 消息列表
|
||||
Route::get('messages', [Merchant\MessageController::class, 'index']);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -0,0 +1,86 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Casts\JsonArray;
|
||||
use Dcat\Admin\Traits\HasDateTimeFormatter;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class MerchantMessage extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use HasDateTimeFormatter;
|
||||
|
||||
public const JUMP_NO = 0;
|
||||
public const JUMP_MIINE = 1;
|
||||
public const JUMP_WAP = 2;
|
||||
|
||||
|
||||
protected $casts = [
|
||||
'ext'=>JsonArray::class,
|
||||
'is_push'=>'bool',
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'title', 'content', 'type', 'ext', 'jump_type', 'jump_link', 'user_id', 'is_push',
|
||||
];
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 此消息的推送任务
|
||||
*/
|
||||
public function pushTasks()
|
||||
{
|
||||
return $this->morphMany(PushMessageTask::class, 'message');
|
||||
}
|
||||
|
||||
public static function userMessages(User $user)
|
||||
{
|
||||
return self::where('created_at', '>=', $user->created_at->subDays(7))->where(function ($q) use ($user) {
|
||||
$q->where('user_id', $user->id)->orWhere('user_id', 0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送预收益消息
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function createDistributionMessage($userId, $params)
|
||||
{
|
||||
$message = self::create([
|
||||
'type' => 1,
|
||||
'title' => $params['title'],
|
||||
'user_id' => $userId,
|
||||
'content' => $params['content'],
|
||||
'jump_type'=> self::JUMP_NO,
|
||||
'is_push' => 1,
|
||||
]);
|
||||
|
||||
if ($message && $message->needPush()) {
|
||||
$message->pushMessage();
|
||||
}
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
public function needPush()
|
||||
{
|
||||
return $this->is_push;
|
||||
}
|
||||
|
||||
public function pushMessage()
|
||||
{
|
||||
//填入推送内容
|
||||
PushMessageTask::create([
|
||||
'sn' => serial_number(),
|
||||
'message_id' => $this->id,
|
||||
'message_type' => $this::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -102,6 +102,12 @@ class UserInfo extends Model
|
|||
self::AGENT_LEVEL_DIRECTOR => 'director',
|
||||
];
|
||||
|
||||
public static $genderTexts = [
|
||||
self::GENDER_UNKNOWN => '未知',
|
||||
self::GENDER_MALE => '男性',
|
||||
self::GENDER_FEMALE => '女性',
|
||||
];
|
||||
|
||||
/**
|
||||
* 代理等级文本
|
||||
*
|
||||
|
|
|
|||
|
|
@ -2,9 +2,72 @@
|
|||
|
||||
namespace App\Services\Push;
|
||||
|
||||
class MerchantUnipushService
|
||||
use App\Models\MerchantMessage;
|
||||
|
||||
class MerchantUnipushService extends UniPushService
|
||||
{
|
||||
protected $appId;
|
||||
|
||||
protected $appKey;
|
||||
|
||||
protected $appSecret;
|
||||
|
||||
protected $masterSecret;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->appId = app_settings('unipush.merchant_app_id', '');
|
||||
$this->appKey = app_settings('unipush.merchant_app_key', '');
|
||||
$this->appSecret = app_settings('unipush.merchant_app_secret', '');
|
||||
$this->masterSecret = app_settings('unipush.merchant_master_secret', '');
|
||||
parent::__construct($this->appId, $this->appKey, $this->appSecret, $this->masterSecret);
|
||||
}
|
||||
|
||||
public function push(string $sn, MerchantMessage $message)
|
||||
{
|
||||
$res = false;
|
||||
if ($message->user_id > 0) {
|
||||
$res = $this->pushMessage($sn, $message);
|
||||
} else {
|
||||
$res = $this->pushAllMessage($sn, $message);
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 推送公告消息
|
||||
*
|
||||
* @param [type] $message
|
||||
* @return void
|
||||
*/
|
||||
public function pushAllMessage(string $sn, MerchantMessage $message)
|
||||
{
|
||||
return $this->pushAll($sn, $message->title, $message->content, [
|
||||
'jump_type' => $message->jump_type == 0 ? 1 : $message->jump_type,
|
||||
'jump_link' => $message->type == 1 || empty($message->jump_link) ? '/pages/news/index' : $message->jump_link,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 推送单条消息
|
||||
*
|
||||
* @param Message $message
|
||||
* @return void
|
||||
*/
|
||||
public function pushMessage(string $sn, MerchantMessage $message)
|
||||
{
|
||||
//如果不是指定消息,直接退出;
|
||||
if (is_null($message->user)) {
|
||||
return false;
|
||||
}
|
||||
//如果拿不到m_cid直接退出
|
||||
if (!$message->user->cid->m_cid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->pushCid($sn, $message->user->cid->m_cid, $message->title, $message->content, [
|
||||
'jump_type' => $message->jump_type == 0 ? 1 : $message->jump_type,
|
||||
'jump_link' => $message->type == 1 || empty($message->jump_link) ? '/pages/news/index' : $message->jump_link,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateMerchantMessagesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('merchant_messages', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('title')->comment('消息标题');
|
||||
$table->text('content')->comment('消息内容');
|
||||
$table->unsignedTinyInteger('type')->default(0)->comment('消息类型:0公告,1预收益提醒');
|
||||
$table->unsignedBigInteger('user_id')->default(0)->comment('指定用户');
|
||||
$table->json('ext')->nullable()->comment('消息扩展内容');
|
||||
$table->tinyInteger('jump_type')->default(0)->comment('跳转类型:0不跳转,1跳转应用内页,2H5链接');
|
||||
$table->string('jump_link')->nullable()->comment('跳转地址');
|
||||
$table->unsignedTinyInteger('is_push')->default(0)->comment('是否推送');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('merchant_messages');
|
||||
}
|
||||
}
|
||||
|
|
@ -89,11 +89,11 @@ class AppSettingSeeder extends Seeder
|
|||
'mall_app_key' => 'JX33P0wP8bAQprI953hpN6',
|
||||
'mall_app_secret' => 'a3u3B6lXjq6fPTBlOGiOc9',
|
||||
'mall_master_secret' => 'MAxmqomwo597xJeDuMCvx1',
|
||||
'merchant_is_use' => false,
|
||||
'merchant_app_id' => '',
|
||||
'merchant_app_key' => '',
|
||||
'merchant_app_secret' => '',
|
||||
'merchant_master_secret' => '',
|
||||
'merchant_is_use' => true,
|
||||
'merchant_app_id' => '5bvlKxO8RK7lCTc9DINcx5',
|
||||
'merchant_app_key' => 'qrPLowCchvArbpMKoPlMV1',
|
||||
'merchant_app_secret' => '5k36Jo49EAAGBDvR0cFqG3',
|
||||
'merchant_master_secret' => 'HCB87uFoF18iWsKHf7VY57',
|
||||
],
|
||||
'remarks' => '个推配置',
|
||||
],
|
||||
|
|
|
|||
|
|
@ -39,6 +39,11 @@ return [
|
|||
'agent_level'=>'管理级别',
|
||||
'growth_value'=>'消费值',
|
||||
'group_sales_value'=>'业绩',
|
||||
'points'=>'积分',
|
||||
'quota_v2'=>'新配额',
|
||||
'quota_v1'=>'老配额',
|
||||
'gender'=>'性别',
|
||||
'birthday'=>'生日',
|
||||
'inviter_info'=>[
|
||||
'user'=>[
|
||||
'phone' =>'推荐人手机',
|
||||
|
|
|
|||
Loading…
Reference in New Issue