初始化

This commit is contained in:
wuhui_zzw 2024-03-09 18:13:32 +08:00
commit 02fd5099c7
20168 changed files with 3385355 additions and 0 deletions

9
.gitignore vendored Normal file
View File

@ -0,0 +1,9 @@
.idea/
/.idea/
/.env
.database/
/storage/logs/
/database
/bootstrap/cache
/addons/yun_shop/index.html
/addons/yun_shop/static

1
.htaccess Normal file
View File

@ -0,0 +1 @@

7
404.html Normal file
View File

@ -0,0 +1,7 @@
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx</center>
</body>
</html>

3
README.md Normal file
View File

@ -0,0 +1,3 @@
芸众商城使用请看以下链接
https://bbs.cloudeapi.com/forum.php?mod=viewthread&tid=24201

22
addons/yun_shop/api.php Normal file
View File

@ -0,0 +1,22 @@
<?php
$env=@file_get_contents('.env');
if (empty($env)) {
$env=@file_get_contents('../../.env');
}
$is_yunshop=strpos($env,"APP_Framework");
$extend = '';
$boot_file = __DIR__ . '/../../framework/bootstrap.inc.php';
if (!$is_yunshop) {
include_once $boot_file;
} else {
$extend = '/../..';
}
include_once __DIR__ . $extend . '/app/laravel.php';
include_once __DIR__ . $extend . '/app/yunshop.php';

1
admin.html Normal file

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,41 @@
<?php
/**
* Created by PhpStorm.
* User: shenyang
* Date: 2017/9/18
* Time: 下午3:46
*/
namespace app\Jobs;
use app\common\models\AdminOperationLog;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
class AdminOperationLogQueueJob implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
protected $queueData;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($queueData)
{
$this->queueData = $queueData;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
AdminOperationLog::insert($this->queueData);
}
}

View File

@ -0,0 +1,40 @@
<?php
/**
* Created by PhpStorm.
* User: 马赛克
* Date: 2020/3/31
* Time: 下午3:38
*/
namespace app\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use app\common\services\member\MemberRelation;
class ChangeMemberRelationJob implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
public $member_id = 0;
public $parent_id = 0;
public function __construct($member_id, $parent_id)
{
$this->member_id = $member_id;
$this->parent_id = $parent_id;
}
public function handle()
{
if (intval($this->member_id) > 0 && intval($this->parent_id) >= 0) {
\Log::debug('修改会员关系---job', [$this->member_id, $this->parent_id]);
$member_relation = new MemberRelation();
return $member_relation->change($this->member_id, $this->parent_id);
}
}
}

View File

@ -0,0 +1,28 @@
<?php
namespace app\Jobs;
use app\backend\modules\charts\modules\member\services\DistributionOrderService;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class CountCommissionOrderJob implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
public function __construct()
{
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
(new DistributionOrderService())->getCommissionOrderNum();
}
}

View File

@ -0,0 +1,38 @@
<?php
/**
* Created by PhpStorm.
* User: yunzhong
* Date: 2019/7/30
* Time: 15:23
*/
namespace app\Jobs;
use app\common\facades\Setting;
use Illuminate\Contracts\Bus\Dispatcher;
class DispatchesJobs
{
const LOW = 'low';
public static function dispatch($job, $queue)
{
$is_open = Setting::getNotUniacid('supervisor.queue.is_classify');
if ($is_open) {
$job->queue = $queue;
}
return app(Dispatcher::class)->dispatch($job);
}
/**
* Dispatch a command to its appropriate handler in the current process.
*
* @param mixed $job
* @return mixed
*/
public function dispatchNow($job)
{
return app(Dispatcher::class)->dispatchNow($job);
}
}

View File

@ -0,0 +1,62 @@
<?php
/**
* Created by PhpStorm.
*
*
*
* Date: 2023/4/19
* Time: 17:38
*/
namespace app\Jobs;
use app\common\facades\Setting;
use app\common\models\Goods;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\DB;
class GoodsSetPriceJob implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
protected $goods_id;
protected $uniacid;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($uniacid,$goods_id)
{
$this->uniacid = $uniacid;
$this->goods_id = $goods_id;
}
/**
* @return bool|void
*/
public function handle()
{
\YunShop::app()->uniacid = Setting::$uniqueAccountId = $this->uniacid;
$good = Goods::find($this->goods_id);
if (!$good) {
return;
}
return $this->setPrice($good);
}
private function setPrice(Goods $good)
{
if ($good->has_option && !$good->hasManyOptions->isEmpty()) {//开启规格
$min_price = $good->hasManyOptions->min('product_price');
$max_price = $good->hasManyOptions->max('product_price');
} else {
$min_price = $good->price;
$max_price = $good->price;
}
DB::table('yz_goods')->where('id',$good->id)->update(['min_price'=>$min_price,'max_price'=>$max_price]);//不能用模型去改
return true;
}
}

29
app/Jobs/Job.php Normal file
View File

@ -0,0 +1,29 @@
<?php
namespace app\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
class Job implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
public $tries = 5;
public $timeout = 120;
protected $event;
public function __construct($event)
{
$this->event = $event;
}
}

View File

@ -0,0 +1,42 @@
<?php
namespace app\Jobs;
use app\common\events\goods\GoodsLimitBuyCloseEvent;
use app\common\models\Goods;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
class LimitBuyEndJob implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
protected $limitBuy;
/**
* LimitBuyEndJob constructor.
* @param $data
*/
public function __construct($data = [])
{
$this->limitBuy = $data;
}
/**
* @return bool
*/
public function handle()
{
$goods = Goods::find($this->limitBuy['goods_id']);
if(!$goods){
return true;
}
//执行限时购结束事件
event(new GoodsLimitBuyCloseEvent($goods));
return true;
}
}

View File

@ -0,0 +1,110 @@
<?php
/**
* Created by PhpStorm.
* User: dingran
* Date: 2018/11/4
* Time: 下午3:44
*/
namespace app\Jobs;
use app\common\models\member\ParentOfMember;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\DB;
use Yunshop\Mryt\models\MrytMemberAddUpVipModel;
use Yunshop\Mryt\models\MrytMemberModel;
class MemberAddupVipJob implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
protected $uid;
protected $uniacid;
protected $curr_date;
public $MrytMemberAddUpVipModel;
public $parentMemberModel;
public function __construct($uid, $uniacid)
{
$this->uid = $uid;
$this->uniacid = $uniacid;
$this->curr_date = date('Ym', time());
}
public function handle()
{
\Log::debug('---------add up vip------');
$insert_ids = [];
$uids = [];
$ExistsIds = [];
$noExistsIds = [];
$this->MrytMemberAddUpVipModel = new MrytMemberAddUpVipModel($this->uniacid);
$this->parentMemberModel = new ParentOfMember();
//查询uid所有父类id
$parent = $this->parentMemberModel->getParentOfMember($this->uid);
if (!$parent->isEmpty()) {
foreach ($parent as $val) {
$insert_ids[] = $val->parent_id;
}
//mrytVVIP会员
$mryt_vvip_ids = MrytMemberModel::getMemberInfosWithLevel($insert_ids, $this->uniacid);
if (!is_null($mryt_vvip_ids)) {
foreach ($mryt_vvip_ids as $rows) {
$uids[] = $rows->uid;
}
$exists_parent = $this->MrytMemberAddUpVipModel->QueryCurrentMonthRecord($uids, $this->curr_date);
if (!$exists_parent->isEmpty()) {
foreach ($exists_parent as $item) {
$ExistsIds [] = $item->uid;
}
foreach ($mryt_vvip_ids as $rows) {
if (!in_array($rows->uid, $ExistsIds)) {
$noExistsIds[] = $rows;
}
}
DB::transaction(function () use ($ExistsIds, $noExistsIds) {
$this->UpdateDate($ExistsIds, $this->curr_date);
$this->InsertDate($noExistsIds);
});
} else {
$this->InsertDate($mryt_vvip_ids);
}
}
}
}
public function InsertDate($no_exists_ids)
{
foreach ($no_exists_ids as $ids) {
$attr[] = [
'uniacid' => $this->uniacid,
'uid' => $ids->uid,
'nums' => 1,
'curr_date' => $this->curr_date,
'created_at' => time(),
'updated_at' => time()
];
}
$this->MrytMemberAddUpVipModel->CreateData($attr);
}
public function UpdateDate($exists_ids, $curr_date)
{
$this->MrytMemberAddUpVipModel->UpdateIncrementNums($exists_ids, $curr_date);
}
}

View File

@ -0,0 +1,48 @@
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/10/31
* Time: 16:05
*/
namespace app\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use app\backend\modules\charts\modules\member\models\MemberLowerCount;
use Illuminate\Support\Facades\DB;
class MemberLowerCountJob
{
use InteractsWithQueue, Queueable, SerializesModels;
public function __construct()
{
}
public function handle()
{
$this->memberCount();
}
/**
*
*/
public function memberCount(){
\Log::debug('下线人数排行定时任务开始执行,公众号id为', \YunShop::app()->uniacid);
$list = DB::select('select count(*) as team_total, sum(if(level=1,1,0)) as first_total, sum(if(level = 2, 1, 0)) AS second_total, sum(if(level = 3, 1, 0)) AS third_total, member_id as uid, uniacid from '. DB::getTablePrefix() . 'yz_member_children where uniacid =' . \YunShop::app()->uniacid . ' group by member_id');
if (empty($list)) {
return;
}
$insert_data = array_chunk($list,2000);
foreach ($insert_data as $k=>$v){
MemberLowerCount::insert($v);
}
\Log::debug('下线人数排行定时任务执行结束,公众号id为', \YunShop::app()->uniacid);
}
}

View File

@ -0,0 +1,214 @@
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/10/31
* Time: 14:55
*/
namespace app\Jobs;
use app\backend\modules\charts\modules\member\models\MemberLowerGroupOrder;
use app\common\models\MemberShopInfo;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\DB;
use Yunshop\ShareChain\common\model\ShopMemberLevel;
class MemberLowerGroupOrderJob implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
public $uniacid;
public $insert_data;
public function __construct()
{
}
public function handle()
{
$this->memberOrder();
}
public function memberOrder()
{
$orders = [];
$order_data = DB::select('select uid, SUM(price) as amount, SUM(goods_total) as goods_count from '. DB::getTablePrefix() . 'yz_order where status > 0 and uniacid =' . \YunShop::app()->uniacid .' group by uid');
foreach ($order_data as $order) {
$orders[$order['uid']] = $order;
}
unset($order_data);
$members = DB::select('select member_id, parent_id from '. DB::getTablePrefix() . 'yz_member where uniacid =' . \YunShop::app()->uniacid );
$tree = $this->tree($members);
unset($members);
$this->getTreeData($tree,$orders);
unset($tree[0]);
$insert_data = array_chunk($this->insert_data,2000);
foreach ($insert_data as $k=>$v){
MemberLowerGroupOrder::insert($v);
}
}
public function tree($members)
{
$items = [];
foreach ($members as $member) {
$items[$member['member_id']] = $member;
}
foreach ($items as $item) {
$items[$item['parent_id']]['son'][$item['member_id']] = &$items[$item['member_id']];
}
return isset($items[0]['son']) ? $items[0]['son'] : [];
}
function getTreeData($tree, $orders)
{
$data = [];
foreach($tree as $kk => $t){
$this_insert_data = [
'uid'=>$t['member_id'],
'uniacid'=>\YunShop::app()->uniacid,
'amount'=>0,
'goods_count'=>0,
'pay_count'=>0,
'team_count'=>0,
'created_at'=>time()
];
$this_order_data = [];
if(isset($t['son'])){
$this_order_data = $this->getTreeData($t['son'], $orders);
$this_insert_data['amount'] = $this_order_data['amount'];
$this_insert_data['goods_count'] = $this_order_data['goods_count'];
$this_insert_data['pay_count'] = $this_order_data['pay_count'];
$this_insert_data['team_count'] = $this_order_data['team_count'];
}
$data['amount'] += $orders[$t['member_id']]['amount'] + $this_order_data['amount'];
$data['goods_count'] += $orders[$t['member_id']]['goods_count'] + $this_order_data['goods_count'];
$pay_count = isset($orders[$t['member_id']]) ? 1 : 0;
$data['pay_count'] += $this_order_data['pay_count'] + $pay_count;
$data['team_count'] += $this_order_data['team_count'] + 1;
$this->insert_data[$kk] = $this_insert_data;
}
return $data;
}
/**
* Execute the job.
*
* @return void
*/
public function memberOrder2(){
$time = time();
\Log::debug('团队支付订单排行定时任务开始执行,公众号id为', \YunShop::app()->uniacid);
$t1 = microtime(true);
$insert_data = [];
//查询归类所有订单开始
$order_data = DB::table('yz_order')
->selectRaw('uid, SUM(price) as amount, COUNT(id) as count, SUM(goods_total) as goods_count')
->where('status','>',0)
->where('uniacid', \YunShop::app()->uniacid)
->groupBy('uid')
->get();
$members = DB::select('select member_id from '. DB::getTablePrefix() . 'yz_member where uniacid =' . \YunShop::app()->uniacid );
$child = DB::table('yz_member_children')
->select(['child_id','member_id'])
->where('uniacid', \YunShop::app()->uniacid)
->get();
foreach ($members as $member){
$memberID = $member['member_id'];
$this_insert_data = [
'uid' => $member['member_id'],
'uniacid'=>\YunShop::app()->uniacid,
'amount'=>0,
'goods_count'=>0,
'pay_count'=>0,
'team_count'=>$child->where('member_id', $member['member_id'])->count(),
// 'team_count'=>$child->filter(function($user) use ($memberID) {
// return $user['member_id'] === $memberID;
// })->count(),
'created_at'=>$time
];
// $total_member = DB::table('yz_member_children')->where('member_id', $member['member_id'])->pluck('child_id');
$total_member = $child->where('member_id', $member['member_id'])->pluck('child_id');
// $total_member = $child->filter(function($user) use ($memberID) {
// return $user['member_id'] === $memberID;
// })->pluck('child_id');
// dd($total_member, $total_member2);
if (!$total_member->isEmpty()) {
$child_member = $order_data->whereIn('uid', $total_member);
// $child_member = $order_data->filter(function($user) use ($total_member) {
// return in_array($user['uid'],$total_member->toArray());
// });
$this_insert_data['pay_count'] = $child_member->sum('count');
$this_insert_data['amount'] = $child_member->sum('amount');
$this_insert_data['goods_count'] = $child_member->sum('goods_count');
}
$insert_data[] = $this_insert_data;
unset($total_member);
unset($child_member);
unset($this_insert_data);
}
$insert_data = array_chunk($insert_data,2000);
foreach ($insert_data as $k=>$v){
MemberLowerGroupOrder::insert($v);
}
\Log::debug('团队支付订单排行定时任务执行结束,公众号id为', \YunShop::app()->uniacid);
}
public function memberOrder1(){
$time = time();
$insert_data = [];
$order_data = DB::select('select uid, SUM(price) as amount, COUNT(id) as count ,SUM(goods_total) as goods_count from '. DB::getTablePrefix() . 'yz_order where status > 0 and uniacid =' . \YunShop::app()->uniacid .' group by uid');
$order_data = array_column($order_data, null, 'uid');
$members = DB::select('select member_id from '. DB::getTablePrefix() . 'yz_member where uniacid =' . \YunShop::app()->uniacid );
foreach ($members as $v){
$child = DB::select('select child_id, level from '. DB::getTablePrefix() . 'yz_member_children where member_id = '.$v['member_id'].' and uniacid =' . \YunShop::app()->uniacid );
$this_insert_data = [
'uid'=>$v['member_id'],
'uniacid'=>\YunShop::app()->uniacid,
'amount'=>0,
'goods_count'=>0,
'pay_count'=>0,
'team_count'=>count($child),
'created_at'=>$time
];
if (!empty($child)) {
$this_child = array_column($child, 'level', 'child_id');
foreach ($this_child as $kk=>$vv){
if (!isset($order_data[$kk])) continue;
$this_order_data = $order_data[$kk];
$this_insert_data['pay_count']++;
$this_insert_data['goods_count'] += $this_order_data['goods_count'];
$this_insert_data['amount'] += $this_order_data['amount'];
}
}
$insert_data[] = $this_insert_data;
}
$insert_data = array_chunk($insert_data,2000);
foreach ($insert_data as $k=>$v){
MemberLowerGroupOrder::insert($v);
}
}
}

View File

@ -0,0 +1,296 @@
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/10/31
* Time: 14:55
*/
namespace app\Jobs;
use app\backend\modules\charts\modules\member\models\MemberLowerOrder;
use app\backend\modules\charts\modules\member\services\LowerOrderService;
use app\common\models\MemberShopInfo;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\DB;
class MemberLowerOrderJob implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
public $uniacid;
public $insert_data;
public function __construct()
{
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$this->memberOrder();
}
public function memberOrder()
{
$orders = [];
$order_data = DB::select('select uid, SUM(price) as amount, COUNT(id) as count from '. DB::getTablePrefix() . 'yz_order where status = 3 and uniacid =' . \YunShop::app()->uniacid .' group by uid');
foreach ($order_data as $order) {
$orders[$order['uid']] = $order;
}
unset($order_data);
$members = DB::select('select member_id, parent_id from '. DB::getTablePrefix() . 'yz_member where uniacid =' . \YunShop::app()->uniacid );
$tree = $this->tree($members);
unset($members);
$this->getTreeData($tree[0]['son'],$orders);
unset($tree[0]);
$this->getFirst($tree,$orders);
$insert_data = array_chunk($this->insert_data,2000);
foreach ($insert_data as $k=>$v){
MemberLowerOrder::insert($v);
}
}
public function tree($members)
{
$items = [];
foreach ($members as $member) {
$items[$member['member_id']] = $member;
}
foreach ($items as $item) {
$items[$item['parent_id']]['son'][$item['member_id']] = &$items[$item['member_id']];
}
return $items;
}
function getTreeData($tree, $orders)
{
$data = [];
foreach($tree as $kk => $t){
$this_insert_data = [
'uid'=> $t['member_id'],
'uniacid'=>\YunShop::app()->uniacid,
'first_order_quantity'=>0,
'first_order_amount'=>0,
'second_order_quantity'=>0,
'second_order_amount'=>0,
'third_order_quantity'=>0,
'third_order_amount'=>0,
'team_order_quantity'=>0,
'team_order_amount'=>0,
'pay_count'=>0,
'created_at'=>time()
];
$this_order_data = [];
if(isset($t['son'])){
$this_order_data = $this->getTreeData($t['son'], $orders);
$this_insert_data['team_order_quantity'] = $this_order_data['count'];
$this_insert_data['team_order_amount'] = $this_order_data['amount'];
}
$data['count'] += $orders[$t['member_id']]['count'] + $this_order_data['count'];
$data['amount'] += $orders[$t['member_id']]['amount'] + $this_order_data['amount'];
$this->insert_data[$kk] = $this_insert_data;
}
return $data;
}
function getFirst($tree, $orders)
{
foreach($tree as $kk => $t){
if(empty($t['son'])) {
continue;
}
if (empty($this->insert_data[$kk])) {
if (empty($t['member_id'])) {
//todo 有出现某会员在yz_member找不到被删了但有其他会员的parent_id还是该会员的id导致下面uid为null插入数据失败
continue;
}
$this->insert_data[$kk] = [
'uid'=> $t['member_id'],
'uniacid'=>\YunShop::app()->uniacid,
'first_order_quantity'=>0,
'first_order_amount'=>0,
'second_order_quantity'=>0,
'second_order_amount'=>0,
'third_order_quantity'=>0,
'third_order_amount'=>0,
'team_order_quantity'=>0,
'team_order_amount'=>0,
'pay_count'=>0,
'created_at'=>time()
];
}
foreach ($t['son'] as $first) {
$this->insert_data[$kk]['first_order_quantity'] += $orders[$first['member_id']]['count'];
$this->insert_data[$kk]['first_order_amount'] += $orders[$first['member_id']]['amount'];
if(!isset($first['son'])) {
continue;
}
foreach ($first['son'] as $second) {
$this->insert_data[$kk]['second_order_quantity'] += $orders[$second['member_id']]['count'];
$this->insert_data[$kk]['second_order_amount'] += $orders[$second['member_id']]['amount'];
if(!isset($second['son'])) {
continue;
}
foreach ($second['son'] as $third) {
$this->insert_data[$kk]['third_order_quantity'] += $orders[$third['member_id']]['count'];
$this->insert_data[$kk]['third_order_amount'] += $orders[$third['member_id']]['amount'];
}
}
}
}
}
public function memberOrder1(){
$time = time();
\Log::debug('下线订单排行定时任务开始执行,公众号id为', \YunShop::app()->uniacid);
$insert_data = [];
$order_data = DB::table('yz_order')
->selectRaw('uid, SUM(price) as amount, COUNT(id) as count')
->where('status', 3)
->where('uniacid', \YunShop::app()->uniacid)
->groupBy('uid')
->get();
$members = DB::select('select member_id from '. DB::getTablePrefix() . 'yz_member where uniacid =' . \YunShop::app()->uniacid );
$child = DB::table('yz_member_children')
->select(['child_id','member_id', 'level'])
->where('uniacid', \YunShop::app()->uniacid)
->get();
foreach ($members as $key => $member) {
$this_insert_data = [
'uid'=>$member['member_id'],
'uniacid'=>\YunShop::app()->uniacid,
'created_at'=>$time,
'first_order_quantity'=>0,
'first_order_amount'=>0,
'second_order_quantity'=>0,
'second_order_amount'=>0,
'third_order_quantity'=>0,
'third_order_amount'=>0,
'team_order_quantity'=>0,
'team_order_amount'=>0,
'pay_count'=>0,
];
$total_member = $child->where('member_id', $member['member_id'])->pluck('child_id');
if (!$total_member->isEmpty()) {
$this_insert_data['team_order_quantity'] = $order_data->whereIn('uid', $total_member)->sum('count');
$this_insert_data['team_order_amount'] = $order_data->whereIn('uid', $total_member)->sum('amount');
$first_member = $child->where('level',1)->where('member_id', $member['member_id'])->pluck('child_id');
if (!$first_member->isEmpty()) {
$this_insert_data['first_order_quantity'] = $order_data->whereIn('uid', $first_member)->sum('count');
$this_insert_data['first_order_amount'] = $order_data->whereIn('uid', $first_member)->sum('amount');
}
$second_member = $child->where('level',2)->where('member_id', $member['member_id'])->pluck('child_id');
if (!$second_member->isEmpty()) {
$this_insert_data['second_order_quantity'] = $order_data->whereIn('uid', $second_member)->sum('count');
$this_insert_data['second_order_amount'] = $order_data->whereIn('uid', $second_member)->sum('amount');
}
$third_member = $child->where('level',3)->where('member_id', $member['member_id'])->pluck('child_id');
if (!$third_member->isEmpty()) {
$this_insert_data['third_order_quantity'] = $order_data->whereIn('uid', $third_member)->sum('count');
$this_insert_data['third_order_amount'] = $order_data->whereIn('uid', $third_member)->sum('amount');
}
}
$insert_data[$key] = $this_insert_data;
unset($this_insert_data);
}
$insert_data = array_chunk($insert_data,2000);
foreach ($insert_data as $k=>$v){
MemberLowerOrder::insert($v);
}
\Log::debug('下线订单排行定时任务执行结束,公众号id为', \YunShop::app()->uniacid);
}
public function memberOrder2(){
$time = time();
$insert_data = [];
$order_data = DB::select('select uid, SUM(price) as amount, COUNT(id) as count from '. DB::getTablePrefix() . 'yz_order where status = 3 and uniacid =' . \YunShop::app()->uniacid .' group by uid');
$order_data = array_column($order_data, null, 'uid');
$members = DB::select('select member_id from '. DB::getTablePrefix() . 'yz_member where uniacid =' . \YunShop::app()->uniacid );
foreach ($members as $v){
$this_insert_data = [
'uid'=>$v['member_id'],
'uniacid'=>\YunShop::app()->uniacid,
'first_order_quantity'=>0,
'first_order_amount'=>0,
'second_order_quantity'=>0,
'second_order_amount'=>0,
'third_order_quantity'=>0,
'third_order_amount'=>0,
'team_order_quantity'=>0,
'team_order_amount'=>0,
'pay_count'=>0,
'created_at'=>$time
];
$child = DB::table('yz_member_children')
->select(['child_id','level'])
->where('member_id',$v['member_id'])
->where('uniacid', \YunShop::app()->uniacid)
->get()
->toArray();
if (!empty($child)) {
$this_child = array_column($child, 'level', 'child_id');
foreach ($this_child as $kk => $vv){
if (!isset($order_data[$kk])) continue;
$this_order_data = $order_data[$kk];
$this_insert_data['pay_count']++;
$this_insert_data['team_order_quantity'] += $this_order_data['count'];
$this_insert_data['team_order_amount'] += $this_order_data['amount'];
if ($vv > 3 ) continue;
switch ($vv){
case 1:
$this_insert_data['first_order_quantity'] += $this_order_data['count'];
$this_insert_data['first_order_amount'] += $this_order_data['amount'];
break;
case 2:
$this_insert_data['second_order_quantity'] += $this_order_data['count'];
$this_insert_data['second_order_amount'] += $this_order_data['amount'];
break;
case 3:
$this_insert_data['third_order_quantity'] += $this_order_data['count'];
$this_insert_data['third_order_amount'] += $this_order_data['amount'];
}
}
}
$insert_data[] = $this_insert_data;
}
$insert_data = array_chunk($insert_data,2000);
foreach ($insert_data as $k=>$v){
MemberLowerOrder::insert($v);
}
}
}

