作者 lyh

Merge branch 'develop' of http://47.244.231.31:8099/zhl/globalso-v6 into develop

<?php
namespace App\Console\Commands;
use App\Helper\OaGlobalsoApi;
use App\Models\Channel\Channel;
use App\Models\Channel\User;
use App\Models\Channel\Zone;
use Illuminate\Console\Command;
/**
* 渠道信息
* Class ChannelInfo
* @package App\Console\Commands
* @author zbj
* @date 2023/6/27
*/
class SyncChannel extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'sync_channel';
/**
* The console command description.
*
* @var string
*/
protected $description = '更新渠道信息';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* @return bool
*/
public function handle()
{
$api = new OaGlobalsoApi();
$res = $api->agents_lists();
if($res && !empty($res['data'])){
foreach ($res['data'] as $item){
$zone = Zone::sync($item['belong']);
$channel = Channel::sync($item, $zone->id);
foreach ($item['users'] as $user){
User::sync($user, $channel->id);
}
}
}
return true;
}
}
... ...
... ... @@ -27,6 +27,7 @@ class Kernel extends ConsoleKernel
$schedule->command('web_traffic 1')->everyThirtyMinutes(); // 引流 1-3个月的项目,半小时一次
$schedule->command('web_traffic 2')->cron('*/18 * * * *'); // 引流 4-8个月的项目,18分钟一次
$schedule->command('web_traffic 3')->cron('*/12 * * * *'); // 引流 大于9个月的项目,12分钟一次
$schedule->command('sync_channel')->dailyAt('06:00')->withoutOverlapping(1); // 渠道信息,每周执行一次
// // 更新域名|证书结束时间,每天凌晨1点执行一次
// $schedule->command('domain_time')->dailyAt('01:00')->withoutOverlapping(1);
// // B站 - 网站数据统计
... ...
<?php
namespace App\Helper;
use App\Utils\HttpUtils;
use GuzzleHttp\Exception\GuzzleException;
/**
* Class OaGlobalsoApi
* @package App\Helper
* @author zbj
* @date 2023/6/27
*/
class OaGlobalsoApi
{
//接口地址
protected $url = 'https://oa.globalso.com';
protected $token = '';
public function __construct()
{
$this->token = md5('oa' . date('Y-m-d'));
}
/**
* 项目信息
* @author zbj
* @date 2023/5/17
*/
public function order_info($order_id)
{
$api_url = $this->url . '/api/order_info';
$params = [
'token' => $this->token,
'order_id' => $order_id,
];
try {
$res = HttpUtils::get($api_url, $params);
$res = Arr::s2a($res);
} catch (\Exception | GuzzleException $e) {
errorLog('项目信息', $params, $e);
return false;
}
return $res;
}
/**
* 渠道信息
* @author zbj
* @date 2023/5/17
*/
public function agents_lists()
{
$api_url = $this->url . '/api/agents_lists';
$params = [
'token' => $this->token,
];
try {
$res = HttpUtils::get($api_url, $params);
$res = Arr::s2a($res);
} catch (\Exception | GuzzleException $e) {
errorLog('渠道信息', $params, $e);
return false;
}
return $res;
}
}
... ...
... ... @@ -2,7 +2,7 @@
namespace App\Http\Controllers\Aside;
use App\Models\Manage\Manage;
use App\Http\Logic\Aside\Project\ProjectLogic;
use App\Utils\LogUtils;
/**
... ... @@ -21,10 +21,13 @@ class NoticeController extends BaseController
* @author zbj
* @date 2023/6/26
*/
public function project()
public function project(ProjectLogic $logic)
{
//首次 续费
LogUtils::info('notice project', $this->param);
if($this->param['order_type'] == '首次'){
$logic->sync($this->param);
}
return $this->success();
}
... ...
... ... @@ -9,6 +9,7 @@ use App\Http\Logic\Aside\Project\ProjectLogic;
use App\Http\Requests\Aside\Project\ProcessRecordsRequest;
use App\Http\Requests\Aside\Project\ProjectRequest;
use App\Models\InquirySet;
use App\Models\Project\Payment;
use App\Rules\Ids;
use Illuminate\Http\Request;
... ... @@ -100,6 +101,20 @@ class ProjectController extends BaseController
}
/**
* 渠道数据源
* @param ProjectLogic $logic
* @return \Illuminate\Http\JsonResponse
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
* @author zbj
* @date 2023/6/27
*/
public function channel_source(ProjectLogic $logic){
$data = $logic->channelSource($this->param);
return $this->success($data);
}
/**
* 进程记录
* @author zbj
* @date 2023/6/25
... ... @@ -124,4 +139,20 @@ class ProjectController extends BaseController
$data = $logic->save($this->param);
return $this->success($data);
}
/**
* 获取合同票据
* @author zbj
* @date 2023/6/27
*/
public function get_contract_bill(Request $request){
$request->validate([
'id'=>'required'
],[
'id.required' => 'ID不能为空'
]);
$payment = Payment::where('project_id', $this->param['id'])->select(['contract', 'bill'])->first();
$data = $payment->makeVisible(['contract', 'bill']);
return $this->success($data ? $data->toArray() : []);
}
}
... ...
... ... @@ -7,6 +7,9 @@ use App\Helper\Arr;
use App\Helper\FormGlobalsoApi;
use App\Http\Logic\Aside\BaseLogic;
use App\Http\Logic\Aside\Manage\ManageLogic;
use App\Models\Channel\Channel;
use App\Models\Channel\User;
use App\Models\Channel\Zone;
use App\Models\City;
use App\Models\InquirySet;
use App\Models\Project\DeployBuild;
... ... @@ -38,7 +41,7 @@ class ProjectLogic extends BaseLogic
$item = [
'id' => $item['id'],
'title' => $item['title'],
'channel' => ($item['channel']['channel']??'') . ' - ' . ($item['channel']['saler']??''),
'channel' => Channel::getChannelText($item['channel']['user_id'] ?? 0),
'key' => $item['deploy_build']['keyword_num'] ?? 0,
'day' => $item['deploy_build']['service_duration'] ?? 0,
'amount' => $item['payment']['amount'] ?? 0,
... ... @@ -78,6 +81,7 @@ class ProjectLogic extends BaseLogic
if(!empty($param['payment']['amount'])) unset($param['payment']['amount']);
if(!empty($param['deploy_build']['test_domain'])) unset($param['deploy_build']['test_domain']);
if(!empty($param['deploy_build']['plan'])) unset($param['deploy_build']['plan']);
if(!empty($param['deploy_optimize']['api_no'])) unset($param['deploy_optimize']['api_no']);
$res = parent::save($param);
$param['id'] = $res['id'];
$this->savePayment($param);
... ... @@ -105,7 +109,7 @@ class ProjectLogic extends BaseLogic
$data = $param['payment'];
$data['project_id'] = $param['id'];
$data['id'] = Payment::where('project_id', $param['id'])->value('id');
Arr::forget($data, ['amount']);
// Arr::forget($data, ['amount']);
return (new PaymentLogic)->save($data);
}
... ... @@ -121,7 +125,7 @@ class ProjectLogic extends BaseLogic
$data = $param['deploy_build'];
$data['project_id'] = $param['id'];
$data['id'] = DeployBuild::where('project_id', $param['id'])->value('id');
Arr::forget($data, ['test_domain', 'plan']);
// Arr::forget($data, ['test_domain', 'plan']);
return (new DeployBuildLogic)->save($data);
}
... ... @@ -137,6 +141,7 @@ class ProjectLogic extends BaseLogic
$data = $param['deploy_optimize'];
$data['project_id'] = $param['id'];
$data['id'] = DeployOptimize::where('project_id', $param['id'])->value('id');
// Arr::forget($data, ['api_no']);
return (new DeployOptimizeLogic)->save($data);
}
... ... @@ -191,4 +196,56 @@ class ProjectLogic extends BaseLogic
}
public function channelSource($param){
switch ($param['type']){
case 1:
return Zone::pluck('title', 'id')->toArray();
case 2:
return Channel::where('zone_id', $param['zone_id']??0)->pluck('alias', 'id')->toArray();
case 3:
return User::where('channel_id', $param['channel_id']??0)->pluck('name', 'id')->toArray();
}
return [];
}
public function sync($param){
$data = [
'title' => $param['company_name'],
'company' => $param['company_name'],
'lead_name' => $param['principal_name'],
'mobile' => $param['principal_mobile'],
'qq' => $param['customer_qq'],
'channel' => Channel::getProjectChannel($param['company_id'], $param['username_sales']),
'requirement' => $param['remark'],
'cooperate_date' => date('Y-m-d', $param['create_time']),
'deploy_build' => [
'service_duration' => $param['id'],
'plan' => [$param['plan_marketing']]
],
'deploy_optimize' => [
'api_no' => $param['id']
],
'payment' => [
'amount' => $param['plan_price'],
'contract' => $param['files'],
'bill' => $param['images'],
],
];
DB::beginTransaction();
try {
$res = parent::save($data);
$data['id'] = $res['id'];
$this->savePayment($data);
$this->saveDeployBuild($data);
$this->saveDeployOptimize($data);
DB::commit();
}catch (\Exception $e){
DB::rollBack();
errorLog('项目同步失败', $data, $e);
$this->fail('同步失败');
}
}
}
... ...
<?php
namespace App\Models\Channel;
use Illuminate\Database\Eloquent\Model;
use phpDocumentor\Reflection\Types\Self_;
/**
* Class Channel
* @package App\Models
* @author zbj
* @date 2023/6/27
*/
class Channel extends Model
{
//设置关联表名
protected $table = 'gl_channel';
public function sync($data, $zone_id){
$channel = self::where('source_id', $data['id'])->first();
if(!$channel){
$channel = new self();
}
$channel->zone_id = $zone_id;
$channel->title = $data['company_name'];
$channel->alias = $data['company_alias'];
$channel->province = $data['province'];
$channel->contact_name = $data['contact_name'];
$channel->contact_mobile = $data['contact_mobile'];
$channel->source_id = $data['id'];
$channel->save();
return $channel;
}
public static function getProjectChannel($source_id, $sales){
$channel = self::where('source_id', $source_id)->first();
if(!$channel){
return [];
}
$user = User::where('channel_id', $channel['id'])->where('name', $sales)->first();
return [
'zone_id' => $channel['zone_id'],
'channel_id' => $channel['id'],
'user_id' => $user['id'] ?? '',
];
}
public static function getChannelText($sales_id){
$user = User::where('id', $sales_id)->select(['name', 'channel_id'])->first();
if(!$user){
return '';
}
$channel_alias = self::where('id', $user['channel_id'])->value('alias');
return $channel_alias . '-' . $user['name'];
}
}
... ...
<?php
namespace App\Models\Channel;
use Illuminate\Database\Eloquent\Model;
/**
* Class User
* @package App\Models
* @author zbj
* @date 2023/6/27
*/
class User extends Model
{
//设置关联表名
protected $table = 'gl_channel_user';
public static function sync($name, $channel_id){
$user = self::where('channel_id', $channel_id)->where('name', $name)->first();
if(!$user){
$user = new self();
$user->name = $name;
$user->channel_id = $channel_id;
$user->save();
}
return $user;
}
}
... ...
<?php
namespace App\Models\Channel;
use Illuminate\Database\Eloquent\Model;
/**
* Class Zone
* @package App\Models
* @author zbj
* @date 2023/6/27
*/
class Zone extends Model
{
//设置关联表名
protected $table = 'gl_channel_zone';
public static function sync($title){
$zone = self::where('title', $title)->first();
if(!$zone){
$zone = new self();
$zone->title = $title;
$zone->save();
}
return $zone;
}
}
... ...
... ... @@ -10,6 +10,7 @@ class Payment extends Base
//设置关联表名
protected $table = 'gl_project_payment';
protected $hidden = ['contract', 'bill'];
public function setRenewalRecordAttribute($value){
$this->attributes['renewal_record'] = Arr::a2s($value);
... ... @@ -19,4 +20,20 @@ class Payment extends Base
return Arr::s2a($value);
}
public function setContractAttribute($value){
$this->attributes['contract'] = Arr::a2s($value);
}
public function getContractAttribute($value){
return Arr::s2a($value);
}
public function setBillAttribute($value){
$this->attributes['bill'] = Arr::a2s($value);
}
public function getBillAttribute($value){
return Arr::s2a($value);
}
}
... ...
... ... @@ -54,21 +54,15 @@ class Project extends Base
public static function planMap()
{
return [
1 => '营销大师-体验版',
2 => '营销大师-标准版',
3 => '营销大师-商务版',
4 => '营销大师-旗舰版',
5 => '数据大师-体验版',
6 => '数据大师-智能版',
7 => '数据大师-智慧版',
8 => 'PLUS-尊享版',
9 => 'PLUS-尊贵版',
10 => 'PLUS-至尊版',
11 => '防疫物质推广方案',
12 => '疫情期间免费版',
13 => '建站大师定制优化方案',
14 => '星链网站(1年版)',
15 => '星链网站(2年版)',
1 => '标准版',
2 => '商务版',
3 => '旗舰版',
4 => '【PLUS】尊贵版',
5 => '【PLUS】至尊版',
6 => '仅建站(模板)',
7 => '仅建站(订制)',
8 => '星链网站(1年版)',
9 => '星链网站(2年版)'
];
}
... ...
... ... @@ -129,9 +129,11 @@ Route::middleware(['aloginauth'])->group(function () {
Route::get('/info', [Aside\Project\ProjectController::class, 'info'])->name('admin.project_info');
Route::post('/save', [Aside\Project\ProjectController::class, 'save'])->name('admin.project_save');
Route::any('/inquiry_set', [Aside\Project\ProjectController::class, 'inquiry_set'])->name('admin.project_inquiry_set');
Route::any('/data_source', [Aside\Project\ProjectController::class, 'data_source'])->name('admin.project_data_source');
Route::any('/get_process_records', [Aside\Project\ProjectController::class, 'get_process_records'])->name('admin.project_get_process_records');
Route::any('/save_process_records', [Aside\Project\ProjectController::class, 'save_process_records'])->name('admin.project_save_process_records');
Route::any('/get_contract_bill', [Aside\Project\ProjectController::class, 'get_contract_bill'])->name('admin.project_get_contract_bill');
Route::any('/data_source', [Aside\Project\ProjectController::class, 'data_source'])->name('admin.project_data_source.white');
Route::any('/channel_source', [Aside\Project\ProjectController::class, 'channel_source'])->name('admin.project_channel_source.white');
});
//工单管理
... ... @@ -215,7 +217,7 @@ Route::group([], function () {
Route::any('/image/{hash}/{w?}/{h?}', [\App\Http\Controllers\File\ImageController::class, 'index'])->name('admin.image_show');
Route::any('/file/{hash}', [\App\Http\Controllers\File\FileController::class, 'index'])->name('admin.file_show');
Route::get('/notice/project', [Aside\NoticeController::class, 'project'])->name('admin.notice.project');
Route::any('/notice/project', [Aside\NoticeController::class, 'project'])->name('admin.notice.project');
});
... ...