diff --git a/app/Admin/Controllers/HomeController.php b/app/Admin/Controllers/HomeController.php index 985c04ed..5945434e 100644 --- a/app/Admin/Controllers/HomeController.php +++ b/app/Admin/Controllers/HomeController.php @@ -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()); diff --git a/app/Admin/Controllers/UserController.php b/app/Admin/Controllers/UserController.php index f875afcd..8cd6a62b 100644 --- a/app/Admin/Controllers/UserController.php +++ b/app/Admin/Controllers/UserController.php @@ -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'); diff --git a/app/Admin/Forms/Settings/Unipush.php b/app/Admin/Forms/Settings/Unipush.php index 95312e78..444f8e3c 100644 --- a/app/Admin/Forms/Settings/Unipush.php +++ b/app/Admin/Forms/Settings/Unipush.php @@ -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); diff --git a/app/Admin/Metrics/StatisticsTotal.php b/app/Admin/Metrics/StatisticsTotal.php index ee577b20..16a095a4 100644 --- a/app/Admin/Metrics/StatisticsTotal.php +++ b/app/Admin/Metrics/StatisticsTotal.php @@ -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
-

{$content['total_distribution']}

+

{$content['total_distribution']}

当前预收益
-

{$content['total_wallet']}

+

{$content['total_wallet']}

总可提
-

{$content['total_balance']}

+

{$content['total_balance']}

总余额
-

{$content['total_points']}

+

{$content['total_points']}

总积分
-

{$content['total_quota_v2']}

+

{$content['total_quota_v2']}

新配额
-

{$content['total_quota_v1']}

+

{$content['total_quota_v1']}

老配额
diff --git a/app/Console/Commands/Distribution/PreIncomeJobCommand.php b/app/Console/Commands/Distribution/PreIncomeJobCommand.php index 0911b4a0..e8b6b4aa 100644 --- a/app/Console/Commands/Distribution/PreIncomeJobCommand.php +++ b/app/Console/Commands/Distribution/PreIncomeJobCommand.php @@ -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); + } } }); } diff --git a/app/Console/Commands/PushMessageCommand.php b/app/Console/Commands/PushMessageCommand.php index f02fa0ae..f03ab6df 100644 --- a/app/Console/Commands/PushMessageCommand.php +++ b/app/Console/Commands/PushMessageCommand.php @@ -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([ diff --git a/app/Endpoint/Api/Http/Controllers/Merchant/MessageController.php b/app/Endpoint/Api/Http/Controllers/Merchant/MessageController.php new file mode 100644 index 00000000..8e313473 --- /dev/null +++ b/app/Endpoint/Api/Http/Controllers/Merchant/MessageController.php @@ -0,0 +1,20 @@ +user()) + ->orderBy('created_at', 'desc') + ->simplePaginate(PaginatorHelper::resolvePerPage('per_page', 20, 50)); + return MessageResource::collection($list); + } +} diff --git a/app/Endpoint/Api/Http/Controllers/PushController.php b/app/Endpoint/Api/Http/Controllers/PushController.php index 4c1e5d0d..1803d3f0 100644 --- a/app/Endpoint/Api/Http/Controllers/PushController.php +++ b/app/Endpoint/Api/Http/Controllers/PushController.php @@ -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) { diff --git a/app/Endpoint/Api/Http/Resources/Merchant/MessageResource.php b/app/Endpoint/Api/Http/Resources/Merchant/MessageResource.php new file mode 100644 index 00000000..a5a90ce1 --- /dev/null +++ b/app/Endpoint/Api/Http/Resources/Merchant/MessageResource.php @@ -0,0 +1,28 @@ + $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(), + ]; + } +} diff --git a/app/Endpoint/Api/routes.php b/app/Endpoint/Api/routes.php index 8901c1f3..40577d74 100644 --- a/app/Endpoint/Api/routes.php +++ b/app/Endpoint/Api/routes.php @@ -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']); }); }); diff --git a/app/Models/MerchantMessage.php b/app/Models/MerchantMessage.php new file mode 100644 index 00000000..3a5b88b6 --- /dev/null +++ b/app/Models/MerchantMessage.php @@ -0,0 +1,86 @@ +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, + ]); + } +} diff --git a/app/Models/UserInfo.php b/app/Models/UserInfo.php index c2b48186..3e35dd52 100644 --- a/app/Models/UserInfo.php +++ b/app/Models/UserInfo.php @@ -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 => '女性', + ]; + /** * 代理等级文本 * diff --git a/app/Services/Push/MerchantUnipushService.php b/app/Services/Push/MerchantUnipushService.php index 34a22799..be0dd885 100644 --- a/app/Services/Push/MerchantUnipushService.php +++ b/app/Services/Push/MerchantUnipushService.php @@ -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, + ]); } } diff --git a/database/migrations/2022_01_04_192819_create_merchant_messages_table.php b/database/migrations/2022_01_04_192819_create_merchant_messages_table.php new file mode 100644 index 00000000..c65189af --- /dev/null +++ b/database/migrations/2022_01_04_192819_create_merchant_messages_table.php @@ -0,0 +1,39 @@ +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'); + } +} diff --git a/database/seeders/AppSettingSeeder.php b/database/seeders/AppSettingSeeder.php index 91443198..07503b03 100644 --- a/database/seeders/AppSettingSeeder.php +++ b/database/seeders/AppSettingSeeder.php @@ -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' => '个推配置', ], diff --git a/resources/lang/zh_CN/user.php b/resources/lang/zh_CN/user.php index 3fdc35bb..4484607a 100644 --- a/resources/lang/zh_CN/user.php +++ b/resources/lang/zh_CN/user.php @@ -39,6 +39,11 @@ return [ 'agent_level'=>'管理级别', 'growth_value'=>'消费值', 'group_sales_value'=>'业绩', + 'points'=>'积分', + 'quota_v2'=>'新配额', + 'quota_v1'=>'老配额', + 'gender'=>'性别', + 'birthday'=>'生日', 'inviter_info'=>[ 'user'=>[ 'phone' =>'推荐人手机',