View File

@ -0,0 +1,45 @@
<?php
/**
* Created by PhpStorm.
* User: dingran
* Date: 2019/4/16
* Time: 下午1:08
*/
namespace app\Jobs;
use app\common\models\member\ChildrenOfMember;
use app\common\models\member\ParentOfMember;
use app\common\services\member\MemberRelation;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class MemberMaxRelatoinJob implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
public $uniacid = 0;
public function __construct($uniacid)
{
$this->uniacid = $uniacid;
}
public function handle()
{
\Log::debug('-----queue max-----', $this->uniacid);
$uniacid = $this->uniacid;
$parentMemberModle = new ParentOfMember();
$childMemberModel = new ChildrenOfMember();
$parentMemberModle->DeletedData($uniacid);
$childMemberModel->DeletedData($uniacid);
$member_relation = new MemberRelation();
$member_relation->createParentOfMember($uniacid);
}
}

34
app/Jobs/MessageJob.php Normal file
View File

@ -0,0 +1,34 @@
<?php
/**
* Created by PhpStorm.
*
* User: king/QQ995265288
* Date: 2018/3/23 下午1:56
* Email: livsyitian@163.com
*/
namespace app\Jobs;
use app\common\events\Event;
use app\common\services\MessageService;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
class MessageJob extends Job
{
use InteractsWithQueue, Queueable, SerializesModels;
public function handle()
{
(new MessageService())->push(
$this->event->member_id,
$this->event->template_id,
$this->event->params,
$this->event->url,
$this->event->uniacid
);
}
}

View File

@ -0,0 +1,81 @@
<?php
namespace app\Jobs;
use app\common\facades\EasyWeChat;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
class MessageNoticeJob implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
/**
* The number of times the job may be attempted.
*
* @var int
*/
public $tries = 5;
/**
* The number of seconds the job can run before timing out.
*
* @var int
*/
public $timeout = 120;
protected $templateId;
protected $noticeData;
protected $openId;
protected $url;
protected $uniacid;
/**
* MessageNoticeJob constructor.
* @param $templateId
* @param $noticeData
* @param $openId
* @param $url
* @param $uniacid
*/
public function __construct($templateId, $noticeData, $openId, $url)
{
$this->templateId = $templateId;
$this->noticeData = $noticeData;
$this->openId = $openId;
$this->url = $url;
$this->uniacid = \YunShop::app()->uniacid;
}
/**
* Execute the job.
*
* @return bool
*/
public function handle()
{
try {
\YunShop::app()->uniacid = \Setting::$uniqueAccountId = $this->uniacid;
if ($this->attempts() > 1) {
\Log::info('消息通知测试,执行大于两次终止');
return true;
}
$app = EasyWeChat::officialAccount();
$res = $app->template_message->send([
'touser' => $this->openId,
'template_id' => $this->templateId,
'url' => $this->url,
'data' => $this->noticeData,
]);
if ($res['errcode']) {
\Log::debug('-------消息发送失败-----',[$res,$this->noticeData]);
}
return true;
} catch (\Exception $e) {
\Log::debug('消息发送失败',$e->getMessage());
}
}
}

View File

@ -0,0 +1,180 @@
<?php
namespace app\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
class MiniMessageNoticeJob implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
/**
* The number of times the job may be attempted.
*
* @var int
*/
public $tries = 5;
/**
* The number of seconds the job can run before timing out.
*
* @var int
*/
public $timeout = 120;
protected $noticeModel;
protected $templateId;
protected $noticeData;
protected $openId;
protected $url;
protected $formId;
protected $app_id;
protected $app_secret;
protected $get_token_url;
protected $miniprogram_state;
protected $lang;
/**
* Create a new job instance.
*
*
*/
public function __construct($options, $templateId, $noticeData, $openId, $url)
{
$this->app_id = $options['app_id'];
$this->app_secret = $options['secret'];
$this->templateId = $templateId;
$this->noticeData = $noticeData;
$this->openId = $openId;
$this->url = $url?:'pages/index/index';
//$this->formId = $formId;
$this->miniprogram_state = 'formal'; //developer为开发版trial为体验版formal为正式版默认为正式版
$this->lang = 'zh_CN'; //支持zh_CN(简体中文)、en_US(英文)、zh_HK(繁体中文)、zh_TW(繁体中文)默认为zh_CN
$this->get_token_url = 'https://api.weixin.qq.com/cgi-bin/token?'
.'grant_type=client_credential&appid=%s&secret=%s';
// "https://api.weixin.qq.com/sns/jscode2session?appid=%s&secret=%s&js_code=$code&grant_type=authorization_code"
}
/**
* Execute the job.
*
* @return bool
*/
public function handle()
{
if ($this->attempts() > 2) {
\Log::info('消息通知测试,执行大于两次终止');
return true;
}
$this->sendTemplate();
//$this->noticeModel->uses($this->templateId)->andData($this->noticeData)->andReceiver($this->openId)->andUrl($this->url)->send();
return true;
}
public function sendTemplate($method_msg = 'sendTemplate'){
$opUrl = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=%s";
//$opUrl = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=%s";
$rawPost = [
'touser' => $this->openId ,
'template_id' => $this->templateId,
'page' => $this->url,
'data' => $this->noticeData,
'miniprogram_state' => $this->miniprogram_state,
'lang' => $this->lang
];
\Log::debug('=================111111参数1111111================');
\Log::debug($rawPost);
$this->opTemplateData($opUrl,$rawPost,$method_msg);
}
/**
* 提取公共方法 获取模板数据
* @param string $opUrl
* @param array $rawPost
* @param string $method
*/
public function opTemplateData($opUrl = '',$rawPost = [],$method = ''){
$access_token = self::opGetAccessToken();
\Log::debug('=================22222 access_token 2222================');
\Log::debug($access_token);
if(!$access_token){
\Log::debug('获取 access_token 时异常,微信内部错误');
return;
}else{
$templateUrl = sprintf($opUrl,$access_token);
$listRes = self::curl_post($templateUrl,$rawPost);
\Log::debug($templateUrl);
\Log::debug($rawPost);
\Log::debug('=================33333333发送返回值333333333================');
\Log::debug($listRes);
$wxResult = json_decode($listRes,true);
if($wxResult['errcode']){
return ($method.' - Failed!:'.$wxResult);
}else{
return $wxResult;
}
}
}
/**
* 提取公共方法 - 获取 AccessToken
* @return bool
*/
public function opGetAccessToken(){
$get_token_url = sprintf($this->get_token_url, $this->app_id,$this->app_secret);
$result = self::curl_get($get_token_url);
$wxResult = json_decode($result,true);
if(empty($wxResult)){
return false;
}else{
$access_token = $wxResult['access_token'];
return $access_token;
}
}
/**
* @param string $url get请求地址
* @param int $httpCode 返回状态码
* @return mixed
*/
protected function curl_get($url,&$httpCode = 0){
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
//不做证书校验部署在linux环境下请改位true
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,true);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,10);
$file_contents = curl_exec($ch);
$httpCode = curl_getinfo($ch,CURLINFO_HTTP_CODE);
curl_close($ch);
return $file_contents;
}
/**
* PHP 处理 post数据请求
* @param $url 请求地址
* @param array $params 参数数组
* @return mixed
*/
protected function curl_post($url,array $params = array()){
//TODO 转化为 json 数据
$data_string = json_encode($params);
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,10);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch,CURLOPT_POSTFIELDS,$data_string);
curl_setopt($ch,CURLOPT_HTTPHEADER,
array(
'Content-Type: application/json'
)
);
$data = curl_exec($ch);
curl_close($ch);
return ($data);
}
}

View File

@ -0,0 +1,45 @@
<?php
namespace app\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Ixudra\Curl\Facades\Curl;
class ModifyPlatformJob implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
protected $platform;
protected $data;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($tripartite_provider,$datas)
{
$this->platform = $tripartite_provider;
$this->data = $datas;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
foreach ($this->platform as $item){
$url = "{$item['domain']}/addons/yun_shop/api.php?i={$item['provider_uniacid']}&mid=0&type=5&shop_id=null&route=plugin.tripartite-provider.admin.tripartiteProvider.list.updatePlatform";
// 提交推送请求
$response = Curl::to($url)->withData(['data' => json_encode($this->data,1)])->asJsonResponse(true)->post();
if ($response['result'] != 1) {
\Log::debug('域名为'.$item['domain'].'公众ID为'.$item['provider_uniacid'].'的平台的域名或公众号ID有误');
}
}
}
}

View File

@ -0,0 +1,144 @@
<?php
/**
* Created by PhpStorm.
* User: dingran
* Date: 2018/7/27
* Time: 下午4:40
*/
namespace app\Jobs;
use app\common\events\member\RegisterByAgent;
use app\common\models\MemberShopInfo;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Yunshop\Commission\models\Agents;
class ModifyRelationJob implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
/**
* 修改关系里的会员id
*
* @var
*/
private $uid;
/**
* 新的会员父级关系链
* @var
*/
private $member_relation;
/**
* 分销插件是否开启
* @var
*/
private $plugin_commission;
/**
* 当前公众号
* @var
*/
private $uniacid;
public function __construct($uid, $member_relation, $plugin_commission)
{
$this->uid = $uid;
$this->member_relation = $member_relation;
$this->plugin_commission = $plugin_commission;
}
public function handle()
{
$level = count($this->member_relation);
\Log::debug('-----------relation-----------', $this->member_relation);
if ($level > 1) {
$first_relation = $this->uid . ',' . $this->member_relation[0] . ',' . $this->member_relation[1];
$second_relation = $this->uid . ',' . $this->member_relation[0];
} else {
if ($this->member_relation[0] != 0) {
$first_relation = $this->uid . ',' . $this->member_relation[0];
$second_relation = $this->uid;
} else {
$first_relation = $this->uid;
$second_relation = $this->uid;
}
}
$this->ChangeFirstMember($this->uid, $first_relation, $this->plugin_commission);
$this->ChangeSecondMember($this->uid, $second_relation, $this->plugin_commission);
}
/**
* @param $uid
* @param $relation
* @param $open_plugin
*/
private function ChangeFirstMember($uid, $relation, $open_plugin)
{
\Log::debug('----------ChangeFirstMember uid-------', $uid);
$memberModel = $this->getMemberModel($uid, 1);
\Log::debug('----------ChangeFirstMember-------', count($memberModel));
if (!$memberModel->isEmpty()) {
foreach ($memberModel as $key => $model) {
$model->relation = $relation;
if ($model->save() && $open_plugin) {
$this->changeAgentRelation($model);
}
}
}
}
private function ChangeSecondMember($uid, $relation, $open_plugin)
{
\Log::debug('----------ChangeSecondMember uid-------', $uid);
$memberModel = $this->getMemberModel($uid, 2);
\Log::debug('----------ChangeSecondMember-------', count($memberModel));
if (!$memberModel->isEmpty()) {
foreach ($memberModel as $key => $model) {
if ($model->parent_id !== 0) {
$model->relation = $model->parent_id . ',' .$relation;
if ($model->save() && $open_plugin) {
$this->changeAgentRelation($model);
}
}
}
}
}
private function getMemberModel($uid, $pos)
{
$memberModel = MemberShopInfo::getSubLevelMember($uid, $pos);
return $memberModel;
}
private function changeAgentRelation($model)
{
$agents = Agents::getAgentByMemberId($model->member_id)->first();
if (!is_null($agents)) {
$agents->parent_id = $model->parent_id;
$agents->parent = $model->relation;
$agents->save();
}
$agent_data = [
'member_id' => $model->member_id,
'parent_id' => $model->parent_id,
'parent' => $model->relation
];
// event(new RegisterByAgent($agent_data));
}
}

View File

@ -0,0 +1,414 @@
<?php
/**
* Created by PhpStorm.
* User: Merlin
* Date: 2021/2/26
* Time: 15:20
*/
namespace app\Jobs;
use app\backend\modules\member\models\MemberRecord;
use app\common\events\member\RegisterByAgent;
use app\common\exceptions\AppException;
use app\common\models\member\ChildrenOfMember;
use app\common\models\member\ParentOfMember;
use app\common\models\MemberShopInfo;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
class ModifyRelationshipChainJob implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
const SUCCESS = 1;
const FAIL = 2;
private $uid;
private $parent_id;
private $record_id;
private $member;
private $parent;
private $uniacid;
private $before_parent;
private $has_yz_agents = false;
private $yz_team_dividend_agency = false;
// 5分钟超时
public $timeout = 300;
public function __construct($uid,$parent_id,$record_id,$uniacid)
{
$this->queue = 'limit:0';
$this->uid = $uid;
$this->parent_id = $parent_id;
$this->record_id = $record_id;
$this->uniacid = $uniacid;
}
public function handle()
{
\YunShop::app()->uniacid = \Setting::$uniqueAccountId = $this->uniacid;
$start_time = time();
\Log::debug('关系链修改开始',$this->record_id);
$this->member = MemberShopInfo::where('member_id',$this->uid)->first();
$this->parent = MemberShopInfo::where('member_id',$this->parent_id)->first();
$this->before_parent = MemberShopInfo::where('member_id',$this->member->parent_id)->first();
//获取所有子级
$all_child = ChildrenOfMember::where('member_id',$this->uid)->get();
//获取新父级的所有父级
$all_new_parent = ParentOfMember::where('member_id',$this->parent_id)->get();
DB::beginTransaction();
try {
//验证是否闭环关系链
$chain = $all_new_parent->pluck('parent_id');
$chain->push($this->uid);
$chain->push($this->parent_id);
if ($chain->count() != $chain->unique()->count()) {
throw new AppException('关系链闭环,请检测关系链');
}
//删除父表
$this->deleteMemberParent($all_child);
//删除子表
$this->deleteMemberChildren($all_child);
//重建父表
$this->addMemberParent($all_new_parent, $all_child);
//重建子表
$this->addMemberChildren($all_new_parent, $all_child);
//分销修改
$this->hasYzAgentsTable();
//经销商修改
$this->hasYzTeamDividendAgency();
//重新分配yz_member和yz_agent的relation
$this->updateMemberRelation($all_child);
//关系链修改状态
$this->updateMemberRecord(static::SUCCESS,$start_time);
DB::commit();
\Log::debug('关系链修改完成',$this->record_id);
} catch (\Exception $e) {
// 关系链修改失败
DB::rollBack();
$this->updateMemberRecord(static::FAIL,$start_time);
\Log::error('关系链修改失败',$e->getMessage());
}
}
/**
* 删除父表数据
* @param $all_child
* @throws \Exception
* @author: Merlin
* @Time: 2021/3/2 15:12
*/
private function deleteMemberParent($all_child)
{
\Log::debug('关系链修改,删除父表开始',$this->record_id);
//删除当前会员的所有父级
ParentOfMember::where('member_id',$this->uid)->delete();
//删除子级会员,级别大于当前会员的所有父级
foreach ($all_child as $key=>$value) {
ParentOfMember::where('member_id',$value['child_id'])->where('level','>',$value->level)->delete();
}
\Log::debug('关系链修改,删除父表完成',$this->record_id);
}
/**
* 删除子表数据
* @param $all_child
* @throws \Exception
* @author: Merlin
* @Time: 2021/3/2 15:12
*/
private function deleteMemberChildren($all_child)
{
\Log::debug('关系链修改,删除子表开始',$this->record_id);
//删除以当前会员为子节点的所有数据
ChildrenOfMember::where('child_id',$this->uid)->delete();
//删除以当前会员的所有下级为子节点的所有数据
foreach ($all_child as $key=>$value) {
ChildrenOfMember::where('child_id',$value['child_id'])->where('level','>',$value->level)->delete();
}
\Log::debug('关系链修改,删除子表完成',$this->record_id);
}
/**
* 重建父表数据
* @param $all_new_parent
* @param $all_child
* @author: Merlin
* @Time: 2021/3/2 15:12
*/
private function addMemberParent($all_new_parent,$all_child)
{
\Log::debug('关系链修改,重建父表开始',$this->record_id);
if ($this->parent_id == 0) {
return;
}
$data = [];
//遍历所有父级,重建当前会员父表
foreach ($all_new_parent as $parent) {
$data[] = [
'uniacid' => $this->member->uniacid,
'parent_id' => $parent->parent_id,
'level' => $parent->level + 1,
'member_id' => $this->uid,
'created_at' => time()
];
}
$this->insertParentOfMember($data);//todo 不要保存到下面一次去array_chunk插入数据多容易溢出试试分批次走插入
$data = [];
//遍历所有父级,遍历当前会员所有子级,重建子级父表
foreach ($all_new_parent as $parent) {
foreach ($all_child as $child) {
$data[] = [
'uniacid' => $this->member->uniacid,
'parent_id' => $parent->parent_id,
//父级到当前会员层别+ 当前会员到子会员层级
'level' => $parent->level + 1 + $child->level,
'member_id' => $child->child_id,
'created_at' => time()
];
}
}
$this->insertParentOfMember($data);
$data = [];
//遍历所有子级,重建所有子级相对于当前会员的父级的节点
foreach ($all_child as $child) {
$data[] = [
'uniacid' => $this->member->uniacid,
'parent_id' => $this->parent_id,
//父级到当前会员层别+ 当前会员到子会员层级
'level' => 1 + $child->level,
'member_id' => $child->child_id,
'created_at' => time()
];
}
//当前会员对父级节点
$data[] = [
'uniacid' => $this->member->uniacid,
'parent_id' => $this->parent_id,
'level' => 1,
'member_id' => $this->uid,
'created_at' => time()
];
$this->insertParentOfMember($data);
\Log::debug('关系链修改,重建父表完成',$this->record_id);
}
private function insertParentOfMember($data)
{
foreach (array_chunk($data,10000) as $value) {
ParentOfMember::insert($value);
}
unset($data);
}
/**
* 重建子表数据
* @param $all_new_parent
* @param $all_child
* @author: Merlin
* @Time: 2021/3/2 15:13
*/
private function addMemberChildren($all_new_parent,$all_child)
{
\Log::debug('关系链修改,重建子表开始',$this->record_id);
if ($this->parent_id == 0) {
return;
}
$data = [];
//遍历所有父级,重建所有父级对当前会员子表
foreach ($all_new_parent as $parent) {
$data[] = [
'uniacid' => $this->member->uniacid,
'child_id' => $this->uid,
'level' => $parent->level + 1,
'member_id' => $parent->parent_id,
'created_at' => time()
];
}
$this->insertChildrenOfMember($data);
$data = [];
//遍历所有父级,重建所有父级对当前会员所有子级的子表
foreach ($all_new_parent as $parent) {
foreach ($all_child as $child) {
$data[] = [
'uniacid' => $this->member->uniacid,
'child_id' => $child->child_id,
//父级到当前会员层别+ 当前会员到子会员层级
'level' => $parent->level + 1 + $child->level,
'member_id' => $parent->parent_id,
'created_at' => time()
];
}
}
$this->insertChildrenOfMember($data);
$data = [];
//遍历所有子级,重建所有子级相对于当前会员的父级的节点
foreach ($all_child as $child) {
$data[] = [
'uniacid' => $this->member->uniacid,
'child_id' => $child->child_id,
//父级到当前会员层别+ 当前会员到子会员层级
'level' => 1 + $child->level,
'member_id' => $this->parent_id,
'created_at' => time()
];
}
//父级对当前会员节点
$data[] = [
'uniacid' => $this->member->uniacid,
'child_id' => $this->uid,
'level' => 1,
'member_id' => $this->parent_id,
'created_at' => time()
];
$this->insertChildrenOfMember($data);
// foreach (array_chunk($data,10000) as $value) {
// ChildrenOfMember::insert($value);
// }
\Log::debug('关系链修改,重建子表完成',$this->record_id);
}
private function insertChildrenOfMember($data)
{
foreach (array_chunk($data,10000) as $value) {
ChildrenOfMember::insert($value);
}
unset($data);
}
/**
* 更新会员及所有子级的relation
* @param $all_child
* @author: Merlin
* @Time: 2021/3/2 15:13
*/
private function updateMemberRelation($all_child)
{
\Log::debug('关系链修改,更新会员开始',$this->record_id);
//只影响当前会员,当前会员下级,当前会员下下级
$child_one = $all_child->where('level',1);
$child_two = $all_child->where('level',2)->load(['hasOneChildYzMember']);
//一级
foreach ($child_one as $child) {
$relation = $this->parent_id?implode(',',[$this->uid,(int)$this->parent_id,(int)$this->parent->parent_id]):implode(',',[$this->uid,(int)$this->parent_id]);
MemberShopInfo::where('member_id',$child['child_id'])->update(['relation'=>$relation]);
$this->updateCommission($child['child_id'],$relation,$this->uid);
$this->updateTeamDividend($child['child_id'],$relation,$this->uid);
}
//二级
foreach ($child_two as $child) {
$relation = [$child->hasOneChildYzMember->parent_id,$this->uid,$this->parent_id];
MemberShopInfo::where('member_id',$child['child_id'])->update(['relation'=>implode(',',$relation)]);
$this->updateCommission($child['child_id'],$relation,$child->hasOneChildYzMember->parent_id);
$this->updateTeamDividend($child['child_id'],$relation,$child->hasOneChildYzMember->parent_id);
}
if ($this->parent_id == 0) {
$relation = [$this->parent_id];
} elseif ($this->parent->parent_id == 0) {
$relation = [$this->parent_id,$this->parent->parent_id];
} else {
$parent_parent_id = MemberShopInfo::where('member_id',$this->parent->parent_id)->value('parent_id');
$relation = [$this->parent_id,$this->parent->parent_id,(int) $parent_parent_id];
}
$this->member->parent_id = $this->parent_id;
$this->member->relation = implode(',',$relation);
$this->member->inviter= 1;
$this->member->child_time= time();
$this->member->save();
$this->updateCommission($this->uid,$this->member->relation,$this->parent_id);
$this->updateTeamDividend($this->uid,$this->member->relation,$this->parent_id);
//触发监听
$agent_data = [
'member_id' => $this->uid,
'parent_id' => $this->parent_id,
'parent' => $this->member->relation
];
event(new RegisterByAgent($agent_data));
\Log::debug('关系链修改,更新会员结束',$this->record_id);
}
/**
* 修改关系链数据状态
* @param $status
* @param $start_time
* @author: Merlin
* @Time: 2021/3/2 15:13
*/
private function updateMemberRecord($status,$start_time)
{
//总耗时
$time = time() - $start_time;
MemberRecord::where('id',$this->record_id)->update(['status'=>$status,'time'=>$time]);
}
/**
* 是否有yz_agents表
* @author: Merlin
* @Time: 2021/3/2 15:14
*/
private function hasYzAgentsTable()
{
//判断是否有yz_agent表而不是判断插件有没有开启防止插件关闭时修改关系链开启后关系错误
if (Schema::hasTable('yz_agents')) {
$this->has_yz_agents = true;
}
}
/**
* 是否有yz_team_dividend_agency表
* @author: Merlin
* @Time: 2021/3/2 15:36
*/
private function hasYzTeamDividendAgency()
{
//判断是否有yz_team_dividend_agency表而不是判断插件有没有开启防止插件关闭时修改关系链开启后关系错误
if (Schema::hasTable('yz_team_dividend_agency')) {
$this->yz_team_dividend_agency = true;
}
}
/**
* 修改yz_agents的relation
* @param $member_id
* @param $parent_id
* @param $relation
* @author: Merlin
* @Time: 2021/3/2 15:14
*/
private function updateCommission($member_id,$relation,$parent_id)
{
if ($this->has_yz_agents) {
DB::table('yz_agents')->where('member_id',$member_id)->update(['parent_id'=>$parent_id,'parent'=>$relation]);
}
}
/**
* 修改yz_team_dividend_agency的relation
* @param $member_id
* @param $parent_id
* @param $relation
* @author: Merlin
* @Time: 2021/3/2 15:26
*/
private function updateTeamDividend($member_id,$parent_id,$relation)
{
if ($this->yz_team_dividend_agency) {
DB::table('yz_team_dividend_agency')->where('uid', $member_id)->update(['parent_id' => $parent_id, 'relation' => $relation]);
}
}
}

View File

@ -0,0 +1,51 @@
<?php
namespace app\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Ixudra\Curl\Facades\Curl;
class ModifySubPlatformJob implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
protected $platform;
protected $data;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($tripartite_provider,$datas)
{
//子平台信息修改
$this->platform = $tripartite_provider;
$this->data = $datas;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
foreach ($this->platform as $item){
\Log::debug('进入handle',$item);
\Log::debug('打印',[$item['domain'],$item['platform_uniacid']]);
$url = "{$item['domain']}/addons/yun_shop/api.php?i={$item['platform_uniacid']}&mid=0&type=5&shop_id=null&route=plugin.provider-platform.api.tripartiteProviderWithdrawal.SubplatformInfo.store";
\Log::debug('进入$url',$url);
// 提交推送请求
$response = Curl::to($url)->withData(['data' => json_encode($this->data,1)])->asJsonResponse(true)->post();
if ($response['result'] != 1) {
\Log::debug('域名为'.$item['domain'].'公众ID为'.$item['platform_uniacid'].'的平台的域名或公众号ID有误');
}
}
}
}

120
app/Jobs/OrderBonusJob.php Normal file
View File

@ -0,0 +1,120 @@
<?php
/**
* Author:
* Date: 2018/9/19
* Time: 下午3:37
*/
namespace app\Jobs;
use app\backend\modules\charts\models\OrderIncomeCount;
use app\common\events\order\CreatedOrderPluginBonusEvent;
use app\common\models\Order;
use app\common\models\order\OrderPluginBonus;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
class OrderBonusJob implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
protected $tableName;
protected $code;
protected $foreignKey;
protected $localKey;
protected $amountColumn;
protected $orderModel;
protected $totalDividend;
protected $condition;
public function __construct($tableName, $code, $foreignKey, $localKey, $amountColumn, $orderModel, $totalDividend = 0, $condition = null)
{
//跟订单使用同个队列运行防止产生相同的orderIncome
$queueCount = Order::queueCount();
if ($queueCount) {
$this->queue = 'order:' . ($orderModel->id % Order::queueCount());
}
$this->tableName = $tableName;
$this->code = $code;
$this->foreignKey = $foreignKey;
$this->localKey = $localKey;
$this->amountColumn = $amountColumn;
$this->orderModel = Order::find($orderModel->id);
$this->totalDividend = $totalDividend;
$this->condition = $condition;
}
public function handle()
{
// 验证表是否存在
$exists_table = Schema::hasTable($this->tableName);
if (!$exists_table) {
return;
}
$build = DB::table($this->tableName)
->select()
->where($this->foreignKey, (string)$this->orderModel[$this->localKey]);
//分红条件
if ($this->condition) {
$build = $build->where($this->condition);
}
// 分红记录IDs
$ids = $build->pluck('id');
// 分红总和
$sum = $build->sum($this->amountColumn);
if ($sum == 0) {
return;
}
$undividend = 0;
if ($this->totalDividend) {
$undividend = $this->totalDividend - $sum;
}
\Log::info($this->code . '分红插入表');
// 存入订单插件分红记录表
$model = OrderPluginBonus::addRow([
'order_id' => $this->orderModel->id,
'uniacid' => $this->orderModel->uniacid,
'table_name' => $this->tableName,
'ids' => $ids,
'code' => $this->code,
'amount' => $sum,
'undividend' => $undividend,
'status' => 0,
'price' => $this->orderModel->price,
'member_id' => $this->orderModel->uid,
'order_sn' => $this->orderModel->order_sn,
]);
if ($model) {
$this->addCount($sum, $undividend);
}
// 暂时不用, 门店利润 在 门店订单结算时重新计算, 各个插件产生分红的事件监听不同.
// 如果后期插件统一事件产生分红,再启用此事件
//event(new CreatedOrderPluginBonusEvent($model));
}
public function addCount($sum, $undividend)
{
// $count = 1;
$field = str_replace('-', '_', $this->code);
$order_income = OrderIncomeCount::where('order_id', $this->orderModel->id)->first();
if (!$order_income) {
\Log::debug('订单分红统计缺少订单ID' . $this->orderModel->id . '的数据');
$order_income = (new OrderCountContentJob($this->orderModel))->handle();
}
$order_income->$field = $sum;
$order_income->undividend += $undividend;
$order_income->save();
}
}

View File

@ -0,0 +1,42 @@
<?php
/**
* Author:
* Date: 2018/9/19
* Time: 下午3:37
*/
namespace app\Jobs;
use app\backend\modules\charts\models\OrderIncomeCount;
use app\common\events\order\CreatedOrderPluginBonusEvent;
use app\common\models\Order;
use app\common\models\order\OrderPluginBonus;
use app\common\models\OrderGoods;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Yunshop\StoreCashier\common\models\CashierOrder;
use Yunshop\StoreCashier\common\models\StoreOrder;
use Yunshop\Supplier\common\models\SupplierOrder;
class OrderBonusStatusJob implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
protected $orderId;
public function __construct($orderId)
{
$this->orderId = $orderId;
}
public function handle()
{
OrderPluginBonus::updateStatus($this->orderId);
}
}

View File

@ -0,0 +1,75 @@
<?php
/**
* Author:
* Date: 2018/9/19
* Time: 下午3:37
*/
namespace app\Jobs;
use app\common\events\order\CreatedOrderPluginBonusEvent;
use app\common\models\order\OrderPluginBonus;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
class OrderBonusUpdateJob implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
protected $tableName;
protected $code;
protected $foreignKey;
// protected $localKey;
protected $amountColumn;
protected $orderId;
protected $condition;
public function __construct($tableName, $code, $foreignKey, $amountColumn, $orderId, $condition = null)
{
$this->tableName = $tableName;
$this->code = $code;
$this->foreignKey = $foreignKey;
// $this->localKey = $localKey;
$this->amountColumn = $amountColumn;
$this->orderId = $orderId;
$this->condition = $condition;
}
public function handle()
{
// 验证表是否存在
$exists_table = Schema::hasTable($this->tableName);
if (!$exists_table) {
return;
}
$build = DB::table($this->tableName)
->select()
->where($this->foreignKey, $this->orderId);
if ($this->condition) {
$build = $build->where($this->condition);
}
// 分红记录IDs
$ids = $build->pluck('id');
// 分红总和
$sum = $build->sum($this->amountColumn);
if ($sum == 0) {
return;
}
// 存入订单插件分红记录表
$model = OrderPluginBonus::updateRow([
'order_id' => $this->orderId,
'ids' => $ids,
'code' => $this->code,
'amount' => $sum
]);
// 暂时不用, 门店利润 在 门店订单结算时重新计算, 各个插件产生分红的事件监听不同.
// 如果后期插件统一事件产生分红,再启用此事件
//event(new CreatedOrderPluginBonusEvent($model));
}
}

View File

@ -0,0 +1,192 @@
<?php
/**
* Author:
* Date: 2018/9/19
* Time: 下午3:37
*/
namespace app\Jobs;
use app\backend\modules\charts\models\OrderIncomeCount;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
class OrderCountContentJob implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
protected $orderModel;
protected $countModel;
public function __construct($orderModel)
{
$this->orderModel = $orderModel;
}
public function handle()
{
$data = [
'uniacid' => $this->orderModel->uniacid,
'price' => $this->orderModel->price,
'uid' => $this->orderModel->uid,
'order_sn' => $this->orderModel->order_sn,
'order_id' => $this->orderModel->id,
'status' => $this->orderModel->status,
'plugin_id' => $this->orderModel->plugin_id,
'dispatch_price' => $this->orderModel->dispatch_price,
'shop_name' => $this->orderModel->shop_name,
'cost_price' => $this->costPrice(),
//'day_time' => Carbon::today()->getTimestamp(),/
'day_time' => strtotime(date('Ymd',$this->orderModel->created_at)),//应该以订单创建时间为准,而不是以队列执行的时间
];
$data['address'] = $this->address();
$data['buy_name'] = $this->buyName();
$parent = $this->referrerName();
$data['parent_id'] = $parent['parent_id'];
$data['parent_name'] = $parent['nickname'];
// $build = OrderIncomeCount::where('order_id',$this->orderModel->id)->first();
// if ($build) {
// return $build;
// } else {
$build = OrderIncomeCount::create($data);
// }
return $build;
}
public function address()
{
$build = DB::table('yz_order_address')
->select()
->where('order_id', $this->orderModel->id);
$content = $build->first()['address'];
if (empty($content)) {
return '';
}
return $content;
}
public function buyName()
{
$build = DB::table('mc_members')
->select()
->where('uid', $this->orderModel->uid);
$content = $build->first()['nickname'];
if (empty($content)) {
return '';
}
return $content;
}
public function referrerName()
{
$referrerTable = DB::table('yz_member')
->select()
->where('member_id', $this->orderModel->uid);
$parent_id = $referrerTable->first()['parent_id'];
if ($parent_id) {
$build = DB::table('mc_members')
->select()
->where('uid', $parent_id);
$content['nickname'] = $build->first()['nickname'];
$content['parent_id'] = $parent_id;
} else {
$content['nickname'] = '总店';
$content['parent_id'] = 0;
}
return $content;
}
//记录商家名称
// public function shopName()
// {
// if ($this->orderModel->is_plugin) {
// $supplierTable = DB::table('yz_supplier_order')
// ->select()
// ->where('order_id', $this->orderModel->id);
// $supplier_id = $supplierTable->first()['supplier_id'];
// $build = DB::table('yz_supplier')
// ->select()
// ->where('id', $supplier_id);
// $content = $build->first()['username'];
// if (empty($content)) {
// $content = '供应商';
// }
//
// } elseif ($this->orderModel->plugin_id == 31) {
// $cashierTable = DB::table('yz_plugin_cashier_order')
// ->select()
// ->where('order_id', $this->orderModel->id);
// $cashier_id = $cashierTable->first()['cashier_id'];
// $build = DB::table('yz_store')
// ->select()
// ->where('cashier_id', $cashier_id);
// $content = $build->first()['store_name'];
// if (empty($content)) {
// $content = '收银台';
// }
//
// } elseif ($this->orderModel->plugin_id == 32) {
// $storeTable = DB::table('yz_plugin_store_order')
// ->select()
// ->where('order_id', $this->orderModel->id);
// $store_id = $storeTable->first()['store_id'];
// $build = DB::table('yz_store')
// ->select()
// ->where('id', $store_id);
// $content = $build->first()['store_name'];
// if (empty($content)) {
// return '门店';
// }
//
// } else {
// $content = '平台自营';
// }
// return $content;
// }
//记录成本价
public function costPrice()
{
if ($this->orderModel->plugin_id == 32) {
$order = DB::table('yz_plugin_store_order')
->select()
->where('order_id', $this->orderModel->id)
->first();
$cost_price = $order['amount'];
} else if ($this->orderModel->plugin_id == 31) {
$order = DB::table('yz_plugin_cashier_order')
->select()
->where('order_id', $this->orderModel->id)
->first();
$cost_price = $order['amount'];
} else if ($this->orderModel->plugin_id == 33) {
$order = DB::table('yz_plugin_hotel_order')
->select()
->where('order_id', $this->orderModel->id)
->first();
$cost_price = $order['amount'];
} else if ($this->orderModel->plugin_id == 36) {
$order = DB::table('yz_plugin_hotel_cashier_order')
->select()
->where('order_id', $this->orderModel->id)
->first();
$cost_price = $order['amount'];
} else {
$cost_price = $this->orderModel->cost_amount;
}
return $cost_price;
}
}

View File

@ -0,0 +1,84 @@
<?php
/**
* Created by PhpStorm.
* User: shenyang
* Date: 2017/9/18
* Time: 下午3:46
*/
namespace app\Jobs;
use app\common\events\order\AfterOrderCreatedEvent;
use app\common\facades\Setting;
use app\common\facades\SiteSetting;
use app\common\models\Order;
use app\common\models\OrderCreatedJob;
use app\frontend\modules\order\models\PreOrder;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\DB;
class OrderCreatedEventQueueJob implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
/**
* @var PreOrder
*/
protected $orderId;
/**
* OrderCreatedEventQueueJob constructor.
* @param $orderId
*/
public function __construct($orderId)
{
$queueCount = Order::queueCount();
if ($queueCount) {
$this->queue = 'order:' . ($orderId % Order::queueCount());
}
$this->orderId = $orderId;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
\Log::info('订单'.$this->orderId.'created任务开始执行');
DB::transaction(function () {
try {
\YunShop::app()->uniacid = null;
$orderId = $this->orderId;
$order = Order::find($orderId);
\YunShop::app()->uniacid = $order->uniacid;
Setting::$uniqueAccountId = $order->uniacid;
if(!$order->orderCreatedJob){
$order->setRelation('orderCreatedJob',new OrderCreatedJob(['order_id'=>$order->id]));
$order->orderCreatedJob->save();
}
if($order->orderCreatedJob->status == 'finished'){
\Log::error('订单完成事件触发失败',"{$orderId}orderCreatedJob记录已");
return;
}
$order->orderCreatedJob->status = 'finished';
$order->orderCreatedJob->save();
$event = new AfterOrderCreatedEvent($order);
app('events')->safeFire($event,$order->id);
}catch (\Exception $exception){
\Log::error('订单'.$this->orderId.'created任务异常',$exception);
throw $exception;
}
});
\Log::info('订单'.$this->orderId.'created任务执行完成');
}
}

View File

@ -0,0 +1,52 @@
<?php
/**
* Created by PhpStorm.
* User: win 10
* Date: 2019/1/12
* Time: 15:05
*/
namespace app\Jobs;
use app\backend\modules\charts\modules\team\models\MemberMonthOrder;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class OrderMemberMonthJob implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
protected $order;
public function __construct($order)
{
$this->order = $order;
}
public function handle()
{
$time = time();
$nowyear = date('Y',$time);
$nowmonth = date('n',$time);
$finder = MemberMonthOrder::where(['member_id'=>$this->order->uid,'year'=>$nowyear,'month'=>$nowmonth])->first();
if($finder){
$finder->order_num += 1;
$finder->order_price = bcadd($finder->order_price ,$this->order->price,2);
$finder->save();
}else{
$data=[];
$data['member_id'] = $this->order->uid;
$data['year'] = $nowyear;
$data['month'] = $nowmonth;
$data['order_num'] = 1;
$data['order_price'] = $this->order->price;
MemberMonthOrder::create($data);
}
}
}

View File

@ -0,0 +1,80 @@
<?php
/**
* Created by PhpStorm.
* User: shenyang
* Date: 2017/9/18
* Time: 下午3:46
*/
namespace app\Jobs;
use app\common\events\order\AfterOrderPaidEvent;
use app\common\facades\Setting;
use app\common\models\OrderCreatedJob;
use app\common\models\OrderPaidJob;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\DB;
use app\common\models\Order;
class OrderPaidEventQueueJob implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
/**
* @var Order
*/
protected $orderId;
/**
* OrderPaidEventQueueJob constructor.
* @param $orderId
*/
public function __construct($orderId)
{
$queueCount = Order::queueCount();
if ($queueCount) {
$this->queue = 'order:' . ($orderId % Order::queueCount());
}
$this->orderId = $orderId;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
\Log::info('订单'.$this->orderId.'paid任务开始执行');
DB::transaction(function () {
$orderId = $this->orderId;
\YunShop::app()->uniacid = null;
$order = Order::find($orderId);
\YunShop::app()->uniacid = $order->uniacid;
Setting::$uniqueAccountId = $order->uniacid;
if(!$order->orderPaidJob){
$order->setRelation('orderPaidJob',new OrderPaidJob(['order_id'=>$order->id]));
$order->orderPaidJob->save();
}
if ($order->orderPaidJob->status == 'finished') {
\Log::error('订单付款事件触发失败',"{$orderId}orderPaidJob记录已存在");
return;
}
$order->orderPaidJob->status = 'finished';
$order->orderPaidJob->save();
$event = new AfterOrderPaidEvent($order);
app('events')->safeFire($event,$order->id);
});
\Log::info('订单'.$this->orderId.'paid任务执行完成');
}
}

View File

@ -0,0 +1,80 @@
<?php
/**
* Created by PhpStorm.
* User: shenyang
* Date: 2017/9/18
* Time: 下午3:46
*/
namespace app\Jobs;
use app\common\events\order\AfterOrderReceivedEvent;
use app\common\facades\Setting;
use app\common\facades\SiteSetting;
use app\common\models\Order;
use app\common\models\OrderPaidJob;
use app\common\models\OrderReceivedJob;
use app\common\modules\shop\ShopConfig;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\DB;
class OrderReceivedEventQueueJob implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
/**
* @var Order
*/
protected $orderId;
/**
* OrderReceivedEventQueueJob constructor.
* @param $orderId
*/
public function __construct($orderId)
{
$queueCount = Order::queueCount();
if($queueCount){
$this->queue = 'order:' . ($orderId % Order::queueCount());
}
$this->orderId = $orderId;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
\Log::info('订单'.$this->orderId.'received任务开始执行');
DB::transaction(function () {
$orderId = $this->orderId;
\YunShop::app()->uniacid = null;
$order = Order::find($orderId);
\YunShop::app()->uniacid = $order->uniacid;
Setting::$uniqueAccountId = $order->uniacid;
if(!$order->orderReceivedJob){
$order->setRelation('orderReceivedJob',new OrderReceivedJob(['order_id'=>$order->id]));
$order->orderReceivedJob->save();
}
if($order->orderReceivedJob->status == 'finished'){
\Log::error('订单收货事件触发失败',"{$orderId}orderReceivedJob记录已");
return;
}
$order->orderReceivedJob->status = 'finished';
$order->orderReceivedJob->save();
$event = new AfterOrderReceivedEvent($order);
app('events')->safeFire($event,$order->id);
});
\Log::info('订单'.$this->orderId.'received任务执行完成');
}
}

View File

@ -0,0 +1,79 @@
<?php
/**
* Created by PhpStorm.
* User: shenyang
* Date: 2017/9/18
* Time: 下午3:46
*/
namespace app\Jobs;
use app\common\events\order\AfterOrderSentEvent;
use app\common\facades\Setting;
use app\common\facades\SiteSetting;
use app\common\models\Order;
use app\common\models\OrderReceivedJob;
use app\common\models\OrderSentJob;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\DB;
class OrderSentEventQueueJob implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
/**
* @var Order
*/
protected $orderId;
/**
* OrderReceivedEventQueueJob constructor.
* @param $orderId
*/
public function __construct($orderId)
{
$queueCount = Order::queueCount();
if($queueCount){
$this->queue = 'order:' . ($orderId % Order::queueCount());
}
$this->orderId = $orderId;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
\Log::info('订单'.$this->orderId.'sent任务开始执行');
DB::transaction(function () {
$orderId = $this->orderId;
\YunShop::app()->uniacid = null;
$order = Order::find($orderId);
\YunShop::app()->uniacid = $order->uniacid;
Setting::$uniqueAccountId = $order->uniacid;
if(!$order->orderSentJob){
$order->setRelation('orderSentJob',new OrderSentJob(['order_id'=>$order->id]));
$order->orderSentJob->save();
}
if($order->orderSentJob->status == 'finished'){
\Log::error('订单发货事件触发失败',"{$orderId}orderSentJob已完成");
return;
}
$order->orderSentJob->status = 'finished';
$order->orderSentJob->save();
$event = new AfterOrderSentEvent($order);
app('events')->safeFire($event,$order->id);
});
\Log::info('订单'.$this->orderId.'sent任务执行完成');
}
}

View File

@ -0,0 +1,29 @@
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/11/2
* Time: 11:06
*/
namespace app\Jobs;
use app\backend\modules\charts\modules\order\services\OrderStatisticsService;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class OrderStatisticsJob
{
use InteractsWithQueue, Queueable, SerializesModels;
public function __construct()
{
}
public function handle()
{
(new OrderStatisticsService())->orderStatistics();
}
}

View File

@ -0,0 +1,47 @@
<?php
/**
* Author:
* Date: 2018/10/4
* Time: 下午5:48
*/
namespace app\Jobs;
use app\common\models\finance\PointQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
class PointQueueJob implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
private $uniacid;
public function __construct($uniacid)
{
\YunShop::app()->uniacid = $uniacid;
$this->uniacid = $uniacid;
}
public function handle()
{
\YunShop::app()->uniacid = $this->uniacid;
$queues = $this->getQueues();
if ($queues->isEmpty()) {
return;
}
foreach ($queues as $queue) {
PointQueue::returnRun($queue);
}
}
private function getQueues()
{
return PointQueue::select()
->where('status', PointQueue::STATUS_RUNING)
->get();
}
}

View File

@ -0,0 +1,35 @@
<?php
/****************************************************************
* Author: libaojia
* Date: 2017/11/22 上午11:26
* Email: livsyitian@163.com
* QQ: 995265288
* User:
****************************************************************/
namespace app\Jobs;
use app\common\services\finance\PointToLoveService;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class PointToLoveJob implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
public $uniacid;
public function __construct($uniacid)
{
$this->uniacid = $uniacid;
}
public function handle()
{
(new PointToLoveService())->handleTransferQueue($this->uniacid);
}
}

41
app/Jobs/SendMessage.php Normal file
View File

@ -0,0 +1,41 @@
<?php
namespace app\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
class SendMessage implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
protected $class = null;
protected $func = null;
protected $condition = null;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($class, $func, $condition)
{
$this->class = $class;
$this->func = $func;
$this->condition = $condition;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$builder = call_user_func_array([$this->class, $this->func], $this->condition);
dd($builder);
//file_put_contents("")
}
}

View File

@ -0,0 +1,47 @@
<?php
namespace app\Jobs;
use app\common\facades\Setting;
use app\common\models\Goods;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class SetGoodsPriceJob implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
public $goodsIds;
public $uniacid;
public function __construct($goodsIds,$uniacid)
{
$this->goodsIds = $goodsIds;
$this->uniacid = $uniacid;
}
public function handle()
{
if (!$this->goodsIds) {
return;
}
Setting::$uniqueAccountId = $this->uniacid;
\YunShop::app()->uniacid = $this->uniacid;
$goods = Goods::uniacid()->whereIn('id',$this->goodsIds)
->with(['hasManyOptions' => function ($options) {
$options->select('id','goods_id','product_price');
}])
->get();
$goods->map(function (Goods $good) {
if ($good->has_option && !$good->hasManyOptions->isEmpty()) {//开启规格
$good->min_price = $good->hasManyOptions->min('product_price');
$good->max_price = $good->hasManyOptions->max('product_price');
} else {
$good->min_price = $good->price;
$good->max_price = $good->price;
}
$good->save();
});
}
}

View File

@ -0,0 +1,34 @@
<?php
namespace app\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Yunshop\SingleReturn\models\ReturnSingleModel;
class TmpAddSingleJob implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
protected $tmpSingleData;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($tmpSingleData)
{
$this->tmpSingleData = $tmpSingleData;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
ReturnSingleModel::insert($this->tmpSingleData);
}
}

View File

@ -0,0 +1,35 @@
<?php
namespace app\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Yunshop\SingleReturn\models\ReturnSingleTmp;
class TmpUpdateStatusJob implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
protected $tmpId;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($tmpId)
{
$this->tmpId = $tmpId;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
ReturnSingleTmp::updateStatusById($this->tmpId,1);
}
}

View File

@ -0,0 +1,45 @@
<?php
/**
* Created by PhpStorm.
* Author:
* Date: 2019/7/12
* Time: 上午 10:00
*/
namespace app\Jobs;
use app\common\models\Withdraw;
use app\frontend\modules\withdraw\services\BalanceAutomateAuditService;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
class WithdrawBalanceAuditFreeJob implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
/**
* @var Withdraw
*/
private $withdrawModel;
public function __construct(Withdraw $withdrawModel)
{
$this->withdrawModel = $withdrawModel;
}
/**
* @throws \app\common\exceptions\ShopException
*/
public function handle()
{
$automateAuditService = new BalanceAutomateAuditService($this->withdrawModel);
$automateAuditService->freeAudit();
}
}

View File

@ -0,0 +1,50 @@
<?php
/**
* Created by PhpStorm.
*
* User: king/QQ995265288
* Date: 2018/6/15 下午2:33
* Email: livsyitian@163.com
*/
namespace app\Jobs;
use app\frontend\modules\withdraw\models\Withdraw;
use app\frontend\modules\withdraw\services\AutomateAuditService;
use app\host\HostManager;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
class WithdrawFreeAuditJob implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
/**
* @var Withdraw
*/
private $withdrawModel;
public function __construct(Withdraw $withdrawModel)
{
$hostCount = count((new HostManager())->hosts() ?: []) ? : 1;
$this->queue = 'limit:'.($withdrawModel->member_id % (3 * $hostCount));
$this->withdrawModel = $withdrawModel;
}
public function handle()
{
$automateAuditService = new AutomateAuditService($this->withdrawModel);
try {
$automateAuditService->freeAudit();
} catch (\Exception $e) {
\Log::debug('提现审核',[$e->getMessage()]);
}
}
}

View File

@ -0,0 +1,34 @@
<?php
namespace app\Jobs;
use app\common\models\GoodsCouponQueue;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
class addGoodsCouponQueueJob implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
protected $queueData;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($queueData)
{
$this->queueData = $queueData;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
GoodsCouponQueue::insert($this->queueData);
}
}

View File

@ -0,0 +1,35 @@
<?php
namespace app\Jobs;
use app\common\models\Income;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
class addReturnIncomeJob implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
protected $incomeData;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($incomeData)
{
$this->incomeData = $incomeData;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
Income::insert($this->incomeData);
}
}

View File

@ -0,0 +1,35 @@
<?php
namespace app\Jobs;
use app\common\models\MemberCoupon;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
class addSendCouponJob implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
protected $couponData;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($couponData)
{
$this->couponData = $couponData;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
MemberCoupon::insert($this->couponData);
}
}

View File

@ -0,0 +1,35 @@
<?php
namespace app\Jobs;
use app\common\models\CouponLog;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
class addSendCouponLogJob implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
protected $logData;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($logData)
{
$this->logData = $logData;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
CouponLog::insert($this->logData);
}
}

View File

@ -0,0 +1,51 @@
<?php
namespace app\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Config;
use Yunshop\TeamReturn\models\TeamReturnLog;
use Yunshop\TeamReturn\services\TimedTaskReturnService;
class addTeamReturnLogJob implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
protected $teamReturnLogData;
protected $config;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($teamReturnLogData)
{
$this->teamReturnLogData = $teamReturnLogData;
$this->config = Config::get('income.teamReturn');
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$logId = TeamReturnLog::insertGetId($this->teamReturnLogData);
$incomeData = [
'uniacid' => $this->teamReturnLogData['uniacid'],
'member_id' => $this->teamReturnLogData['uid'],
'incometable_type' => $this->config['class'],
'incometable_id' => $logId,
'type_name' => $this->config['title'],
'amount' => $this->teamReturnLogData['amount'],
'status' => 0,
'pay_status' => 0,
'create_month' => date('Y-m'),
'created_at' => time()
];
(new TimedTaskReturnService())->addIncome($incomeData);
}
}

View File

@ -0,0 +1,46 @@
<?php
/**
* Created by PhpStorm.
*
*
*
* Date: 2021/6/15
* Time: 15:00
*/
namespace app\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\DB;
class deleteUniacidColumnsJob implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
protected $table_name;
protected $uniacid;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($table_name, $uniacid)
{
$this->table_name = $table_name;
$this->uniacid = $uniacid;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
DB::select("DELETE FROM `{$this->table_name}` WHERE `uniacid` = {$this->uniacid}");
}
}

View File

@ -0,0 +1,89 @@
<?php
/**
* Created by PhpStorm.
* User: dingran
* Date: 2018/10/24
* Time: 上午6:32
*/
namespace app\Jobs;
use app\backend\modules\member\models\Member;
use app\common\models\member\ChildrenOfMember;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class memberChildOfMemberJob implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
private $uniacid;
public $memberModel;
public $childMemberModel;
public function __construct($uniacid)
{
$this->uniacid = $uniacid;
}
public function handle()
{
\Log::debug('-----queue uniacid-----', $this->uniacid);
return $this->synRun($this->uniacid);
}
public function synRun($uniacid)
{
$childMemberModel = new ChildrenOfMember();
$memberModel = new Member();
$memberModel->_allNodes = collect([]);
\Log::debug('--------------清空表数据------------');
//$childMemberModel->DeletedData();
$memberInfo = $memberModel->getTreeAllNodes($uniacid);
if ($memberInfo->isEmpty()) {
\Log::debug('----is empty-----');
return;
}
foreach ($memberInfo as $item) {
$memberModel->_allNodes->put($item->member_id, $item);
}
\Log::debug('--------queue synRun -----');
foreach ($memberInfo as $key => $val) {
$attr = [];
\Log::debug('--------foreach start------', $val->member_id);
$data = $memberModel->getDescendants($uniacid, $val->member_id);
if (!$data->isEmpty()) {
\Log::debug('--------insert init------');
foreach ($data as $k => $v) {
if ($k != $val->member_id) {
$attr[] = [
'uniacid' => $uniacid,
'child_id' => $k,
'level' => $v['depth'] + 1,
'member_id' => $val->member_id,
'created_at' => time()
];
} else {
file_put_contents(storage_path("logs/" . date('Y-m-d') . "_batchchild.log"), print_r([$val->member_id, $v], 1), FILE_APPEND);
}
}
$childMemberModel->createData($attr);
}
}
}
}

View File

@ -0,0 +1,118 @@
<?php
/**
* Created by PhpStorm.
* User: dingran
* Date: 2018/10/22
* Time: 下午3:50
*/
namespace app\Jobs;
use app\backend\modules\member\models\Member;
use app\common\models\member\ChildrenOfMember;
use app\common\models\member\ParentOfMember;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class memberParentOfMemberJob implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
private $uniacid;
private $member_info;
public $memberModel;
public $childMemberModel;
public $pageSize;
public $offset;
public function __construct($uniacid, $pageSize, $offset)
{
$this->queue = 'statistics';
$this->uniacid = $uniacid;
$this->pageSize = $pageSize;
$this->offset = $offset;
}
public function handle()
{
\Log::debug('-----queue uniacid-----', $this->uniacid);
return $this->synRun($this->uniacid);
}
/**
* @param $uniacid
*/
public function synRun($uniacid)
{
ini_set("memory_limit","-1");
$parentMemberModle = new ParentOfMember();
$childMemberModel = new ChildrenOfMember();
$memberModel = new Member();
$memberModel->_allNodes = collect([]);
$memberInfo = $memberModel->getTreeAllNodes($uniacid);
if ($memberInfo->isEmpty()) {
\Log::debug('----is empty-----');
return;
}
foreach ($memberInfo as $item) {
$memberModel->_allNodes->put($item->member_id, $item);
}
$this->member_info = Member::getAllMembersInfosByQueue($uniacid, $this->pageSize,
$this->offset)->distinct()->get();
\Log::debug('------queue member count-----', $this->member_info->count());
if (!$this->member_info->isEmpty()) {
\Log::debug('-----queue member empty-----');
}
\Log::debug('--------queue synRun -----');
foreach ($this->member_info as $key => $val) {
$attr = [];
$child_attr = [];
\Log::debug('--------foreach start------', $val->member_id);
$memberModel->filter = [];
$data = $memberModel->getNodeParents($uniacid, $val->member_id);
if (!$data->isEmpty()) {
\Log::debug('--------insert init------');
foreach ($data as $k => $v) {
if ($k != $val->member_id) {
$attr[] = [
'uniacid' => $uniacid,
'parent_id' => $k,
'level' => $v['depth'] + 1,
'member_id' => $val->member_id,
'created_at' => time()
];
$child_attr[] = [
'uniacid' => $uniacid,
'child_id' => $val->member_id,
'level' => $v['depth'] + 1,
'member_id' => $k,
'created_at' => time()
];
} else {
file_put_contents(storage_path("logs/" . date('Y-m-d') . "_batchparent.log"),
print_r([$val->member_id, $v, 'insert'], 1), FILE_APPEND);
}
}
$parentMemberModle->createData($attr);
$childMemberModel->createData($child_attr);
}
}
}
}

View File

@ -0,0 +1,174 @@
<?php
/**
* Created by PhpStorm.
* User: dingran
* Date: 2018/7/6
* Time: 下午3:24
*/
namespace app\Jobs;
use app\common\models\Member;
use app\common\models\MemberShopInfo;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Yunshop\Commission\models\Agents;
use Yunshop\Poster\models\Poster;
use Yunshop\Poster\models\PosterQrcode;
use Yunshop\Poster\models\Qrcode;
class scanPostConcernQueueJob implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
/**
* 处理事件
*
* @var
*/
protected $postProcessor;
/**
* 当前公众号
*
* @var
*/
protected $uniacid;
/**
* 扫码关注者
*
* @var
*/
protected $from;
/**
* 海报用户
*
* @var
*/
protected $to;
/**
* 海报消息
*
* @var
*/
protected $msg;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($uniacid, $postProcessor)
{
$this->uniacid = $uniacid;
$this->postProcessor = $postProcessor;
$this->msg = $this->postProcessor->message;
$this->from = $this->postProcessor->message['fromusername'];
$this->to = $this->postProcessor->message['eventkey'];
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
\Log::debug('-------scan poster from-----', [$this->from]);
\Log::debug('-------scan poster to-------', [$this->to]);
//$from关注者用户是否存在存在验证上线
$from_member_model = MemberShopInfo::getMemberShopInfoByOpenid($this->from);
if (!is_null($from_member_model)) {
//\Log::debug('--------poster member is not null------');
$from_member_id = $from_member_model->member_id;
$from_parent_id = $from_member_model->parent_id;
//\Log::debug('------poster from member id----', [$from_member_id]);
//\Log::debug('------poster from parent id----', [$from_parent_id]);
//$to海报用户信息
$qrcodeId = $this->getPosterForUser($this->msg);
//\Log::debug('------poster qrcodeId-----', [$qrcodeId]);
$to_member_id = PosterQrcode::getRecommenderIdByQrcodeId($qrcodeId);
//\Log::debug('------poster to_member_id-----', [$to_member_id]);
$posterId = PosterQrcode::getPosterIdByQrcodeId($qrcodeId);
$poster = Poster::getPosterById($posterId);
if ($poster->auto_sub == 0) {
\Log::debug('-------------未开启了海报的"扫码关注成为下线"------------');
return;
}
if (!empty($to_member_id)
&& date('Ymd') == $from_member_model->created_at->format('Ymd')
&& $from_member_id != $to_member_id
&& 0 == $from_parent_id
) {
//$from->parent_id 是否为0是0改为$to->uid
$from_member_model->parent_id = $to_member_id;
//\Log::debug('------poster modify parent_id----');
$from_member_model->save();
//分销-会员关系链
Member::createRealtion($from_member_id, $to_member_id);
//更新分销商
$this->updateAgent($from_member_id);
}
} else {
\Log::debug('-----poster member is null by openid-----', [$this->from]);
}
}
private function getPosterForUser($msg)
{
$msgEvent = strtolower($msg['event']);
$msgEventKey = strtolower($msg['eventkey']);
if ($msgEvent == 'scan') {
$scene = $msgEventKey;
} else {
//如果用户之前未关注,进行关注后推送的 Event 是 "subscribe",
//推送的 EventKey 是以 "qrscene_" 为前缀,后面跟着二维码的参数值.
//因为需求中提到存在这种情况 -- "尽管之前已经关注,但还不是商城的会员",
//所以这里并不根据 Event 类型来判别是否是会员, 只是识别出二维码的特征值(场景值/场景字符串), 用于定位二维码 ID
$scene = substr($msgEventKey, strpos($msgEventKey, '_') + 1);
}
if (is_int($scene) && ($scene != 0)) { //临时二维码
$sceneId = $scene;
$qrcode = Qrcode::getQrcodeBySceneId($sceneId);
} else { //永久二维码
$sceneStr = $scene;
$qrcode = Qrcode::getForeverQrcodeBySceneStr($sceneStr);
}
return $qrcode->id;
}
private function updateAgent($from_member_id)
{
$from_member = MemberShopInfo::getMemberShopInfo($from_member_id);
$agent = Agents::getAgentByMemberId($from_member_id)->first();
if (!is_null($agent) && (0 == $agent->parent_id || $agent->parent_id != $from_member->parent_id)) {
$agent->parent_id = $from_member->parent_id;
$agent->parent = $from_member->relation;
$agent->save();
//\Log::debug('------poster modify agent----');
}
}
}

View File

@ -0,0 +1,37 @@
<?php
namespace app\Jobs;
use app\common\models\GoodsCouponQueue;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
class updateCouponQueueJob implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
protected $condition;
protected $updatedData;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($condition, $updatedData)
{
$this->condition = $condition;
$this->updatedData = $updatedData;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
GoodsCouponQueue::updatedData($this->condition, $this->updatedData);
}
}

View File

@ -0,0 +1,36 @@
<?php
namespace app\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Yunshop\SingleReturn\models\ReturnSingleModel;
class updatedSingleJob implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
protected $singleId;
protected $returnSingledata;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($singleId,$returnSingledata)
{
$this->singleId = $singleId;
$this->returnSingledata = $returnSingledata;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
ReturnSingleModel::where('id',$this->singleId)->update($this->returnSingledata);
}
}

View File

@ -0,0 +1,154 @@
<?php
/**
* Created by PhpStorm.
* User: dingran
* Date: 2018/10/16
* Time: 上午10:24
*/
namespace app\Jobs;
use app\backend\modules\member\models\Member;
use app\common\helpers\Cache;
use app\common\models\AccountWechats;
use app\frontend\modules\member\models\MemberUniqueModel;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class wechatUnionidJob implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
private $uniacid;
private $member_info;
public function __construct($uniacid, $member_info)
{
$this->uniacid = $uniacid;
$this->member_info = $member_info->toArray();
}
public function handle()
{
\Log::debug('-----queque uniacid-----', $this->uniacid);
return $this->synRun($this->uniacid, $this->member_info);
}
public function synRun($uniacid, $member_info)
{
$account = AccountWechats::getAccountByUniacid($uniacid);
$appId = $account->key;
$appSecret = $account->secret;
$global_access_token_url = $this->_getAccessToken($appId, $appSecret);
$global_token = \Curl::to($global_access_token_url)
->asJsonResponse(true)
->get();
return $this->requestWechatApi($uniacid, $member_info, $global_token);
}
private function requestWechatApi($uniacid, $member_info, $global_token)
{
if (!is_null($member_info)) {
\Log::debug('------queque member_info-------');
$time = time();
$path = 'logs/' . $time . '_member_openid.log';
$upgrade_path = 'logs/' . $time . '_upgrade_member_openid.log';
$error_path = 'logs/' . $time . '_error_member_openid.log';
collect($member_info)->map(function($item) use ($uniacid, $global_token, $path, $upgrade_path, $error_path) {
\Log::debug('------queuqe coll-----', $item);
if (!is_null($item)) {
$UnionidInfo = MemberUniqueModel::getUnionidInfoByMemberId($uniacid, $item['uid'])->first();
$this->printLog($path, $item['openid'] . '-' . $item['uid']);
if (is_null($UnionidInfo) && !empty($item['openid'])) {
\Log::debug('----start---', [$item['uid']]);
$ids = Cache::get('queque_wechat_ids') ?: [];
if (in_array($item['uid'], $ids)) {
return $item;
}
$global_userinfo_url = $this->_getInfo($global_token['access_token'], $item['openid']);
$user_info = \Curl::to($global_userinfo_url)
->asJsonResponse(true)
->get();
if (isset($user_info['errcode'])) {
\Log::debug('----error---', [$item['uid']]);
$this->printLog($error_path, $item['uid'] . '-' . $user_info['errmsg']);
return ['error' => 1, 'msg' => $user_info['errmsg']];
}
if (isset($user_info['unionid'])) {
MemberUniqueModel::insertData(array(
'uniacid' => $uniacid,
'unionid' => $user_info['unionid'],
'member_id' => $item['uid'],
'type' => 1
));
array_push($ids, $item['uid']);
Cache::put('queque_wechat_ids', $ids, 60);
\Log::debug('----insert---', [$item['uid']]);
$this->printLog($upgrade_path, $item['openid'] . '-' . $item['uid']);
}
}
return $item;
}
return $item;
});
Cache::setUniacid($uniacid);
if (Cache::has('queque_wechat_page')) {
\Log::debug('----queque cache1----');
$page = Cache::get('queque_wechat_page');
$page++;
\Log::debug('----queque cache1 page----', $page);
Cache::put('queque_wechat_page', $page, 30);
} else {
\Log::debug('----queque cache2----');
Cache::put('queque_wechat_page', 1, 30);
}
}
}
private function printLog($path, $openid)
{
file_put_contents(storage_path($path), $openid . "\r\n", FILE_APPEND);
}
/**
* 获取全局ACCESS TOKEN
* @return string
*/
private function _getAccessToken($appId, $appSecret)
{
return 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . $appId . '&secret=' . $appSecret;
}
/**
* 获取用户信息
*
* 是否关注公众号
*
* @param $accesstoken
* @param $openid
* @return string
*/
private function _getInfo($accesstoken, $openid)
{
return 'https://api.weixin.qq.com/cgi-bin/user/info?access_token=' . $accesstoken . '&openid=' . $openid;
}
}

75
app/Kernel.php Normal file
View File

@ -0,0 +1,75 @@
<?php
namespace app;
use app\common\middleware\Install;
use app\common\middleware\ShopRoute;
use Illuminate\Cookie\Middleware\EncryptCookies;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
class Kernel extends HttpKernel
{
/**
* The application's global HTTP middleware stack.
*
* These middleware are run during every request to your application.
*
* @var array
*/
protected $middleware = [
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
ShopRoute::class
];
/**
* The application's route middleware groups.
*
* @var array
*/
protected $middlewareGroups = [
'web' => [
//EncryptCookies::class,
//\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
//\Illuminate\Session\Middleware\StartSession::class,
//\Illuminate\View\Middleware\ShareErrorsFromSession::class,
//VerifyCsrfToken::class,
],
'admin' => [
//EncryptCookies::class,
Install::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
\Illuminate\Session\Middleware\AuthenticateSession::class,
],
'api' => [
'throttle:60,1',
],
'business' => [
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
\Illuminate\Session\Middleware\AuthenticateSession::class,
],
];
/**
* The application's route middleware.
*
* These middleware may be assigned to groups or used individually.
*
* @var array
*/
protected $routeMiddleware = [
'auth' => \app\common\middleware\Authenticate::class,
'authAdmin' => \app\common\middleware\AuthenticateAdmin::class,
'authShop' => \app\common\middleware\AuthenticateShop::class,
'checkPasswordSafe' => \app\common\middleware\CheckPasswordSafe::class,
'shopBootStrap' => \app\common\middleware\ShopBootstrap::class,
'business' => \business\middleware\Business::class,
'businessLogin' => \business\middleware\BusinessLogin::class,
'AuthenticateFrontend'=>\app\common\middleware\AuthenticateFrontend::class,
];
}

34
app/Mail/ErrorReport.php Normal file
View File

@ -0,0 +1,34 @@
<?php
namespace app\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
class ErrorReport extends Mailable
{
use Queueable, SerializesModels;
private $data = '';
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($title,$data)
{
$this->data = $data;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->view('emails.errorReport',['data'=>$this->data]);
}
}

38
app/Mail/OrderInvoice.php Normal file
View File

@ -0,0 +1,38 @@
<?php
namespace app\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
class OrderInvoice extends Mailable
{
use Queueable, SerializesModels;
protected $data = [];
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($imagePath)
{
$this->data['imagePath'] = $imagePath;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->view('emails.orderInvoice', ['data' =>$this->data]);
}
}

View File

@ -0,0 +1,43 @@
<?php
/**
* Created by PhpStorm.
*
*
*
* Date: 2022/2/22
* Time: 16:03
*/
namespace app\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class OrderInvoiceEmail extends Mailable
{
use Queueable, SerializesModels;
public $data;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($data)
{
$this->data = $data;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->from($this->data['send_email'])->view('invoice.goEmail', ['data' => $this->data]);
}
}

76
app/Upload.php Normal file
View File

@ -0,0 +1,76 @@
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use zgldh\UploadManager\UploadManager;
/**
* Class Upload
* @property string $name
* @property string $description
* @property string $disk
* @property string $path
* @property string $size
* @property string $user_id
* @package App
*/
class Upload extends Model
{
protected $table = 'uploads';
public function user()
{
return $this->belongsTo('App\User', 'user_id', 'id');
}
public function uploadable()
{
return $this->morphTo();
}
public function getUrlAttribute()
{
$manager = UploadManager::getInstance();
$url = $manager->getUploadUrl($this->disk, $this->path);
return $url;
}
public function deleteFile($autoSave = true)
{
if ($this->path) {
$disk = \Storage::disk($this->disk);
if ($disk->exists($this->path)) {
$disk->delete($this->path);
$this->path = '';
if($autoSave)
{
$this->save();
}
}
}
}
public function isInDisk($diskName)
{
return $this->disk == $diskName ? true : false;
}
public function moveToDisk($newDiskName)
{
if ($newDiskName == $this->disk) {
return true;
}
$currentDisk = \Storage::disk($this->disk);
$content = $currentDisk->get($this->path);
$newDisk = \Storage::disk($newDiskName);
$newDisk->put($this->path, $content);
if ($newDisk->exists($this->path)) {
$this->disk = $newDiskName;
$this->save();
$currentDisk->delete($this->path);
return true;
}
return false;
}
}

View File

@ -0,0 +1,76 @@
<?php
/**
* Created by PhpStorm.
* Author:
* Date: 2017/4/27
* Time: 下午4:26
*/
namespace app\backend\controllers;
use app\common\components\BaseController;
use app\common\models\Address;
use app\common\models\Street;
class AddressController extends BaseController
{
public function getAddress()
{
$addressData = [];
switch (\YunShop::request()->type) {
case 'province':
$addressData = Address::getProvince();
break;
case 'city':
$addressData = Address::getCityByParentId(\YunShop::request()->parentid);
break;
case 'district':
$addressData = Address::getAreaByParentId(\YunShop::request()->parentid);
break;
case 'street':
$addressData = Street::getStreetByParentId(\YunShop::request()->parentid);
break;
}
echo json_encode($addressData);
}
public function getAjaxAddress()
{
$addressData = [];
switch (request()->input('type')) {
case 'province':
$addressData = Address::getProvince();
break;
case 'city':
$addressData = Address::getCityByParentId(request()->input('parentid'));
break;
case 'district':
$addressData = Address::getAreaByParentId(request()->input('parentid'));
break;
case 'street':
$addressData = Street::getStreetByParentId(request()->input('parentid'));
break;
}
return $this->successJson('ok',$addressData);
}
public function getAjaxExpress()
{
$data = \app\common\repositories\ExpressCompany::create()->all();
return $this->successJson('ok',$data);
}
public function test()
{
$pay = new \app\common\services\AliPay();
$result = $pay->withdrawCert('ywkpgl2852@sandbox.com','沙箱环境','CS'.time(),'1');
dd($result);
}
}

View File

@ -0,0 +1,28 @@
<?php
/****************************************************************
* Author: libaojia
* Date: 2017/7/12 上午10:57
* Email: livsyitian@163.com
* QQ: 995265288
* User:
****************************************************************/
namespace app\backend\controllers;
use app\common\components\BaseController;
class CacheController extends BaseController
{
protected $isPublic = true;
public function update()
{
\Artisan::call('config:cache');
\Artisan::call('view:clear');
\Cache::flush();
return $this->message('缓存更新成功');
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace app\backend\controllers;
use app\common\components\BaseController;
use app\common\services\ComponentService;
class ComponentController extends BaseController
{
/**
* 跳转页面的链接
* @return \Illuminate\Http\JsonResponse
*/
public function getJumpLink()
{
$data['jump_link'] = ComponentService::getComponentList();
return $this->successJson('ok',$data);
}
}

View File

@ -0,0 +1,49 @@
<?php
/**
* Created by PhpStorm.
* User: shenyang
* Date: 2018/7/9
* Time: 下午5:32
*/
namespace app\backend\controllers;
use Illuminate\Routing\Controller;
class CornController extends Controller
{
public function index()
{
// Get security key from config
$cronkeyConfig = \Config::get('liebigCron.cronKey');
// If no security key is set in the config, this route is disabled
if (empty($cronkeyConfig)) {
\Log::error('Cron route call with no configured security key');
\App::abort(404);
}
// Get security key from request
$cronkeyRequest = request()->get('key');
// Create validator for security key
$validator = \Validator::make(
array('cronkey' => $cronkeyRequest),
array('cronkey' => 'required|alpha_num')
);
if ($validator->passes()) {
if ($cronkeyConfig === $cronkeyRequest) {
\Artisan::call('cron:run', array());
} else {
// Configured security key is not equals the sent security key
\Log::error('Cron route call with wrong security key');
\App::abort(404);
}
} else {
// Validation not passed
\Log::error('Cron route call with missing or no alphanumeric security key');
\App::abort(404);
}
return;
}
}

View File

@ -0,0 +1,472 @@
<?php
/**
* Created by PhpStorm.
* User: dingran
* Date: 2018/8/8
* Time: 下午6:52
*/
namespace app\backend\controllers;
use app\common\components\BaseController;
use app\common\models\Income;
use app\common\models\Order;
use app\common\services\member\MemberRelation;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Support\Facades\DB;
use Yunshop\Commission\models\Agents;
use Yunshop\Commission\models\Commission;
use Yunshop\Commission\models\CommissionOrder;
use Yunshop\Commission\services\CommissionOrderService;
use Yunshop\Mryt\job\UpgradeByRegisterJob;
use Yunshop\Mryt\listeners\MemberRelationEventListener;
use Yunshop\Mryt\services\UpgradeService;
use Yunshop\TeamDividend\models\TeamDividendModel;
class FixController extends BaseController
{
use DispatchesJobs;
public function getAgentUniacid()
{
$agents = DB::select('select ya.* FROM ims_yz_agents as ya LEFT JOIN ims_yz_agent_level as al on al.id = ya.agent_level_id where ya.uniacid <> al.uniacid');
echo '该系统有'. count($agents).'条错误数据。';
}
public function agentUniacid()
{
$agents = DB::select('select ya.* FROM ims_yz_agents as ya LEFT JOIN ims_yz_agent_level as al on al.id = ya.agent_level_id where ya.uniacid <> al.uniacid');
$success = 0;
$error = 0;
foreach ($agents as $agent) {
$log = DB::table('yz_commission_log')
->where('uid',$agent['member_id'])
->where('after_level_id',$agent['agent_level_id'])
->orderBy('id','desc')
->first();
$this->fixAgentUniacid($agent, $log['before_level_id']);
$success ++;
}
echo '成功:'. $success.'。失败:'.$error;
}
public function fixAgentUniacid($agent, $level_id)
{
if ($level_id == 0) {
DB::table('yz_agents')->where('member_id', $agent['member_id'])->update(['agent_level_id' => 0]);
} else {
$level = DB::table('yz_agent_level')->where('id',$level_id)->first();
if ($agent['uniacid'] == $level['uniacid']) {
DB::table('yz_agents')->where('member_id', $agent['member_id'])->update(['agent_level_id' => $level_id,'updated_at' => time()]);
} else {
$log = DB::table('yz_commission_log')
->where('uid',$agent['member_id'])
->where('after_level_id',$level_id)
->orderBy('id','desc')
->first();
$this->fixAgentUniacid($agent, $log['before_level_id']);
}
}
}
public function errorDividendData()
{
$a = DB::table('yz_team_dividend')->select(['yz_team_dividend.uniacid as tuniacid','mc_members.uniacid as uniacid','yz_team_dividend.id' , 'yz_order.id as orderid', 'yz_order.uid', 'yz_team_dividend.order_sn', 'yz_team_dividend.member_id', 'yz_team_dividend.status'])
->join('yz_order', 'yz_order.order_sn', '=', 'yz_team_dividend.order_sn')
->join('mc_members', 'mc_members.uid', '=', 'yz_team_dividend.member_id')
->where(DB::raw('ims_mc_members.uniacid != ims_yz_team_dividend.uniacid'))
->orderBy('yz_team_dividend.id', 'asc')
->get();
dump($a);
}
public function handleCommissionOrder()
{
$handle = 0;
$success = 0;
$waitCommissionOrder = CommissionOrder::uniacid()->whereStatus(0)->get();
$status = \Setting::get('plugin.commission')['settlement_event'] ? 1 : 3;
if (!$waitCommissionOrder->isEmpty()) {
foreach ($waitCommissionOrder as $key => $commissionOrder) {
$orderModel = Order::uniacid()->whereId($commissionOrder->ordertable_id)->first();
if ($orderModel->status >= $status) {
$handle += 1;
$commissionOrder->status = 1;
if ($status == 1) {
$commissionOrder->recrive_at = strtotime($orderModel->pay_time);
} else {
$commissionOrder->recrive_at = strtotime($orderModel->finish_time);
}
if ($commissionOrder->save()) {
$success += 1;
}
}
unset($orderModel);
}
}
echo "分销订单未结算总数:{$waitCommissionOrder->count()},已完成订单数:{$handle}, 执行成功数:{$success}";
}
public function fixTeam()
{
$search_date = strtotime('2018-10-25 12:00:00');
$error = [];
$tmp = [];
$pos = [];
$res = DB::table('yz_team_dividend as t')
->select(['t.id' , 'o.id as orderid', 'o.uid', 't.order_sn', 't.member_id', 't.status'])
->join('yz_order as o', 'o.order_sn', '=', 't.order_sn')
->where('t.created_at', '>', $search_date)
->orderBy('t.id', 'asc')
->get();
if (!$res->isEmpty()) {
foreach ($res as $key => $rows) {
if (!$tmp[$rows['orderid']]) {
// $pos = [$rows->member_id => $key];
$tmp[$rows['orderid']] = [
'id' => $rows['id'],
'order_id' => $rows['orderid'],
'uid' => $rows['uid'],
'order_sn' => $rows['order_sn'],
'parent_id' => $rows['member_id'],
'status' => $rows['status'],
];
file_put_contents(storage_path('logs/team_fix.log'), print_r($tmp, 1), FILE_APPEND);
} else {
// $k = $pos[$rows->member_id];
// $tmp[$k]['member_id'][] = $rows->member_id;
}
}
}
//订单会员->关系链 不匹配
foreach ($tmp as $k => $v) {
$total = DB::table('yz_member')
->where('member_id', '=', $v['uid'])
->where('parent_id', '=', $v['parent_id'])
->count();
if (0 == $total) {
$error[] = $v;
file_put_contents(storage_path('logs/team_fix_error.log'), print_r($v, 1), FILE_APPEND);
}
}
collect($error)->each(function ($item) {
if (0 == $item['status']) {
$model = Order::find($item['order_id']);
if (!is_null($model)) {
DB::transaction(function () use ($item, $model) {
DB::table('yz_team_dividend')
->where('order_sn', '=', $item['order_sn'])
->delete();
DB::table('yz_order_plugin_bonus')
->where('order_id', '=', $item['order_id'])
->where('table_name', '=', 'yz_team_dividend')
->delete();
(new \Yunshop\TeamDividend\Listener\OrderCreatedListener)->fixOrder($model);
file_put_contents(storage_path('logs/team_fix_del.log'), print_r($item, 1), FILE_APPEND);
});
}
}
});
echo '数据修复ok';
}
public function fixArea()
{
$search_date = strtotime('2018-10-25 12:00:00');
$error = [];
$tmp = [];
$res = DB::table('yz_area_dividend as t')
->select(['t.id' , 'o.id as orderid', 'o.uid', 't.order_sn', 't.member_id', 't.status'])
->join('yz_order as o', 'o.order_sn', '=', 't.order_sn')
->where('t.created_at', '>', $search_date)
->orderBy('t.id', 'asc')
->get();
if (!$res->isEmpty()) {
foreach ($res as $key => $rows) {
if (!$tmp[$rows['orderid']]) {
// $pos = [$rows->member_id => $key];
$tmp[$rows['orderid']] = [
'id' => $rows['id'],
'order_id' => $rows['orderid'],
'uid' => $rows['uid'],
'order_sn' => $rows['order_sn'],
'parent_id' => $rows['member_id'],
'status' => $rows['status'],
];
file_put_contents(storage_path('logs/area_fix.log'), print_r($tmp, 1), FILE_APPEND);
}
}
}
// //订单会员->关系链 不匹配
// foreach ($tmp as $k => $v) {
// $total = DB::table('yz_member')
// ->where('member_id', '=', $v['uid'])
// ->where('parent_id', '=', $v['parent_id'])
// ->count();
//
// if (0 == $total) {
// $error[] = $v;
//
// file_put_contents(storage_path('logs/area_fix_error.log'), print_r($v, 1), FILE_APPEND);
// }
// }
collect($tmp)->each(function ($item) {
if (0 == $item['status']) {
$model = Order::find($item['order_id']);
DB::transaction(function () use ($item, $model) {
DB::table('yz_area_dividend')
->where('order_sn', '=', $item['order_sn'])
->delete();
DB::table('yz_order_plugin_bonus')
->where('order_id', '=', $item['order_id'])
->where('table_name', '=', 'yz_area_dividend')
->delete();
(new \Yunshop\AreaDividend\Listener\OrderCreatedListener)->fixOrder($model);
file_put_contents(storage_path('logs/area_fix_del.log'), print_r($item, 1), FILE_APPEND);
});
}
});
echo '数据修复ok';
}
public function fixIncome()
{
$count = 0;
$income = Income::whereBetween('created_at', [1539792000,1541433600])->get();
foreach ($income as $value) {
$pattern1 = '/\\\u[\d|\w]{4}/';
preg_match($pattern1, $value->detail, $exists);
if (empty($exists)) {
$pattern2 = '/(u[\d|\w]{4})/';
$value->detail = preg_replace($pattern2, '\\\$1', $value->detail);
$value->save();
$count++;
}
}
echo "修复了{$count}";
}
public function mr()
{
$m = new MemberRelationEventListener();
$parent_id = 6080;
$m->fixRelation($parent_id);
}
public function ma()
{
$m = new MemberRelationEventListener();
$parent_id = 6080;
$m->fixAward($parent_id);
}
public function changeField()
{
$sql1 = 'ALTER TABLE `' . DB::getTablePrefix() . 'users_permission` MODIFY `modules` text NULL';
$sql2 = 'ALTER TABLE `' . DB::getTablePrefix() . 'users_permission` MODIFY `templates` text NULL';
try {
DB::select($sql1);
DB::select($sql2);
echo '数据已修复';
} catch (\Exception $e) {
echo $e->getMessage();
}
}
public function handleTeamOrder()
{
$handle = 0;
$success = 0;
$status = \Setting::get('plugin.team_dividend')['settlement_event'] ? 1 : 3;
$waitTeamOrder = \Yunshop\TeamDividend\models\TeamDividendModel::uniacid()->whereStatus(0)->get();
if (!$waitTeamOrder->isEmpty()) {
foreach ($waitTeamOrder as $key => $teamOrder) {
$orderModel = \app\common\models\Order::uniacid()->where('order_sn',$teamOrder->order_sn)->first();
if ($orderModel->status >= $status) {
$handle += 1;
$teamOrder->recrive_at = strtotime($orderModel->pay_time);
$teamOrder->is_pay = 1;
if ($teamOrder->save()) {
$success += 1;
}
}
unset($orderModel);
}
}
echo "经销商订单未结算总数:{$waitTeamOrder->count()},已完成订单数:{$handle}, 执行成功数:{$success}";
}
public function handleAreaOrder()
{
$handle = 0;
$success = 0;
$waitTeamOrder = \Yunshop\AreaDividend\models\AreaDividend::uniacid()->whereStatus(0)->get();
if (!$waitTeamOrder->isEmpty()) {
foreach ($waitTeamOrder as $key => $teamOrder) {
$orderModel = \app\common\models\Order::uniacid()->where('order_sn',$teamOrder->order_sn)->first();
if ($orderModel->status == 3) {
$handle += 1;
$teamOrder->recrive_at = strtotime($orderModel->finish_time);
if ($teamOrder->save()) {
$success += 1;
}
}
unset($orderModel);
}
}
echo "区域分红订单未结算总数:{$waitTeamOrder->count()},已完成订单数:{$handle}, 执行成功数:{$success}";
}
public function fixCommissionAmount()
{
$CommissionOrder = CommissionOrder::uniacid()->whereNull('commission_amount')->get();
$set = \Setting::get('plugin.commission');
$count = 0;
foreach ($CommissionOrder as $commission) {
$orderModel = Order::find($commission->ordertable_id);
$orderGoods = $orderModel->hasManyOrderGoods;
$commissionAmount = 0;
$formula = '';
foreach ($orderGoods as $key => $og) {
//获取商品分销设置信息
$commissionGoods = Commission::getGoodsById($og->goods_id)->first();
if (!$commissionGoods->is_commission) {
continue;
}
if ($commissionGoods) {
if ($commissionGoods['has_commission'] == '1') {
//商品独立佣金
$commissionAmount += $og['payment_amount']; //分佣计算金额
$formula .= "+商品独立佣金";//分佣计算方式
} else {
$countAmount = CommissionOrderService::getCountAmount($orderModel, $og, '', $set);
$commissionAmount += $countAmount['amount'];
$formula = $countAmount['method'];
}
}
}
$commission->commission_amount = $commissionAmount;
$commission->formula = $formula;
$commission->save();
$count++;
}
echo '修改了'.$count.'条信息';
}
public function fixNotCommission()
{
$order_sn = \YunShop::request()->order_sn;
$order = Order::uniacid()->where('order_sn', $order_sn)->first();
$commission_order = CommissionOrder::uniacid()->where('ordertable_id', $order->id)->first();
if ($commission_order) {
echo '已有这条分红';
} else {
$result = (new \Yunshop\Commission\Listener\OrderCreatedListener())->handler($order);
$commission_order = CommissionOrder::uniacid()->where('ordertable_id', $order->id)->first();
if ($commission_order) {
echo '成功';
} else {
echo '不成功,请检查设置是否正确,一定绝对必须要检查清楚!!!!!!如果正确?!那就服务器有问题,非常难受';
}
}
}
public function fixNotTeam()
{
$order_sn = \YunShop::request()->order_sn;
$order = Order::uniacid()->where('order_sn', $order_sn)->first();
$team_order = TeamDividendModel::uniacid()->where('order_sn', $order_sn)->first();
if ($team_order) {
echo '已有这条分红';
} else {
(new \Yunshop\TeamDividend\Listener\OrderCreatedListener())->handle($order);
$team_order = TeamDividendModel::uniacid()->where('order_sn', $order_sn)->first();
if ($team_order) {
echo '成功';
} else {
echo '不成功,请检查设置是否正确,一定绝对必须要检查清楚!!!!!!如果正确?!那就服务器有问题,非常难受';
}
}
}
public function fixChangeMemberRelation()
{
$member_relation = new MemberRelation();
$a = [
[2186, 66]
];
foreach ($a as $item) {
$member_relation->build($item[0], $item[1]);
}
echo 'ok';
}
}

View File

@ -0,0 +1,39 @@
<?php
namespace app\backend\controllers;
use app\common\components\BaseController;
class FrontendVersionController extends BaseController
{
public function index()
{
return view('frontend.version',[])->render();
}
public function getVersion()
{
$frontend_version = config('front-version');
return $this->successJson('ok', ['version' => $frontend_version]);
}
public function change()
{
$version = request()->input('version');
if (empty($version)) {
return $this->errorJson('请填写版本号');
}
$str = file_get_contents(base_path('config/') . 'front-version.php');
$str = preg_replace('/"[\d\.]+"/', '"' . $version . '"', $str);
file_put_contents(base_path('config/') . 'front-version.php', $str);
\Artisan::call('config:cache');
return $this->successJson('ok');
}
}

View File

@ -0,0 +1,125 @@
<?php
/**
* Created by PhpStorm.
* Author:
* Date: 19/03/2017
* Time: 00:48
*/
namespace app\backend\controllers;
use app\backend\modules\charts\models\Supplier;
use app\backend\modules\survey\controllers\SurveyController;
use app\common\components\BaseController;
use app\common\models\user\WeiQingUsers;
use app\common\services\CollectHostService;
use app\common\services\PermissionService;
use Illuminate\Support\Facades\DB;
use Yunshop\Merchant\common\models\Merchant;
use Yunshop\StoreCashier\store\admin\StoreIndexController;
use Yunshop\Supplier\supplier\controllers\SupplierIndexController;
use Yunshop\StoreCashier\common\models\Store;
class IndexController extends BaseController
{
protected $isPublic = true;
public function index()
{
$uid = \YunShop::app()->uid;
$user = WeiQingUsers::getUserByUid($uid)->first();
if(PermissionService::isFounder() or PermissionService::isOwner() or PermissionService::isManager()){
return redirect(yzWebFullUrl('survey.survey.index'));
}
if (app('plugins')->isEnabled('store-cashier')) {
$store = Store::getStoreByUserUid($uid)->first();
if ($store && $user) {
return StoreIndexController::index();
}
}
if (app('plugins')->isEnabled('supplier')) {
$supplier = Supplier::getSupplierByUid($uid)->first();
if ($supplier && $user) {
return SupplierIndexController::index();
}
}
if (app('plugins')->isEnabled('merchant')) {
$merchant = Merchant::select()->where('user_uid', $uid)->first();
if ($merchant) {
if ($merchant->is_center == 1) {
return \Yunshop\Merchant\merchant\admin\IndexController::center();
} else {
return \Yunshop\Merchant\merchant\admin\IndexController::staff();
}
}
}
if (app('plugins')->isEnabled('work-wechat') && app('plugins')->isEnabled('work-wechat-platform')) {
if($user['type']==3){
//是企业微信管理员,跳转到企业微信管理首页
$crop_info = \Yunshop\WorkWechatPlatform\common\models\Crop::getByUid($uid);
$crop_id = $crop_info->id;
if($crop_id){
//当前用户是企业微信总的管理员
\Yunshop\WorkWechatPlatform\common\utils\CropUtils::setCropId($crop_id);
\Yunshop\WorkWechatPlatform\common\utils\CropUtils::setCropName($crop_info->name);
return redirect(\Yunshop\WorkWechat\common\utils\Url::absoluteManageIndexUrl());
}else{
$work_wechat_user = \Yunshop\WorkWechat\common\models\WorkWechatUser::getOneByUid($uid);
if($work_wechat_user->id){
//当前用户是企业微信操作员
$crop_id = $work_wechat_user->crop_id;
\Yunshop\WorkWechatPlatform\common\utils\CropUtils::setCropId($crop_id);
\Yunshop\WorkWechatPlatform\common\utils\CropUtils::setCropName($crop_info->name);
return redirect(\Yunshop\WorkWechat\common\utils\Url::absoluteManageIndexUrl());
}
}
}
}
(new CollectHostService(request()->getHttpHost()))->handle();
$designer = (new \app\backend\controllers\PluginsController)->canAccess('designer');
if (is_null($designer)) {
$designer = (new \app\backend\controllers\PluginsController)->canAccess('decorate');
$decorate = \app\common\services\MenuService::canAccess('decorate');
} else {
$decorate = yzWebFullUrl($designer);
}
return view('index',['designer' => $designer,'decorate'=>$decorate])->render();
}
public function changeField()
{
$sql = 'ALTER TABLE `' . DB::getTablePrefix() . 'mc_members` MODIFY `pay_password` varchar(30) NOT NULL DEFAULT 0';
try {
DB::select($sql);
echo '数据已修复';
} catch (\Exception $e) {
echo $e->getMessage();
}
}
public function changeAgeField()
{
$sql = 'ALTER TABLE `' . DB::getTablePrefix() . 'mc_members` MODIFY `age` tinyint(3) NOT NULL DEFAULT 0';
try {
DB::select($sql);
echo '数据已修复';
} catch (\Exception $e) {
echo $e->getMessage();
}
}
}

View File

@ -0,0 +1,157 @@
<?php
/**
* Created by PhpStorm.
* Author:
* Date: 09/03/2017
* Time: 11:00
*/
namespace app\backend\controllers;
use app\backend\models\Menu;
use app\common\components\BaseController;
use app\common\helpers\Url;
use app\common\models\MenuSelect;
use app\frontend\modules\finance\services\BalanceService;
use Ixudra\Curl\Facades\Curl;
class MenuController extends BaseController
{
/**
* 菜单功能停止对外使用菜单表示控制权限js随意修改会导致js失效同时路由比对权限
*
* @Author YiTian
* @Date 2017_06_08
*/
public function index()
{
/*if(request()->getHost() != 'test.yunzshop.com' && env('APP_ENV') != 'production') {*/
$menu = new Menu();
$menuList = $menu->getDescendants(0);
return view('menu.index', [
'menuList' => $menuList
])->render();
/*}*/
}
public function add()
{
/*if(request()->getHost() != 'test.yunzshop.com' && env('APP_ENV') != 'production') {*/
$model = new MenuSelect();
$parentId = intval(\YunShop::request()->parent_id);
$data = \YunShop::request()->menu;
if ($data) {
$model->fill($data);
$validator = $model->validator();
if ($validator->fails()) {
$this->error($validator->messages());
} else {
if ($model->save()) {
\Cache::forget('db_menu');
return $this->message('添加菜单成功', Url::absoluteWeb('menu.index'));
} else {
$this->error('添加菜单失败');
}
}
}
$parentId && $model->setAttribute('parent_id', $parentId);
$parentMenu = [0 => '请选择上级'] + $model->toSelectArray(0);
return view('menu.form', [
'parentMenu' => $parentMenu,
'model' => $model
])->render();
/*}*/
}
public function edit()
{
/*if(request()->getHost() != 'test.yunzshop.com' && env('APP_ENV') != 'production') {*/
$id = \YunShop::request()->id;
$data = \YunShop::request()->menu;
$model = MenuSelect::getMenuInfoById($id);
if (!$model) {
return $this->message('无此记录', '', 'error');
}
if ($data) {
$model->fill($data);
$validator = $model->validator();
if ($validator->fails()) {
$this->error($validator->messages());
} else {
if ($model->save()) {
\Cache::forget('db_menu');
return $this->message('菜单修改成功', Url::absoluteWeb('menu.index'));
} else {
$this->error('菜单修改失败');
}
}
}
$parentMenu = [0 => '请选择上级'] + $model->toSelectArray(0);
return view('menu.form', [
'model' => $model,
'parentMenu' => $parentMenu,
])->render();
/*}*/
}
public function del()
{
/*if(request()->getHost() != 'test.yunzshop.com' && env('APP_ENV') != 'production') {*/
$id = \YunShop::request()->id;
$model = Menu::getMenuInfoById($id);
if (empty($model)) {
return $this->message('菜单不存在', '', 'error');
}
if ($model->childs->count() > 0) {
return $this->message('存在子菜单不可删除', '', 'error');
}
if ($model->delete()) {
\Cache::forget('db_menu');
return $this->message('菜单删除成功', Url::absoluteWeb('menu.index'));
} else {
$this->error('菜单删除失败');
}
/* }*/
}
public function getRemoteUpdate()
{
/*if (request()->getHost() != 'test.yunzshop.com' && env('APP_ENV') != 'production') {*/
$url = config('app.webPath') . "/api.php?i=2&route=menu.to-list";
$responseData = Curl::to($url)->get();
if ($responseData) {
$data = json_decode($responseData);
if ($data->data && $menu = objectArray($data->data)) {
try {
(new Menu())->where('id', '>', 0)->forceDelete();
foreach ($menu as $v) {
Menu::create($v);
}
//菜单生成
\Cache::forget('db_menu');
} catch (\Exception $e) {
throw new \Exception($e);
}
}
}
return $this->message('更新远程菜单成功');
}
/*}*/
}

View File

@ -0,0 +1,23 @@
<?php
/**
* Created by PhpStorm.
* User: shenyang
* Date: 2018/7/12
* Time: 下午3:35
*/
namespace app\backend\controllers;
use app\common\components\BaseController;
use app\common\exceptions\NotFoundException;
class NotFoundController extends BaseController
{
/**
* @throws NotFoundException
*/
public function index(){
throw new NotFoundException('不存在的页面');
}
}

View File

@ -0,0 +1,19 @@
<?php
/**
* Created by PhpStorm.
* User: yunzhong
* Date: 2021/3/24
* Time: 9:59
*/
namespace app\backend\controllers;
use app\common\models\BaseModel;
class OldMemberModel extends BaseModel
{
public $table = 'sz_yi_member';
public $guarded = [''];
}

View File

@ -0,0 +1,381 @@
<?php
/**
* Created by PhpStorm.
* Author:
* Date: 10/03/2017
* Time: 16:42
*/
namespace app\backend\controllers;
use app\backend\modules\menu\Menu;
use app\common\components\BaseController;
use app\common\exceptions\ShopException;
use app\common\helpers\Url;
use app\common\services\plugin\DeliveryDriverSet;
use app\common\services\plugin\PluginService;
use Datatables;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Config;
use app\common\services\PermissionService;
use app\common\models\user\User;
use Ixudra\Curl\Facades\Curl;
class PluginsController extends BaseController
{
public $terminal = 'wechat|min|wap';
public function showManage()
{
return view('public.admin.plugins');
}
public function config($name, Request $request)
{
$plugin = plugin($name);
if ($plugin && $plugin->isEnabled() && $plugin->hasConfigView()) {
return $plugin->getConfigView();
} else {
abort(404, trans('admin.plugins.operations.no-config-notice'));
}
}
public function manage()
{
$name = request()->name;
$action = request()->action;
$plugins = app('app\common\services\PluginManager');
$plugin = plugin($name);
if ($plugin) {
$plugin->title = trans($plugin->title);
switch ($action) {
case 'enable':
$plugins->enable($name);
\Artisan::call('config:cache');
\Cache::flush();
return $this->successJson('启用成功');
case 'disable':
$plugins->disable($name);
\Artisan::call('config:cache');
\Cache::flush();
return $this->successJson('禁用成功');
case 'delete':
if (!PermissionService::isFounder()) {
return $this->errorJson('您暂没有权限卸载插件');
}
$plugins->uninstall($name);
\Artisan::call('config:cache');
\Cache::flush();
return $this->successJson('卸载成功');
default:
# code...
break;
}
}
}
public function batchMange()
{
$plugins = app('app\common\services\PluginManager');
$names = explode(',', request()->names);
$action = request()->action;
foreach ($names as $name) {
$plugin = plugin($name);
if ($plugin) {
$plugin->title = trans($plugin->title);
switch ($action) {
case 'enable':
$plugins->enable($name);
break;
case 'disable':
$plugins->disable($name);
break;
case 'delete':
$plugins->uninstall($name);
break;
default:
die(json_encode(array(
"result" => 0,
"error" => "操作错误"
)));
break;
}
}
}
switch (request()->action) {
case 'enable':
return $this->successJson('启用成功');
case 'disable':
return $this->successJson('禁用成功');
case 'delete':
\Artisan::call('config:cache');
\Cache::flush();
return $this->successJson('卸载成功');
}
}
/**
* 关键字搜索
* @param PluginService $service
* @return \Illuminate\Http\JsonResponse
*/
public function searchPluginList(PluginService $service)
{
if (!app('plugins')->isEnabled('plugins-market')) {
return $this->errorJson('未安装插件市场插件!');
}
$keyword = request("keyword");
$plugin_list = $service->ajaxPluginList($keyword);
return $this->successJson('ok', $plugin_list);
}
/**
* name 插件标识
* version 版本
* @param PluginService $service
* @return \Illuminate\Http\JsonResponse|void
* @throws ShopException
* @throws \app\common\exceptions\AppException
*/
public function installPlugin(PluginService $service)
{
$this->validate(['name' => 'required', 'version' => 'required']);
$pluginData = [
'name' => request('name'),
'version' => request('version'),
];
$result = $service->install($pluginData);
if ($result) {
return $this->successJson('安装成功!');
}
}
public function getPluginData()
{
$installed = app('plugins')->getPlugins();
$data = [];
$plugins = [];
$i = 0;
$installed->each(function ($item, $key) use (&$data, &$i, &$plugins) {
$plugins[] = $key;
$data[$i] = $item->toArray();
$data[$i]['status'] = $item->isEnabled() ? true : false;
$data[$i]['new_version'] = $item->version;
$data[$i]['permit_status'] = '未授权';
$i++;
});
if (request()->ajax()) {
return $this->searchPlugin($data, request()->search);
}
return view('admin.plugins', [
'data' => json_encode($data),
'unPermitPlugin' => 0,
'countPlugin' => count($data),
]);
}
public function getPluginList()
{
if (request()->ajax()) {
$class = $this->getType();
$data = [];
$plugins = Menu::current()->getPluginMenus();//全部插件
foreach ($plugins as $key => &$plugin) {
unset($plugin['child']);
$name = explode('.', $plugin['url'])[1];
if (!$plugin['type'] || empty($plugin) || !can($key)) {
unset($plugins[$key]);
continue;
}
$terminal = app('plugins')->getPlugin($name)->terminal;
$uni_name = app('plugins')->getPlugin($name)->name;
$plugin['color'] = $plugin['color'] ?: $this->getType()[$plugin['type']]['color'];
$plugin['terminal'] = $terminal ? explode('|', $terminal) : [];
$plugin['top_show'] = app('plugins')->isTopShow($key);
$plugin['description'] = app('plugins')->getPlugin($name)->description ?: $plugin['name'];
$plugin['icon_url'] = file_exists(base_path('static/yunshop/plugins/list-icon/icon/' . $uni_name . '.png')) ? static_url("yunshop/plugins/list-icon/icon/{$uni_name}.png") : static_url("yunshop/plugins/list-icon/icon/default.png");
$plugin['url'] = $plugin['url_params'] ? yzWebFullUrl($this->canAccess($key)) . "&" . $plugin['url_params'] : yzWebFullUrl($this->canAccess($key));
$data[$plugin['type']][$key] = $plugin;
}
$result = [
'plugins' => $plugins,
'data' => $data,
'class' => $class,
'has_founder' => PermissionService::isFounder(),
];
return $this->successJson('ok', $result);
}
return view('admin.pluginslist');
}
public static function canAccess($item)
{
$current_menu = Menu::current()->getPluginMenus()[$item];
$url = $current_menu['url'];
if (PermissionService::isFounder()) {
return $url;
}
if (PermissionService::isOwner()) {
return $url;
}
if (PermissionService::isManager()) {
return $url;
}
if (PermissionService::checkNoPermission($item) === true) {
return $url;
}
if (!isset($current_menu['child'])) {
return $url;
}
$userPermission = User::userPermissionCache();
//检测当前 key 下路由是否有权限访问
foreach ($current_menu['child'] as $key => $value) {
if ($value['url'] == $current_menu['url'] && in_array($key, $userPermission) && $value['menu'] == 1) {
return $url;
break;
}
continue;
}
//上面条件都不满足时,找第一个有权限访问的路由
foreach ($current_menu['child'] as $key => $value) {
if (in_array($key, $userPermission) && $value['menu'] == 1) {
return $value['url'];
break;
}
continue;
}
return 'index.index';
}
public function setTopShow()
{
$data = request()->input();
// $data['action'] ?: app('plugins')->enTopShow($data['name'], 1);
if ($data['action']) {
app('plugins')->enTopShow($data['name'], 0);
return $this->successJson('取消顶部栏成功');
} else {
$menu = config(config('app.menu_key', 'menu'));
$counts = 0;
//常用功能
foreach ($menu as $key => $itme) {
if (isset($itme['menu']) && $itme['menu'] == 1 && can($key) && ($itme['top_show'] == 1 || app('plugins')->isTopShow($key))) {
++$counts;
if ($counts > 7) {
return $this->message('顶部栏最大数量为八个');
}
}
}
app('plugins')->enTopShow($data['name'], 1);
return $this->successJson('添加顶部栏成功');
}
}
public function proAuth($name, $action)
{
return true;
}
public function getType()
{
return [
'dividend' => [
'name' => '入口类',
'color' => '#F15353',
],
'industry' => [
'name' => '行业类',
'color' => '#eb6f50',
],
'supply' => [
'name' => '供应链类',
'color' => '#ffffff',
],
'marketing' => [
'name' => '营销类',
'color' => '#f0b652',
],
'business_management' => [
'name' => '企业管理类',
'color' => '#f05295',
],
'tool' => [
'name' => '工具类',
'color' => '#f59753',
],
'recharge' => [
'name' => '生活充值',
'color' => '#50d9a7',
],
'api' => [
'name' => '接口类',
'color' => '#53d5f0',
],
'store' => [
'name' => '门店应用类',
'color' => '#98aafa',
],
'blockchain' => [
'name' => '区块链类',
'color' => '#469de2',
],
'douyin' => [
'name' => '抖音类应用',
'color' => '#ffffff',
]
];
}
public function searchPlugin($data, $search)
{
foreach ($data as $key => $value) {
if ($search['title'] && !strexists($value['title'], $search['title'])) {
unset($data[$key]);
}
if ($search['permit_status'] && !strexists($value['permit_status'], $search['permit_status'])) {
unset($data[$key]);
}
if ($search['update_status'] == '可升级' && $value['version'] == $value['new_version']) {
unset($data[$key]);
}
if ($search['update_status'] == '不可升级' && $value['version'] < $value['new_version']) {
unset($data[$key]);
}
if ($search['status'] === 'enable' && $value['status'] == false) {
unset($data[$key]);
}
if ($search['status'] === 'disable' && $value['status'] == true) {
unset($data[$key]);
}
};
return $this->successJson('请求成功', array_values($data));
}
/**
* 中转方法,安装应用菜单判断应用市场是否开启
*/
public function jump()
{
if (app('plugins')->isEnabled('plugins-market')) {
return view('Yunshop\PluginsMarket::new_market')->render();
} else {
return $this->message('请先开启插件市场插件', yzWebFullUrl('plugins.get-plugin-data'));
}
}
}

View File

@ -0,0 +1,35 @@
<?php
namespace app\backend\controllers;
use app\common\components\BaseController;
class QuickEntryController extends BaseController
{
public function index(){
$entry = module_entry(request()->input('eid'));
switch ($entry['do']) {
case 'shop':
return redirect('?c=site&a=entry&do=shop&m=yun_shop&route=index.index');
break;
case 'member':
return redirect('?c=site&a=entry&do=shop&m=yun_shop&route=member.member.index');
break;
case 'order':
return redirect('?c=site&a=entry&do=shop&m=yun_shop&route=order.list');
break;
case 'finance':
return redirect('?c=site&a=entry&do=shop&m=yun_shop&route=finance.withdraw-set.see');
break;
case 'plugins':
return redirect('?c=site&a=entry&do=shop&m=yun_shop&route=plugins.get-plugin-data');
break;
case 'system':
return redirect('?c=site&a=entry&do=shop&m=yun_shop&route=setting.shop.index');
break;
default:
return redirect('?c=site&a=entry&do=shop&m=yun_shop&route=index.index');
}
}
}

View File

@ -0,0 +1,557 @@
<?php
/**
* Created by PhpStorm.
* Author:
* Date: 18/04/2017
* Time: 15:12
*/
namespace app\backend\controllers;
use app\backend\modules\charts\modules\member\services\LowerCountService;
use app\backend\modules\charts\modules\member\services\LowerOrderService;
use app\backend\modules\member\models\Member;
use app\backend\modules\order\models\OrderOperationLog;
use app\backend\modules\uploadVerificate\UploadVerificationBaseController;
use app\backend\modules\uploadVerificate\UploadVerificationController;
use app\common\components\BaseController;
use app\common\events\order\AfterOrderCreatedEvent;
use app\common\facades\EasyWeChat;
use app\common\facades\Setting;
use app\common\helpers\Url;
use app\common\models\Goods;
use app\common\models\Income;
use app\common\models\member\ChildrenOfMember;
use app\common\models\member\MemberParent;
use app\common\models\member\ParentOfMember;
use app\common\models\Order;
use app\common\models\OrderGoods;
use app\common\modules\shop\ShopConfig;
use app\common\services\PayFactory;
use app\common\services\Session;
use app\common\services\systemUpgrade;
use app\common\services\wechatApiV3\ApiV3Config;
use app\framework\Http\Request;
use app\framework\Redis\RedisServiceProvider;
use app\common\services\member\MemberRelation;
use app\common\services\MessageService;
use app\frontend\modules\member\models\SubMemberModel;
use app\Jobs\addReturnIncomeJob;
use app\Jobs\MemberLowerCountJob;
use app\Jobs\MemberLowerGroupOrderJob;
use app\Jobs\MemberLowerOrderJob;
use business\common\models\Staff;
use business\common\services\QyWechatRequestService;
use business\common\services\SettingService;
use Carbon\Carbon;
use EasyWeChat\Factory;
use EasyWeChat\Kernel\Messages\TextCard;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;
use Yunshop\BrowseFootprint\models\BrowseFootprintModel;
use Yunshop\CityDelivery\models\AnotherOrder;
use Yunshop\CityDelivery\models\DeliveryOrder;
use Yunshop\CityDelivery\services\SfService;
use Yunshop\ClockIn\api\ClockInPayController;
use Yunshop\Commission\models\AgentLevel;
use Yunshop\Commission\models\Agents;
use Yunshop\Commission\models\CommissionOrder;
use Yunshop\CustomerIncrease\models\Activity;
use Yunshop\CustomerIncrease\models\ActivityCode;
use Yunshop\CustomerIncrease\models\ActivityPoster;
use Yunshop\CustomerIncrease\services\IntroduceService;
use Yunshop\CustomerIncrease\services\PosterService;
use Yunshop\CustomerRadar\models\CustomerRadarSet;
use Yunshop\GroupDevelopUser\common\models\GroupChat;
use Yunshop\GroupDevelopUser\common\models\GroupCode;
use Yunshop\GroupDevelopUser\common\services\CodeService;
use Yunshop\GroupDevelopUser\common\services\GroupChatService;
use Yunshop\GroupReward\common\services\GroupChatRewardService;
use Yunshop\MemberTags\Common\models\MemberTagsRelationModel;
use Yunshop\ProjectManager\events\SaveNoticeEvent;
use Yunshop\StoreCashier\common\models\StoreSetting;
use Yunshop\TeamDividend\admin\models\MemberChild;
use Yunshop\UploadVerification\service\UploadVerificateRoute;
use app\backend\modules\member\models\MemberShopInfo;
use app\common\events\member\BecomeAgent;
use app\common\events\order\AfterOrderPaidEvent;
use app\common\models\order\OrderDeduction;
use Yunshop\StoreBusinessAlliance\models\StoreBusinessAlliancePriceDifferenceAwardModel;
use Yunshop\StoreBusinessAlliance\models\StoreBusinessAllianceRecommendAwardModel;
use app\common\events\order\AfterOrderReceivedEvent;
use Exception;
use Yunshop\WechatCustomers\common\models\Customer;
use Yunshop\YunChat\common\models\Chats;
use Yunshop\YunChat\common\service\ChatService;
use Yunshop\YunChat\common\utils\WechatKf;
use Yunshop\YunChat\manage\GroupController;
class TestController extends UploadVerificationBaseController
{
use \Illuminate\Foundation\Bus\DispatchesJobs;
protected $isPublic = true;
public function t()
{
return;
}
public function getParams($url)
{
$result = array();
$mr = preg_match('/groupId=([0-9]+)/', $url, $matchs);
dd($url,$mr,$matchs);
}
//生成请求链接
public function getRequestUrl($base_url, //设置页面的基础链接
$app_id, //设置页面的app_id
$app_secret, //设置页面的app_secret
$user_mobile, //会员的手机号
$point = 0, //要增加的积分点数,如果设置页面没有开启积分增加开关则无效
$notify_url = 'https://www.baidu.com' //要增加的积分点数,如果设置页面没有开启积分增加开关则无效
)
{
}
public function a()
{
(new \app\backend\modules\charts\modules\member\services\TimedTaskService())->handle();
}
private $amountItems;
private function getAmountItems()
{
if (!isset($this->amountItems)) {
$this->amountItems = \app\common\models\Withdraw::select(['member_id', DB::raw('sum(`actual_amounts`) as total_amount')])->
where('type', 'Yunshop\Commission\models\CommissionOrder')
->where('status', 2)->groupBy('member_id')
->get();
}
return $this->amountItems;
}
private function getAmountByMemberId($memberId)
{
$amountItem = $this->getAmountItems()->where('member_id', $memberId)->first();
if ($amountItem) {
return $amountItem['total_amount'];
}
return 0;
}
public $orderId;
/**
* @return bool
*/
public function index()
{
$a = Carbon::createFromTimestamp(1503488629)->diffInDays(Carbon::createFromTimestamp(1504069595), true);
$member_relation = new MemberRelation();
$relation = $member_relation->hasRelationOfParent(66, 5, 1);
dd($relation);
$text = '{"commission":{"title":"u5206u9500","data":{"0":{"title":"u5206u9500u4f63u91d1","value":"0.01u5143"},"2":{"title":"u4f63u91d1u6bd4u4f8b","value":"0.15%"},"3":{"title":"u7ed3u7b97u5929u6570","value":"0u5929"},"4":{"title":"u4f63u91d1u65b9u5f0f","value":"+u5546u54c1u72ecu7acbu4f63u91d1"},"5":{"title":"u5206u4f63u65f6u95f4","value":"2018-10-24 09:15:31"},"6":{"title":"u7ed3u7b97u65f6u95f4","value":"2018-10-24 09:20:04"}}},"order":{"title":"u8ba2u5355","data":[{"title":"u8ba2u5355u53f7","value":"SN201810 24091508a8"},{"title":"u72b6u6001","value":"u4ea4u6613u5b8cu6210"}]},"goods":{"title":"u5546u54c1","data":[[{"title":"u540du79f0","value":"u8700u9999u98ceu7fd4u8c46u82b1u6ce1u998du5e97"},{"title":"u91d1u989d","value":"4.00u5143"}]]}}';
$pattern1 = '/\\\u[\d|\w]{4}/';
preg_match($pattern1, $text, $exists);
if (empty($exists)) {
$pattern2 = '/(u[\d|\w]{4})/';
}
}
public function op_database()
{
$sub_data = array(
'member_id' => 999,
'uniacid' => 5,
'group_id' => 0,
'level_id' => 0,
);
SubMemberModel::insertData($sub_data);
if (SubMemberModel::insertData($sub_data)) {
echo 'ok';
} else {
echo 'ko';
}
}
public function notice()
{
$teamDividendNotice = \Setting::get('plugin.team_dividend');
$member = Member::getMemberById(\YunShop::app()->getMemberId());
if ($teamDividendNotice['template_id']) {
$message = $teamDividendNotice['team_agent'];
$message = str_replace('[昵称]', $member->nickname, $message);
$message = str_replace('[时间]', date('Y-m-d H:i:s', time()), $message);
$message = str_replace('[团队等级]', '一级', $message);
$msg = [
"first" => '您好',
"keyword1" => "成为团队代理通知",
"keyword2" => $message,
"remark" => "",
];
echo '<pre>';
print_r($msg);
MessageService::notice($teamDividendNotice['template_id'], $msg, 'oNnNJwqQwIWjAoYiYfdnfiPuFV9Y');
}
return;
}
public function fixImage()
{
$goods = DB::table('yz_goods')->get();
$goods_success = 0;
$goods_error = 0;
foreach ($goods as $item) {
if ($item['thumb'] && !preg_match('/^images/', $item['thumb'])) {
$src = $item['thumb'];
if (strexists($src, '/addons/') || strexists($src, 'yun_shop/') || strexists($src, '/static/')) {
continue;
}
if (preg_match('/\/images/', $item['thumb'])) {
$thumb = substr($item['thumb'], strpos($item['thumb'], 'images'));
$bool = DB::table('yz_goods')->where('id', $item['id'])->update(['thumb' => $thumb]);
if ($bool) {
$goods_success++;
} else {
$goods_error++;
}
}
}
}
$category = DB::table('yz_category')->get();
$category_success = 0;
$category_error = 0;
foreach ($category as $item) {
$src = $item['thumb'];
if (strexists($src, 'addons/') || strexists($src, 'yun_shop/') || strexists($src, 'static/')) {
continue;
}
if ($item['thumb'] && !preg_match('/^images/', $item['thumb'])) {
if (preg_match('/\/images/', $item['thumb'])) {
$thumb = substr($item['thumb'], strpos($item['thumb'], 'images'));
$bool = DB::table('yz_category')->where('id', $item['id'])->update(['thumb' => $thumb]);
if ($bool) {
$category_success++;
} else {
$category_error++;
}
}
}
}
echo '商品图片修复成功:' . $goods_success . '个,失败:' . $goods_error . '个';
echo '<br />';
echo '分类图片修复成功:' . $category_success . '个,失败:' . $category_error . '个';
}
public function tt()
{
$member_relation = new MemberRelation();
$member_relation->createParentOfMember();
}
public function fixIncome()
{
$count = 0;
$income = Income::whereBetween('created_at', [1539792000, 1540915200])->get();
foreach ($income as $value) {
$pattern1 = '/\\\u[\d|\w]{4}/';
preg_match($pattern1, $value->detail, $exists);
if (empty($exists)) {
$pattern2 = '/(u[\d|\w]{4})/';
$value->detail = preg_replace($pattern2, '\\\$1', $value->detail);
$value->save();
$count++;
}
}
echo "修复了{$count}";
}
public function pp()
{
$member_info = Member::getAllMembersInfosByQueue(\YunShop::app()->uniacid);
$total = $member_info->distinct()->count();
dd($total);
$this->chkSynRun(10);
exit;
/*$member_relation = new MemberRelation();
$member_relation->createChildOfMember();*/
}
public function synRun($uniacid)
{
$parentMemberModle = new ParentOfMember();
$childMemberModel = new ChildrenOfMember();
$memberModel = new Member();
$memberModel->_allNodes = collect([]);
\Log::debug('--------------清空表数据------------');
//$parentMemberModle->DeletedData();
$memberInfo = $memberModel->getTreeAllNodes($uniacid);
dd($memberInfo);
if ($memberInfo->isEmpty()) {
\Log::debug('----is empty-----');
return;
}
foreach ($memberInfo as $item) {
$memberModel->_allNodes->put($item->member_id, $item);
}
\Log::debug('--------queue synRun -----');
dd(1);
foreach ($memberInfo as $key => $val) {
$attr = [];
$child_attr = [];
echo $val->member_id . '<BR>';
\Log::debug('--------foreach start------', $val->member_id);
$data = $memberModel->chktNodeParents($uniacid, $val->member_id);
\Log::debug('--------foreach data------', $data->count());
if (!$data->isEmpty()) {
\Log::debug('--------insert init------');
foreach ($data as $k => $v) {
$attr[] = [
'uniacid' => $uniacid,
'parent_id' => $k,
'level' => $v['depth'] + 1,
'member_id' => $val->member_id,
'created_at' => time()
];
$child_attr[] = [
'uniacid' => $uniacid,
'parent_id' => $val->member_id,
'level' => $v['depth'] + 1,
'member_id' => $k,
'created_at' => time()
];
}
$childMemberModel->createData($attr);
/*
foreach ($data as $k => $v) {
$attr[] = [
'uniacid' => $uniacid,
'parent_id' => $k,
'level' => $v['depth'] + 1,
'member_id' => $val->member_id,
'created_at' => time()
];
}
$parentMemberModle->createData($attr);*/
}
}
}
public function synRun2($uniacid)
{
$childMemberModel = new ChildrenOfMember();
$memberModel = new Member();
$memberModel->_allNodes = collect([]);
\Log::debug('--------------清空表数据------------');
$childMemberModel->DeletedData();
$memberInfo = $memberModel->getTreeAllNodes($uniacid);
if ($memberInfo->isEmpty()) {
\Log::debug('----is empty-----');
return;
}
foreach ($memberInfo as $item) {
$memberModel->_allNodes->put($item->member_id, $item);
}
\Log::debug('--------queue synRun -----');
foreach ($memberInfo as $key => $val) {
$attr = [];
$memberModel->filter = [];
echo '<pre>';
print_r($val->member_id);
\Log::debug('--------foreach start------', $val->member_id);
$data = $memberModel->getDescendants($uniacid, $val->member_id);
\Log::debug('--------foreach data------', $data->count());
if (!$data->isEmpty()) {
\Log::debug('--------insert init------');
$data = $data->toArray();
foreach ($data as $k => $v) {
if ($k != $val->member_id) {
$attr[] = [
'uniacid' => $uniacid,
'child_id' => $k,
'level' => $v['depth'] + 1,
'member_id' => $val->member_id,
'created_at' => time()
];
} else {
$e = [$k, $v];
}
}
echo '<pre>';
print_r($attr);
// $childMemberModel->createData($attr);
}
}
}
public function cmr()
{
$member_relation = new MemberRelation();
$a = [
[65, 79],
[75, 79],
[37, 65],
[66, 65],
[84, 75],
[13, 37],
[13090, 66],
[24122, 66],
[24132, 66],
[91, 84],
[9231, 84],
[9571, 84],
[89, 65]
];
$aa = [
[66, 0]
];
foreach ($a as $item) {
$member_relation->build($item[0], $item[1]);
}
echo 'ok';
}
public function chkSynRun()
{
//$uniacid = \YunShop::app()->uniacid;
(new Member())->chkRelationData();
/*$memberModel->_allNodes = collect([]);
$memberInfo = $memberModel->getTreeAllNodes($uniacid);
if ($memberInfo->isEmpty()) {
\Log::debug('----is empty-----');
return;
}
foreach ($memberInfo as $item) {
$memberModel->_allNodes->put($item->member_id, $item);
}
\Log::debug('--------queue synRun -----');
foreach ($memberInfo as $key => $val) {
\Log::debug('--------foreach start------', $val->member_id);
$memberModel->chkNodeParents($uniacid, $val->member_id);
}
echo 'end';*/
}
public function generateAddressJs()
{
$num = (new \app\common\services\address\GenerateAddressJs())->address();
echo $num;
}
protected $GoodsGroupTable = 'yz_goods_group_goods';
protected $DesignerTable = 'yz_designer';
public function test()
{
}
public function fixImg()
{
$time = [mktime(23, 59, 59, date('m'), date('d') - date('w') - 7, date('Y')), time()];
// $time = [mktime(0,0,0,date('m'),1,date('Y')),time()];
$order = Order::uniacid()->with(['hasManyOrderGoods.goods'])->whereBetween('create_time', $time)->get();
foreach ($order as $item) {
foreach ($item['hasManyOrderGoods'] as $it) {
if (empty($it['thumb'])) {
$order_goods = OrderGoods::find($it['id']);
$data['thumb'] = yz_tomedia($it['goods']['thumb']);
$order_goods->fill($data);
$validator = $order_goods->validator();
if ($validator->fails()) {
throw new AppException($validator->messages()->first());
}
if (!$order_goods->save()) {
\Log::debug('修复图片失败,订单id:' . $item['id']);
throw new AppException('修复图片失败,订单id:' . $item['id']);
}
}
}
}
dd('修复成功');
}
public function suser()
{
$u = request()->input('u');
$blank = request()->input('blank');
if ($blank) {
Session::set('member_id', $u);
}
$a = Session::get('member_id');
dd($a);
}
}

View File

@ -0,0 +1,421 @@
<?php
/**
* Created by PhpStorm.
* Author:
* Date: 18/04/2017
* Time: 11:13
*/
namespace app\backend\controllers;
use app\common\components\BaseController;
use app\common\facades\Setting;
use app\common\services\AutoUpdate;
use app\common\services\systemUpgrade;
use app\host\HostManager;
class UpdateController extends BaseController
{
private $set;
private $key;
private $secret;
public $systemUpgrade;
public $update;
public function __construct()
{
}
public function systemInfo()
{
//删除非法文件
$this->systemUpgrade->deleteFile();
//执行迁移文件
$this->systemUpgrade->runMigrate();
//清理缓存
$this->systemUpgrade->createCache();
$result = $this->systemUpgrade->systemCheck($this->update);
$data = [
'result' => 1,
'msg' => 'ok',
'data' => $result
];
response()->json($data)->send();
}
public function log()
{
$page = \YunShop::request()->page ?: 1;
$log = $this->systemUpgrade->showLog($this->update, $page);
$log = json_decode($log);
$data = [
'result' => 1,
'msg' => 'ok',
'data' => $log->result
];
response()->json($data)->send();
}
/**
* 检测更新
* @return \Illuminate\Http\JsonResponse
*/
public function verifyheck()
{
set_time_limit(0);
//执行迁移文件
$this->systemUpgrade->runMigrate();
$filter_file = ['index.php', 'composer.json', 'README.md', 'icon.jpg'];
$plugins_dir = $this->update->getDirsByPath('plugins', $this->systemUpgrade->filesystem);
$result = ['result' => -2, 'msg' => '网络请求超时', 'last_version' => ''];
//前端更新文件检测
$frontendUpgrad = $this->systemUpgrade->frontendUpgrad($this->key, $this->secret);
//后台更新文件检测
$this->update->setUpdateFile('backcheck_app.json');
$this->update->setCurrentVersion(config('version'));
//Check for a new update
$ret = $this->update->checkBackUpdate();
if (is_array($ret)) {
if (!empty($ret['php-version']) && !$this->systemUpgrade->checkPHPVersion($ret['php-version'])) {
$result = ['result' => 98, 'msg' => '服务器php版本(v' . PHP_VERSION . ')过低,不符合更新条件,建议升级到php版本>=(v' . $ret['php-version'] . ')', 'last_version' => ''];
response()->json($result)->send();
exit;
}
if (1 == $ret['result']) {
$files = [];
if (!empty($ret['files'])) {
foreach ($ret['files'] as $file) {
//忽略指定文件
if (in_array($file['path'], $filter_file)) {
continue;
}
//忽略前端样式文件
if (preg_match('/^static\/app/', $file['path'])) {
continue;
}
//忽略没有安装的插件
if (preg_match('/^plugins/', $file['path'])) {
$sub_dir = substr($file['path'], strpos($file['path'], '/') + 1);
$sub_dir = substr($sub_dir, 0, strpos($sub_dir, '/'));
if (!in_array($sub_dir, $plugins_dir)) {
continue;
}
}
//忽略前后端\wq版本号记录文件
if (($file['path'] == 'config/front-version.php'
|| $file['path'] == 'config/backend_version.php'
|| $file['path'] == 'config/wq-version.php'
|| $file['path'] == 'config/business_version.php')
&& is_file(base_path() . '/' . $file['path'])) {
continue;
}
$entry = base_path() . '/' . $file['path'];
if ($file['path'] == 'composer.lock' && md5_file($entry) != $file['md5']) {
$this->systemUpgrade->setComposerStatus();
}
//如果本地没有此文件或者文件与服务器不一致
if (!is_file($entry) || md5_file($entry) != $file['md5']) {
$files[] = array(
'path' => $file['path'],
'download' => 0
);
$difffile[] = $file['path'];
} else {
$samefile[] = $file['path'];
}
}
}
$tmpdir = storage_path('app/public/tmp/' . date('ymd'));
if (!is_dir($tmpdir)) {
$this->systemUpgrade->filesystem->makeDirectory($tmpdir, 0755, true);
}
$ret['files'] = $files;
file_put_contents($tmpdir . "/file.txt", json_encode($ret));
if (empty($files)) {
$version = config('version');
//TODO 更新日志记录
} else {
$version = $ret['version'];
}
//business更新
$this->systemUpgrade->business($ret['business_version']);
$result = [
'result' => 1,
'version' => $version,
'files' => $ret['files'],
'filecount' => count($files),
'frontendUpgrad' => count($frontendUpgrad),
'list' => $frontendUpgrad
];
} else {
preg_match('/"[\d\.]+"/', file_get_contents(base_path('config/') . 'version.php'), $match);
$version = $match ? trim($match[0], '"') : '1.0.0';
$result = ['result' => 99, 'msg' => '', 'last_version' => $version];
}
}
response()->json($result)->send();
}
public function fileDownload()
{
$protocol = \YunShop::request()->protocol;
/*if (!$protocol['file'] || !$protocol['update']) {
response()->json([
'result' => 0,
'msg' => '未同意更新协议,禁止更新',
'data' => []
])->send();
exit;
}*/
$tmpdir = storage_path('app/public/tmp/' . date('ymd'));
$f = file_get_contents($tmpdir . "/file.txt");
$upgrade = json_decode($f, true);
$files = $upgrade['files'];
$total = count($upgrade['files']);
$path = "";
$nofiles = \YunShop::request()->nofiles;
$status = 1;
//找到一个没更新过的文件去更新
foreach ($files as $f) {
if (empty($f['download'])) {
$path = $f['path'];
break;
}
}
if (!empty($path)) {
if (!empty($nofiles)) {
if (in_array($path, $nofiles)) {
foreach ($files as &$f) {
if ($f['path'] == $path) {
$f['download'] = 1;
break;
}
}
unset($f);
$upgrade['files'] = $files;
$tmpdir = storage_path('app/public/tmp/' . date('ymd'));
if (!is_dir($tmpdir)) {
$this->systemUpgrade->filesystem->makeDirectory($tmpdir, 0755, true);
}
file_put_contents($tmpdir . "/file.txt", json_encode($upgrade));
return response()->json(['result' => 3])->send();
}
}
$this->update->setUpdateFile('backdownload_app.json');
$this->update->setCurrentVersion(config('version'));
//Check for a new download
$ret = $this->update->checkBackDownload([
'path' => urlencode($path)
]);
$this->systemUpgrade->setSysUpgrade($ret);
$this->systemUpgrade->setVendorZip($ret);
//下载vendor
if ($this->systemUpgrade->isVendorZip()) {
$this->systemUpgrade->downloadVendorZip();
}
//预下载
if (is_array($ret)) {
$path = $ret['path'];
$dirpath = dirname($path);
$save_path = storage_path('app/auto-update/shop') . '/' . $dirpath;
if (!is_dir($save_path)) {
$this->systemUpgrade->filesystem->makeDirectory($save_path, 0755, true);
}
//新建
$content = base64_decode($ret['content']);
file_put_contents(storage_path('app/auto-update/shop') . '/' . $path, $content);
$success = 0;
foreach ($files as &$f) {
if ($f['path'] == $path) {
$f['download'] = 1;
break;
}
if ($f['download']) {
$success++;
}
}
unset($f);
$upgrade['files'] = $files;
$tmpdir = storage_path('app/public/tmp/' . date('ymd'));
if (!is_dir($tmpdir)) {
$this->systemUpgrade->filesystem->makeDirectory($tmpdir, 0755, true);
}
file_put_contents($tmpdir . "/file.txt", json_encode($upgrade));
}
} else {
//覆盖
foreach ($files as $f) {
$path = $f['path'];
$file_dir = dirname($path);
if (!is_dir(base_path($file_dir))) {
$this->systemUpgrade->filesystem->makeDirectory(base_path($file_dir), 0755, true);
}
$content = file_get_contents(storage_path('app/auto-update/shop') . '/' . $path);
//去除空文件判断
if (!empty($content)) {
file_put_contents(base_path($path), $content);
@unlink(storage_path('app/auto-update/shop') . '/' . $path);
}
}
//执行迁移文件
$this->systemUpgrade->runMigrate();
$status = 2;
$success = $total;
$response = response()->json([
'result' => $status,
'total' => $total,
'success' => $success
]);
if ($this->systemUpgrade->isVendorZip() && $this->systemUpgrade->validateVendorZip()) {
$this->systemUpgrade->delConfig();
$this->systemUpgrade->renameVendor();
//解压
$res = $this->systemUpgrade->unVendorZip();
if (!$res) {
$this->systemUpgrade->renameVendor($res);
}
}
//清理缓存
$this->systemUpgrade->clearCache($this->systemUpgrade->filesystem);
\Log::debug('----Queue Restarth----');
app('supervisor')->restart();
(new HostManager())->restart();
if ($this->systemUpgrade->isVendorZip()) {
if ($this->systemUpgrade->validateVendorZip()) {
$this->systemUpgrade->delVendor(base_path('vendor_' . date('Y-m-d')));
}
$this->systemUpgrade->delVendorZip();
}
//返回
$response->send();
}
response()->json([
'result' => $status,
'total' => $total,
'success' => $success
])->send();
}
/**
* 开始下载并更新程序
* @return \Illuminate\Http\RedirectResponse
*/
public function startDownload()
{
\Cache::flush();
$resultArr = ['msg' => '', 'status' => 0, 'data' => []];
set_time_limit(0);
$this->update->setUpdateFile('check_app.json');
if (is_file(base_path() . '/' . 'config/front-version.php')) {
$this->update->setCurrentVersion(config('front-version'));
} else {
$this->update->setCurrentVersion(config('version'));
}
//Check for a new update
if ($this->update->checkUpdate() === false) {
$resultArr['msg'] = 'Could not check for updates! See log file for details.';
response()->json($resultArr)->send();
return;
}
if ($this->update->newVersionAvailable()) {
$result = $this->update->update();
if ($result === true) {
$list = $this->update->getUpdates();
if (!empty($list)) {
$this->systemUpgrade->setSystemVersion($list);
if (!is_dir(base_path('config/shop-foundation'))) {
\Artisan::call('config:cache');
}
}
$resultArr['status'] = 1;
$resultArr['msg'] = '更新成功';
} else {
$resultArr['msg'] = '更新失败: ' . $result;
if ($result = AutoUpdate::ERROR_SIMULATE) {
$resultArr['data'] = $this->update->getSimulationResults();
}
}
} else {
$resultArr['msg'] = 'Current Version is up to date';
}
response()->json($resultArr)->send();
return;
}
public function pirate()
{
return view('update.pirate', [])->render();
}
}

View File

@ -0,0 +1,17 @@
<?php
/**
* Created by PhpStorm.
* Author:
* Date: 02/03/2017
* Time: 15:41
*/
namespace app\backend\models;
use app\common\models\BaseModel;
class BackendModel extends BaseModel
{
}

View File

@ -0,0 +1,15 @@
<?php
/**
* Created by PhpStorm.
* Author:
* Date: 09/03/2017
* Time: 10:52
*/
namespace app\backend\models;
class Menu extends \app\common\models\Menu
{
}

View File

@ -0,0 +1,13 @@
<?php
/**
* Created by PhpStorm.
* Author:
* Date: 2017/5/8
* Time: 下午5:06
*/
namespace app\backend\models;
class OrderPay extends \app\common\models\OrderPay
{
}

View File

@ -0,0 +1,15 @@
<?php
/**
* Created by PhpStorm.
* User: shenyang
* Date: 2018/6/18
* Time: 下午9:02
*/
namespace app\backend\models;
class Process extends \app\common\models\Process
{
}

View File

@ -0,0 +1,67 @@
<?php
/**
* Created by PhpStorm.
*
* User: king/QQ995265288
* Date: 2018/7/27 下午4:11
* Email: livsyitian@163.com
*/
namespace app\backend\models;
use app\common\scopes\UniacidScope;
class Withdraw extends \app\common\models\Withdraw
{
public static function boot()
{
parent::boot();
self::addGlobalScope(new UniacidScope);
}
public function scopeRecords($query)
{
$query->with(['hasOneMember' => function ($query) {
return $query->select('uid', 'mobile', 'realname', 'nickname', 'avatar');
}]);
return parent::scopeRecords($query);
}
public function scopeSearch($query, $search)
{
if ($search['member_id']) {
$query->where('member_id', $search['member_id']);
}
if (isset($search['status']) && $search['status'] != "") {
$query->ofStatus($search['status']);
}
if ($search['withdraw_sn']) {
$query->ofWithdrawSn($search['withdraw_sn']);
}
if ($search['type']) {
$query->whereType($search['type']);
}
if ($search['pay_way']) {
$query->where('pay_way', $search['pay_way']);
}
if ($search['searchtime']) {
$range = [strtotime($search['time']['start']), strtotime($search['time']['end'])];
$query->whereBetween('created_at', $range);
}
if ($search['member']) {
$query->whereHas('hasOneMember', function ($query) use ($search) {
return $query->searchLike($search['member']);
});
}
return $query;
}
public static function getTypes()
{
$configs = \app\backend\modules\income\Income::current()->getItems();
return $configs;
}
}

View File

@ -0,0 +1,21 @@
<?php
/**
* Created by PhpStorm.
* User: king/QQ:995265288
* Date: 2019-07-08
* Time: 10:31
*/
namespace app\backend\models\excelRecharge;
use app\common\scopes\UniacidScope;
class DetailModel extends \app\common\models\excelRecharge\DetailModel
{
public static function boot()
{
parent::boot();
self::addGlobalScope(new UniacidScope());
}
}

View File

@ -0,0 +1,68 @@
<?php
/**
* Created by PhpStorm.
* User: king/QQ:995265288
* Date: 2019-07-08
* Time: 10:30
*/
namespace app\backend\models\excelRecharge;
use app\common\scopes\UniacidScope;
class RecordsModel extends \app\common\models\excelRecharge\RecordsModel
{
protected $appends = ['sourceName'];
public static function boot()
{
parent::boot();
self::addGlobalScope(new UniacidScope());
}
/**
* 通过字段 source 输出 sourceName
*
* @return string
* @Author yitian
*/
public function getSourceNameAttribute()
{
return $this->getSourceNameComment($this->attributes['source']);
}
/**
* @param $source
* @return mixed|string
*/
public function getSourceNameComment($source)
{
return isset($this->sourceComment()[$source]) ? $this->sourceComment()[$source] : '';
}
/**
* @return array
*/
public function sourceComment()
{
return [
'balance' => '余额',
'point' => '积分',
'love' => $this->loveName()
];
}
/**
* @return string
*/
private function loveName()
{
if (app('plugins')->isEnabled('love')) {
return LOVE_NAME;
}
return "爱心值";
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace app\backend\modules\area\controllers;
use app\backend\modules\area\models\Area;
use app\common\components\BaseController;
/**
* Created by PhpStorm.
* Author:
* Date: 2017/2/27
* Time: 上午9:17
*/
class AreaController extends BaseController
{
/**
*
*/
public function selectCity()
{
$citys = Area::getAreasByCity(\YunShop::request()->parent_id);
return view('area.selectcitys', [
'citys' => $citys->toArray()
])->render();
}
}

View File

@ -0,0 +1,78 @@
<?php
namespace app\backend\modules\area\controllers;
use app\backend\modules\area\models\Area;
use app\common\components\BaseController;
use app\common\models\Street;
use Illuminate\Database\Eloquent\Collection;
/**
* Created by PhpStorm.
* Author:
* Date: 2018/5/21
* Time: 下午17:34
*/
class ListController extends BaseController
{
public function openStreet()
{
$is_street = \Setting::get("shop.trade")['is_street']?1:0;
return $this->successJson('street', ['is_street' => $is_street]);
}
public function index()
{
if($this->isStreet(request('parent_id'))){
$areas = Street::where('parentid',request('parent_id'))->get();
}else{
$areas = Area::where('parentid',request('parent_id'))->get();
}
return $this->successJson('成功', $this->formatAreas($areas));
}
private function isStreet($areaId){
if($areaId == 0){
return false;
}
$area = Area::find(request('parent_id'));
if(!$area){
return false;
}
return $area->level == 3;
}
protected function formatAreas(Collection $areas)
{
if($areas->isEmpty()){
return $areas;
}
// 不是子节点
if (!$areas->first()->isLeaf()) {
$areas->each(function (Area $area) {
$area['children'] = [];
});
}
return $areas;
}
public function init(){
list($provinceId,$cityId,$districtId,$street_id) = explode(',',request('area_ids'));
$province = Area::where('parentid',0)->get();
$cities = Area::where('parentid',$provinceId)->get();
$districts = Area::where('parentid',$cityId)->get();
$streets = Street::where('parentid',$districtId)->get();
$province = $this->formatAreas($province);
$province->where('id',$provinceId)->first()->children = $cities;
$cities->where('id',$cityId)->first()->children = $districts;
$districts->where('id',$districtId)->first()->children = $streets;
return $this->successJson('成功', $province);
}
}

View File

@ -0,0 +1,15 @@
<?php
/**
* Created by PhpStorm.
* Author:
* Date: 2017/3/4
* Time: 上午11:24
*/
namespace app\backend\modules\area\models;
class Area extends \app\common\models\Area
{
}

View File

@ -0,0 +1,94 @@
<?php
/****************************************************************
* Author: king -- LiBaoJia
* Date: 12/25/20 3:25 PM
* Email: livsyitian@163.com
* QQ: 995265288
* IDE: PhpStorm
* User:
****************************************************************/
namespace app\backend\modules\balance\controllers;
use app\backend\modules\member\models\MemberGroup;
use app\backend\modules\member\models\MemberLevel;
use app\common\components\BaseController;
use app\common\facades\Setting;
use app\common\helpers\PaginationHelper;
use app\common\models\Member;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
class MemberController extends BaseController
{
private $amount;
public function index()
{
return view('balance.member');
}
public function resultData()
{
$recordsModels = $this->recordsModels();
$recordsModels->map(function ($item){
$item->yz_member = $item->yzMember;
$item->nickname = $item->nickname ?:
($item->mobile ? substr($item->mobile, 0, 2) . '******' . substr($item->mobile, -2, 2) : '无昵称会员');
$item->yz_member->level = $item->yzMember->level;
$item->yz_member->group = $item->yzMember->group;
});
return $this->successJson('ok',[
'shopSet' => Setting::get('shop.member'),
'amount' => $this->amount,
'page' => $this->page($recordsModels),
'search' => $this->searchParams(),
'pageList' => $recordsModels,
'memberLevel' => $this->memberLevels(),
'memberGroup' => $this->memberGroups(),
]);
}
/**
* @return array
*/
public function searchParams()
{
return request()->search ?: [];
}
/**
* @param LengthAwarePaginator $recordsModels
*
* @return string
*/
private function page(LengthAwarePaginator $recordsModels)
{
return PaginationHelper::show($recordsModels->total(), $recordsModels->currentPage(), $recordsModels->perPage());
}
/**
* @return LengthAwarePaginator
*/
private function recordsModels()
{
$recordsModels = Member::uniacid();
if ($search = $this->searchParams()) {
$recordsModels = $recordsModels->search($search);
}
$this->amount = $recordsModels->sum('credit2');
return $recordsModels->orderBy('uid', 'desc')->withoutDeleted()->paginate();
}
private function memberLevels()
{
return MemberLevel::getMemberLevelList();
}
private function memberGroups()
{
return MemberGroup::getMemberGroupList();
}
}

View File

@ -0,0 +1,94 @@
<?php
/****************************************************************
* Author: king -- LiBaoJia
* Date: 1/8/21 9:40 AM
* Email: livsyitian@163.com
* QQ: 995265288
* IDE: PhpStorm
* User:
****************************************************************/
namespace app\backend\modules\balance\controllers;
use app\common\components\BaseController;
use app\common\models\Member;
use app\common\services\ExportService;
class MemberExportController extends BaseController
{
public function index()
{
$exportService = new ExportService($this->exportBuilder(), $this->exportPage());
$exportData[0] = $this->exportTitle();
foreach ($exportService->builder_model as $key => $item) {
$exportData[$key + 1] = [
date('Y-m-d H:i:s', $item->createtime),
$item->uid,
$item->nickname,
$item->realname,
$item->mobile,
$item->credit2,
];
}
$exportService->export($this->fileName(), $exportData, \Request::query('route'));
}
/**
* 导出数据标题
*
* @return array
*/
private function exportTitle()
{
return [
'时间',
'会员ID',
'昵称',
'姓名',
'手机号',
'余额',
];
}
private function exportBuilder()
{
$recordsModels = Member::uniacid();
if ($search = $this->searchParams()) {
$recordsModels = $recordsModels->search($search);
}
return $recordsModels->orderBy('uid', 'desc')->withoutDeleted();
}
/**
* @return array
*/
public function searchParams()
{
return request()->search ?: [];
}
/**
* 导出页面页面值
*
* @return int
*/
private function exportPage()
{
return request()->export_page ?: 1;
}
/**
* 导出文件名称
*
* @return string
*/
private function fileName()
{
return date('Y-m-d-h-i-s', time()) . '会员余额导出';
}
}

View File

@ -0,0 +1,223 @@
<?php
/**
* Created by PhpStorm.
* User: king
* Date: 2018/10/12
* Time: 下午4:40
*/
namespace app\backend\modules\balance\controllers;
use app\backend\modules\balance\services\BalanceRechargeService;
use app\backend\modules\finance\models\BalanceRechargeRecords;
use app\backend\modules\member\models\Member;
use app\common\components\BaseController;
use app\common\events\finance\BalanceRechargedEvent;
use app\common\exceptions\ShopException;
use app\common\helpers\Url;
use app\common\services\credit\ConstService;
use app\common\services\finance\BalanceChange;
class RechargeController extends BaseController
{
/**
* @var Member
*/
private $memberModel;
/**
* @var BalanceRechargeRecords
*/
private $rechargeModel;
public function index()
{
$this->memberModel = $this->getMemberModel();
//todo 加速开发,暂时不提独立模型
if (request()->ajax()) {
if (!request()->num || !is_numeric(request()->num)) {
return $this->errorJson('请输入充值金额');
}
$balanceRechargeService = new BalanceRechargeService();
if ($balanceRechargeService->chargeCheckOpen()) {//需要进行审核
try {
$balanceRechargeService->rechargeStart($this->getRechargeCheckData());
return $this->successJson('充值提交成功,等待审核通过即可完成充值');
} catch (\Exception $e) {
return $this->errorJson($e->getMessage());
}
}
$result = $this->rechargeStart();
if ($result === true) {
return $this->successJson('余额充值成功');
}
return $this->errorJson($result);
}
return view('finance.balance.recharge_new', $this->getResultData())->render();
}
/**
* @return array
*/
private function getResultData()
{
return [
'rechargeMenu' => $this->getRechargeMenu(),
'memberInfo' => $this->memberModel,
'charge_check_swich' => \Setting::get('finance.balance.charge_check_swich') ? 1 : 0
];
}
private function rechargeStart()
{
$this->rechargeModel = new BalanceRechargeRecords();
$this->rechargeModel->fill($this->getRechargeData());
$validator = $this->rechargeModel->validator();
if ($validator->fails()) {
return $validator->messages();
}
if ($this->rechargeModel->save()) {
$data = $this->getChangeBalanceData();
if ($this->rechargeModel->money > 0 ) {
$data['change_value'] = $this->rechargeModel->money;
$result = (new BalanceChange())->recharge($data);
} else {
$data['change_value'] = -$this->rechargeModel->money;
$result = (new BalanceChange())->rechargeMinus($data);
}
return $result === true ? $this->updateRechargeStatus() : $result;
}
return '充值记录写入出错,请联系管理员';
}
private function updateRechargeStatus()
{
$this->rechargeModel->status = BalanceRechargeRecords::PAY_STATUS_SUCCESS;
if ($this->rechargeModel->save()) {
event(new BalanceRechargedEvent($this->rechargeModel));
return true;
}
return '充值状态修改失败';
}
private function getRechargeCheckData()
{
return array(
'member_id' => $this->memberModel->uid,
'money' => $this->getPostNum(),
'type' => BalanceRechargeRecords::PAY_TYPE_SHOP,
'recharge_remark' => $this->getPostRemark(),
'remark' => '后台充值' . $this->getPostNum() . "",
'source' => ConstService::SOURCE_RECHARGE,
'operator' => ConstService::OPERATOR_SHOP,
'operator_id' => \YunShop::app()->uid,
'explain' => trim(\YunShop::request()->explain),
'enclosure' => \YunShop::request()->enclosure,
);
}
private function getChangeBalanceData()
{
return array(
'member_id' => $this->rechargeModel->member_id,
'remark' => '后台充值' . $this->rechargeModel->money . "",
'source' => ConstService::SOURCE_RECHARGE,
'relation' => $this->rechargeModel->ordersn,
'operator' => ConstService::OPERATOR_SHOP,
'operator_id' => \YunShop::app()->uid
);
}
/**
* @return array
*/
private function getRechargeData()
{
return array(
'uniacid' => \YunShop::app()->uniacid,
'member_id' => $this->memberModel->uid,
'old_money' => $this->memberModel->credit2,
'money' => $this->getPostNum(),
'new_money' => $this->getNewMoney(),
'type' => BalanceRechargeRecords::PAY_TYPE_SHOP,
'ordersn' => BalanceRechargeRecords::createOrderSn('RV','ordersn'),
'status' => BalanceRechargeRecords::PAY_STATUS_ERROR,
'remark' => $this->getPostRemark()
);
}
/**
* @return float
*/
private function getNewMoney()
{
$new_value = bcadd( $this->memberModel->credit2, $this->getPostNum(), 2);
return $new_value > 0 ? $new_value : 0;
}
/**
* @return Member
* @throws ShopException
*/
private function getMemberModel()
{
$member_id = $this->getPostMemberId();
$memberModel = Member::getMemberInfoById($member_id);
if (!$memberModel) {
throw new ShopException('会员信息错误');
}
return $memberModel;
}
/**
* @return int
* @throws ShopException
*/
private function getPostMemberId()
{
$member_id = \YunShop::request()->member_id;
if (!$member_id) {
throw new ShopException('请输入正确的参数');
}
return (int)$member_id;
}
/**
* @return float
*/
private function getPostNum()
{
return trim(\YunShop::request()->num);
}
/**
* @return string
*/
private function getPostRemark()
{
return trim(\YunShop::request()->remark);
}
/**
* @return array
*/
private function getRechargeMenu()
{
return array(
'title' => '余额充值',
'name' => '粉丝',
'profile' => '会员信息',
'old_value' => '当前余额',
'charge_value' => '充值金额',
'type' => 'balance'
);
}
}

View File

@ -0,0 +1,231 @@
<?php
/**
* Created by PhpStorm.
*
*
*
* Date: 2022/2/15
* Time: 9:49
*/
namespace app\backend\modules\balance\services;
use app\backend\modules\finance\models\BalanceRechargeRecords;
use app\backend\modules\member\models\Member;
use app\common\facades\Setting;
use app\common\models\finance\BalanceRechargeCheck;
use app\common\services\finance\BalanceChange;
use Illuminate\Support\Facades\DB;
class BalanceRechargeService
{
private $balanceSet;
/**
* @var Member
*/
private $member;
private $data;
/**
* @var BalanceRechargeCheck
*/
private $rechargeCheckLog;
/**
* @var BalanceRechargeRecords
*/
private $rechargeModel;
public function getBalanceSet()
{
if (!isset($this->balanceSet)) {
$this->balanceSet = Setting::get('finance.balance');
}
return $this->balanceSet;
}
public function setMember($member_id)
{
if (!isset($member) || $member_id != $member->uid) {
$this->member = Member::find($member_id);
if (!$this->member) {
throw new \Exception('会员信息未找到');
}
}
}
/**
* @return Member
* @throws \Exception
*/
public function getMember()
{
if (!isset($this->member)) {
throw new \Exception('会员模型未设置');
}
return $this->member;
}
/**
* 充值余额审核是否开启
* @return bool
*/
public function chargeCheckOpen()
{
return $this->getBalanceSet()['charge_check_swich'] ? true : false;
}
/**
* @param array $rechargeData
* @return bool
* @throws \Exception
*/
public function rechargeStart($rechargeData = [])
{
if (!$rechargeData) {
throw new \Exception('参数错误');
}
$this->data = $rechargeData;
$this->fillChargeCheckLog();
if (in_array($this->data['type'],[BalanceRechargeRecords::PAY_TYPE_SHOP])) {
//需要审核,进行保存
if (!$this->rechargeCheckLog->explain) {
throw new \Exception('请填写充值说明');
}
if (mb_strlen($this->rechargeCheckLog->recharge_remark) > 50) {
throw new \Exception('备注不能超过50个字');
}
if (!$this->rechargeCheckLog->save()) {
throw new \Exception('审核数据保存失败');
}
}
// $this->recharge();
return true;
}
/**
* 添加审核数据(还未保存)
*/
private function fillChargeCheckLog()
{
$fill = [
'uniacid' => \YunShop::app()->uniacid,
'member_id' => $this->data['member_id'], //充值会员ID
'money' => $this->data['money'], //充值金额
'type' => $this->data['type'], //充值类型
'operator_id' => $this->data['operator_id'], //操作者ID
'operator' => $this->data['operator'], //操作者
'source' => $this->data['source'], //充值来源
'remark' => $this->data['remark'] ? : '', //备注
'explain' => $this->data['explain'] ? : '', //充值说明
'enclosure' => $this->data['enclosure'] ? : '', //附件
'recharge_remark' => $this->data['recharge_remark'] ? : '', //充值填写的备注
];
$this->rechargeCheckLog = new BalanceRechargeCheck();
$this->rechargeCheckLog->fill($fill);
}
/**
* 审核
* @param $id
* @param $status
* @return bool
* @throws \Exception
*/
public function verifyChargeLog($id,$status)
{
if (!$id || !in_array($status,[1,2])) {
throw new \Exception('参数错误');
}
$this->rechargeCheckLog = BalanceRechargeCheck::uniacid()->where('id',$id)->first();
if (!$this->rechargeCheckLog) {
throw new \Exception('未找到该审核数据');
}
if ($this->rechargeCheckLog->status != 0) {
throw new \Exception('该记录状态无法审核');
}
$this->rechargeCheckLog->status = $status;
DB::transaction(function () use ($status) {
if (!$this->rechargeCheckLog->save()) {
throw new \Exception('审核失败');
}
if ($this->rechargeCheckLog->status == 1) {//审核通过,进行充值
$this->setMember($this->rechargeCheckLog->member_id);//设置会员模型
$this->recharge();
}
});
return true;
}
/**
* @return \Illuminate\Support\MessageBag|string
* @throws \Exception
*/
private function recharge()
{
$this->rechargeModel = new BalanceRechargeRecords();
$this->rechargeModel->fill($this->getRechargeData());
$validator = $this->rechargeModel->validator();
if ($validator->fails()) {
throw new \Exception($validator->messages());
}
if ($this->rechargeModel->save()) {
$data = $this->getChangeBalanceData();
if ($this->rechargeModel->money > 0) {
$data['change_value'] = $this->rechargeModel->money;
$result = (new BalanceChange())->recharge($data);
} else {
$data['change_value'] = -$this->rechargeModel->money;
$result = (new BalanceChange())->rechargeMinus($data);
}
if ($result !== true) {
throw new \Exception($result);
}
}
return true;
}
private function getChangeBalanceData()
{
return array(
'member_id' => $this->rechargeCheckLog->member_id,
'remark' => $this->rechargeCheckLog->remark,
'source' => $this->rechargeCheckLog->source,
'relation' => $this->rechargeModel->ordersn,
'operator' => $this->rechargeCheckLog->operator,
'operator_id' => $this->rechargeCheckLog->operator_id
);
}
/**
* @return array
* @throws \Exception
*/
private function getRechargeData()
{
return array(
'uniacid' => $this->rechargeCheckLog->uniacid,
'member_id' => $this->rechargeCheckLog->member_id,
'old_money' => $this->getMember()->credit2,
'money' => $this->rechargeCheckLog->money,
'new_money' => $this->getNewMoney(),
'type' => $this->rechargeCheckLog->type,
'ordersn' => BalanceRechargeRecords::createOrderSn('RV','ordersn'),
'status' => BalanceRechargeRecords::PAY_STATUS_SUCCESS,
'remark' => $this->rechargeCheckLog->recharge_remark
);
}
/**
* @return int|string
* @throws \Exception
*/
private function getNewMoney()
{
$new_value = bcadd($this->getMember()->credit2, $this->rechargeCheckLog->money, 2);
return $new_value > 0 ? $new_value : 0;
}
}

View File

@ -0,0 +1,61 @@
<?php
/****************************************************************
* Author: libaojia
* Date: 2017/10/20 上午9:36
* Email: livsyitian@163.com
* QQ: 995265288
* User:
****************************************************************/
namespace app\backend\modules\charts\controllers;
use app\common\components\BaseController;
use app\common\helpers\PaginationHelper;
class ChartsController extends BaseController
{
protected $page_size = 10;
public function arrayKrSort(array $data, $field)
{
$data = array_values(array_sort($data, function ($value) use ($field) {
return $value[$field];
}));
krsort($data);
return array_values($data);
}
protected function getPagination(array $data)
{
return PaginationHelper::show(sizeof($data) - $this->page_size, $this->getPage(), $this->page_size);
}
protected function getPageData(array $data)
{
$start = $this->getPage() * $this->page_size - $this->page_size;
$end = $start + $this->page_size;
$data = array_where($data, function ($value, $key) use($start,$end) {
return $key >= $start && $key < $end;
});
return $data;
}
protected function getPage()
{
return \YunShop::request()->page ?: 1;
}
}

View File

@ -0,0 +1,28 @@
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/9/5
* Time: 15:47
*/
namespace app\backend\modules\charts\listeners;
use app\backend\modules\charts\modules\order\services\TimedTaskService;
use Illuminate\Foundation\Bus\DispatchesJobs;
class OrderStatistics
{
use DispatchesJobs;
public function subscribe()
{
\Event::listen('cron.collectJobs', function () {
\Cron::add('OrderStatistics', '0 1 * * *', function () {
(new TimedTaskService())->handle();
return;
});
});
}
}

View File

@ -0,0 +1,63 @@
<?php
/**
* Created by PhpStorm.
* User: BC
* Date: 2018/10/14
* Time: 18:43
*/
namespace app\backend\modules\charts\models;
class Balance extends \app\common\models\finance\Balance
{
/**
* @param $searchTime
* @return mixed
*/
public function getUseCount($searchTime)
{
if ($searchTime) {
return self::uniacid()->whereBetween('created_at', [$searchTime['start'], $searchTime['end']])->sum('change_money');
}
return self::uniacid()->sum('change_money');
}
/**
* @param $searchTime
* @return mixed
*/
public function getUsedCount($searchTime)
{
if ($searchTime) {
return self::uniacid()->where('type', 2)->whereBetween('created_at', [$searchTime['start'], $searchTime['end']])->sum('change_money');
}
return self::uniacid()->where('type', 2)->sum('change_money');
}
/**
* @param $searchTime
* @return mixed
*/
public function getWithdrawCount($searchTime)
{
if ($searchTime) {
return self::uniacid()->where('service_type', 2)->whereBetween('created_at', [$searchTime['start'], $searchTime['end']])->sum('change_money');
}
return self::uniacid()->where('service_type', 2)->sum('change_money');
}
/**
* @param $searchTime
* @return mixed
*/
public function getGivenCount($searchTime)
{
if ($searchTime) {
return self::uniacid()->whereIn('service_type', [5,7])->whereBetween('created_at', [$searchTime['start'], $searchTime['end']])->sum('change_money');
}
return self::uniacid()->whereIn('service_type', [5,7])->sum('change_money');
}
}

View File

@ -0,0 +1,18 @@
<?php
/**
* Created by PhpStorm.
* User: BC
* Date: 2018/10/14
* Time: 22:08
*/
namespace app\backend\modules\charts\models;
use app\common\models\BaseModel;
use app\common\models\MemberCoupon;
class CouponLog extends BaseModel
{
public $table = 'yz_member_coupon';
}

View File

@ -0,0 +1,54 @@
<?php
/**
* Created by PhpStorm.
* User: yunzhong
* Date: 2018/10/22
* Time: 17:37
*/
namespace app\backend\modules\charts\models;
use app\common\models\Withdraw;
use Illuminate\Support\Facades\DB;
class Income extends \app\common\models\Income
{
public function scopeSearch($query,$search)
{
$query->uniacid();
if ($search['member_id']) {
$query->whereHas('hasOneMember',function ($q) use($search) {
$q->whereUid($search['member_id']);
});
}
if ($search['member']) {
$query->whereHas('hasOneMember',function ($q) use($search) {
$q->searchLike($search['member']);
});
}
if ($search['is_time']) {
$searchTime = [strtotime($search['time']['start']),strtotime($search['time']['end'])];
$query->whereBetween('created_at', $searchTime);
}
$query->whereHas('hasOneMember',function ($q) use($search) {
$q->where('uid',DB::raw('ims_yz_member_income.member_id'));
});
return $query;
}
public function hasOneWithdraw()
{
return $this->hasOne(Withdraw::class, 'member_id', 'member_id');
}
public function hasOneMember()
{
return $this->hasOne(\app\common\models\Member::class, 'uid', 'member_id');
}
}

View File

@ -0,0 +1,31 @@
<?php
/****************************************************************
* Author: libaojia
* Date: 2017/10/19 上午11:30
* Email: livsyitian@163.com
* QQ: 995265288
* User:
****************************************************************/
namespace app\backend\modules\charts\models;
use app\common\scopes\UniacidScope;
class Member extends \app\backend\modules\member\models\Member
{
public static function boot()
{
parent::boot();
self::addGlobalScope( new UniacidScope);
}
}

View File

@ -0,0 +1,214 @@
<?php
/**
* Created by PhpStorm.
* User: yunzhong
* Date: 2018/10/4
* Time: 15:28
*/
namespace app\backend\modules\charts\models;
use app\common\models\MemberShopInfo;
use app\common\models\order\OrderPluginBonus;
use Illuminate\Support\Facades\DB;
use Yunshop\StoreCashier\common\models\CashierOrder;
use Yunshop\StoreCashier\common\models\StoreOrder;
use Yunshop\Supplier\common\models\SupplierOrder;
class Order extends \app\common\models\Order
{
//订单导出订单数据
public static function getExportOrders($search)
{
$builder = Order::exportOrders($search);
$orders = $builder->get()->toArray();
return $orders;
}
public function scopeExportOrders($query, $search)
{
$order_builder = $query->search($search);
$orders = $order_builder->with([
'belongsToMember' => self::memberBuilder(),
'hasManyOrderGoods' => self::orderGoodsBuilder(),
'hasOneDispatchType',
'address',
'hasOneOrderRemark',
'express',
'hasOnePayType',
'hasOneOrderPay'
]);
return $orders;
}
public function belongsToRecommender()
{
return $this->belongsTo(MemberShopInfo::class, 'uid', 'member_id');
}
public function scopeOrders($order_builder, $search)
{
$order_builder->search($search);
$order_builder->where('status','>',0);
$orders = $order_builder->with([
'belongsToMember' => function ($query) {
$query->select(['uid', 'mobile', 'nickname', 'realname','avatar']);
},
'hasOneOrderGoods' => function ($query) {
$query->select(DB::raw('sum(goods_cost_price) as total_cost_price'),'order_id')->groupBy('order_id');
// $query->whereRaw('sum(goods_cost_price) as total_cost_price')->groupBy('order_id');
},
'hasOneDispatchType',
'belongsToRecommender' => function ($query) {
},
'hasOnePayType',
'address',
'express',
'hasOneRefundApply' => self::refundBuilder(),
'hasOneOrderRemark',
// 'hasOneOrderPay'=> function (Builder $query) {
// $query->orderPay();
// },
]);
return $orders;
}
private static function refundBuilder()
{
return function ($query) {
return $query->with('returnExpress')->with('resendExpress');
};
}
private static function memberBuilder()
{
return function ($query) {
return $query->select(['uid', 'mobile', 'nickname', 'realname','avatar']);
};
}
private static function orderGoodsBuilder()
{
return function ($query) {
$query->orderGoods();
};
}
public function scopeSearch($order_builder, $params)
{
if (array_get($params, 'ambiguous.field', '') && array_get($params, 'ambiguous.string', '')) {
//订单.支付单号
if ($params['ambiguous']['field'] == 'order') {
call_user_func(function () use (&$order_builder, $params) {
list($field, $value) = explode(':', $params['ambiguous']['string']);
if (isset($value)) {
return $order_builder->where($field, $value);
} else {
return $order_builder->where(function ($query)use ($params){
$query->searchLike($params['ambiguous']['string']);
$query->orWhereHas('hasOneOrderPay', function ($query) use ($params) {
$query->where('pay_sn','like',"%{$params['ambiguous']['string']}%");
});
});
}
});
}
//用户
if ($params['ambiguous']['field'] == 'member') {
call_user_func(function () use (&$order_builder, $params) {
list($field, $value) = explode(':', $params['ambiguous']['string']);
if (isset($value)) {
return $order_builder->where($field, $value);
} else {
return $order_builder->whereHas('belongsToMember', function ($query) use ($params) {
return $query->searchLike($params['ambiguous']['string']);
});
}
});
}
//订单商品
if ($params['ambiguous']['field'] == 'order_goods') {
$order_builder->whereHas('hasManyOrderGoods', function ($query) use ($params) {
$query->searchLike($params['ambiguous']['string']);
});
}
//快递单号
if ($params['ambiguous']['field'] == 'dispatch') {
$order_builder->whereHas('express', function ($query) use ($params) {
$query->searchLike($params['ambiguous']['string']);
});
}
}
//支付方式
if (array_get($params, 'pay_type', '')) {
$order_builder->where('pay_type_id', $params['pay_type']);
}
//操作时间范围
if (array_get($params, 'time_range.field', '') && array_get($params, 'time_range.start', 0) && array_get($params, 'time_range.end', 0)) {
$range = [strtotime($params['time_range']['start']), strtotime($params['time_range']['end'])];
$order_builder->whereBetween($params['time_range']['field'], $range);
}
return $order_builder;
}
public static function getOrderDetailById($order_id)
{
return self::orders()->with(['deductions','coupons','discounts','orderPays'=> function ($query) {
$query->with('payType');
},'hasOnePayType'])->find($order_id);
}
public static function boot()
{
parent::boot();
// static::addGlobalScope(function (Builder $builder) {
// $builder->isPlugin();
// });
}
public function hasManyOrderGoods()
{
return $this->hasMany(OrderGoods::class, 'order_id', 'id');
}
public function hasManyCashierOrder()
{
return $this->hasMany(CashierOrder::class,'order_id','id');
}
public function hasManyStoreOrder()
{
return $this->hasMany(StoreOrder::class,'order_id','id');
}
public function hasManySupplierOrder()
{
return $this->hasMany(SupplierOrder::class,'order_id','id');
}
public function hasManyOrderPluginBonus()
{
return $this->hasMany(OrderPluginBonus::class, 'order_id', 'id');
}
}

View File

@ -0,0 +1,22 @@
<?php
/**
* Created by PhpStorm.
* Author:
* Date: 2017/5/8
* Time: 下午5:06
*/
namespace app\backend\modules\charts\models;
use app\backend\modules\goods\models\Goods;
class OrderGoods extends \app\common\models\OrderGoods
{
// static protected $needLog = true;
// public function goods()
// {
// return $this->hasOne(Goods::class, 'id', 'goods_id');
// }
}

View File

@ -0,0 +1,98 @@
<?php
/**
* Created by PhpStorm.
* User: yunzhong
* Date: 2018/10/31
* Time: 14:38
*/
namespace app\backend\modules\charts\models;
use app\common\models\BaseModel;
use app\common\models\OrderAddress;
class OrderIncomeCount extends BaseModel
{
public $table = 'yz_order_income_count';
protected $guarded = [''];
public function scopeSearch($query, $search)
{
$query->uniacid();
if ($search['order_sn']) {
$query->where('order_sn', $search['order_sn']);
}
if ($search['shop_name']) {
$query->where('shop_name','like','%'.$search['shop_name'].'%');
}
if ($search['member']) {
$query->whereHas('hasOneMember', function ($q) use ($search) {
$q->searchLike($search['member']);
});
}
if ($search['recommend']) {
$query->whereHas('hasOneRecommend', function ($q) use ($search) {
$q->searchLike($search['recommend']);
});
}
if ($search['member_id']) {
$query->where('uid', $search['member_id']);
}
if ($search['status'] != '') {
$query->where('status', $search['status']);
}
if ($search['is_time']) {
if ($search['time']) {
$range = [strtotime($search['time']['start']), strtotime($search['time']['end'])];
$query->whereBetween('created_at', $range);
}
}
if ($search['order_sn']) {
$query->where('order_sn', $search['order_sn']);
}
if ($search['province_id']) {
$query->whereHas('hasOneOrderAddress',function ($q) use ($search) {
if ($search['street_id']) {
$q->where('street_id', $search['street_id']);
} elseif ($search['district_id']) {
$q->where('district_id', $search['district_id']);
} elseif ($search['city_id']) {
$q->where('city_id', $search['city_id']);
} else {
$q->where('province_id', $search['province_id']);
}
});
}
return $query;
}
public static function updateByOrderId($order_id, $data)
{
return self::uniacid()->where('order_id', $order_id)->update($data);
}
public function hasOneMember()
{
return $this->hasOne('app\common\models\Member', 'uid', 'uid');
}
public function hasOneRecommend()
{
return $this->hasOne('app\common\models\Member', 'uid', 'parent_id');
}
public function hasOneOrderAddress()
{
return $this->hasOne(OrderAddress::class, 'order_id', 'order_id');
}
}

View File

@ -0,0 +1,46 @@
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/11/1
* Time: 18:46
*/
namespace app\backend\modules\charts\models;
use app\common\models\BaseModel;
class OrderStatistics extends BaseModel
{
protected $table = 'yz_order_statistics';
protected $guarded = [''];
protected $fillable = [];
public $timestamps = true;
public function belongsToMember()
{
return $this->belongsTo(\app\common\models\Member::class, 'uid', 'uid');
}
public static function getMember($search)
{
$model = self::uniacid()->with('belongsToMember');
if (!empty($search['member_id'])) {
$model->whereHas('belongsToMember', function ($q) use($search) {
$q->where('uid', $search['member_id']);
});
}
if (!empty($search['member_info'])) {
$model->whereHas('belongsToMember', function ($q) use($search) {
$q->where('nickname', 'like' , '%' . $search['member_info'] . '%')
->orWhere('realname', 'like' , '%' . $search['member_info'] . '%')
->orWhere('mobile', 'like' , '%' . $search['member_info'] . '%');
});
}
return $model;
}
}

View File

@ -0,0 +1,50 @@
<?php
/**
* Created by PhpStorm.
* Author:
* Date: 2017/4/10
* Time: 下午5:47
*/
namespace app\backend\modules\charts\models;
class PointLog extends \app\common\models\finance\PointLog
{
/**
* @param $searchTime
* @return mixed
*/
public function getUsedCount($searchTime)
{
if ($searchTime) {
return self::uniacid()->where('point_income_type', -1)->where('created_at', '<=', $searchTime)->sum('point') * -1;
}
return self::uniacid()->where('point_income_type', -1)->sum('point') * -1;
}
/**
* @param $searchTime
* @return mixed
*/
public function getUseCount($searchTime)
{
if ($searchTime) {
return self::uniacid()->where('created_at', '<=', $searchTime)->sum('point');
}
return self::uniacid()->sum('point');
}
/**
* @param $searchTime
* @return mixed
*/
public function getGivenCount($searchTime)
{
if ($searchTime) {
return self::uniacid()->where('point_income_type', 1)->where('created_at', '<=', $searchTime)->sum('point');
}
return self::uniacid()->where('point_income_type', 1)->sum('point');
}
}

View File

@ -0,0 +1,41 @@
<?php
/**
* Created by PhpStorm.
* User: yunzhong
* Date: 2018/10/15
* Time: 16:32
*/
namespace app\backend\modules\charts\models;
use Yunshop\Supplier\common\models\SupplierWithdraw;
use Yunshop\Supplier\supplier\models\SupplierOrder;
class Supplier extends \Yunshop\Supplier\common\models\Supplier
{
public function hasOneSupplierOrder()
{
return $this->hasOne(SupplierOrder::class, 'supplier_id', 'id'); // TODO: Change the autogenerated stub
}
public function hasManySupplierOrderCount()
{
return $this->hasMany(SupplierOrder::class, 'supplier_id', 'id'); // TODO: Change the autogenerated stub
}
public function hasOneSupplierWithdraw()
{
return $this->hasOne(SupplierWithdraw::class, 'supplier_id', 'id'); // TODO: Change the autogenerated stub
}
public function hasOneSupplierWithdrawing()
{
return $this->hasOne(SupplierWithdraw::class, 'supplier_id', 'id'); // TODO: Change the autogenerated stub
}
public function hasManyOrder()
{
return $this->belongsToMany(\app\common\models\Order::class,'yz_supplier_order', 'supplier_id', 'order_id');
}
}

Some files were not shown because too many files have changed in this diff Show More