添加:区域代理插件

优化:购买商品赠送权重值 - 经纪人赠送
修复:购买商品经纪人二级赠送设置无效
修复:代理商升级奖励权重值未按照阶梯赠送
This commit is contained in:
wuhui_zzw 2023-10-24 15:11:27 +08:00
parent ad141178db
commit 3fc6fca7fb
120 changed files with 14517 additions and 39 deletions

View File

@ -0,0 +1,10 @@
<?php
return [
app\common\events\PluginWasEnabled::class => function ($plugins) {
\Artisan::call('migrate', ['--path' => 'plugins/area-dividend/migrations', '--force' => true]);
},
app\common\events\PluginWasDeleted::class => function ($plugins) {
\Artisan::call('migrate:rollback', ['--path' => 'plugins/area-dividend/migrations']);
},
];

View File

@ -0,0 +1,8 @@
"use strict";
$.extend($.locales['en'], {
'examplePlugin': {
test: "JavaScript i18n test: English"
}
});

View File

@ -0,0 +1,5 @@
<?php
return [
'title'=>'this is test title'
];

View File

@ -0,0 +1,9 @@
<?php
/**
* Author: 芸众商城 www.yunzshop.com
* Date: 2017/7/10
* Time: 下午2:38
*/
return [
'title'=>'区域分红',
];

View File

@ -0,0 +1,6 @@
$.extend($.locales['zh-CN'], {
'examplePlugin': {
test: "JavaScript i18n test: 简体中文"
}
});

View File

@ -0,0 +1,6 @@
<?php
return [
'title'=>'测试标题',
'name'=>'测试名字'
];

View File

@ -0,0 +1,41 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateImsYzGoodsAreaDividendTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if (!Schema::hasTable('yz_goods_area_dividend')) {
Schema::create('yz_goods_area_dividend', function (Blueprint $table) {
$table->increments('id');
$table->integer('goods_id')->nullable();
$table->integer('is_dividend')->nullable()->comment('是否开启区域分红');
$table->integer('created_at')->nullable();
$table->integer('updated_at')->nullable();
$table->integer('deleted_at')->nullable();
});
\Illuminate\Support\Facades\DB::statement("ALTER TABLE " . app('db')->getTablePrefix()
. "yz_goods_area_dividend comment '区域分红--商品设置信息'");//表注释
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('ims_yz_goods_area_dividend');
}
}

View File

@ -0,0 +1,57 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateImsYzAreaDividendAgentTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if (!Schema::hasTable('yz_area_dividend_agent')) {
Schema::create('yz_area_dividend_agent', function (Blueprint $table) {
$table->increments('id');
$table->integer('uniacid')->default(0);
$table->integer('member_id')->default(0)->comment('会员ID');
$table->string('real_name')->nullable()->comment('真实姓名');
$table->string('mobile', 60)->nullable()->comment('联系方式');
$table->integer('province_id')->nullable()->comment('省级ID');
$table->string('province_name', 60)->nullable()->default('')->comment('省级名称');
$table->integer('city_id')->nullable()->default(0)->comment('市级ID');
$table->string('city_name', 60)->nullable()->default('')->comment('市级名称');
$table->integer('district_id')->nullable()->default(0)->comment('区级ID');
$table->string('district_name', 60)->nullable()->default('')->comment('区级名称');
$table->integer('street_id')->nullable()->default(0)->comment('街道级ID');
$table->string('street_name', 60)->nullable()->comment('街道级名称');
$table->boolean('agent_level')->nullable()->default(0)->comment('0无效1省代2市代3区代4街道代理');
$table->boolean('status')->nullable()->default(0)->comment('0待审核1通过-1驳回');
$table->integer('agent_at')->nullable()->comment('成为代理时间');
$table->decimal('count_order_amount', 14)->nullable()->default(0.00)->comment('区域订单消费金额');
$table->decimal('count_settle_amount', 14)->nullable()->default(0.00)->comment('累计结算分红金额');
$table->decimal('settle_dividend_amount', 14)->nullable()->default(0.00)->comment('已结算分红');
$table->decimal('unsettled_dividend_amount', 14)->nullable()->default(0.00)->comment('未结算分红');
$table->integer('created_at')->nullable();
$table->integer('updated_at')->nullable();
$table->integer('deleted_at')->nullable();
});
\Illuminate\Support\Facades\DB::statement("ALTER TABLE " . app('db')->getTablePrefix()
. "yz_area_dividend_agent comment '区域分红--区域代理'");//表注释
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('ims_yz_area_dividend_agent');
}
}

View File

@ -0,0 +1,54 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateImsYzAreaDividendTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if (!Schema::hasTable('yz_area_dividend')) {
Schema::create('yz_area_dividend', function (Blueprint $table) {
$table->increments('id');
$table->integer('uniacid');
$table->integer('member_id');
$table->boolean('area_level')->comment('区域等级');
$table->string('agent_area', 100)->default('')->comment('代理区域');
$table->string('order_sn', 60)->default('')->comment('订单号');
$table->decimal('order_amount', 12)->comment('订单金额');
$table->decimal('amount', 12)->comment('分红结算金额');
$table->integer('dividend_rate')->comment('分红比例');
$table->integer('lower_level_rate')->nullable()->comment('下级分红比例');
$table->integer('same_level_number')->nullable()->comment('同级人数');
$table->decimal('dividend_amount', 12)->comment('分红金额');
$table->boolean('status')->default(0)->comment('分红状态 0:未结算 1已结算');
$table->string('create_month', 20)->nullable();
$table->integer('recrive_at')->nullable()->comment('收货时间');
$table->integer('settle_days')->default(0)->comment('结算天数');
$table->integer('statement_at')->nullable()->comment('结算时间');
$table->integer('created_at')->nullable();
$table->integer('updated_at')->nullable();
$table->integer('deleted_at')->nullable();
});
\Illuminate\Support\Facades\DB::statement("ALTER TABLE " . app('db')->getTablePrefix()
. "yz_area_dividend comment '区域分红--分红记录'");//表注释
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('ims_yz_area_dividend');
}
}

View File

@ -0,0 +1,39 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddHasDividendToYzGoodsAreaDividend extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if (\Schema::hasTable('yz_goods_area_dividend')) {
Schema::table('yz_goods_area_dividend', function (Blueprint $table) {
if (!Schema::hasColumn('yz_goods_area_dividend', 'has_dividend')) {
$table->tinyInteger('has_dividend')->default(3);
}
if (!Schema::hasColumn('yz_goods_area_dividend', 'has_dividend_price')) {
$table->decimal('has_dividend_price', 10)->nullable()->default(0.00);
}
});
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}

View File

@ -0,0 +1,36 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddHasDividendRateToYzGoodsAreaDividend extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if (\Schema::hasTable('yz_goods_area_dividend')) {
Schema::table('yz_goods_area_dividend', function (Blueprint $table) {
if (!Schema::hasColumn('yz_goods_area_dividend', 'has_dividend_rate')) {
$table->decimal('has_dividend_rate', 10)->nullable()->default(0.00);
}
});
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}

View File

@ -0,0 +1,42 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class EditDividendRateToYzAreaDividend extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if (\Schema::hasTable('yz_area_dividend')) {
Schema::table('yz_area_dividend', function (Blueprint $table) {
if (Schema::hasColumn('yz_area_dividend', 'lower_level_rate')) {
$table->decimal('lower_level_rate', 10)->nullable()->default(0.00)->change();
}
});
Schema::table('yz_area_dividend', function (Blueprint $table) {
if (Schema::hasColumn('yz_area_dividend', 'dividend_rate')) {
$table->decimal('dividend_rate', 10)->nullable()->default(0.00)->change();
}
});
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}

View File

@ -0,0 +1,40 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddPluginIdToYzAreaDividendOrder extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if (Schema::hasTable('yz_area_dividend_order')) {
Schema::table('yz_area_dividend_order', function (Blueprint $table) {
if (!Schema::hasColumn('yz_area_dividend_agent', 'plugin_id')) {
$table->integer('plugin_id')->default(0);
}
});
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
if (Schema::hasTable('yz_area_dividend_order')) {
Schema::table('yz_area_dividend_order', function (Blueprint $table) {
if (Schema::hasColumn('yz_area_dividend_agent', 'plugin_id')) {
$table->dropColumn('plugin_id');
}
});
}
}
}

View File

@ -0,0 +1,46 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddUserToYzAreaDividendAgent extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if (Schema::hasTable('yz_area_dividend_agent')) {
Schema::table('yz_area_dividend_agent', function (Blueprint $table) {
if (!Schema::hasColumn('yz_area_dividend_agent', 'user_id')) {
$table->integer('user_id')->default(0);
}
if (!Schema::hasColumn('yz_area_dividend_agent', 'username')) {
$table->string('username', 100)->nullable()->default('');
}
if (!Schema::hasColumn('yz_area_dividend_agent', 'password')) {
$table->string('password', 50)->nullable()->default('');
}
});
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
if (Schema::hasTable('yz_area_dividend_agent')) {
Schema::table('yz_area_dividend_agent', function (Blueprint $table) {
if (Schema::hasColumn('yz_area_dividend_agent', 'uid')) {
$table->dropColumn('uid');
}
});
}
}
}

View File

@ -0,0 +1,29 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class RepairDividendData extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
}
}

View File

@ -0,0 +1,46 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateImsYzErrorTeamDividendTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if (!Schema::hasTable('yz_error_team_dividend')) {
Schema::create('yz_error_team_dividend', function (Blueprint $table) {
$table->integer('id', true);
$table->integer('team_dividend_id')->nullable();
$table->integer('member_id')->nullable()->comment('会员id');
$table->string('order_sn', 23)->default('')->comment('订单号');
$table->text('note')->nullable();
$table->decimal('dividend_amount', 12,2)->nullable()->default(0.00)->comment('分红金额');
$table->integer('created_at')->nullable();
$table->integer('updated_at')->nullable();
$table->integer('deleted')->nullable();
});
\Illuminate\Support\Facades\DB::statement("ALTER TABLE " . app('db')->getTablePrefix()
. "yz_error_team_dividend comment '区域分红--分紅错误记录'");//表注释
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('yz_error_team_dividend');
}
}

View File

@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddManageToImsYzAreaDividendAgentTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if (Schema::hasTable('yz_area_dividend_agent')) {
Schema::table('yz_area_dividend_agent',
function (Blueprint $table) {
if (!Schema::hasColumn('yz_area_dividend_agent', 'manage')) {
$table->integer('manage')->nullable()->default(0);
}
});
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('yz_area_dividend_agent', function (Blueprint $table) {
$table->dropColumn('manage');
});
}
}

View File

@ -0,0 +1,40 @@
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddRatioToImsYzAreaDividendAgentTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if (Schema::hasTable('yz_area_dividend_agent')) {
Schema::table('yz_area_dividend_agent',
function (Blueprint $table) {
if (!Schema::hasColumn('yz_area_dividend_agent', 'ratio')) {
$table->decimal('ratio', 10)->nullable();
}
if (!Schema::hasColumn('yz_area_dividend_agent', 'has_ratio')) {
$table->integer('has_ratio')->nullable();
}
});
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('yz_area_dividend_agent', function (Blueprint $table) {
$table->dropColumn('ratio');
$table->integer('has_ratio')->nullable();
});
}
}

View File

@ -0,0 +1,38 @@
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateImsYzAreaDividendOrderTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if (!Schema::hasTable('yz_area_dividend_order')) {
Schema::create('yz_area_dividend_order', function (Blueprint $table) {
$table->increments('id');
$table->integer('order_id')->nullable()->comment('订单id');
$table->integer('agent_id')->nullable()->comment('代理ID');
$table->integer('created_at')->nullable();
$table->integer('updated_at')->nullable();
$table->integer('deleted_at')->nullable();
});
\Illuminate\Support\Facades\DB::statement("ALTER TABLE " . app('db')->getTablePrefix()
. "yz_area_dividend_order comment '区域分红--分紅订单'");//表注释
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('ims_yz_area_dividend_order');
}
}

View File

@ -0,0 +1,50 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateImsYzAreaDividendLockTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if (!Schema::hasTable('yz_area_dividend_lock')) {
Schema::create('yz_area_dividend_lock',
function (Blueprint $table) {
$table->increments('id');
$table->integer('uniacid')->nullable();
$table->integer('uid')->nullable();
$table->integer('province_id')->nullable()->comment('锁定省ID');
$table->integer('city_id')->nullable()->comment('锁定城市ID');
$table->integer('district_id')->nullable()->comment('锁定区、镇ID');
$table->integer('street_id')->nullable()->comment('锁定街道ID');
$table->integer('level')->nullable()->comment('代理级别');
$table->integer('created_at')
->nullable();
$table->integer('updated_at')
->nullable();
$table->integer('deleted_at')
->nullable();
});
\Illuminate\Support\Facades\DB::statement("ALTER TABLE " . app('db')->getTablePrefix()
. "yz_area_dividend_lock comment '区域分红--区域锁定'");//表注释
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('yz_area_dividend_lock');
}
}

View File

@ -0,0 +1,56 @@
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
class AddSaltToImsYzAreaDividendAgentTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if (Schema::hasTable('yz_area_dividend_agent')) {
Schema::table('yz_area_dividend_agent',
function (Blueprint $table) {
if (!Schema::hasColumn('yz_area_dividend_agent', 'salt')) {
$table->string('salt')->nullable();
}
if (Schema::hasColumn('yz_area_dividend_agent', 'password')) {
$table->string('password',255)->change();
}
});
$agents = DB::table('yz_area_dividend_agent')->get();
foreach ($agents as $agent) {
if (empty($agent['password'])) {
continue;
}
if (config('app.framework') == 'platform') {
$data['password'] = bcrypt($agent['password']);
$data['salt'] = randNum(8);
} else {
global $_W;
$data['salt'] = randNum(8);
$data['password'] = sha1("{$agent['password']}-{$data['salt']}-{$_W['config']['setting']['authkey']}");
}
DB::table('yz_area_dividend_agent')->where('id', $agent['id'])->update($data);
}
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('yz_area_dividend_agent', function (Blueprint $table) {
$table->dropColumn('salt');
});
}
}

View File

@ -0,0 +1,48 @@
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
class AddOrderIdToImsYzAreaDividendTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if (Schema::hasTable('yz_area_dividend')) {
Schema::table('yz_area_dividend',
function (Blueprint $table) {
if (!Schema::hasColumn('yz_area_dividend', 'order_id')) {
$table->integer('order_id')->default(0)->index();
}
});
}
try {
//批量更新
DB::statement('UPDATE ims_yz_area_dividend AS ad INNER JOIN ims_yz_order AS o ON ad.order_sn = o.order_sn SET ad.order_id = o.id');
// $area_dividend = DB::table('yz_area_dividend')->select('order_sn')->get();
// foreach ($area_dividend as $item) {
// $order = DB::table('yz_order')->select('id')->where('order_sn', $item['order_sn'])->first();
// Yunshop\AreaDividend\models\AreaDividend::where('order_sn', $item['order_sn'])->update(['order_id' => $order['id']]);
// }
} catch (\Exception $e) {
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('yz_area_dividend', function (Blueprint $table) {
$table->dropColumn('order_id');
});
}
}

View File

@ -0,0 +1,41 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddPidToYzAreaDividendOrder extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if (Schema::hasTable('yz_area_dividend_order')) {
Schema::table('yz_area_dividend_order', function (Blueprint $table) {
if (!Schema::hasColumn('yz_area_dividend_order', 'plugin_id')) {
$table->integer('plugin_id')->default(0);
}
});
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
if (Schema::hasTable('yz_area_dividend_order')) {
Schema::table('yz_area_dividend_order', function (Blueprint $table) {
if (Schema::hasColumn('yz_area_dividend_order', 'plugin_id')) {
$table->dropColumn('plugin_id');
}
});
}
}
}

View File

@ -0,0 +1,34 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddInvestorUidToYzAreaDividendAgentTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if (Schema::hasTable('yz_area_dividend_agent')) {
Schema::table('yz_area_dividend_agent', function (Blueprint $table) {
if (!Schema::hasColumn('yz_area_dividend_agent', 'investor_uid')) {
$table->integer('investor_uid')->default(0)->comment('招商专员会员ID');
}
});
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}

View File

@ -0,0 +1,65 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class UpdateYzGoodsAreaDividendTable20211015 extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if (\Schema::hasTable('yz_goods_area_dividend')) {
Schema::table('yz_goods_area_dividend', function (Blueprint $table) {
if (!Schema::hasColumn('yz_goods_area_dividend', 'alone_rule')) {
$table->tinyInteger('alone_rule')->default(0)->comment('是否启用独立规则0不启用');
}
if (!Schema::hasColumn('yz_goods_area_dividend', 'province_rate')) {
$table->decimal('province_rate')->nullable()->comment('省比例');
}
if (!Schema::hasColumn('yz_goods_area_dividend', 'city_rate')) {
$table->decimal('city_rate')->nullable()->comment('市比例');
}
if (!Schema::hasColumn('yz_goods_area_dividend', 'area_rate')) {
$table->decimal('area_rate')->nullable()->comment('区/县比例');
}
if (!Schema::hasColumn('yz_goods_area_dividend', 'street_rate')) {
$table->decimal('street_rate')->nullable()->comment('街道比例');
}
});
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
if (Schema::hasTable('yz_goods_area_dividend')) {
Schema::table('yz_goods_area_dividend', function (Blueprint $table) {
if (Schema::hasColumn('yz_goods_area_dividend', 'alone_rule')) {
$table->dropColumn('alone_rule');
}
if (Schema::hasColumn('yz_goods_area_dividend', 'province_rate')) {
$table->dropColumn('province_rate');
}
if (Schema::hasColumn('yz_goods_area_dividend', 'city_rate')) {
$table->dropColumn('city_rate');
}
if (Schema::hasColumn('yz_goods_area_dividend', 'area_rate')) {
$table->dropColumn('area_rate');
}
if (Schema::hasColumn('yz_goods_area_dividend', 'street_rate')) {
$table->dropColumn('street_rate');
}
});
}
}
}

View File

@ -0,0 +1,11 @@
{
"name": "area-dividend",
"terminal": "wechat|min|wap",
"version": "1.0.171",
"title": "区域分红",
"description": "线上实现行政区域代理渠道,依据地址进行分红。",
"author": "",
"url": "",
"namespace": "Yunshop\\AreaDividend",
"config": "config.tpl"
}

View File

@ -0,0 +1,146 @@
<?php
/**
* Created by PhpStorm.
*
* User: king/QQ995265288
* Date: 2018/5/8 下午2:17
* Email: livsyitian@163.com
*/
namespace Yunshop\AreaDividend\Frontend\Services;
use app\frontend\modules\finance\interfaces\IIncomePage;
use Yunshop\AreaDividend\models\AreaDividendAgent;
class IncomePageService implements IIncomePage
{
private $itemModel;
public function __construct()
{
$this->itemModel = $this->getItemModel();
}
/**
* return string
*/
public function getMark()
{
return 'area_dividend';
}
/**
* @return bool
*/
public function isShow()
{
return \Setting::get('plugin.area_dividend.is_area_dividend') ? true : false;
}
/**
* @return bool|string
*/
public function isAvailable()
{
if($this->itemModel) return true; else return false;
}
/**
* @return string
*/
public function getTitle()
{
return trans('Yunshop\AreaDividend::index.title');
}
/**
* @return string
*/
public function getIcon()
{
return 'icon-quyu01';
}
/**
* @return string
*/
public function getTypeValue()
{
return 'Yunshop\AreaDividend\models\AreaDividend';
}
/**
* @return string
*/
public function getLevel()
{
if ($this->itemModel) return $this->itemModel->level_name; else return '';
}
public function getAppUrl()
{
$teamManage = app('plugins')->isEnabled('team-manage');
if ($teamManage) {
$url = 'selectionarea';
} else {
$url = 'applyRegionalAgency';
}
return $this->isAvailable() ? 'regionalAgencyCenter' : $url;
}
public function getMiniUrl()
{
$teamManage = app('plugins')->isEnabled('team-manage');
if ($teamManage) {
$mini_url = '';
} else {
$mini_url = '/packageB/member/income/applyRegionalAgency/applyRegionalAgency';
}
return $this->isAvailable() ? '/packageB/member/income/regionalAgencyCenter/regionalAgencyCenter' : $mini_url;
}
/**
* @return bool
*/
public function needIsAgent()
{
return false;
}
/**
* @return bool
*/
public function needIsRelation()
{
return false;
}
/**
* 获取区域代理等级,防止多次查询,赋值给属性 $this->area_agent_level
*
* @return string|bool
*/
private function getItemModel()
{
$member_id = \YunShop::app()->getMemberId();
$levelModel = AreaDividendAgent::uniacid()->where('member_id',$member_id)->where('status',1)->first();
return $levelModel;
}
}

View File

@ -0,0 +1,203 @@
<?php
namespace Yunshop\AreaDividend\Listener;
use app\common\facades\Setting;
use app\common\models\Order;
use app\Jobs\OrderBonusJob;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Yunshop\AreaDividend\event\CreatedAreaDividendBonusEvent;
use Yunshop\AreaDividend\models\AreaDividend;
use Yunshop\AreaDividend\models\AreaDividendAgent;
use Yunshop\AreaDividend\models\AreaDividendGoods;
use Yunshop\AreaDividend\services\OrderCreatedNewService;
use Yunshop\AreaDividend\services\OrderCreatedService;
use Yunshop\Commission\event\CreatedCommissionEvent;
class CreatedCommissionListener
{
use DispatchesJobs;
public $orderModle;
public $setting;
public $totalDividend = 0;
public $commission = 0;
public function subscribe(Dispatcher $events)
{
$events->listen(CreatedCommissionEvent::class, function ($event) {
$this->handle($event->getOrder(), $event->getAmount());
});
}
public function handle($orderModel, $amount)
{
\Log::debug('区域分红:一级分销事件handle()');
$this->orderModle = $orderModel;
$this->setting = $this->orderModle->getSetting('plugin.area_dividend');
if (!$this->setting['is_range_commission']) {
\Log::debug('基础设置没有开启分销极差,返回');
return;
}
if (!$this->setting['is_area_dividend']) {
\Log::debug('基础设置没有开启区域分红,返回');
return;
}
$commission = $amount;
if ($commission > 0) {
$this->commission = $commission;
}
\Log::debug('一级分销金额:' . $commission);
//开启分销极差,去除旧数据
$this->delData($this->orderModle);
//重新生成新数据
$this->getAreaAgent($this->orderModle->address);
//取消队列修改为同步
$order_bonus_job = new OrderBonusJob('yz_area_dividend', 'area-dividend', 'order_sn', 'order_sn', 'dividend_amount', $this->orderModle, $this->totalDividend);
$order_bonus_job->handle();
}
public function getAreaAgent($address)
{
\Log::debug('getAreaAgent()');
//区域代理
$area_level = [];
$area_agent = [];
if ($address->street_id) {
$area_agent['street'] = $this->getStreet($address->street_id);
$area_level['level_4'] = $this->getLevelStatus($area_agent['street']);
}
if ($address->district_id) {
$area_agent['district'] = $this->getDistrict($address->district_id);
$area_level['level_3'] = $this->getLevelStatus($area_agent['district']);
}
if ($address->city_id) {
$area_agent['city'] = $this->getCity($address->city_id);
$area_level['level_2'] = $this->getLevelStatus($area_agent['city']);
}
if ($address->province_id) {
$area_agent['province'] = $this->getProvince($address->province_id);
$area_level['level_1'] = $this->getLevelStatus($area_agent['province']);
}
if ($area_agent) {
\Log::debug('区域代理不为空,继续');
$this->runDividendData($area_agent, $area_level);
} else {
\Log::debug('区域代理为空,返回');
}
}
public function getAmount()
{
$price = 0;
foreach ($this->orderModle->orderGoods as $goods) {
$areaDividendGoods = AreaDividendGoods::getGoodsByGoodsId($goods->goods_id)->first();
if ($areaDividendGoods) {
$price += OrderCreatedService::gerPrice($price, $areaDividendGoods, $goods, $this->setting, $this->orderModle);
}
}
return $price;
}
public function runDividendData($area_agent, $area_level)
{
\Log::debug('runDividendData()');
$order = Order::find($this->orderModle->id);//订单信息
$order['goods'] = $this->orderModle->orderGoods;//订单商品
\Log::error('区域分红订单'.$this->model->id.'开始分红');
$service = new OrderCreatedNewService($order,$area_level,false,$this->commission);
foreach ($area_agent as $key => $time) {
$service->addAreaDividendData($time,$key);
}
//预计分红
$this->totalDividend = $service->expectedDividend();
\Log::error('区域分红订单'.$this->model->id.'预计分红',[$this->totalDividend,$service->amount]);
\Log::error('区域分红订单'.$this->model->id.'分红结束');
}
/**
* @param $provinceId
* @return mixed
*/
public function getProvince($provinceId)
{
return AreaDividendAgent::getAreaAgentByAddressId($provinceId, $level = 1)->get();
}
/**
* @param $cityId
* @return mixed
*/
public function getCity($cityId)
{
return AreaDividendAgent::getAreaAgentByAddressId($cityId, $level = 2)->get();
}
/**
* @param $districtId
* @return mixed
*/
public function getDistrict($districtId)
{
return AreaDividendAgent::getAreaAgentByAddressId($districtId, $level = 3)->get();
}
/**
* @param $streetId
* @return mixed
*/
public function getStreet($streetId)
{
return AreaDividendAgent::getAreaAgentByAddressId($streetId, $level = 4)->get();
}
/**
* @param $value
* @return int
*/
public function getLevelStatus($value)
{
return !$value->isEmpty() ? 1 : 0;
}
//开启分销极差,删除区域分红
public function delData($order)
{
\Log::debug('分销极差订单',$order);
//AreaDividendAgent 分红会员统计金额,目前结构无法删除第一次累计金额
//额外奖励积分与区域分红金额无关
//删除订单分红记录
\app\common\models\order\OrderPluginBonus::where('order_id',$order->id)->delete();
//删除第一次区域分红
AreaDividend::uniacid()->where('order_sn',$order->order_sn)->delete();
//删除第一次感恩奖数据
if (app('plugins')->isEnabled('gratitude-reward')) {
\Yunshop\GratitudeReward\services\BonusService::delBonus($order->order_sn);
}
//删除第一次区域分红记录
if(app('plugins')->isEnabled('team-manage')) {
\Yunshop\TeamManage\common\model\Bonus::uniacid()->where('order_id',$order->id)->delete();
}
}
}

View File

@ -0,0 +1,397 @@
<?php
namespace Yunshop\AreaDividend\Listener;
use app\common\models\Order;
use app\common\services\finance\PointService;
use app\Jobs\OrderBonusJob;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Yunshop\AreaDividend\event\CreatedAreaDividendBonusEvent;
use Yunshop\AreaDividend\models\AreaDividend;
use Yunshop\AreaDividend\models\AreaDividendAgent;
use Yunshop\AreaDividend\services\OrderCreatedService;
use Yunshop\SpecialSettlement\common\AreaRecalculate;
use Yunshop\SpecialSettlement\common\CommissionRecalculate;
class OrderCreatedListener
{
use DispatchesJobs;
public $set;
public $model;
public $is_fix;
public $totalDividend;
/**
* @param Dispatcher $events
*/
public function subscribe(Dispatcher $events)
{
$events->listen(\app\common\events\order\AfterOrderCreatedEvent::class, function ($event) {
$this->handle($event->getOrderModel());
});
}
/**
* @param $order
*/
public function dividend($order){
\Log::debug('dividend()');
//订单model
$this->model = $order;
if ($this->model->uid == 0) {
\Log::debug('订单会员id为0,返回');
return;
}
$this->set = $this->model->getSetting('plugin.area_dividend');
\Log::debug('区域分红执行设置:', json_encode($this->set, 256));
if (!$this->set['is_area_dividend']) {
\Log::debug('基础设置没有开启区域分红,返回');
return;
}
\Log::debug('区域分红订单模型:', json_encode($this->model, 256));
$order['address'] = $this->model->address;//订单地址
if ($order->plugin_id == 0 || $order->plugin_id == 92 || $order->plugin_id == 32) {
\Yunshop\AreaDividend\models\Order::agentOrder($order);
}
$this->getAreaAgent($order['address']);
}
public function handle($order,$is_fix = false)
{
$this->is_fix = $is_fix;
\Log::debug('区域分红:订单创建事件handle()');
$this->set = $order->getSetting('plugin.area_dividend');
$this->dividend($order);
\Log::debug('区域分红' . $this->model->id .'完成');
$order_bonus_job = new OrderBonusJob('yz_area_dividend', 'area-dividend', 'order_sn', 'order_sn', 'dividend_amount', $this->model, $this->totalDividend);
$order_bonus_job->handle();
}
/**
* @param $address
*/
public function getAreaAgent($address)
{
\Log::debug('getAreaAgent()');
//区域代理
$area_level = [];
$area_agent = [];
if ($address->province_id) {
$area_agent['province'] = $this->getProvince($address->province_id);
$area_level['level_1'] = $this->getLevelStatus($area_agent['province']);
}
if ($address->city_id) {
$area_agent['city'] = $this->getCity($address->city_id);
$area_level['level_2'] = $this->getLevelStatus($area_agent['city']);
}
if ($address->district_id) {
$area_agent['district'] = $this->getDistrict($address->district_id);
$area_level['level_3'] = $this->getLevelStatus($area_agent['district']);
}
if ($address->street_id) {
$area_agent['street'] = $this->getStreet($address->street_id);
$area_level['level_4'] = $this->getLevelStatus($area_agent['street']);
}
if (!$area_agent) {
\Log::debug('区域代理为空,返回');
} else {
\Log::debug('区域代理不为空,继续');
$this->runDividendData($area_agent, $area_level);
}
}
/**
* @param $area_agent
* @param $area_level
*/
public function runDividendData($area_agent, $area_level)
{
\Log::debug('runDividendData()');
$order = Order::find($this->model->id);//订单信息
$order['goods'] = $this->model->hasManyOrderGoods;//订单商品
$amount = OrderCreatedService::gerAmount($order, $this->set);
\Log::debug('订单分红金额:'.$amount);
//分销极差开启不执行门店特殊计算
if (!$this->setting['is_range_commission']) {
/**特殊结算插件**/
if (app('plugins')->isEnabled('special-settlement') && \Setting::get('plugin.special-settlement.profit-rule')["area_dividend"]==1) {
if ($this->model->plugin_id == 31 || $this->model->plugin_id == 32) {
\Log::debug('执行门店特殊结算');
$recalculate=new AreaRecalculate();
$recalculate->setGoodsPrice($amount);
$recalculate->setPluginId($this->model->plugin_id);
$recalculate->setOrderId($this->model->id);
$amount=$recalculate->getAmount();
\Log::debug('订单分红金额:'.$amount);
}
}
}
//分红结算金额
if ($amount <= 0) {
\Log::debug('区域分红' . $this->model->id .'订单金额为0');
return;
}
//预计分红
$this->totalDividend = OrderCreatedService::expectedDividend($amount, $this->set);
//分红比例
$dividendRate = OrderCreatedService::gerDividendRate($area_level);
//区域分红数据
$areaDividendData = $this->getAreaDividendData($order, $amount);
\Log::error('区域分红订单'.$this->model->id.'开始分红');
//区域,金额,比例。分红数据
$this->getAreaData($area_agent, $amount, $dividendRate, $areaDividendData);
\Log::error('区域分红订单'.$this->model->id.'分红结束');
}
/**
* @param $order
* @param $amount
* @return array
*/
public function getAreaDividendData($order, $amount)
{
return $areaDividendData = [
'uniacid' => \YunShop::app()->uniacid,
'order_sn' => $order->order_sn,
'order_id' => $order->id,
'amount' => $amount,
'order_amount' => $order->price,
'settle_days' => $this->set['settle_days'] ? $this->set['settle_days'] : 0,
'create_month' => date('Y-m'),
'created_at' => $order['create_time']->timestamp,
];
}
/**
* @param $area_agent
* @param $amount
* @param $dividendRate
* @param $areaDividendData
*/
public function getAreaData($area_agent, $amount, $dividendRate, $areaDividendData)
{
foreach ($area_agent as $key => $time) {
if (!$time->isEmpty()) {
$same_level_num = $time->count('id'); //同级人数
\Log::debug('区域分红' . $this->model->id .$key.'同级人数'.$same_level_num);
foreach ($time as $agent) {
if($agent['agent_at'] > $areaDividendData['created_at']){
\Log::debug("区域分红{$this->model->id}: {$key}{$agent['id']}成为区域代理的时间大于下单时间");
continue;
}
$areaName = $this->getAreaName($agent);
$dividend_rate = $this->getDividendRate($dividendRate,
$agent);
$lower_level_rate = $this->getLowerLevelRate($dividendRate,
$agent);
$this->addAreaDividendData($areaDividendData, $agent,
$areaName, $dividend_rate, $lower_level_rate,
$same_level_num, $amount);
/*if($agent['member_id']){
if ($this->is_fix) {
continue;
}
// 额外赠送积分
AreaDividendAgent::awardPoint($dividendRate,
$agent, $this->model, $this->set);
}*/
}
}else{
\Log::debug('区域分红' . $this->model->id .$key.'团队为空');
}
}
}
private function addPoint($uid, $point)
{
$point_data = [
'point_income_type' => PointService::POINT_INCOME_GET,
'point_mode' => PointService::POINT_MODE_TEAM,
'member_id' => $uid,
'point' => $point,
'remark' => '区域分红奖励'
];
$point_service = new PointService($point_data);
$point_service->changePoint();
}
/**
* @param $areaDividendData
* @param $agent
* @param $areaName
* @param $dividend_rate
* @param $lower_level_rate
* @param $same_level_num
* @param $amount
*/
public function addAreaDividendData($areaDividendData, $agent, $areaName, $dividend_rate, $lower_level_rate, $same_level_num, $amount)
{
$areaDividendData['member_id'] = $agent['member_id'];
$areaDividendData['area_level'] = $agent['agent_level'];
$areaDividendData['agent_area'] = $areaName;
$areaDividendData['dividend_rate'] = $dividend_rate;
$areaDividendData['lower_level_rate'] = $lower_level_rate;
$areaDividendData['same_level_number'] = $same_level_num;
//是否开启同等级平均分红
if ($this->set['is_average']) {
$areaDividendData['dividend_amount'] = proportionMath($amount / $same_level_num ,$areaDividendData['dividend_rate']);
} else {
$areaDividendData['dividend_amount'] = proportionMath($amount , $areaDividendData['dividend_rate']);
}
//如果存在对应记录
$exist = AreaDividend::where([
'member_id' => $agent['member_id'],
'area_level' => $agent['agent_level'],
'order_sn' => $areaDividendData['order_sn'],
])->count();
if ($exist) {
\Log::info("订单{$areaDividendData['order_sn']}:", "{$agent['member_id']}的分红记录已存在");
return ;
}
//todo 防止多队列支付先走
$order = \app\common\models\Order::find($this->model->id);
if ($order->status >= 3) {
$areaDividendData['recrive_at'] = strtotime($order->finish_time);
}
$dividendModel = AreaDividend::create($areaDividendData);
if ($this->is_fix) {
return;
}
event(new CreatedAreaDividendBonusEvent($this->model, $agent['member_id'], $areaDividendData['dividend_amount'], $dividendModel->id));
OrderCreatedService::setAareaDividend($areaDividendData, $agent);
\Log::info("订单{$areaDividendData['order_sn']}:", "{$agent['member_id']}的分红记录生成成功");
return;
}
/**
* @param $agent
* @return string
*/
public function getAreaName($agent)
{
$areaName = '';
$areaName = $agent->province_name;
$areaName .= $agent->city_name ? "-" . $agent->city_name : '';
$areaName .= $agent->district_name ? "-" . $agent->district_name : '';
$areaName .= $agent->street_name ? "-" . $agent->street_name : '';
return $areaName;
}
/**
* @param $dividendRate
* @param $agent
* @return int
*/
public function getDividendRate($dividendRate, $agent)
{
$ratio = $dividendRate['rate_' . $agent['agent_level']]['rate'] ? $dividendRate['rate_' . $agent['agent_level']]['rate'] : 0;
if ($agent->has_ratio == 1) {
$ratio = $agent->ratio;
}
return $ratio;
}
/**
* @param $dividendRate
* @param $agent
* @return int
*/
public function getLowerLevelRate($dividendRate, $agent)
{
$ratio = $dividendRate['rate_' . $agent['agent_level']]['lower_level_rate'] ? $dividendRate['rate_' . $agent['agent_level']]['lower_level_rate'] : 0;
if ($agent->has_ratio == 1) {
$ratio = $agent->ratio;
}
return $ratio;
}
/**
* @param $value
* @return int
*/
public function getLevelStatus($value)
{
return !$value->isEmpty() ? 1 : 0;
}
/**
* @param $provinceId
* @return mixed
*/
public function getProvince($provinceId)
{
return AreaDividendAgent::getAreaAgentByAddressId($provinceId, $level = 1)->get();
}
/**
* @param $cityId
* @return mixed
*/
public function getCity($cityId)
{
return AreaDividendAgent::getAreaAgentByAddressId($cityId, $level = 2)->get();
}
/**
* @param $districtId
* @return mixed
*/
public function getDistrict($districtId)
{
return AreaDividendAgent::getAreaAgentByAddressId($districtId, $level = 3)->get();
}
/**
* @param $streetId
* @return mixed
*/
public function getStreet($streetId)
{
return AreaDividendAgent::getAreaAgentByAddressId($streetId, $level = 4)->get();
}
}

View File

@ -0,0 +1,179 @@
<?php
namespace Yunshop\AreaDividend\Listener;
use app\common\models\Order;
use app\Jobs\OrderBonusJob;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Yunshop\AreaDividend\models\AreaDividendAgent;
use Yunshop\AreaDividend\services\OrderCreatedNewService;
class OrderCreatedListener
{
use DispatchesJobs;
public $set;
public $model;
public $is_fix;
public $totalDividend;
/**
* @param Dispatcher $events
*/
public function subscribe(Dispatcher $events)
{
$events->listen(\app\common\events\order\AfterOrderCreatedEvent::class, function ($event) {
$this->handle($event->getOrderModel());
});
}
public function handle($order,$is_fix = false)
{
$this->is_fix = $is_fix;
\Log::debug('区域分红:订单创建事件handle()');
$this->set = $order->getSetting('plugin.area_dividend');
\Log::debug('区域分红执行设置:', json_encode($this->set, 256));
$this->dividend($order);
\Log::debug('区域分红' . $this->model->id .'完成');
$order_bonus_job = new OrderBonusJob('yz_area_dividend', 'area-dividend', 'order_sn', 'order_sn', 'dividend_amount', $this->model, $this->totalDividend);
$order_bonus_job->handle();
}
/**
* @param $order
*/
public function dividend($order){
\Log::debug('dividend()');
//订单model
$this->model = $order;
if ($this->model->uid == 0) {
\Log::debug('订单会员id为0,返回');
return;
}
if (!$this->set['is_area_dividend']) {
\Log::debug('基础设置没有开启区域分红,返回');
return;
}
\Log::debug('区域分红订单模型:', json_encode($this->model, 256));
$order['address'] = $this->model->address;//订单地址
if ($order->plugin_id == 0 || $order->plugin_id == 92 || $order->plugin_id == 32) {
\Yunshop\AreaDividend\models\Order::agentOrder($order);
}
$this->getAreaAgent($order['address']);
}
/**
* @param $address
*/
public function getAreaAgent($address)
{
\Log::debug('getAreaAgent()');
//区域代理
$area_level = [];
$area_agent = [];
if ($address->province_id) {
$area_agent['province'] = $this->getProvince($address->province_id);
$area_level['level_1'] = $this->getLevelStatus($area_agent['province']);
}
if ($address->city_id) {
$area_agent['city'] = $this->getCity($address->city_id);
$area_level['level_2'] = $this->getLevelStatus($area_agent['city']);
}
if ($address->district_id) {
$area_agent['district'] = $this->getDistrict($address->district_id);
$area_level['level_3'] = $this->getLevelStatus($area_agent['district']);
}
if ($address->street_id) {
$area_agent['street'] = $this->getStreet($address->street_id);
$area_level['level_4'] = $this->getLevelStatus($area_agent['street']);
}
if (!$area_agent) {
\Log::debug('区域代理为空,返回');
} else {
\Log::debug('区域代理不为空,继续');
$this->runDividendData($area_agent, $area_level);
}
}
/**
* @param $area_agent
* @param $area_level
*/
public function runDividendData($area_agent, $area_level)
{
\Log::debug('runDividendData()');
$order = Order::find($this->model->id);//订单信息
$order['goods'] = $this->model->hasManyOrderGoods;//订单商品
\Log::error('区域分红订单'.$this->model->id.'开始分红');
$service = new OrderCreatedNewService($order,$area_level,$this->is_fix);
foreach ($area_agent as $key => $time) {
$service->addAreaDividendData($time,$key);
}
//预计分红
$this->totalDividend = $service->expectedDividend();
\Log::error('区域分红订单'.$this->model->id.'预计分红',[$this->totalDividend,$service->amount]);
\Log::error('区域分红订单'.$this->model->id.'分红结束');
}
/**
* @param $value
* @return int
*/
public function getLevelStatus($value)
{
return !$value->isEmpty() ? 1 : 0;
}
/**
* @param $provinceId
* @return mixed
*/
public function getProvince($provinceId)
{
return AreaDividendAgent::getAreaAgentByAddressId($provinceId, $level = 1)->get();
}
/**
* @param $cityId
* @return mixed
*/
public function getCity($cityId)
{
return AreaDividendAgent::getAreaAgentByAddressId($cityId, $level = 2)->get();
}
/**
* @param $districtId
* @return mixed
*/
public function getDistrict($districtId)
{
return AreaDividendAgent::getAreaAgentByAddressId($districtId, $level = 3)->get();
}
/**
* @param $streetId
* @return mixed
*/
public function getStreet($streetId)
{
return AreaDividendAgent::getAreaAgentByAddressId($streetId, $level = 4)->get();
}
}

View File

@ -0,0 +1,397 @@
<?php
namespace Yunshop\AreaDividend\Listener;
use app\common\models\Order;
use app\common\services\finance\PointService;
use app\Jobs\OrderBonusJob;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Yunshop\AreaDividend\event\CreatedAreaDividendBonusEvent;
use Yunshop\AreaDividend\models\AreaDividend;
use Yunshop\AreaDividend\models\AreaDividendAgent;
use Yunshop\AreaDividend\services\OrderCreatedService;
use Yunshop\SpecialSettlement\common\AreaRecalculate;
use Yunshop\SpecialSettlement\common\CommissionRecalculate;
class OrderCreatedOldListener
{
use DispatchesJobs;
public $set;
public $model;
public $is_fix;
public $totalDividend;
/**
* @param Dispatcher $events
*/
public function subscribe(Dispatcher $events)
{
$events->listen(\app\common\events\order\AfterOrderCreatedEvent::class, function ($event) {
$this->handle($event->getOrderModel());
});
}
/**
* @param $order
*/
public function dividend($order){
\Log::debug('dividend()');
//订单model
$this->model = $order;
if ($this->model->uid == 0) {
\Log::debug('订单会员id为0,返回');
return;
}
$this->set = $this->model->getSetting('plugin.area_dividend');
\Log::debug('区域分红执行设置:', json_encode($this->set, 256));
if (!$this->set['is_area_dividend']) {
\Log::debug('基础设置没有开启区域分红,返回');
return;
}
\Log::debug('区域分红订单模型:', json_encode($this->model, 256));
$order['address'] = $this->model->address;//订单地址
if ($order->plugin_id == 0 || $order->plugin_id == 92 || $order->plugin_id == 32) {
\Yunshop\AreaDividend\models\Order::agentOrder($order);
}
$this->getAreaAgent($order['address']);
}
public function handle($order,$is_fix = false)
{
$this->is_fix = $is_fix;
\Log::debug('区域分红:订单创建事件handle()');
$this->set = $order->getSetting('plugin.area_dividend');
$this->dividend($order);
\Log::debug('区域分红' . $this->model->id .'完成');
$order_bonus_job = new OrderBonusJob('yz_area_dividend', 'area-dividend', 'order_sn', 'order_sn', 'dividend_amount', $this->model, $this->totalDividend);
$order_bonus_job->handle();
}
/**
* @param $address
*/
public function getAreaAgent($address)
{
\Log::debug('getAreaAgent()');
//区域代理
$area_level = [];
$area_agent = [];
if ($address->province_id) {
$area_agent['province'] = $this->getProvince($address->province_id);
$area_level['level_1'] = $this->getLevelStatus($area_agent['province']);
}
if ($address->city_id) {
$area_agent['city'] = $this->getCity($address->city_id);
$area_level['level_2'] = $this->getLevelStatus($area_agent['city']);
}
if ($address->district_id) {
$area_agent['district'] = $this->getDistrict($address->district_id);
$area_level['level_3'] = $this->getLevelStatus($area_agent['district']);
}
if ($address->street_id) {
$area_agent['street'] = $this->getStreet($address->street_id);
$area_level['level_4'] = $this->getLevelStatus($area_agent['street']);
}
if (!$area_agent) {
\Log::debug('区域代理为空,返回');
} else {
\Log::debug('区域代理不为空,继续');
$this->runDividendData($area_agent, $area_level);
}
}
/**
* @param $area_agent
* @param $area_level
*/
public function runDividendData($area_agent, $area_level)
{
\Log::debug('runDividendData()');
$order = Order::find($this->model->id);//订单信息
$order['goods'] = $this->model->hasManyOrderGoods;//订单商品
$amount = OrderCreatedService::gerAmount($order, $this->set);
\Log::debug('订单分红金额:'.$amount);
//分销极差开启不执行门店特殊计算
if (!$this->setting['is_range_commission']) {
/**特殊结算插件**/
if (app('plugins')->isEnabled('special-settlement') && \Setting::get('plugin.special-settlement.profit-rule')["area_dividend"]==1) {
if ($this->model->plugin_id == 31 || $this->model->plugin_id == 32) {
\Log::debug('执行门店特殊结算');
$recalculate=new AreaRecalculate();
$recalculate->setGoodsPrice($amount);
$recalculate->setPluginId($this->model->plugin_id);
$recalculate->setOrderId($this->model->id);
$amount=$recalculate->getAmount();
\Log::debug('订单分红金额:'.$amount);
}
}
}
//分红结算金额
if ($amount <= 0) {
\Log::debug('区域分红' . $this->model->id .'订单金额为0');
return;
}
//预计分红
$this->totalDividend = OrderCreatedService::expectedDividend($amount, $this->set);
//分红比例
$dividendRate = OrderCreatedService::gerDividendRate($area_level);
//区域分红数据
$areaDividendData = $this->getAreaDividendData($order, $amount);
\Log::error('区域分红订单'.$this->model->id.'开始分红');
//区域,金额,比例。分红数据
$this->getAreaData($area_agent, $amount, $dividendRate, $areaDividendData);
\Log::error('区域分红订单'.$this->model->id.'分红结束');
}
/**
* @param $order
* @param $amount
* @return array
*/
public function getAreaDividendData($order, $amount)
{
return $areaDividendData = [
'uniacid' => \YunShop::app()->uniacid,
'order_sn' => $order->order_sn,
'order_id' => $order->id,
'amount' => $amount,
'order_amount' => $order->price,
'settle_days' => $this->set['settle_days'] ? $this->set['settle_days'] : 0,
'create_month' => date('Y-m'),
'created_at' => $order['create_time']->timestamp,
];
}
/**
* @param $area_agent
* @param $amount
* @param $dividendRate
* @param $areaDividendData
*/
public function getAreaData($area_agent, $amount, $dividendRate, $areaDividendData)
{
foreach ($area_agent as $key => $time) {
if (!$time->isEmpty()) {
$same_level_num = $time->count('id'); //同级人数
\Log::debug('区域分红' . $this->model->id .$key.'同级人数'.$same_level_num);
foreach ($time as $agent) {
if($agent['agent_at'] > $areaDividendData['created_at']){
\Log::debug("区域分红{$this->model->id}: {$key}{$agent['id']}成为区域代理的时间大于下单时间");
continue;
}
$areaName = $this->getAreaName($agent);
$dividend_rate = $this->getDividendRate($dividendRate,
$agent);
$lower_level_rate = $this->getLowerLevelRate($dividendRate,
$agent);
$this->addAreaDividendData($areaDividendData, $agent,
$areaName, $dividend_rate, $lower_level_rate,
$same_level_num, $amount);
/*if($agent['member_id']){
if ($this->is_fix) {
continue;
}
// 额外赠送积分
AreaDividendAgent::awardPoint($dividendRate,
$agent, $this->model, $this->set);
}*/
}
}else{
\Log::debug('区域分红' . $this->model->id .$key.'团队为空');
}
}
}
private function addPoint($uid, $point)
{
$point_data = [
'point_income_type' => PointService::POINT_INCOME_GET,
'point_mode' => PointService::POINT_MODE_TEAM,
'member_id' => $uid,
'point' => $point,
'remark' => '区域分红奖励'
];
$point_service = new PointService($point_data);
$point_service->changePoint();
}
/**
* @param $areaDividendData
* @param $agent
* @param $areaName
* @param $dividend_rate
* @param $lower_level_rate
* @param $same_level_num
* @param $amount
*/
public function addAreaDividendData($areaDividendData, $agent, $areaName, $dividend_rate, $lower_level_rate, $same_level_num, $amount)
{
$areaDividendData['member_id'] = $agent['member_id'];
$areaDividendData['area_level'] = $agent['agent_level'];
$areaDividendData['agent_area'] = $areaName;
$areaDividendData['dividend_rate'] = $dividend_rate;
$areaDividendData['lower_level_rate'] = $lower_level_rate;
$areaDividendData['same_level_number'] = $same_level_num;
//是否开启同等级平均分红
if ($this->set['is_average']) {
$areaDividendData['dividend_amount'] = proportionMath($amount / $same_level_num ,$areaDividendData['dividend_rate']);
} else {
$areaDividendData['dividend_amount'] = proportionMath($amount , $areaDividendData['dividend_rate']);
}
//如果存在对应记录
$exist = AreaDividend::where([
'member_id' => $agent['member_id'],
'area_level' => $agent['agent_level'],
'order_sn' => $areaDividendData['order_sn'],
])->count();
if ($exist) {
\Log::info("订单{$areaDividendData['order_sn']}:", "{$agent['member_id']}的分红记录已存在");
return ;
}
//todo 防止多队列支付先走
$order = \app\common\models\Order::find($this->model->id);
if ($order->status >= 3) {
$areaDividendData['recrive_at'] = strtotime($order->finish_time);
}
$dividendModel = AreaDividend::create($areaDividendData);
if ($this->is_fix) {
return;
}
event(new CreatedAreaDividendBonusEvent($this->model, $agent['member_id'], $areaDividendData['dividend_amount'], $dividendModel->id));
OrderCreatedService::setAareaDividend($areaDividendData, $agent);
\Log::info("订单{$areaDividendData['order_sn']}:", "{$agent['member_id']}的分红记录生成成功");
return;
}
/**
* @param $agent
* @return string
*/
public function getAreaName($agent)
{
$areaName = '';
$areaName = $agent->province_name;
$areaName .= $agent->city_name ? "-" . $agent->city_name : '';
$areaName .= $agent->district_name ? "-" . $agent->district_name : '';
$areaName .= $agent->street_name ? "-" . $agent->street_name : '';
return $areaName;
}
/**
* @param $dividendRate
* @param $agent
* @return int
*/
public function getDividendRate($dividendRate, $agent)
{
$ratio = $dividendRate['rate_' . $agent['agent_level']]['rate'] ? $dividendRate['rate_' . $agent['agent_level']]['rate'] : 0;
if ($agent->has_ratio == 1) {
$ratio = $agent->ratio;
}
return $ratio;
}
/**
* @param $dividendRate
* @param $agent
* @return int
*/
public function getLowerLevelRate($dividendRate, $agent)
{
$ratio = $dividendRate['rate_' . $agent['agent_level']]['lower_level_rate'] ? $dividendRate['rate_' . $agent['agent_level']]['lower_level_rate'] : 0;
if ($agent->has_ratio == 1) {
$ratio = $agent->ratio;
}
return $ratio;
}
/**
* @param $value
* @return int
*/
public function getLevelStatus($value)
{
return !$value->isEmpty() ? 1 : 0;
}
/**
* @param $provinceId
* @return mixed
*/
public function getProvince($provinceId)
{
return AreaDividendAgent::getAreaAgentByAddressId($provinceId, $level = 1)->get();
}
/**
* @param $cityId
* @return mixed
*/
public function getCity($cityId)
{
return AreaDividendAgent::getAreaAgentByAddressId($cityId, $level = 2)->get();
}
/**
* @param $districtId
* @return mixed
*/
public function getDistrict($districtId)
{
return AreaDividendAgent::getAreaAgentByAddressId($districtId, $level = 3)->get();
}
/**
* @param $streetId
* @return mixed
*/
public function getStreet($streetId)
{
return AreaDividendAgent::getAreaAgentByAddressId($streetId, $level = 4)->get();
}
}

View File

@ -0,0 +1,42 @@
<?php
/**
* Created by PhpStorm.
* User: yunzhong
* Date: 2018/5/24
* Time: 17:03
*/
namespace Yunshop\AreaDividend\Listener;
use Illuminate\Contracts\Events\Dispatcher;
use Yunshop\AreaDividend\models\AreaDividend;
use Yunshop\Article\models\Log;
class OrderFailureListener
{
public function subscribe(Dispatcher $events)
{
$events->listen(\app\common\events\order\AfterOrderCanceledEvent::class, function ($event) {
\Log::debug('区域分红监听订单关闭事件:uniacid['.\YunShop::app()->uniacid.']');
//订单model
$model = $event->getOrderModel();
\Log::debug('ouniacid['.$model->uniacid.']');
\Log::debug('order_sn['.$model->order_sn.']');
$orderData = AreaDividend::getDataByOrderSn($model->order_sn);
\Log::debug('分红status['.$orderData->status.']');
if ($orderData->status != 1) {
\Log::debug('执行:更改状态已失效');
self::updateStatus($model);
} else {
\Log::debug('不执行');
return;
}
});
}
public function updateStatus($model) {
//修改分红佣金状态-进入结算期
$areaDividendData = ['status' => -1];
$areaDividendWhere = ['order_sn' => $model->order_sn];
AreaDividend::updatedAreaDividend($areaDividendData, $areaDividendWhere);
}
}

View File

@ -0,0 +1,75 @@
<?php
namespace Yunshop\AreaDividend\Listener;
use app\common\facades\Setting;
use app\common\models\Order;
use Illuminate\Contracts\Events\Dispatcher;
use Yunshop\AreaDividend\models\AreaDividend;
use Yunshop\AreaDividend\models\AreaDividendAgent;
use Yunshop\AreaDividend\services\OrderCreatedService;
use Yunshop\Commission\models\AgentLevel;
class OrderReceiveListener
{
public function subscribe(Dispatcher $events)
{
$events->listen(\app\common\events\order\AfterOrderReceivedEvent::class, function ($event) {
$this->handle($event->getOrderModel());
});
}
public function handle($order)
{
//修改分红佣金状态-进入结算期
$areaDividendData = ['recrive_at' => time()];
$areaDividendWhere = ['order_id' => $order->id];
AreaDividend::updatedAreaDividend($areaDividendData, $areaDividendWhere);
// 奖励积分 todo 查询订单所有奖励,每个代理商都获得奖励
$areaDividendModels = AreaDividend::select('member_id','area_level','status')
->where('order_id', $order->id)
->get();
if ($areaDividendModels->isEmpty()) {
$areaDividendModels = AreaDividend::select('member_id','area_level','status')
->where('order_sn', $order->order_sn)
->get();
}
if ($areaDividendModels->isEmpty()) {
return;
}
$set = Setting::get('plugin.area_dividend');
foreach ($areaDividendModels as $areaDividendModel) {
// $agent = $areaDividendModel->hasOneAgent;
// if (!$agent || !$agent->member_id) {
// continue;
// }
// $agent = $agent->toArray();
if (!$areaDividendModel->area_level) {
continue;
}
$point_ratio = AgentLevel::getUserRate($areaDividendModel->member_id,$areaDividendModel->agent_level);
// switch ($areaDividendModel->area_level) {
// case 1:
// $point_ratio = $set['province_point'];
// break;
// case 2:
// $point_ratio = $set['city_point'];
// break;
// case 3:
// $point_ratio = $set['area_point'];
// break;
// default:
// $point_ratio = $set['street_point'];
// break;
// }
$dividendRate['rate_' . $areaDividendModel->area_level]['point_ratio'] = $point_ratio;
// 额外赠送积分
AreaDividendAgent::awardPoint($dividendRate, $areaDividendModel->area_level,$areaDividendModel->member_id, $order, $set);
}
}
}

View File

@ -0,0 +1,530 @@
<?php
/**
* Created by PhpStorm.
* User: shenyang
* Date: 2018/12/24
* Time: 3:38 PM
*/
namespace Yunshop\AreaDividend;
use app\backend\modules\menu\Menu;
use app\common\facades\Setting;
use app\common\models\MemberCart;
use app\common\modules\shop\ShopConfig;
use Config;
use Yunshop\AreaDividend\Listener\CreatedCommissionListener;
use Yunshop\AreaDividend\Listener\OrderCreatedListener;
use Yunshop\AreaDividend\Listener\OrderFailureListener;
use Yunshop\AreaDividend\Listener\OrderReceiveListener;
use Yunshop\AreaDividend\models\AreaDividendAgent;
use Yunshop\AreaDividend\services\TimedTaskService;
use Yunshop\Supplier\common\modules\order\OrderManager;
class PluginApplication extends \app\common\services\PluginApplication
{
public function getIncomePageItems()
{
return [
'areaDividend' => [
'class' => 'Yunshop\AreaDividend\Frontend\Services\IncomePageService',
'type' => 'industry'
]
];
}
public function incomePageIdentity($memberId)
{
$levelModel = AreaDividendAgent::uniacid()->where('member_id', $memberId)->where('status', 1)->first();
if ($levelModel && $levelModel->level_name) {
return [$levelModel->level_name];
}
return [""];
}
public function getTemplateItems()
{
return ['area_dividend_become_agent' => [
'title' => trans('Yunshop\AreaDividend::index.title') . "成为区域代理通知",
'subtitle' => '成为区域代理通知',
'value' => 'area_dividend_become_agent',
'param' => [
'昵称', '时间', '省', '市', '区/县', '街道/乡镇'
]
], 'area_dividend_statement_notice' => [
'title' => trans('Yunshop\AreaDividend::index.title') . "分红结算通知",
'subtitle' => '分红结算通知',
'value' => 'area_dividend_statement_notice',
'param' => [
'昵称', '时间', '等级', '金额'
]
]];
}
protected function setConfig()
{
\app\common\modules\shop\ShopConfig::current()->set('plugins.area-dividend.id', 10);
// 手动分红配置
\app\common\modules\shop\ShopConfig::current()->set('manual_arr.area_dividend_and_level', [
'uidColumn' => 'member_id',
'levelNameColumn' => 'level_name',
'relationsColumn' => 'agent_level',
'enableLevel' => true,
'type_name' => '区域代理',
'role_type' => 'area_dividend_and_level'
]);
\app\common\modules\shop\ShopConfig::current()->set('manual_arr_cfg.area_dividend_and_level', [
'roleTableClass' => \Yunshop\AreaDividend\models\AreaDividendAgent::class
]);
\app\common\modules\shop\ShopConfig::current()->set('plugin.areaDividend', [
'title' => trans('Yunshop\AreaDividend::index.title'),
'ico' => 'icon-quyu01',
'type' => 'areaDividend',
'class' => 'Yunshop\AreaDividend\models\AreaDividend',
'order_class' => '',
'agent_class' => 'Yunshop\AreaDividend\models\AreaDividendAgent',
'agent_name' => 'getAgentByMemberId',
'agent_status' => '1',
]);
\app\common\modules\shop\ShopConfig::current()->set('observer.goods.area_dividend', [
'class' => 'Yunshop\AreaDividend\models\AreaDividendGoods',
'function_validator' => 'relationValidator',
'function_save' => 'relationSave'
]);
\app\common\modules\shop\ShopConfig::current()->push('shop-foundation.member-cart.with', 'goods.areaDividendGoods');
\app\common\modules\shop\ShopConfig::current()->push('shop-foundation.member-cart.with', 'goods.areaDividendGoods');
}
public function getShopConfigItems()
{
return [];
}
public function getWidgetItems()
{
return ['goods.tab_area_dividend' => [
'title' => trans('Yunshop\AreaDividend::index.title'),
'class' => 'Yunshop\AreaDividend\widgets\DividendWidget'
], 'withdraw.tab_area_dividend' => [
'title' => '区域分红提现',
'class' => 'Yunshop\AreaDividend\widgets\AreaDividendWithdrawWidget'
], 'vue-goods.area_dividend' => [
'title' => trans('Yunshop\AreaDividend::index.title'),
'class' => \Yunshop\AreaDividend\widgets\DividendVueWidget::class,
]];
}
protected function setMenuConfig()
{
/**
* 区域分红菜单
*/
\app\backend\modules\menu\Menu::current()->setPluginMenu('area_dividend', [
'name' => '区域分红',
'type' => 'marketing',
'url' => 'plugin.area-dividend.admin.area-dividend-set.index',
'url_params' => '',
'permit' => 1,
'menu' => 1,
'top_show' => 0,
'left_first_show' => 0,
'left_second_show' => 1,
'icon' => 'fa-child',//菜单图标
'list_icon' => 'area_dividend',//菜单图标
'parents' => [],
'child' => [
'area_dividend_set' => [
'name' => '分红设置',
'permit' => 1,
'menu' => 1,
'icon' => '',
'url' => 'plugin.area-dividend.admin.area-dividend-set.index',
'url_params' => '',
'parents' => ['area_dividend'],
'child' => [
'dividend_set' => [
'name' => '分红设置',
'url' => 'plugin.area-dividend.admin.area-dividend-set.index',
'permit' => 1,
'menu' => 0,
'parents' => ['area_dividend', 'area_dividend_set'],
]
]
],
'area_dividend_agent' => [
'name' => '区域代理管理',
'permit' => 1,
'menu' => 1,
'icon' => '',
'url' => 'plugin.area-dividend.admin.agent.index',
'url_params' => '',
'parents' => ['area_dividend'],
'child' => [
'agent_index' => [
'name' => '代理列表',
'url' => 'plugin.area-dividend.admin.agent.index',
'permit' => 1,
'menu' => 0,
'parents' => ['area_dividend', 'area_dividend_agent']
],
'agent_add' => [
'name' => '添加代理',
'url' => 'plugin.area-dividend.admin.agent.create-agent',
'permit' => 1,
'menu' => 0,
'parents' => ['area_dividend',
'area_dividend_agent']
],
'agent_deleted' => ['name' => '删除代理',
'permit' => 1,
'url' => 'plugin.area-dividend.admin.agent.daletedAgency',
'menu' => 0,
'parents' => ['area_dividend', 'area_dividend_agent']
],
'agent_edit' => ['name' => '编辑账号',
'permit' => 1,
'url' => 'plugin.area-dividend.admin.agent.editAgency',
'menu' => 0,
'parents' => ['area_dividend', 'area_dividend_agent']
],
'agent_update_level' => ['name' => '修改代理等级',
'permit' => 0,
'url' => 'plugin.area-dividend.admin.agent.change',
'menu' => 0,
'parents' => ['area_dividend', 'area_dividend_agent']
],
'agent_export' => [
'name' => '导出 EXCEL',
'url' => 'plugin.area-dividend.admin.agent.export',
'permit' => 1,
'menu' => 0,
'parents' => ['area_dividend', 'area_dividend_agent']
],
]
],
'area_dividend_agent_apply' => [
'name' => '区域代理申请',
'permit' => 1,
'menu' => 1,
'icon' => '',
'url' => 'plugin.area-dividend.admin.agent.agent-apply',
'url_params' => '',
'parents' => ['area_dividend'],
'child' => [
'agent_apply' => [
'name' => '查看申请',
'url' => 'plugin.area-dividend.admin.agent.agent-apply',
'permit' => 1,
'menu' => 0,
'parents' => ['area_dividend', 'area_dividend_agent_apply'],
],
'apply' => [
'name' => '申请审核',
'url' => 'plugin.area-dividend.admin.agent.cope-apply',
'permit' => 1,
'menu' => 0,
'parents' => ['area_dividend', 'area_dividend_agent_apply'],
]
]
],
'area_dividend_log' => [
'name' => '区域分红记录',
'permit' => 1,
'menu' => 1,
'icon' => '',
'url' => 'plugin.area-dividend.admin.dividend.get-list',
'url_params' => '',
'parents' => ['area_dividend'],
'child' => [
'agent_apply' => [
'name' => '查看记录',
'url' => 'plugin.area-dividend.admin.dividend.get-list',
'permit' => 1,
'menu' => 0,
'parents' => ['area_dividend', 'area_dividend_log'],
],
'agent_export' => [
'name' => '导出',
'url' => 'plugin.area-dividend.admin.dividend.export',
'permit' => 1,
'menu' => 0,
'parents' => ['area_dividend', 'area_dividend_log'],
],
'agent_detail' => [
'name' => '查看详情',
'url' => 'plugin.area-dividend.admin.dividend.get-detail',
'permit' => 1,
'menu' => 0,
'parents' => ['area_dividend', 'area_dividend_log'],
]
]
]
]
]);
$area = \Yunshop\AreaDividend\models\AreaDividendAgent::getAgentByUserId(\YunShop::app()->uid)->first();
if ($area) {
Config::set('menu', []);
Menu::current()->setMainMenu('area_admin_menu', [
'name' => '区域',
'url' => 'plugin.area-dividend.area.order-manage.index',// url 可以填写http 也可以直接写路由
'urlParams' => '',//如果是url填写的是路由则启用参数否则不启用
'permit' => 0,//如果不设置则不会做权限检测
'menu' => 1,//如果不设置则不显示菜单,子菜单也将不显示
'icon' => 'fa-home',//菜单图标
'parents' => [],
'top_show' => 0,
'left_first_show' => 1,
'left_second_show' => 1,
'child' => [
'area_admin_order' => [
'name' => '区域订单',
'url' => 'plugin.area-dividend.area.area-order.index',
'url_params' => '',
'permit' => 0,
'menu' => 1,
'icon' => '',
'item' => 'area_admin_order',
'parents' => ['area_admin_menu'],
'child' => [
'area_order_export' => [
'name' => '导出',
'url' => 'plugin.area-dividend.area.area-order.export',
'permit' => 0,
'menu' => 0,
'parents' => ['area_admin_menu', 'area_admin_order'],
],
]
],
'area_admin_shop' => [
'name' => '区域商家',
'url' => 'plugin.area-dividend.area.area-shop.index',
'url_params' => '',
'permit' => 0,
'menu' => 1,
'icon' => '',
'item' => 'area_admin_shop',
'parents' => ['area_admin_menu'],
'child' => [
'shop_export' => [
'name' => '导出',
'url' => 'plugin.area-dividend.area.area-shop.export',
'permit' => 0,
'menu' => 0,
'parents' => ['area_admin_menu', 'area_admin_shop'],
],
]
],
'area_admin_dividend_log' => [
'name' => '区域分红',
'url' => 'plugin.area-dividend.area.dividend-log.index',
'url_params' => '',
'permit' => 0,
'menu' => 1,
'icon' => '',
'item' => 'area_admin_dividend_log',
'parents' => ['area_admin_menu'],
'child' => [
'dividend_export' => [
'name' => '导出',
'url' => 'plugin.area-dividend.area.dividend-log.export',
'permit' => 0,
'menu' => 0,
'parents' => ['area_admin_menu', 'area_admin_dividend_log'],
],
]
],
'area_admin_return_address' => [
'name' => '退货地址设置',
'url' => 'plugin.area-dividend.area.return-address.index',
'url_params' => '',
'permit' => 0,
'menu' => 1,
'icon' => '',
'item' => 'area_admin_return_address',
'parents' => ['area_admin_menu'],
'child' => [
'area_admin_return_address_add' => [
'name' => '添加',
'url' => 'plugin.area-dividend.area.return-address.add',
'permit' => 0,
'menu' => 0,
'parents' => ['area_admin_menu', 'area_admin_return_address'],
],
'area_admin_return_address_edit' => [
'name' => '修改',
'url' => 'plugin.area-dividend.area.return-address.edit',
'permit' => 0,
'menu' => 0,
'parents' => ['area_admin_menu', 'area_admin_return_address'],
],
'area_admin_return_address_del' => [
'name' => '删除',
'url' => 'plugin.area-dividend.area.return-address.delete',
'permit' => 0,
'menu' => 0,
'parents' => ['area_admin_menu', 'area_admin_return_address'],
],
]
],
'area_admin_order_manage' => [
'name' => '订单列表',
'url' => 'plugin.area-dividend.area.order-manage.index',
'url_params' => '',
'permit' => 0,
'menu' => 1,
'icon' => '',
'item' => 'area_admin_order_manage',
'parents' => ['area_admin_menu'],
'child' => [
'area_admin_order_detail' => [
'name' => '订单详情',
'url' => 'plugin.area-dividend.area.order-detail.index',
'permit' => 0,
'menu' => 0,
'parents' => ['area_admin_menu', 'area_admin_order_manage'],
],
'area_admin_order_refund_reject' => [
'name' => '驳回',
'url' => 'refund.operation.reject',
'permit' => 0,
'menu' => 0,
'parents' => ['area_admin_menu', 'area_admin_order_manage'],
],
'area_admin_order_refund_pass' => [
'name' => '通过',
'url' => 'refund.operation.pass',
'permit' => 0,
'menu' => 0,
'parents' => ['area_admin_menu', 'area_admin_order_manage'],
],
'area_admin_order_operation_send' => [
'name' => '发货',
'url' => 'order.operation.send',
'permit' => 0,
'menu' => 0,
'parents' => ['area_admin_menu', 'area_admin_order_manage'],
],
'area_admin_order_operation_cancel_send' => [
'name' => '取消发货',
'url' => 'order.operation.cancel-send',
'permit' => 0,
'menu' => 0,
'parents' => ['area_admin_menu', 'area_admin_order_manage'],
],
//order.operation.cancel-send
]
],
'area_admin_store_order_manage' => [
'name' => '门店订单列表',
'url' => 'plugin.area-dividend.area.store-order-manage.index',
'url_params' => '',
'permit' => 0,
'menu' => 1,
'icon' => '',
'item' => 'area_admin_store_order_manage',
'parents' => ['area_admin_menu'],
'child' => [
'area_admin_store-order_detail' => [
'name' => '门店订单详情',
'url' => 'plugin.area-dividend.area.order-detail.store-index',
'permit' => 0,
'menu' => 0,
'parents' => ['area_admin_menu', 'area_admin_store_order_manage'],
],
//order.operation.cancel-send
]
],
'area_admin_order_batch_send' => [
'name' => '批量发货',
'url' => 'plugin.area-dividend.area.batch-send.index',
'url_params' => '',
'permit' => 0,
'menu' => 1,
'icon' => '',
'item' => 'area_admin_order_batch_send',
'parents' => ['area_admin_menu'],
'child' => [
'area_admin_order_batch_send_example' => [
'name' => '下载模版',
'url' => 'plugin.area-dividend.area.batch-send..get-example',
'permit' => 0,
'menu' => 0,
'parents' => ['area_admin_menu', 'area_admin_order_batch_send'],
],
]
],
]
]);
}
}
public function getIncomeItems()
{
$lang = \Setting::get('shop.lang', ['lang' => 'zh_cn'])['zh_cn']['area_dividend'];
return ['areaDividend' => [
'title' => $lang['title'] ?: trans('Yunshop\AreaDividend::index.title'),
'type' => 'areaDividend',
'class' => 'Yunshop\AreaDividend\models\AreaDividend',
'order_class' => '',
]];
}
public function boot()
{
$events = app('events');
/**
* 创建订单
* OrderCreatedListener
*/
$events->subscribe(OrderCreatedListener::class);
$events->subscribe(CreatedCommissionListener::class);
/**
* 订单收货
* OrderReceiveListener
*
*/
$events->subscribe(OrderReceiveListener::class);
/**
* 订单失效
* OrderReceiveListener
*
*/
$events->subscribe(OrderFailureListener::class);
/*
* 定时任务处理
*
*/
\Event::listen('cron.collectJobs', function () {
\Cron::add('Area-dividend', '*/1 * * * *', function () {
(new TimedTaskService())->handle();
return;
});
});
}
public function register()
{
$this->singleton('OrderManager', OrderManager::class);
$this->bind(MemberCart::class, function (PluginApplication $pluginApp, array $params) {
return new \Yunshop\Supplier\common\models\MemberCart($params[0]);
});
}
}

View File

@ -0,0 +1,467 @@
<?php
namespace Yunshop\AreaDividend\admin;
use app\common\components\BaseController;
use app\common\exceptions\ShopException;
use app\common\facades\Setting;
use app\common\helpers\PaginationHelper;
use app\common\helpers\Url;
use app\common\models\Member;
use Illuminate\Support\Facades\Storage;
use Yunshop\AreaDividend\models\AreaDividendAgent;
use Yunshop\AreaDividend\models\Lock;
use Yunshop\AreaDividend\models\weiqing\WeiQingUsers;
use Yunshop\AreaDividend\services\AgentService;
use Yunshop\AreaDividend\services\MessageService;
/**
* Created by PhpStorm.
* User: yanglei
* Date: 2017/4/24
* Time: 下午4:50
*/
class AgentController extends BaseController
{
public function index()
{
$search = \YunShop::request()->search;
$pageSize = 20;
$list = AreaDividendAgent::getAgents($search)->orderBy('id','DESC')->paginate($pageSize);
$pager = PaginationHelper::show($list->total(), $list->currentPage(), $list->perPage());
if(!$search['time']){
$search['time']['start'] = date("Y-m-d H:i:s",time());
$search['time']['end'] = date("Y-m-d H:i:s",time());
}
return view('Yunshop\AreaDividend::admin.list', [
'list' => $list->toarray(),
'pager' => $pager,
'total' => $list->total(),
'search' => $search,
])->render();
}
public function createAgent()
{
$agentData = \YunShop::request()->agent;
$wq_data = \YunShop::request()->wq;
if ($agentData) {
$agent = AreaDividendAgent::getAgentByMemberId($agentData['member_id'])->where('status','<>',-1)->first();
if(!empty($agent)){
$set = Setting::get('plugin.area_dividend');
if($agent->status == 0){
return $this->message('添加失败,此会员已进行申请,请在申请列表进行审核', '', 'error');
}else if($agent->status == 1 && !$set['agent_many']){
return $this->message('添加失败,此会员已是代理商', '', 'error');
}
}
$agentData = AgentService::setAgentData($agentData);
$retLock = Lock::verify($agentData);
if ($retLock) return $this->message('该区域已被锁定', '', 'error');
if (trim($wq_data['username']) && trim($wq_data['password'])) {
if (trim($wq_data['password_again']) != trim($wq_data['password'])) {
return $this->message('两次密码不相同', '', 'error');
}
$verifyPassword = verifyPasswordStrength(trim($wq_data['password']));
if($verifyPassword !== true){
return $this->message($verifyPassword, '', 'error');
}
$result = WeiQingUsers::getUserByUserName(trim($wq_data['username']))->first();
if ($result) {
return $this->message('用户名已存在', '', 'error');
}
$user = WeiQingUsers::register(trim($wq_data['username']), $wq_data['password']);
$agentData['user_id'] = $user['user_id'];
$agentData['username'] = $user['username'];
$agentData['password'] = $user['password'];
$agentData['salt'] = $user['salt'];
}
$agentModel = new AreaDividendAgent();
//将数据赋值到model
$agentModel->setRawAttributes($agentData);
//其他字段赋值
$agentModel->uniacid = \YunShop::app()->uniacid;
$agentModel->status = 1;
$agentModel->agent_at = time();
$agentModel->title = request()->title;
$agentModel->min_status = request()->min_status;
$agentModel->min_app_id = request()->min_app_id;
$agentModel->min_app_secret = request()->min_app_secret;
$agentModel->min_mch_id = request()->min_mch_id;
$agentModel->min_api_secret = request()->min_api_secret;
if (request()->file('apiclient_cert')) $agentModel->min_apiclient_cert = $this->uploadFile('apiclient_cert', $agentModel->min_app_id);
if (request()->file('apiclient_key')) $agentModel->min_apiclient_key = $this->uploadFile('apiclient_key', $agentModel->min_app_id);
//字段检测
$validator = $agentModel->validator($agentModel->getAttributes());
if ($validator->fails()) {
//检测失败
$this->error($validator->messages());
} else {
//数据保存
if ($agentModel->save()) {
$data=[
'member_id'=>$agentData['member_id'],
'username'=>$agentData['username'],
'created_at' => time(),
];
event(new \app\common\events\plugin\AreaDividendEvent($data));
// 发送消息
$member = Member::getMemberByUid($agentModel->member_id)->with('hasOneFans')->first();
MessageService::becomeAgent($agentModel, $member->hasOneFans);
//显示信息并跳转
return $this->message('添加成功', yzWebUrl('plugin.area-dividend.admin.agent'));
} else {
return $this->message('添加失败', '', 'error');
}
}
}
return view('Yunshop\AreaDividend::admin.create-agent', [
'wq_data' => $wq_data,
])->render();
}
public function editAgency(){
$id = \YunShop::request()->id;
$agency = AreaDividendAgent::find($id);
if(!$agency) return $this->message('无此区域代理或已经删除','','error');
if ($agency->user_id) {
$user = WeiQingUsers::getUserByUid($agency->user_id)->first();
if (!$user) return $this->message('微擎账号不存在','','error');
}
if (request()->isMethod('post')) {
$wq_data = \YunShop::request()->wq;
if ($wq_data['password'] && $wq_data['password_again']) {
if (trim($wq_data['password_again']) != trim($wq_data['password'])) {
return $this->message('两次密码不相同', '', 'error');
}
$verifyPassword = verifyPasswordStrength(trim($wq_data['password']));
if($verifyPassword !== true){
return $this->message($verifyPassword, '', 'error');
}
if ($agency->user_id && $user) {
WeiQingUsers::editPwd(trim($wq_data['password']), $user);
return $this->message('修改密码成功', yzWebUrl('plugin.area-dividend.admin.agent'));
} else {
$result = WeiQingUsers::getUserByUserName(trim($wq_data['username']))->first();
if ($result) {
return $this->message('用户名已存在', '', 'error');
}
$user = WeiQingUsers::register(trim($wq_data['username']), $wq_data['password']);
$agentData['user_id'] = $user['user_id'];
$agentData['username'] = $user['username'];
$agentData['password'] = $user['password'];
$agentData['salt'] = $user['salt'];
$agentData['user_id'] = $user['user_id'];
$agency->setRawAttributes($agentData);
if ($agency->save()) {
//显示信息并跳转
return $this->message('账号添加成功', yzWebUrl('plugin.area-dividend.admin.agent'));
} else {
return $this->message('账号添加失败', '', 'error');
}
}
}
else {
if (request()->order_manage == 1) {
$whereColumn = 'province_id';
if ($agency->agent_level == 4) {
$whereColumn = 'street_id';
} else if ($agency->agent_level == 3) {
$whereColumn = 'district_id';
} else if ($agency->agent_level == 2) {
$whereColumn = 'city_id';
}
$existModel = AreaDividendAgent::uniacid()
->where('agent_level', $agency->agent_level)
->where('status', 1)
->where($whereColumn, $agency->$whereColumn)
->where('manage', 1)
->where('id', '!=', $agency->id)
->first();
if ($existModel) {
return $this->message('该区域下已存在[订单管理权限]的代理商', '', 'error');
}
}
$agency->manage = request()->order_manage;
$agency->ratio = request()->ratio;
$agency->has_ratio = request()->has_ratio;
$agency->title = request()->title;
// 支付信息修改
$agency->min_status = request()->min_status;
$agency->min_app_id = request()->min_app_id;
$agency->min_app_secret = request()->min_app_secret;
$agency->min_mch_id = request()->min_mch_id;
$agency->min_api_secret = request()->min_api_secret;
if (request()->file('apiclient_cert')) $agency->min_apiclient_cert = $this->uploadFile('apiclient_cert', $agency->min_app_id);
if (request()->file('apiclient_key')) $agency->min_apiclient_key = $this->uploadFile('apiclient_key', $agency->min_app_id);
if (intval(request()->input('agent')['investor_uid'])) $agency->investor_uid = intval(request()->input('agent')['investor_uid']);
$agency->save();
return $this->message('账号编辑成功', yzWebUrl('plugin.area-dividend.admin.agent'));
}
}
return view('Yunshop\AreaDividend::admin.change-pwd', [
'username' => $user->username,
'agency' => $agency->toArray()
])->render();
}
public function agentApply()
{
$search = request()->search;
if ($search) {
$pageSize = 20;
$list = AreaDividendAgent::getApplyAgentsBySearch($search)->paginate($pageSize);
$pager = PaginationHelper::show($list->total(), $list->currentPage(), $list->perPage());
return view('Yunshop\AreaDividend::admin.apply', [
'list' => $list->toarray(),
'pager' => $pager,
])->render();
}
$pageSize = 20;
$list = AreaDividendAgent::getApplyAgents()->paginate($pageSize);
$pager = PaginationHelper::show($list->total(), $list->currentPage(), $list->perPage());
return view('Yunshop\AreaDividend::admin.apply', [
'list' => $list->toarray(),
'pager' => $pager,
])->render();
}
public function copeApply()
{
$id = \YunShop::request()->id;
$status = \YunShop::request()->status;
$agentModel = AreaDividendAgent::find($id);
if (!$agentModel) {
return $this->message('操作失败,代理商不存在!', '', 'error');
}
$result = false;
if ($status == '1') {
if ($agentModel->username) {
$user = WeiQingUsers::getUserByUserName($agentModel->username)->first();
if ($user) {
return $this->message('用户名已存在,请驳回后重新申请','','error');
}
}
$result = static::setApplyAdopt($agentModel, $status);
} elseif ($status == '-1') {
$result = static::setApplyReject($agentModel, $status);
}
if ($result) {
if ($status == '1') {
$member = Member::getMemberByUid($agentModel->member_id)->with('hasOneFans')->first();
MessageService::becomeAgent($agentModel, $member->hasOneFans);
}
$data=[
'member_id'=>$agentModel['member_id'],
'username'=>$agentModel['real_name'],
'created_at' => time(),
];
event(new \app\common\events\plugin\AreaDividendEvent($data));
if (app('plugins')->isEnabled('instation-message')) {
//开启了站内消息插件
$agentModelNew = AreaDividendAgent::find($id);
event(new \Yunshop\InstationMessage\event\AreaDividendEvent($agentModelNew));
}
return $this->message('操作成功', yzWebUrl('plugin.area-dividend.admin.agent.agent-apply'));
} else {
return $this->message('操作失败', '', 'error');
}
}
protected static function setApplyAdopt($agentModel, $status)
{
$agentModel->status = $status;
if (!empty($agentModel->username) && !empty($agentModel->password)) {
$user_uid= WeiQingUsers::registerBySalt($agentModel->username, $agentModel->password, $agentModel->salt);
$agentModel->user_id = $user_uid;
}
$agentModel->agent_at = time();
return $agentModel->save();
}
protected static function setApplyReject($agentModel, $status)
{
$agentModel->status = $status;
return $agentModel->save();
}
/**
* 数据导出
*
*/
public function export()
{
$file_name = date('Ymdhis', time()) . '区域代理导出';
$search = \YunShop::request()->search;
$list = AreaDividendAgent::getAgents($search)
->get()
->toArray();
$export_data[0] = [
'ID',
'会员id',
'会员',
'姓名/手机号',
'成为代理时间',
'申请区域',
'申请等级',
'区域消费总额',
'分红比例',
'累计结算佣金',
'已结算分红金额',
'未结算分红金额'
];
foreach ($list as $key => $item) {
$area = '';
if ($item['province_name']) {
$area .= $item['province_name'];
}
if ($item['city_name']) {
$area .= $item['city_name'];
}
if ($item['district_name']) {
$area .= $item['district_name'];
}
if ($item['street_name']) {
$area .= $item['street_name'];
}
$export_data[$key + 1] = [
$item['id'],
$item['has_one_member']['uid'] ?: '',
$item['has_one_member']['nickname'] ?: '',
$item['has_one_member']['realname'].'/'.$item['has_one_member']['mobile'],
$item['created_at'],
$area,
$item['level_name'],
$item['count_order_amount']."",
$item['rate']."%",
$item['count_settle_amount']."",
$item['settle_dividend_amount']."",
$item['unsettled_dividend_amount'].""
];
}
return \app\exports\ExcelService::fromArrayExport($export_data,$file_name);
// 商城更新,无法使用
// \Excel::create($file_name, function ($excel) use ($export_data) {
// // Set the title
// $excel->setTitle('Office 2005 XLSX Document');
//
// // Chain the setters
// $excel->setCreator('芸众商城')
// ->setLastModifiedBy("芸众商城")
// ->setSubject("Office 2005 XLSX Test Document")
// ->setDescription("Test document for Office 2005 XLSX, generated using PHP classes.")
// ->setKeywords("office 2005 openxml php")
// ->setCategory("report file");
//
// $excel->sheet('info', function ($sheet) use ($export_data) {
// $sheet->rows($export_data);
// });
//
//
// })->export('xls');
}
public function change()
{
$id = \YunShop::request()->id;
$agent = AreaDividendAgent::find($id);
$agentData = \YunShop::request()->value;
$agentData = AgentService::setAgentData($agentData);
$whereColumn = 'province_id';
if ($agentData['agent_level'] == 4) {
$whereColumn = 'street_id';
} else if ($agentData['agent_level'] == 3) {
$whereColumn = 'district_id';
} else if ($agentData['agent_level'] == 2) {
$whereColumn = 'city_id';
}
$existModel = AreaDividendAgent::uniacid()
->where('agent_level', $agentData['agent_level'])
->where('status', 1)
->where($whereColumn, $agentData[$whereColumn])
->where('manage', 1)
->where('id', '!=', $id)
->first();
if ($existModel) {
return $this->errorJson('该区域下已存在[订单管理权限]的代理商');
} else {
$agent->setRawAttributes($agentData);
$agent->save();
return $this->errorJson('成功');
}
}
public function daletedAgency()
{
$id = \YunShop::request()->id;
$agency = AreaDividendAgent::find($id);
if(!$agency) {
return $this->message('无此区域代理或已经删除','','error');
}
//删除登录
if ($agency->user_id) {
WeiQingUsers::delUser($agency->user_id);
}
$result = AreaDividendAgent::daletedAgency($id);
if($result) {
return $this->message('删除成功',Url::absoluteWeb('plugin.area-dividend.admin.agent'));
}else{
return $this->message('删除失败','','error');
}
}
/**
* Common: 证书上传 - 仅用于区域代理中的微信小程序配置中证书文件上传
* Author: wu-hui
* Time: 2023/05/31 17:08
* @param $fileKey
* @param $appId
* @return string
* @throws ShopException
*/
private function uploadFile($fileKey,$appId){
$file = request()->file($fileKey);
if ($file->isValid()) {
//文件原名
$originalName = $file->getClientOriginalName();
//扩展名
$fileExt = $file->getClientOriginalExtension();
//临时文件的绝对路径
$realPath = $file->getRealPath();
//新文件名
$fileName = "area_pem_{$appId}_{$originalName}";
if ($fileExt != 'pem') throw new ShopException("{$originalName}文件格式错误");
$bool = Storage::disk('cert')->put($fileName, file_get_contents($realPath));
if ($bool) return storage_path("cert/{$fileName}");
}
throw new ShopException("{$fileKey}.pem文件上传错误");
}
}

View File

@ -0,0 +1,56 @@
<?php
namespace Yunshop\AreaDividend\admin;
use app\common\components\BaseController;
use app\common\facades\Setting;
use app\common\helpers\Url;
use app\common\models\notice\MessageTemp;
use Illuminate\Support\Facades\DB;
use Yunshop\AreaDividend\models\AreaDividendAgent;
/**
* Created by PhpStorm.
* User: yanglei
* Date: 2017/4/24
* Time: 下午4:50
*/
class AreaDividendSetController extends BaseController
{
public function index()
{
$set = Setting::get('plugin.area_dividend');
$agreement = Setting::get('area_dividend.agreement');
$requestModel = \YunShop::request()->setdata;
if($requestModel){
Setting::set('area_dividend.agreement', $requestModel['agreement']);
unset($requestModel['agreement']);
if ($requestModel['agent_many'] == 0) {
$has_count = AreaDividendAgent::uniacid()
->select('member_id')
->whereIn('status',[0,1])
->groupBy('member_id')
->havingRaw('COUNT(*) > 1')
->count();
if ($has_count) {
return $this->message('存在一人代理多个区域情况,不能关闭代理多个区域功能', Url::absoluteWeb('plugin.area-dividend.admin.area-dividend-set'),'error');
}
}
if (Setting::set('plugin.area_dividend', $requestModel)) {
return $this->message('设置成功', Url::absoluteWeb('plugin.area-dividend.admin.area-dividend-set'));
} else {
return $this->error('设置失败');
}
}
$temp_list = MessageTemp::getList();
return view('Yunshop\AreaDividend::admin.set', [
'set' => $set,
'agreement' => $agreement,
'temp_list' => $temp_list,
])->render();
}
}

View File

@ -0,0 +1,110 @@
<?php
/**
* Created by PhpStorm.
* User: yanglei
* Date: 2017/5/15
* Time: 下午4:49
*/
namespace Yunshop\AreaDividend\admin;
use app\common\components\BaseController;
use app\common\services\ExportService;
use Yunshop\AreaDividend\models\AreaDividend;
use app\common\helpers\PaginationHelper;
class DividendController extends BaseController
{
public function getList()
{
$pageSize = 20;
$search = \YunShop::request()->get('search');
$list = AreaDividend::getDividends($search)->orderBy('id', 'desc')->paginate($pageSize);
$pager = PaginationHelper::show($list->total(), $list->currentPage(), $list->perPage());
if ($search['statistics'] == 1) {
$statisti['total'] = AreaDividend::getDividends($search)->sum('dividend_amount');
$statisti['settled'] = AreaDividend::getDividends($search)->where('status','1')->sum('dividend_amount');
$statisti['unsettled'] = AreaDividend::getDividends($search)->where('status','0')->sum('dividend_amount');
}
if(!$search['time']){
$search['time']['start'] = date("Y-m-d H:i:s",time());
$search['time']['end'] = date("Y-m-d H:i:s",time());
}
return view('Yunshop\AreaDividend::admin.dividend-list', [
'list' => $list->toarray(),
'pager' => $pager,
'statisti' => $statisti,
'search' => $search,
])->render();
}
public function getDetail()
{
$id = \YunShop::request()->get('id');
$info = AreaDividend::getDetailById($id)->first();
if (!$info) {
return $this->message('无此记录或已被删除', '', 'error');
}
return view('Yunshop\AreaDividend::admin.dividend-detail', [
'info' => $info->toarray(),
])->render();
}
public function export()
{
$search = \YunShop::request()->get('search');
$list = AreaDividend::getDividends($search);
$export_page = request()->export_page ? request()->export_page : 1;
$export_model = new ExportService($list, $export_page);
$file_name = date('Ymdhis', time()) . '区域代理分红导出';
$export_data[0] = [
'代理ID',
'时间',
'会员',
'姓名',
'手机号码',
'区域等级',
'代理区域',
'订单号',
'订单金额',
'分红结算金额',
'分红比例',
'下级分红比例',
'分红金额',
'状态',
];
foreach ($export_model->builder_model as $key => $item)
{
$export_data[$key + 1] = [
$item->id,
$item->created_at->toDateTimeString(),
$item->hasOneMember->nickname,
$item->hasOneMember->realname,
$item->hasOneMember->mobile,
$item->level_name,
$item->agent_area,
$item->order_sn,
$item->order_amount,
$item->amount,
$item->dividend_rate,
$item->lower_level_rate,
$item->dividend_amount,
$item->status_name,
];
}
$export_model->export($file_name, $export_data, \Request::query('route'));
}
}

View File

@ -0,0 +1,55 @@
<?php
/**
* Created by PhpStorm.
* User: shenyang
* Date: 2018/10/29
* Time: 下午7:55
*/
namespace Yunshop\AreaDividend\admin;
use app\common\components\BaseController;
use app\common\events\order\AfterOrderCreatedEvent;
use app\common\models\Order;
use Yunshop\AreaDividend\Listener\OrderCreatedListener;
use Yunshop\AreaDividend\models\AreaDividendAgent;
use Yunshop\Commission\event\CreatedCommissionEvent;
class FixController extends BaseController
{
public $transactionActions = ['*'];
public function index(){
$order = Order::find(4399);
event(new CreatedCommissionEvent($order, 336, 5));
dd('ok');
}
public function error(){
(new \Yunshop\AreaDividend\admin\modules\dividend\WrongDataRepair())->handle();
echo '执行成功';
}
public function test()
{
$order = Order::find(13920);
(new OrderCreatedListener())->handle($order);
dd('ok');
exit;
}
private function getOrderAgent($orderAddress)
{
if ($orderAddress->street_id) {
$agent = AreaDividendAgent::getSpecifiedAgent($orderAddress->street_id, 'street_id', 4);
}
if ($orderAddress->district_id && !$agent) {
$agent = AreaDividendAgent::getSpecifiedAgent($orderAddress->district_id, 'district_id', 3);
}
if ($orderAddress->city_id && !$agent) {
$agent = AreaDividendAgent::getSpecifiedAgent($orderAddress->city_id, 'city_id', 2);
}
if ($orderAddress->province_id && !$agent) {
$agent = AreaDividendAgent::getSpecifiedAgent($orderAddress->province_id, 'province_id', 1);
}
return $agent;
}
}

View File

@ -0,0 +1,37 @@
<?php
/**
* Created by PhpStorm.
* User: shenyang
* Date: 2018/10/30
* Time: 上午9:45
*/
namespace Yunshop\AreaDividend\admin\modules\dividend;
use app\common\facades\Setting;
use app\common\models\Order;
use Carbon\Carbon;
use Yunshop\AreaDividend\Listener\OrderCreatedListener;
use Yunshop\AreaDividend\models\AreaDividend;
class Repair
{
public function handle(){
$orders = Order::where('created_at','>',Carbon::create(2018,10,25)->timestamp)->where('status','!=',-1)->with(['hasManyOrderGoods','address'])->get();
$orders->each(function ($order) {
\YunShop::app()->uniacid = $order->uniacid;
Setting::$uniqueAccountId = $order->uniacid;
(new OrderCreatedListener)->dividend($order);
});
$completedOrders = Order::where('created_at','>',Carbon::create(2018,10,25)->timestamp)->where('status','=',3)->with(['hasManyOrderGoods','address'])->get();
$completedOrders->each(function ($order) {
\YunShop::app()->uniacid = $order->uniacid;
Setting::$uniqueAccountId = $order->uniacid;
$areaDividendData = ['recrive_at' => $order->finish_time];
$areaDividendWhere = ['order_sn' => $order->order_sn];
AreaDividend::updatedAreaDividend($areaDividendData, $areaDividendWhere);
});
}
}

View File

@ -0,0 +1,36 @@
<?php
/**
* Created by PhpStorm.
* User: shenyang
* Date: 2018/11/2
* Time: 4:14 PM
*/
namespace Yunshop\AreaDividend\admin\modules\dividend;
use Yunshop\AreaDividend\models\AreaDividend;
use Yunshop\AreaDividend\models\Order;
class WrongDataRepair
{
public function handle()
{
// todo 找到订单下单时间早于 分红用户成为区域代理时间的 分红记录
$areaDividends = AreaDividend::select('yz_area_dividend.*')
->join('yz_order', 'yz_order.order_sn', '=', 'yz_area_dividend.order_sn')
->join('yz_area_dividend_agent', function ($join) {
$join->on('yz_area_dividend_agent.member_id', '=', 'yz_area_dividend.member_id');
$join->on('yz_area_dividend_agent.agent_at', '>', 'yz_order.create_time');
})
->where('create_time', '>', strtotime('2018-10-25 00:00:00'))
->with(['hasOneOrder', 'hasOneAgent', 'income'])->get();
$areaDividends->each(function (AreaDividend $areaDividend) {
// 如果已结算 删除收入记录
$areaDividend->rollBack();
});
// todo 删除订单对应的分红日志
}
}

View File

@ -0,0 +1,369 @@
<?php
namespace Yunshop\AreaDividend\api;
use app\common\components\ApiController;
use app\common\facades\Setting;
use app\common\models\Member;
use app\common\services\SystemMsgService;
use Carbon\Carbon;
use Yunshop\AreaDividend\models\AreaDividend;
use Yunshop\AreaDividend\models\AreaDividendAgent;
use Yunshop\AreaDividend\models\Lock;
use Yunshop\AreaDividend\models\weiqing\WeiQingUsers;
use Yunshop\AreaDividend\services\AgentService;
use Yunshop\AreaDividend\services\MessageService;
use app\common\helpers\PaginationHelper;
class AreaDividendController extends ApiController
{
public function getAreaAgent()
{
//plugin.area-dividend.api.area-dividend.get-area-agent
$request = AreaDividendAgent::getAgentByMemberId(\YunShop::app()->getMemberId())
->select('member_id', 'real_name', 'mobile', 'agent_level','status','province_name', 'city_name', 'district_name', 'street_name')
->where('status',1)
->orderBy('created_at','desc')
->first();
$agent_many = Setting::get('plugin.area_dividend.agent_many') ? : 0;
if ($request) {
$request = $request->toArray();
$request['level_name']='代理区域:'.$request['province_name'];
$request['city_name'] ? $request['level_name']=$request['level_name'].'-'.$request['city_name'] : '';
$request['district_name'] ? $request['level_name']=$request['level_name'].'-'.$request['district_name'] : '';
$request['street_name'] ? $request['level_name']=$request['level_name'].'-'.$request['street_name'] : '';
$request['agent_many'] = $agent_many;
return $this->successJson('成功', $request);
}
$request['agent_many'] = $agent_many;
return $this->errorJson('不是区域代理!', $request);
}
public function getAllAreaAgent()
{
$requests = AreaDividendAgent::getAgentByMemberId(\YunShop::app()->getMemberId())
->select('member_id', 'real_name', 'mobile', 'agent_level','status','province_name', 'city_name', 'district_name', 'street_name')
->where('status',1)
->orderBy('created_at','desc')
->get()->toArray();
if ($requests) {
foreach ($requests as &$request) {
$request['level_name'] = $request['province_name'];
$request['city_name'] ? $request['level_name'] = $request['level_name'].'-'.$request['city_name'] : '';
$request['district_name'] ? $request['level_name'] = $request['level_name'].'-'.$request['district_name'] : '';
$request['street_name'] ? $request['level_name'] = $request['level_name'].'-'.$request['street_name'] : '';
}
unset($request);
}
return $this->successJson('成功', $requests);
}
public function getDividendStatistic()
{
//plugin.area-dividend.api.area-dividend.get-dividend-statistic
$yesterday = strtotime(date("Y-m-d", strtotime("-1 day")));//昨天
$today = strtotime(date("Y-m-d")); //今天
$week = strtotime(date('Y-m-d 00:00:00', strtotime('this week')));//本周第一天
$month = strtotime(date('Y-m-01 00:00:00')); //本月第一天
$current = strtotime(date("Y-m-d H:i:s"));//当前时间
//昨日
$data['yesterday'] = AreaDividend::getStatistic($yesterday, $today)->sum('dividend_amount');
//今日
$data['today'] = AreaDividend::getStatistic($today, $current)->sum('dividend_amount');
//本周
$data['this_week'] = AreaDividend::getStatistic($week, $current)->sum('dividend_amount');
//本月
$data['this_month'] = AreaDividend::getStatistic($month, $current)->sum('dividend_amount');
if ($data) {
return $this->successJson('成功', $data);
}
return $this->errorJson('未检测到数据!', $data);
}
public function getDividendList()
{
//plugin.area-dividend.api.area-dividend.get-dividend-list&status=1
$search = \YunShop::request()->get();
$status = \YunShop::request()->status;
$create_month = \YunShop::request()->create_month;
$list = [];
// $area_dividend = new AreaDividend();
$dividendList = AreaDividend::getDividendList($status)
->where('member_id', \YunShop::app()->getMemberId())->get();
if ((!empty($status) || $status == "0") && empty($create_month)){
$create_month = $dividendList[0]->create_month;
}
if (empty($create_month) && empty($status)){
$create_month = $dividendList[0]->create_month;
}
$list_data = AreaDividend::getStatusDividendList($create_month,$status)->where('member_id', \YunShop::app()->getMemberId())->paginate(10);
PaginationHelper::show($list_data->total(), $list_data->currentPage(), $list_data->perPage());
$list['time'] = $dividendList;
$list['data'] = $list_data;
if (count($list['time']) > 0 && count($list['data']) > 0){
return $this->successJson('成功', $list);
}
return $this->successJson('未检测到数据!', $list);
}
// /*
// * 按月份获取分红订单分页
// */
// public function getTimeDividendList()
// {
// $create_month = \YunShop::request()->create_month;
//
// $dividendList = AreaDividend::getDividendList('')
// ->where('member_id', \YunShop::app()->getMemberId())->get();
//
// if ($dividendList) {
// return $this->successJson('成功', $dividendList);
// }
// return $this->errorJson('未检测到数据!', $dividendList);
// }
public function setAgentApply()
{
//plugin.area-dividend.api.area-dividend.set-agent-apply
$set = Setting::get('plugin.area_dividend');
$agentData = \YunShop::request()->get('data');
if (!$agentData) {
return $this->errorJson('未检测到数据!');
}
if (!$agentData['real_name'] || !$agentData['mobile']) {
return $this->errorJson('未检测到会员数据!');
}
if (!$agentData['province_id']) {
return $this->errorJson('未检测到申请区域数据!');
}
if (!$set['agent_many']) {//一人可代理多个区域
$agent = AreaDividendAgent::getAgentByMemberId(\YunShop::app()->getMemberId())
->first();
if ($agent) {
return $this->errorJson('您已申请区域代理!');
}
}
$agentData = AgentService::setAgentData($agentData);
if ($set['agent_many']) {//一人可代理多个区域
$agent = AreaDividendAgent::uniacid()
->where('member_id',\YunShop::app()->getMemberId())
->where('agent_level',$agentData['agent_level'])
->where('province_name',$agentData['province_name']);
switch ($agentData['agent_level']) {
case 1:
$agent = $agent->first();
break;
case 2:
$agent = $agent->where('city_name',$agentData['city_name'])
->first();
break;
case 3:
$agent = $agent->where('city_name',$agentData['city_name'])
->where('district_name',$agentData['district_name'])
->first();
break;
case 4:
$agent = $agent->where('city_name',$agentData['city_name'])
->where('district_name',$agentData['district_name'])
->where('street_name',$agentData['street_name'])
->first();
break;
default:
return $this->errorJson('申请信息错误');
}
if ($agent && in_array($agent->status,[0,1])) {
return $this->errorJson('您已申请过该区域的代理!');
} elseif ($agent && $agent->status == -1) {
AreaDividendAgent::uniacid()
->where('id',$agent->id)->delete();
}
}
$retLock = Lock::verify($agentData);
if ($retLock) {
return $this->errorJson('该区域已被锁定!');
}
if (trim($agentData['username']) && trim($agentData['password'])) {
$user = WeiQingUsers::getUserByUserName($agentData['username'])->first();
if ($user) {
return $this->errorJson('账号重复!');
}
$agentData['username'] = trim($agentData['username']);
}
$verifyPassword = verifyPasswordStrength($agentData['password']);
if($verifyPassword !== true){
return $this->errorJson($verifyPassword);
}
if (empty($set['become_check'])) {
$user = WeiQingUsers::register($agentData['username'], $agentData['password']);
$agentData['user_id'] = $user['user_id'];
$agentData['password'] = $user['password'];
$agentData['salt'] = $user['salt'];
} else {
$agentData['salt'] = randNum(8);
$agentData['password'] = user_hash($agentData['password'], $agentData['salt']);
}
$agentModel = new AreaDividendAgent();
//将数据赋值到model
$agentModel->setRawAttributes($agentData);
//其他字段赋值
$agentModel->uniacid = \YunShop::app()->uniacid;
$agentModel->member_id = \YunShop::app()->getMemberId();
$agentModel->status = $set['become_check'] ? 0 : 1;
$agentModel->agent_at = time();
//数据保存
if ($agentModel->save()) {
if (!$set['become_check']) {
// 发送消息
$member = Member::getMemberByUid($agentModel->member_id)->with('hasOneFans')->first();
MessageService::becomeAgent($agentModel, $member->hasOneFans);
}
\Log::debug('------------系统消息通知-------------',$agentModel);
//【系统消息通知】
(new SystemMsgService())->applyNotice($agentModel,'area-dividend');
//显示信息并跳转
return $this->successJson('提交申请资料成功');
}
return $this->errorJson('申请失败');
}
public function applyStatus()
{
// plugin.area-dividend.api.area-dividend.apply-st
//atus
$set = Setting::get('plugin.area_dividend');
$agreement = Setting::get('area_dividend.agreement');
$agent = AreaDividendAgent::getAgentByMemberId(\YunShop::app()->getMemberId())->first();
$data = [
'apply_background' => $set['apply_background'] ? yz_tomedia($set['apply_background']) : '',
];
if(!$agent || $set['agent_many']){
return $this->successJson('可以申请!',array_merge($data,[
'apply' => '1',
'is_open' => isset($set['is_open']) ? $set['is_open'] : 0,
'agreement' => htmlspecialchars_decode($agreement)
]));
}
if($agent->status == 0){
return $this->successJson('正在审核中...,请耐心等待!',array_merge($data,['apply'=>'0']));
}
if($agent->status == -1){
if($set['apply_again']){
return $this->successJson('申请驳回后可再次申请!',array_merge($data,[
'apply'=>'2',
'is_open' => isset($set['is_open']) ? $set['is_open'] : 0,
'agreement' => htmlspecialchars_decode($agreement)
]));
}else{
return $this->successJson('申请驳回后不可再次申请!',array_merge($data,['apply'=>'3']));
}
}
return $this->successJson('您已是区域代理!',array_merge($data,['apply'=>'4']));
}
public function applyAgain()
{
// plugin.area-dividend.api.area-dividend.apply-again
$set = Setting::get('plugin.area_dividend');
$agent = AreaDividendAgent::getAgentByMemberId(\YunShop::app()->getMemberId())->first();
if($agent->status != -1){
return $this->errorJson('再次申请失败.');
}
$agentData = \YunShop::request()->get('data');
if (!$agentData) {
return $this->errorJson('未检测到数据!');
}
if (!$agentData['real_name'] || !$agentData['mobile']) {
return $this->errorJson('未检测到会员数据!');
}
if (!$agentData['province_id']) {
return $this->errorJson('未检测到申请区域数据!');
}
$agentData = AgentService::setAgentData($agentData);
$agent->setRawAttributes($agentData);
$agent->status = 0;
if($agent->save()) {
//【系统消息通知】
(new SystemMsgService())->applyNotice($agent,'area-dividend');
return $this->successJson('再次申请成功');
}
return $this->errorJson('再次申请失败!');
}
public function canApplyAgentLevel()
{
//plugin.area-dividend.api.area-dividend.can-apply-agent-level
$arr = [
0 => ['name' => '省级代理', 'tag' => 0],
1 => ['name' => '市级代理', 'tag' => 1],
2 => ['name' => '区/县级代理', 'tag' => 2],
];
// 开启街道代理
if(\Setting::get('shop.trade.is_street')){
$arr[3] = ['name' => '街道代理', 'tag' => 3];
}
return $this->successJson('代理', $arr);
}
public function getAreaDividend()
{
$result['unliquidated'] = AreaDividend::getAreaDividendByMemberId(0)->sum('dividend_amount');
$result['liquidated'] = AreaDividend::getAreaDividendByMemberId(1)->sum('dividend_amount');
if ($result) {
return $this->successJson('获取数据成功', $result);
}
return $this->errorJson('未检测到数据!');
}
/**
* Common: 根据条件获取区域代理列表
* Author: wu-hui
* Time: 2023/06/01 16:55
* @return \Illuminate\Http\JsonResponse
*/
public function getAreaDividendAgent(){
// 参数获取
$provinceId = request()->input('province_id');
// 列表获取
$list = AreaDividendAgent::uniacid()
->select(['id','title','real_name','province_name','city_name','district_name'])
->where('province_id',$provinceId)
->where('status',1)
->where('min_status',1)
->get();
if($list) $list = $list->toArray();
return $this->successJson('区域代理列表',$list);
}
}

View File

@ -0,0 +1,125 @@
<?php
namespace Yunshop\AreaDividend\api;
use app\backend\modules\member\models\MemberRecord;
use app\common\components\ApiController;
use app\common\exceptions\AppException;
use app\common\models\member\ParentOfMember;
use app\common\services\payment\WechatPayCodePay;
use app\frontend\modules\member\models\SubMemberModel;
use app\Jobs\ModifyRelationshipChainJob;
use Illuminate\Support\Facades\DB;
use Matrix\Exception;
use Yunshop\TeamDividend\models\TeamDividendAgencyModel;
use Yunshop\TeamDividend\models\TeamDividendLevelModel;
use Yunshop\TeamDividend\services\UpgradeService;
class PaymentCodeController extends ApiController{
/**
* Common: 付款码支付
* Author: wu-hui
* Time: 2023/06/03 11:01
* @return \Illuminate\Http\JsonResponse
* @throws Exception
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function createOrder(){
// 参数获取
request()->offsetSet('is_auto_order', true);// 标识为自动下单
$params = [
'auth_code' => request()->input('auth_code'),// 扫码支付付款码,设备读取用户微信中的条码或者二维码信息
'parent_id' => (int)\YunShop::app()->getMemberId(),// 上级用户id
'nickname' => request()->input('nickname'),// 用户昵称
'mobile' => request()->input('mobile'),// 用户手机号
'area_id' => request()->input('area_id'),// 区域代理id
'pay_uid' => (int)request()->input('pay_uid'),// 付款用户id
'operate_type' => (int)request()->input('operate_type'),// 操作类型 0=获取用户信息1=下单支付
];
if($params['parent_id'] <= 0) throw new Exception('请登录后操作!');
$weChatMinPaymentCodeModel = new WechatPayCodePay();
// 开始进行付款码付款处理流程
DB::beginTransaction();
try{
$result = [];
// 判断:获取用户信息 or 下单付款
if($params['operate_type'] != 1){
// 获取用户信息
$result['pay_uid'] = $weChatMinPaymentCodeModel->getPayUserId($params);
$message = '用户信息处理成功';
}else{
if($params['pay_uid'] <= 0) throw new AppException('付款用户信息获取失败!');
// 用户信息处理
$memberId = (int)$weChatMinPaymentCodeModel->userManage($params);
\Log::debug('微信付款码支付 - 用户信息处理 - UID',$memberId);
// 上下级关系绑定
$this->parentSubRelationship($params['parent_id'],$memberId);
// 付款码下单处理
$_COOKIE['imitate_login_member_id'] = $memberId;// 变更登录用户 模拟为付款人下单
$orderIds = $weChatMinPaymentCodeModel->createOrder($memberId);
// 开始支付
$weChatMinPaymentCodeModel->orderPay($orderIds,$params);
// 不是经销商成为经销商
\Log::debug('微信付款码支付 - 经销商处理 - UID',$memberId);
if((int)TeamDividendAgencyModel::where('uid',$memberId)->value('id') <= 0){
$levelId = (new TeamDividendLevelModel())->orderBy('level_weight', 'ASC')->value('id');
(new UpgradeService())->memberUpgradeToAgency($memberId, $levelId);
}
// 开启推广员权限
\Log::debug('微信付款码支付 - 开启推广员权限 - UID',$memberId);
SubMemberModel::where('member_id',$memberId)->update([
'is_agent' => 1
]);
$message = '支付成功';
}
DB::commit();
return $this->successJson($message,$result);
}
catch(\Exception $e){
DB::rollBack();
return $this->errorJson($e->getMessage());
}
}
/**
* Common: 上下级绑定 存在上级则不改变,不存在或者为绑定则改变
* Author: wu-hui
* Time: 2023/06/02 16:46
* @param $parent_id
* @param $uid
* @throws AppException
* @throws Exception
*/
public function parentSubRelationship($parent_id,$uid){
$member = SubMemberModel::getMemberShopInfo($uid);
if($member['inviter'] != 1 || $member['parent_id'] <= 0){
// 判断修改的上级是否推广员
if ($parent_id != 0) {
$parent = SubMemberModel::getMemberShopInfo($parent_id);
if (!($parent->is_agent == 1 && $parent->status == 2)) throw new Exception('上线没有推广权限!');
if ($parent->parent_id == $uid) throw new Exception('会员上下线冲突!');
//验证是否闭环关系链
$chain = ParentOfMember::where('member_id', $parent_id)->pluck('parent_id');
$chain->push($uid);
$chain->push($parent_id);
if ($chain->count() != $chain->unique()->count()) throw new Exception('关系链闭环,请检测关系链!');
}
$record_data = [
'uid' => $uid,
'parent_id' => $member->parent_id,
'after_parent_id' => $parent_id,
'status' => 0,
'uniacid' => \YunShop::app()->uniacid
];
$member_record = MemberRecord::create($record_data);
$this->dispatch(new ModifyRelationshipChainJob($uid, $parent_id, $member_record->id, \YunShop::app()->uniacid));
}
}
}

View File

@ -0,0 +1,169 @@
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/10/29
* Time: 14:23
*/
namespace Yunshop\AreaDividend\area;
use app\common\helpers\PaginationHelper;
use Yunshop\AreaDividend\models\AreaDividendAgent;
use Yunshop\AreaDividend\models\area\Order;
class AreaOrderController extends CommonController
{
public function index()
{
if( !app('plugins')->isEnabled('store-cashier') || !app('plugins')->isEnabled('supplier') ){
return $this->message('请开启供应商插件和门店收银台插件');
}
$search = \YunShop::request()->search?:[];
if ($search) {
$search = array_filter($search, function ($item) {
return $item !== '';// && $item !== 0;
});
}
$search = array_merge($search, $this->setAddress($search));
$list = Order::getOrderList($search)->orderBy('id', 'desc')->paginate(20);
$pager = PaginationHelper::show($list->total(), $list->currentPage(), $list->perPage());
if ($search['statistics'] == 1) {
$tou['amount'] = Order::getOrderList($search)->sum('price');
$tou['total'] = $list->total();
}
if(!$search['time']){
$search['time']['start'] = date("Y-m-d H:i:s",time());
$search['time']['end'] = date("Y-m-d H:i:s",time());
}
return view('Yunshop\AreaDividend::area.order-list', [
'list' => $list->toArray(),
'pager' => $pager,
'search' => $search,
'statisti' => $tou,
])->render();
}
/**
* @return array
*/
protected function setAddress($search)
{
$address = [];
switch ($this->agent_model->agent_level) {
case 1:
$address['province_id'] = $this->agent_model->province_id;
break;
case 2:
$address = [
'province_id' =>$this->agent_model->province_id,
'city_id' =>$this->agent_model->city_id,
];
break;
case 3:
$address = [
'province_id' =>$this->agent_model->province_id,
'city_id' =>$this->agent_model->city_id,
'district_id' =>$this->agent_model->district_id,
];
break;
case 4:
$address = [
'province_id' =>$this->agent_model->province_id,
'city_id' =>$this->agent_model->city_id,
'district_id' =>$this->agent_model->district_id,
'street_id' =>$this->agent_model->street_id,
];
break;
default:
break;
}
return $address;
}
public function export()
{
//dd('QwQ');
$file_name = date('Ymdhis', time()) . '区域订单';
$search = \YunShop::request()->search?:[];
if ($search) {
$search = array_filter($search, function ($item) {
return $item !== '';// && $item !== 0;
});
}
$search = array_merge($search, $this->setAddress($search));
$list = Order::getOrderList($search)->orderBy('id', 'desc')
->get()
->toArray();
$export_data[0] = [
'时间',
'订单号',
'订单地址',
'订单类型',
'店铺名称',
'订单金额(元)',
'区域代理结算金额',
];
foreach ($list as $key => $item) {
$name = '';
if ($item['plugin_id'] == 32) {
$name = $item['has_one_store_order']['has_one_store']['store_name'];
} elseif($item['plugin_id'] == 31) {
$name = $item['has_one_cashier_order']['has_one_store']['store_name'];
} elseif($item['is_plugin'] == 1) {
$name = $item['has_one_supplier_order']['beLongs_to_supplier']['realname'];
} else {
$name = '自营';
}
$export_data[$key + 1] = [
date('Y-m-d H:i:s',$item['created_at']),
$item['order_sn'],
$item['address']['address'],
$item['plugin_name'],
$name,
$item['price'],
$item['has_one_area_dividend'] ? $item['has_one_area_dividend']['amount'] : '无分红',
];
}
return \app\exports\ExcelService::fromArrayExport($export_data,$file_name);
// 商城更新,无法使用
// \Excel::create($file_name, function ($excel) use ($export_data) {
// // Set the title
// $excel->setTitle('Office 2005 XLSX Document');
//
// // Chain the setters
// $excel->setCreator('芸众商城')
// ->setLastModifiedBy("芸众商城")
// ->setSubject("Office 2005 XLSX Test Document")
// ->setDescription("Test document for Office 2005 XLSX, generated using PHP classes.")
// ->setKeywords("office 2005 openxml php")
// ->setCategory("report file");
//
// $excel->sheet('info', function ($sheet) use ($export_data) {
// $sheet->rows($export_data);
// });
//
//
// })->export('xls');
}
}

View File

@ -0,0 +1,185 @@
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/10/30
* Time: 9:46
*/
namespace Yunshop\AreaDividend\area;
use app\common\helpers\PaginationHelper;
use Yunshop\AreaDividend\models\area\AreaStoreShop;
class AreaShopController extends CommonController
{
public function index()
{
if( !app('plugins')->isEnabled('store-cashier') || !app('plugins')->isEnabled('supplier') ){
return $this->message('请开启供应商插件和门店收银台插件');
}
$search = \YunShop::request()->search?:[];
if ($search) {
$search = array_filter($search, function ($item) {
return $item !== '';// && $item !== 0;
});
}
$search = array_merge($search, $this->setAddress($search));
$list = AreaStoreShop::getList($search)->areaShop($search)->orderBy('id', 'desc')->paginate(20);
$pager = PaginationHelper::show($list->total(), $list->currentPage(), $list->perPage());
if(!$search['time']){
$search['time']['start'] = date("Y-m-d H:i:s",time());
$search['time']['end'] = date("Y-m-d H:i:s",time());
}
if ($search['statistics'] == 1) {
$he = AreaStoreShop::getList($search)->areaShop($search)->get();
$tou['store_amount'] = $this->storeAmount($he);
$tou['cashier_amount'] = $this->cashierAmount($he);
$tou['total'] = $list->total();
}
return view('Yunshop\AreaDividend::area.area-shop', [
'list' => $list,
'pager' => $pager,
'search' => $search,
'tou' => $tou,
])->render();
}
public function export()
{
//dd('QwQ');
$file_name = date('Ymdhis', time()) . '区域商家';
$search = \YunShop::request()->search?:[];
if ($search) {
$search = array_filter($search, function ($item) {
return $item !== '';// && $item !== 0;
});
}
$search = array_merge($search, $this->setAddress($search));
$list = AreaStoreShop::getList($search)->areaShop($search)->orderBy('id', 'desc')
->get();
$export_data[0] = [
'商家ID',
'入驻时间',
'所在区域',
'店长信息',
'店铺名称',
'门店分类',
'累计收款金额(元)',
];
foreach ($list as $key => $item) {
$amount = $item->hasManyStoreOrder ? '门店:'.$item->hasManyStoreOrder->sum('amount').'元' : '门店0元';
$amount .= $item->hasManyCashierOrder? '收银台:'.$item->hasManyCashierOrder->sum('amount').'元' : '收银台0元';
$export_data[$key + 1] = [
$item['id'],
$item['created_at'],
$item['full_address'],
$item['has_one_member']['nickname'] ? $item['has_one_member']['nickname'] : $item['has_one_member']['mobile'],
$item['store_name'],
$item['has_one_category']['name'],
$item['has_one_area_dividend'] ? $item['has_one_area_dividend']['amount'] : '无分红',
$amount,
];
}
return \app\exports\ExcelService::fromArrayExport($export_data,$file_name);
// 商城更新,无法使用
// \Excel::create($file_name, function ($excel) use ($export_data) {
// // Set the title
// $excel->setTitle('Office 2005 XLSX Document');
//
// // Chain the setters
// $excel->setCreator('芸众商城')
// ->setLastModifiedBy("芸众商城")
// ->setSubject("Office 2005 XLSX Test Document")
// ->setDescription("Test document for Office 2005 XLSX, generated using PHP classes.")
// ->setKeywords("office 2005 openxml php")
// ->setCategory("report file");
//
// $excel->sheet('info', function ($sheet) use ($export_data) {
// $sheet->rows($export_data);
// });
//
//
// })->export('xls');
}
protected function storeAmount($he)
{
$result = $he->sum(function ($storeOrder) {
if ($storeOrder->hasManyStoreOrder) {
return $storeOrder->hasManyStoreOrder->sum('amount');
}
return 0;
});
return $result;
}
protected function cashierAmount($he)
{
$result = $he->sum(function ($cashierOrder) {
if ($cashierOrder->hasManyCashierOrder) {
return $cashierOrder->hasManyCashierOrder->sum('amount');
}
return 0;
});
return $result;
}
protected function setAddress($search)
{
$address = [];
switch ($this->agent_model->agent_level) {
case 1:
$address['province_id'] = $this->agent_model->province_id;
break;
case 2:
$address = [
'province_id' =>$this->agent_model->province_id,
'city_id' =>$this->agent_model->city_id,
];
break;
case 3:
$address = [
'province_id' =>$this->agent_model->province_id,
'city_id' =>$this->agent_model->city_id,
'district_id' =>$this->agent_model->district_id,
];
break;
case 4:
$address = [
'province_id' =>$this->agent_model->province_id,
'city_id' =>$this->agent_model->city_id,
'district_id' =>$this->agent_model->district_id,
'street_id' =>$this->agent_model->street_id,
];
break;
default:
break;
}
return $address;
}
}

View File

@ -0,0 +1,210 @@
<?php
/**
* Author: 芸众商城 www.yunzshop.com
* Date: 2017/11/21
* Time: 下午4:01
*/
namespace Yunshop\AreaDividend\area;
use app\common\exceptions\ShopException;
use app\common\helpers\Url;
use app\common\models\order\Express;
use Yunshop\AreaDividend\models\Order;
class BatchSendController extends CommonController
{
private $originalName;
private $reader;
private $success_num = 0;
private $err_array = [];
private $error_msg;
public function __construct()
{
// 生成目录
if (!is_dir(storage_path('app/public/orderexcel'))) {
mkdir(storage_path('app/public/orderexcel'), 0777);
}
}
// plugin.area-dividend.area.batch-send.index
public function index()
{
$send_data = request()->send;
if (request()->isMethod('post')) {
if ($send_data['express_company_name'] == "顺丰" && $send_data['express_code'] != "SF") {
return $this->message('上传失败,请重新上传', Url::absoluteWeb('plugin.area-dividend.area.batch-send.index'), 'error');
}
if (!$send_data['excelfile']) {
return $this->message('请上传文件', Url::absoluteWeb('plugin.area-dividend.area.batch-send.index'), 'error');
}
if ($send_data['excelfile']->isValid()) {
$this->uploadExcel($send_data['excelfile']);
$this->readExcel();
$this->handleOrders($this->getRow(), $send_data);
$msg = $this->success_num . '个订单发货成功。';
return $this->message($msg . $this->error_msg, Url::absoluteWeb('plugin.area-dividend.area.batch-send.index'));
}
}
return view('Yunshop\AreaDividend::area.order.batch_send', [])->render();
}
/**
* @name 保存excel文件
* @author
* @param $file
* @throws ShopException
*/
private function uploadExcel($file)
{
$originalName = $file->getClientOriginalName(); // 文件原名
$ext = $file->getClientOriginalExtension(); // 扩展名
$realPath = $file->getRealPath(); //临时文件的绝对路径
if (!in_array($ext, ['xls', 'xlsx'])) {
throw new ShopException('不是xls、xlsx文件格式');
}
$newOriginalName = md5($originalName . str_random(6)) . $ext;
\Storage::disk('orderexcel')->put($newOriginalName, file_get_contents($realPath));
$this->originalName = $newOriginalName;
}
/**
* @name 读取文件
* @author
*/
private function readExcel()
{
$this->reader = \Excel::load(storage_path('app/public/orderexcel') . '/' . $this->originalName);
}
/**
* @name 获取表格内容
* @author
* @return array
*/
private function getRow()
{
$values = [];
$sheet = $this->reader->getActiveSheet();
$highestRow = $sheet->getHighestRow();
$highestColumn = $sheet->getHighestColumn();
$highestColumnCount = \PHPExcel_Cell::columnIndexFromString($highestColumn);
$row = 2;
while ($row <= $highestRow)
{
$rowValue = array();
$col = 0;
while ($col < $highestColumnCount)
{
$rowValue[] = (string)$sheet->getCellByColumnAndRow($col, $row)->getValue();
++$col;
}
$values[] = $rowValue;
++$row;
}
return $values;
}
/**
* @name 订单发货
* @author
* @param $values
* @param $send_data
*/
private function handleOrders($values, $send_data)
{
foreach ($values as $rownum => $col) {
$order_sn = trim($col[0]);
$express_sn = trim($col[1]);
if (empty($order_sn)) {
continue;
}
if (empty($express_sn)) {
$this->err_array[] = $order_sn;
continue;
}
// $order = Order::select('id', 'order_sn', 'status', 'refund_id')->whereStatus(1)->whereOrderSn($order_sn)->first();
$order = Order::select('id', 'order_sn', 'status', 'refund_id')
->whereHas('hasOneAgentOrder', function ($agentOrder) {
$agentOrder->where('agent_id', $this->agent_model->id);
})
->whereStatus(1)
->whereOrderSn($order_sn)
->first();
if (!$order) {
$this->err_array[] = $order_sn;
continue;
}
$express_model = Express::where('order_id',$order->id)->first();
!$express_model && $express_model = new Express();
$express_model->order_id = $order->id;
$express_model->express_company_name = $send_data['express_company_name'];
$express_model->express_code = $send_data['express_code'];
$express_model->express_sn = $express_sn;
$express_model->save();
$order->send_time = time();
$order->status = 2;
$order->save();
$this->success_num += 1;
}
$this->setErrorMsg();
}
/**
* @name 设置错误信息
* @author
*/
private function setErrorMsg()
{
if (count($this->err_array) > 0) {
$num = 1;
$this->error_msg = '<br>' . count($this->err_array) . '个订单发货失败,失败的订单编号: <br>';
foreach ($this->err_array as $k => $v )
{
$this->error_msg .= $v . ' ';
if (($num % 2) == 0)
{
$this->error_msg .= '<br>';
}
++$num;
}
}
}
/**
* @name 获取示例excel
* @author
*/
public function getExample()
{
$export_data[0] = ["订单编号", "快递单号"];
return \app\exports\ExcelService::fromArrayExport($export_data,'批量发货数据模板');
// 商城更新,无法使用
// \Excel::create('批量发货数据模板', function ($excel) use ($export_data) {
// $excel->setTitle('Office 2005 XLSX Document');
// $excel->setCreator('芸众商城')
// ->setLastModifiedBy("芸众商城")
// ->setSubject("Office 2005 XLSX Test Document")
// ->setDescription("Test document for Office 2005 XLSX, generated using PHP classes.")
// ->setKeywords("office 2005 openxml php")
// ->setCategory("report file");
// $excel->sheet('info', function ($sheet) use ($export_data) {
// $sheet->rows($export_data);
// });
// })->export('xls');
}
}

View File

@ -0,0 +1,29 @@
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/10/29
* Time: 14:25
*/
namespace Yunshop\AreaDividend\area;
use app\common\components\BaseController;
use Yunshop\AreaDividend\models\AreaDividendAgent;
class CommonController extends BaseController
{
public $agent_model;
public function preAction()
{
parent::preAction();
$agent_model = AreaDividendAgent::getAgentByUserId(\YunShop::app()->uid)->first();
if ($agent_model) {
$this->agent_model = $agent_model;
} else {
exit($this->message('您不是该区域管理者', '', 'error'));
}
}
}

View File

@ -0,0 +1,134 @@
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/10/30
* Time: 13:46
*/
namespace Yunshop\AreaDividend\area;
use app\common\helpers\PaginationHelper;
use Yunshop\AreaDividend\models\AreaDividend;
class DividendLogController extends CommonController
{
public function index()
{
$search = \YunShop::request()->search?:[];
if ($search) {
$search = array_filter($search, function ($item) {
return $item !== '';// && $item !== 0;
});
}
$list = AreaDividend::getDividends($search)->agent($this->getAreaName())->orderBy('id', 'desc')->paginate(20);
$pager = PaginationHelper::show($list->total(), $list->currentPage(), $list->perPage());
if ($search['statistics'] == 1) {
$statisti = $this->getAreaName();
$statisti['total'] = AreaDividend::getDividends($search)->agent($this->getAreaName())->sum('dividend_amount');
}
if(!$search['time']){
$search['time']['start'] = date("Y-m-d H:i:s",time());
$search['time']['end'] = date("Y-m-d H:i:s",time());
}
return view('Yunshop\AreaDividend::area.dividend-list', [
'list' => $list,
'pager' => $pager,
'search' => $search,
'statisti' => $statisti,
])->render();
}
protected function getAreaName()
{
$address = [
'province_name' =>$this->agent_model->province_name,
'city_name' =>$this->agent_model->city_name,
'district_name' =>$this->agent_model->district_name,
'street_name' =>$this->agent_model->street_name,
];
return [
'member_id' => $this->agent_model->member_id,
'agent_level'=> $this->agent_model->agent_level,
'agent_area' => rtrim(implode('-', $address), '-'),
];
}
public function export()
{
// dd('QwQ');
$file_name = date('Ymdhis', time()) . '区域分红';
$search = \YunShop::request()->search?:[];
if ($search) {
$search = array_filter($search, function ($item) {
return $item !== '';// && $item !== 0;
});
}
$list = AreaDividend::getDividends($search)->agent($this->getAreaName())->orderBy('id', 'desc')
->get()
->toArray();
$export_data[0] = [
'ID',
'分红时间',
'订单号',
'订单金额(元)',
'分红结算金额',
'分红金额',
'分红金额',
];
foreach ($list as $key => $item) {
$export_data[$key + 1] = [
$item['id'],
$item['created_at'],
$item['order_sn'],
$item['order_amount'],
$item['amount'],
$item['dividend_rate'].'%',
$item['lower_level_rate'].'%',
$item['dividend_amount'],
$item['status_name'],
];
}
return \app\exports\ExcelService::fromArrayExport($export_data,$file_name);
// 商城更新,无法使用
// \Excel::create($file_name, function ($excel) use ($export_data) {
// // Set the title
// $excel->setTitle('Office 2005 XLSX Document');
//
// // Chain the setters
// $excel->setCreator('芸众商城')
// ->setLastModifiedBy("芸众商城")
// ->setSubject("Office 2005 XLSX Test Document")
// ->setDescription("Test document for Office 2005 XLSX, generated using PHP classes.")
// ->setKeywords("office 2005 openxml php")
// ->setCategory("report file");
//
// $excel->sheet('info', function ($sheet) use ($export_data) {
// $sheet->rows($export_data);
// });
//
//
// })->export('xls');
}
}

View File

@ -0,0 +1,129 @@
<?php
/**
* Author: 芸众商城 www.yunzshop.com
* Date: 2019-04-18
* Time: 22:37
*/
namespace Yunshop\AreaDividend\area;
use app\backend\modules\member\models\Member;
use app\common\exceptions\AppException;
use app\common\models\goods\ReturnAddress;
use app\common\services\DivFromService;
use Yunshop\AreaDividend\models\Order;
class OrderDetailController extends CommonController
{
public function index()
{
$order = Order::orders([])->whereHas('hasOneAgentOrder')->with(['deductions', 'coupons', 'discounts', 'orderPays' => function ($query) {
$query->with('payType');
}, 'hasOnePayType']);
if (request()->has('id')) {
$order = $order->find(request('id'));
}
if (request()->has('order_sn')) {
$order = $order->where('order_sn', request('order_sn'))->first();
}
if (!$order) {
throw new AppException('未找到订单');
}
if (!empty($order->express)) {
$express = $order->express->getExpress($order->express->express_code, $order->express->express_sn);
$dispatch['express_sn'] = $order->express->express_sn;
$dispatch['company_name'] = $order->express->express_company_name;
$dispatch['data'] = $express['data'];
$dispatch['thumb'] = $order->hasManyOrderGoods[0]->thumb;
$dispatch['tel'] = '95533';
$dispatch['status_name'] = $express['status_name'];
}
$trade = \Setting::get('shop.trade');
/*$plugins_id = \app\common\modules\shop\ShopConfig::current()->get('plugins.area-dividend.id');
$refund_address = ReturnAddress::uniacid()
->where('plugins_id', $plugins_id)
->where('store_id', $this->agent_model->id)
->orderBy('id', 'desc')
->get();*/
return view('Yunshop\AreaDividend::area.order.detail', [
'order' => $order ? $order->toArray() : [],
'invoice_set'=>$trade['invoice'],
'dispatch' => $dispatch,
'div_from' => $this->getDivFrom($order),
'var' => \YunShop::app()->get(),
'ops' => 'Yunshop\AreaDividend::area.order.ops',
'edit_goods' => 'goods.goods.edit',
//'refund_address' => $refund_address
])->render();
}
private function getDivFrom($order)
{
if (!$order || !$order->hasManyOrderGoods) {
return ['status' => false];
}
$goods_ids = [];
foreach ($order->hasManyOrderGoods as $key => $goods) {
$goods_ids[] = $goods['goods_id'];
}
$memberInfo = Member::select('realname', 'idcard')->where('uid', $order->uid)->first();
$result['status'] = DivFromService::isDisplay($goods_ids);
$result['member_name'] = $memberInfo->realname;
$result['member_card'] = $memberInfo->idcard;
return $result;
}
/**
* 门店订单详情
*/
public function storeIndex()
{
$order = Order::orders([])->whereHas('hasOneAgentOrder')->with(['deductions', 'coupons', 'discounts', 'orderPays' => function ($query) {
$query->with('payType');
}, 'hasOnePayType']);
if (request()->has('id')) {
$order = $order->find(request('id'));
}
if (request()->has('order_sn')) {
$order = $order->where('order_sn', request('order_sn'))->first();
}
if (!$order) {
throw new AppException('未找到订单');
}
if (!empty($order->express)) {
$express = $order->express->getExpress($order->express->express_code, $order->express->express_sn);
$dispatch['express_sn'] = $order->express->express_sn;
$dispatch['company_name'] = $order->express->express_company_name;
$dispatch['data'] = $express['data'];
$dispatch['thumb'] = $order->hasManyOrderGoods[0]->thumb;
$dispatch['tel'] = '95533';
$dispatch['status_name'] = $express['status_name'];
}
$trade = \Setting::get('shop.trade');
/*$plugins_id = \app\common\modules\shop\ShopConfig::current()->get('plugins.area-dividend.id');
$refund_address = ReturnAddress::uniacid()
->where('plugins_id', $plugins_id)
->where('store_id', $this->agent_model->id)
->orderBy('id', 'desc')
->get();*/
return view('Yunshop\AreaDividend::area.order.store-detail', [
'order' => $order ? $order->toArray() : [],
'invoice_set'=>$trade['invoice'],
'dispatch' => $dispatch,
'div_from' => $this->getDivFrom($order),
'var' => \YunShop::app()->get(),
'ops' => 'Yunshop\AreaDividend::area.order.ops',
'edit_goods' => 'goods.goods.edit',
//'refund_address' => $refund_address
])->render();
}
}

View File

@ -0,0 +1,260 @@
<?php
/**
* Author: 芸众商城 www.yunzshop.com
* Date: 2019-04-18
* Time: 22:09
*/
namespace Yunshop\AreaDividend\area;
use app\backend\modules\goods\models\GoodsOption;
use app\backend\modules\order\models\OrderGoods;
use app\common\components\BaseController;
use app\common\helpers\PaginationHelper;
use app\common\services\ExportService;
use Yunshop\AreaDividend\models\Order;
use app\common\services\OrderExportService;
class OrderManageController extends CommonController
{
public function index()
{
$this->export();
$orderModel = Order::select('yz_order.*')->orders(request()->search)
->join('yz_area_dividend_order',function ($join) {
$join->on('yz_area_dividend_order.order_id','yz_order.id')
->where('yz_area_dividend_order.agent_id', $this->agent_model->id)->whereNotIn('yz_area_dividend_order.plugin_id',[32]);
});
$requestSearch = \YunShop::request()->get('search');
$requestSearch['plugin'] = 'fund';
if ($requestSearch) {
$requestSearch = array_filter($requestSearch, function ($item) {
return !empty($item);
});
}
$list['total_price'] = $orderModel->sum('price');
$list += $orderModel->orderBy('yz_order.id', 'desc')->paginate(10)->toArray();
$pager = PaginationHelper::show($list['total'], $list['current_page'],
$list['per_page']);
return view('Yunshop\AreaDividend::area.order.list', [
'list' => $list,
'total_price' => $list['total_price'],
'pager' => $pager,
'requestSearch' => $requestSearch,
'var' => \YunShop::app()->get(),
'url' => request('route'),
'include_ops' => 'Yunshop\AreaDividend::area.order.ops',
'detail_url' => 'plugin.area-dividend.area.order-detail.index',
'route' => request()->route
])->render();
}
public function export()
{
if (request()->export == '1') {
$export_page = request()->export_page ? request()->export_page : 1;
$orderModel = Order::select('yz_order.*')->orders(request()->search)
->whereHas('hasOneAgentOrder', function ($agentOrder) {
$agentOrder->where('agent_id', $this->agent_model->id);
});
$export_model = new ExportService($orderModel, $export_page);
if (!$export_model->builder_model->isEmpty()) {
$file_name = date('Ymdhis', time()) . '订单导出';//返现记录导出
$export_data[0] = $this->getColumns();
foreach ($export_model->builder_model->toArray() as $key => $item) {
$address = explode(' ', $item['address']['address']);
$export_data[$key + 1] = [
$item['id'],
$item['order_sn'],
$item['has_one_order_pay']['pay_sn'],
$item['belongs_to_member']['uid'],
$this->getNickname($item['belongs_to_member']['nickname']),
$item['address']['realname'],
$item['address']['mobile'],
!empty($address[0]) ? $address[0] : '',
!empty($address[1]) ? $address[1] : '',
!empty($address[2]) ? $address[2] : '',
$item['address']['address'],
$this->getGoods($item, 'goods_title'),
$this->getGoods($item, 'goods_sn'),
$this->getGoods($item, 'total'),
$item['pay_type_name'],
$this->getExportDiscount($item, 'deduction'),
$this->getExportDiscount($item, 'coupon'),
$this->getExportDiscount($item, 'enoughReduce'),
$this->getExportDiscount($item, 'singleEnoughReduce'),
$item['goods_price'],
$item['dispatch_price'],
$item['price'],
$this->getGoods($item, 'cost_price'),
$item['status_name'],
$item['create_time'],
!empty(strtotime($item['pay_time'])) ? $item['pay_time'] : '',
!empty(strtotime($item['send_time'])) ? $item['send_time'] : '',
!empty(strtotime($item['finish_time'])) ? $item['finish_time'] : '',
$item['express']['express_company_name'],
'[' . $item['express']['express_sn'] . ']',
$item['has_one_order_remark']['remark'],
$item['note']
];
}
$export_model->export($file_name, $export_data, 'plugin.area-dividend.area.order-manage.index');
}
} elseif(request()->export == '2') {
$export_page = request()->export_page ? request()->export_page : 1;
$orderModel = Order::orders(request()->search)
->whereHas('hasOneAgentOrder', function ($agentOrder) {
$agentOrder->where('agent_id', $this->agent_model->id);
});
$export_model = new OrderExportService($orderModel, $export_page);
if (!$export_model->builder_model->isEmpty()) {
$file_name = date('Ymdhis', time()) . '订单导出';//返现记录导出
$export_data[0] = $this->getColumns2();
foreach ($export_model->builder_model->toArray() as $key => $item) {
$goods = [];
foreach ($item['has_many_order_goods'] as $v) {
$goods[] = [
$v['title'],
$v['goods_option_title'],
$v['goods_sn'],
$v['total'],
$v['goods_cost_price'],
$v['price']
];
}
$address = explode(' ', $item['address']['address']);
$export_data[$key + 1] = [
$item['id'],
$item['order_sn'],
$item['has_one_order_pay']['pay_sn'],
$item['belongs_to_member']['uid'],
$this->getNickname($item['belongs_to_member']['nickname']),
$item['address']['realname'],
$item['address']['mobile'],
!empty($address[0]) ? $address[0] : '',
!empty($address[1]) ? $address[1] : '',
!empty($address[2]) ? $address[2] : '',
$item['address']['address'],
$goods,
$item['pay_type_name'],
$this->getExportDiscount($item, 'deduction'),
$this->getExportDiscount($item, 'coupon'),
$this->getExportDiscount($item, 'enoughReduce'),
$this->getExportDiscount($item, 'singleEnoughReduce'),
$item['goods_price'],
$item['dispatch_price'],
$item['price'],
$item['status_name'],
$item['create_time'],
!empty(strtotime($item['pay_time'])) ? $item['pay_time'] : '',
!empty(strtotime($item['send_time'])) ? $item['send_time'] : '',
!empty(strtotime($item['finish_time'])) ? $item['finish_time'] : '',
$item['express']['express_company_name'],
'[' . $item['express']['express_sn'] . ']',
$item['has_one_order_remark']['remark'],
$item['note']
];
}
$export_model->export($file_name, $export_data, 'plugin.area-dividend.area.order-manage.index');
}
}
}
private function getColumns()
{
return ["订单id","订单编号", "支付单号", "会员ID", "粉丝昵称", "会员姓名", "联系电话", '省', '市', '区', "收货地址", "商品名称", "商品编码", "商品数量", "支付方式", '抵扣金额', '优惠券优惠', '全场满减优惠', '单品满减优惠', "商品小计", "运费", "应收款", "成本价", "状态", "下单时间", "付款时间", "发货时间", "完成时间", "快递公司", "快递单号", "订单备注", "用户备注", "首单"];
}
private function getColumns2()
{
return ["订单id","订单编号", "支付单号", "会员ID", "粉丝昵称", "会员姓名", "联系电话", '省', '市', '区', "收货地址", "商品名称", "商品规格","商品编码", "商品数量", "成本价","商品价格","支付方式", '抵扣金额', '优惠券优惠', '全场满减优惠', '单品满减优惠', "商品小计", "运费", "应收款", "状态", "下单时间", "付款时间", "发货时间", "完成时间", "快递公司", "快递单号", "订单备注", "用户备注", "首单"];
}
protected function getExportDiscount($order, $key)
{
$export_discount = [
'deduction' => 0, //抵扣金额
'coupon' => 0, //优惠券优惠
'enoughReduce' => 0, //全场满减优惠
'singleEnoughReduce' => 0, //单品满减优惠
];
foreach ($order['discounts'] as $discount) {
if ($discount['discount_code'] == $key) {
$export_discount[$key] = $discount['amount'];
}
}
if (!$export_discount['deduction']) {
foreach ($order['deductions'] as $k => $v) {
$export_discount['deduction'] += $v['amount'];
}
}
return $export_discount[$key];
}
private function getGoods($order, $key)
{
$goods_title = '';
$goods_sn = '';
$total = '';
$cost_price = 0;
foreach ($order['has_many_order_goods'] as $goods) {
$res_title = $goods['title'];
$res_title = str_replace('-', '', $res_title);
$res_title = str_replace('+', '', $res_title);
$res_title = str_replace('/', '', $res_title);
$res_title = str_replace('*', '', $res_title);
$res_title = str_replace('=', '', $res_title);
if ($goods['goods_option_title']) {
$res_title .= '[' . $goods['goods_option_title'] . ']';
}
$order_goods = OrderGoods::find($goods['id']);
if ($order_goods->goods_option_id) {
$goods_option = GoodsOption::find($order_goods->goods_option_id);
if ($goods_option) {
$goods_sn .= '【' . $goods_option->goods_sn . '】';
}
} else {
$goods_sn .= '【' . $goods['goods_sn'] . '】';
}
$goods_title .= '【' . $res_title . '*' . $goods['total'] . '】';
$total .= '【' . $goods['total'] . '】';
$cost_price += $goods['goods_cost_price'];
}
$res = [
'goods_title' => $goods_title,
'goods_sn' => $goods_sn,
'total' => $total,
'cost_price' => $cost_price
];
return $res[$key];
}
private function getNickname($nickname)
{
if (substr($nickname, 0, strlen('=')) === '=') {
$nickname = '' . $nickname;
}
return $nickname;
}
}

View File

@ -0,0 +1,184 @@
<?php
/**
* Author: 芸众商城 www.yunzshop.com
* Date: 2019-04-17
* Time: 21:13
*/
namespace Yunshop\AreaDividend\area;
use app\common\helpers\PaginationHelper;
use app\common\helpers\Url;
use app\common\models\goods\ReturnAddress;
use app\common\models\member\Address;
use app\common\models\Street;
class ReturnAddressController extends CommonController
{
public function getDefaultModel()
{
return ReturnAddress::uniacid()
->where('plugins_id', \app\common\modules\shop\ShopConfig::current()->get('plugins.area-dividend.id'))
->where('store_id', $this->agent_model->id)
->where('is_default', 1)
->first();
}
public function index()
{
$plugins_id = \app\common\modules\shop\ShopConfig::current()->get('plugins.area-dividend.id');
$list = ReturnAddress::uniacid()
->where('plugins_id', $plugins_id)
->where('store_id', $this->agent_model->id)
->orderBy('id', 'desc')
->paginate();
$pager = PaginationHelper::show($list->total(), $list->currentPage(), $list->perPage());
return view('Yunshop\AreaDividend::area.return.list', [
'list' => $list,
'pager' => $pager,
])->render();
}
public function add()
{
$addressModel = new ReturnAddress();
$requestAddress = \YunShop::request()->address;
if ($requestAddress) {
if (!$requestAddress['province_id']) {
return $this->message('请选择省份', Url::absoluteWeb('plugin.area-dividend.area.return-address.add'));
}
if (!$requestAddress['city_id']) {
return $this->message('请选择城市', Url::absoluteWeb('plugin.area-dividend.area.return-address.add'));
}
if (!$requestAddress['district_id']) {
return $this->message('请选择区域', Url::absoluteWeb('plugin.area-dividend.area.return-address.add'));
}
if (!$requestAddress['street_id']) {
return $this->message('请选择街道', Url::absoluteWeb('plugin.area-dividend.area.return-address.add'));
}
//将数据赋值到model
$addressModel->setRawAttributes($requestAddress);
//其他字段赋值
$province = Address::find($requestAddress['province_id'])->areaname;
$city = Address::find($requestAddress['city_id'])->areaname;
$district = Address::find($requestAddress['district_id'])->areaname;
$street = Street::find($requestAddress['street_id'])->areaname;
$addressModel->province_name = $province;
$addressModel->city_name = $city;
$addressModel->district_name = $district;
$addressModel->street_name = $street;
$addressModel->plugins_id = \app\common\modules\shop\ShopConfig::current()->get('plugins.area-dividend.id');//商城
$addressModel->uniacid = \YunShop::app()->uniacid;
$addressModel->store_id = $this->agent_model->id;
//字段检测
$validator = $addressModel->validator($addressModel->getAttributes());
if ($validator->fails()) {//检测失败
$this->error($validator->messages());
} else {
//取消其他默认模板
if($addressModel->is_default){
$defaultModel = $this->getDefaultModel();
if ($defaultModel) {
$defaultModel->is_default = 0;
$defaultModel->save();
}
}
//数据保存
if ($addressModel->save()) {
//显示信息并跳转
return $this->message('退货地址创建成功', Url::absoluteWeb('plugin.area-dividend.area.return-address.index'));
} else {
return $this->message('退货地址创建失败');
}
}
}
return view('Yunshop\AreaDividend::area.return.info', [
'address' => $addressModel
])->render();
}
public function edit()
{
$addressModel = ReturnAddress::uniacid()
->where('store_id', $this->agent_model->id)
->where('id', request()->id)
->first();
if (!$addressModel) {
return $this->message('无此记录或已被删除', '', 'error');
}
$requestAddress = \YunShop::request()->address;
if ($requestAddress) {
if (!$requestAddress['province_id']) {
return $this->message('请选择省份', Url::absoluteWeb('goods.return-address.edit',['id' => $addressModel->id]));
}
if (!$requestAddress['city_id']) {
return $this->message('请选择城市', Url::absoluteWeb('goods.return-address.edit',['id' => $addressModel->id]));
}
if (!$requestAddress['district_id']) {
return $this->message('请选择区域', Url::absoluteWeb('goods.return-address.edit',['id' => $addressModel->id]));
}
if (!$requestAddress['street_id']) {
return $this->message('请选择街道', Url::absoluteWeb('goods.return-address.edit',['id' => $addressModel->id]));
}
//将数据赋值到model
$addressModel->setRawAttributes($requestAddress);
//其他字段赋值
$province = Address::find($requestAddress['province_id'])->areaname;
$city = Address::find($requestAddress['city_id'])->areaname;
$district = Address::find($requestAddress['district_id'])->areaname;
$street = Street::find($requestAddress['street_id'])->areaname;
$addressModel->province_name = $province;
$addressModel->city_name = $city;
$addressModel->district_name = $district;
$addressModel->street_name = $street;
$addressModel->uniacid = \YunShop::app()->uniacid;
//字段检测
$validator = $addressModel->validator($addressModel->getAttributes());
if ($validator->fails()) {//检测失败
$this->error($validator->messages());
} else {
//取消其他默认模板
if($addressModel->is_default){
$defaultModel = $this->getDefaultModel();
if ($defaultModel && ($defaultModel->id != \YunShop::request()->id) ) {
$defaultModel->is_default = 0;
$defaultModel->save();
}
}
//数据保存
if ($addressModel->save()) {
//显示信息并跳转
return $this->message('退货地址创建成功', Url::absoluteWeb('plugin.area-dividend.area.return-address.index'));
} else {
return $this->message('退货地址创建失败');
}
}
}
return view('Yunshop\AreaDividend::area.return.info', [
'address' => $addressModel
])->render();
}
public function delete()
{
$addressModel = ReturnAddress::uniacid()
->where('store_id', $this->agent_model->id)
->where('id', request()->id)
->first();
if (!$addressModel) {
return $this->message('无此配送模板或已经删除', '', 'error');
}
if ($addressModel->delete()) {
return $this->message('删除模板成功', '');
} else {
return $this->message('删除模板失败', '', 'error');
}
}
}

View File

@ -0,0 +1,258 @@
<?php
/**
* Author: 芸众商城 www.yunzshop.com
* Date: 2019-04-18
* Time: 22:09
*/
namespace Yunshop\AreaDividend\area;
use app\backend\modules\goods\models\GoodsOption;
use app\backend\modules\order\models\OrderGoods;
use app\common\helpers\PaginationHelper;
use app\common\services\ExportService;
use Yunshop\AreaDividend\models\Order;
use app\common\services\OrderExportService;
class StoreOrderManageController extends CommonController
{
public function index()
{
$this->export();
$orderModel = Order::orders(request()->search)
->whereHas('hasOneAgentOrder', function ($agentOrder) {
$agentOrder->where('agent_id', $this->agent_model->id)->where('plugin_id','32');
});
$requestSearch = \YunShop::request()->get('search');
$requestSearch['plugin'] = 'fund';
if ($requestSearch) {
$requestSearch = array_filter($requestSearch, function ($item) {
return !empty($item);
});
}
$list['total_price'] = $orderModel->sum('price');
$list += $orderModel->orderBy('id', 'desc')->paginate(10)->toArray();
$pager = PaginationHelper::show($list['total'], $list['current_page'],
$list['per_page']);
return view('Yunshop\AreaDividend::area.order.store-list', [
'list' => $list,
'total_price' => $list['total_price'],
'pager' => $pager,
'requestSearch' => $requestSearch,
'var' => \YunShop::app()->get(),
'url' => request('route'),
'include_ops' => 'Yunshop\AreaDividend::area.order.ops',
'detail_url' => 'plugin.area-dividend.area.order-detail.store-index',
'route' => request()->route
])->render();
}
public function export()
{
if (request()->export == '1') {
$export_page = request()->export_page ? request()->export_page : 1;
$orderModel = Order::orders(request()->search)
->whereHas('hasOneAgentOrder', function ($agentOrder) {
$agentOrder->where('agent_id', $this->agent_model->id)->where('plugin_id','32');
});
$export_model = new ExportService($orderModel, $export_page);
if (!$export_model->builder_model->isEmpty()) {
$file_name = date('Ymdhis', time()) . '订单导出';//返现记录导出
$export_data[0] = $this->getColumns();
foreach ($export_model->builder_model->toArray() as $key => $item) {
$address = explode(' ', $item['address']['address']);
$export_data[$key + 1] = [
$item['id'],
$item['order_sn'],
$item['has_one_order_pay']['pay_sn'],
$item['belongs_to_member']['uid'],
$this->getNickname($item['belongs_to_member']['nickname']),
$item['address']['realname'],
$item['address']['mobile'],
!empty($address[0]) ? $address[0] : '',
!empty($address[1]) ? $address[1] : '',
!empty($address[2]) ? $address[2] : '',
$item['address']['address'],
$this->getGoods($item, 'goods_title'),
$this->getGoods($item, 'goods_sn'),
$this->getGoods($item, 'total'),
$item['pay_type_name'],
$this->getExportDiscount($item, 'deduction'),
$this->getExportDiscount($item, 'coupon'),
$this->getExportDiscount($item, 'enoughReduce'),
$this->getExportDiscount($item, 'singleEnoughReduce'),
$item['goods_price'],
$item['dispatch_price'],
$item['price'],
$this->getGoods($item, 'cost_price'),
$item['status_name'],
$item['create_time'],
!empty(strtotime($item['pay_time'])) ? $item['pay_time'] : '',
!empty(strtotime($item['send_time'])) ? $item['send_time'] : '',
!empty(strtotime($item['finish_time'])) ? $item['finish_time'] : '',
$item['express']['express_company_name'],
'[' . $item['express']['express_sn'] . ']',
$item['has_one_order_remark']['remark'],
$item['note']
];
}
$export_model->export($file_name, $export_data, 'plugin.area-dividend.area.order-manage.index');
}
} elseif(request()->export == '2') {
$export_page = request()->export_page ? request()->export_page : 1;
$orderModel = Order::orders(request()->search)
->whereHas('hasOneAgentOrder', function ($agentOrder) {
$agentOrder->where('agent_id', $this->agent_model->id)->where('plugin_id','32');
});
$export_model = new OrderExportService($orderModel, $export_page);
if (!$export_model->builder_model->isEmpty()) {
$file_name = date('Ymdhis', time()) . '订单导出';//返现记录导出
$export_data[0] = $this->getColumns2();
foreach ($export_model->builder_model->toArray() as $key => $item) {
$address = explode(' ', $item['address']['address']);
$goods = [];
foreach ($item['has_many_order_goods'] as $v) {
$goods[] = [
$v['title'],
$v['goods_option_title'],
$v['goods_sn'],
$v['total'],
$v['goods_cost_price'],
$v['price']
];
}
$export_data[$key + 1] = [
$item['id'],
$item['order_sn'],
$item['has_one_order_pay']['pay_sn'],
$item['belongs_to_member']['uid'],
$this->getNickname($item['belongs_to_member']['nickname']),
$item['address']['realname'],
$item['address']['mobile'],
!empty($address[0]) ? $address[0] : '',
!empty($address[1]) ? $address[1] : '',
!empty($address[2]) ? $address[2] : '',
$item['address']['address'],
$goods,
$item['pay_type_name'],
$this->getExportDiscount($item, 'deduction'),
$this->getExportDiscount($item, 'coupon'),
$this->getExportDiscount($item, 'enoughReduce'),
$this->getExportDiscount($item, 'singleEnoughReduce'),
$item['goods_price'],
$item['dispatch_price'],
$item['price'],
$item['status_name'],
$item['create_time'],
!empty(strtotime($item['pay_time'])) ? $item['pay_time'] : '',
!empty(strtotime($item['send_time'])) ? $item['send_time'] : '',
!empty(strtotime($item['finish_time'])) ? $item['finish_time'] : '',
$item['express']['express_company_name'],
'[' . $item['express']['express_sn'] . ']',
$item['has_one_order_remark']['remark'],
$item['note']
];
}
$export_model->export($file_name, $export_data, 'plugin.area-dividend.area.order-manage.index');
}
}
}
private function getColumns()
{
return ["订单id","订单编号", "支付单号", "会员ID", "粉丝昵称", "会员姓名", "联系电话", '省', '市', '区', "收货地址", "商品名称", "商品编码", "商品数量", "支付方式", '抵扣金额', '优惠券优惠', '全场满减优惠', '单品满减优惠', "商品小计", "运费", "应收款", "成本价", "状态", "下单时间", "付款时间", "发货时间", "完成时间", "快递公司", "快递单号", "订单备注", "用户备注", "首单"];
}
private function getColumns2()
{
return ["订单id","订单编号", "支付单号", "会员ID", "粉丝昵称", "会员姓名", "联系电话", '省', '市', '区', "收货地址", "商品名称", "商品规格","商品编码", "商品数量", "成本价","商品价格","支付方式", '抵扣金额', '优惠券优惠', '全场满减优惠', '单品满减优惠', "商品小计", "运费", "应收款", "成本价", "状态", "下单时间", "付款时间", "发货时间", "完成时间", "快递公司", "快递单号", "订单备注", "用户备注", "首单"];
}
protected function getExportDiscount($order, $key)
{
$export_discount = [
'deduction' => 0, //抵扣金额
'coupon' => 0, //优惠券优惠
'enoughReduce' => 0, //全场满减优惠
'singleEnoughReduce' => 0, //单品满减优惠
];
foreach ($order['discounts'] as $discount) {
if ($discount['discount_code'] == $key) {
$export_discount[$key] = $discount['amount'];
}
}
if (!$export_discount['deduction']) {
foreach ($order['deductions'] as $k => $v) {
$export_discount['deduction'] += $v['amount'];
}
}
return $export_discount[$key];
}
private function getGoods($order, $key)
{
$goods_title = '';
$goods_sn = '';
$total = '';
$cost_price = 0;
foreach ($order['has_many_order_goods'] as $goods) {
$res_title = $goods['title'];
$res_title = str_replace('-', '', $res_title);
$res_title = str_replace('+', '', $res_title);
$res_title = str_replace('/', '', $res_title);
$res_title = str_replace('*', '', $res_title);
$res_title = str_replace('=', '', $res_title);
if ($goods['goods_option_title']) {
$res_title .= '[' . $goods['goods_option_title'] . ']';
}
$order_goods = OrderGoods::find($goods['id']);
if ($order_goods->goods_option_id) {
$goods_option = GoodsOption::find($order_goods->goods_option_id);
if ($goods_option) {
$goods_sn .= '【' . $goods_option->goods_sn . '】';
}
} else {
$goods_sn .= '【' . $goods['goods_sn'] . '】';
}
$goods_title .= '【' . $res_title . '*' . $goods['total'] . '】';
$total .= '【' . $goods['total'] . '】';
$cost_price += $goods['goods_cost_price'];
}
$res = [
'goods_title' => $goods_title,
'goods_sn' => $goods_sn,
'total' => $total,
'cost_price' => $cost_price
];
return $res[$key];
}
private function getNickname($nickname)
{
if (substr($nickname, 0, strlen('=')) === '=') {
$nickname = '' . $nickname;
}
return $nickname;
}
}

View File

@ -0,0 +1,47 @@
<?php
/**
* Author: 芸众商城 www.yunzshop.com
* Date: 2019-08-13
* Time: 22:45
*/
namespace Yunshop\AreaDividend\event;
use app\common\events\Event;
abstract class AreaDividendEvent extends Event
{
protected $order;
protected $uid;
protected $amount;
protected $dividendId;
public function __construct($order, $uid, $amount, $dividendId)
{
$this->order = $order;
$this->uid = $uid;
$this->amount = $amount;
$this->dividendId = $dividendId;
}
public function getOrder()
{
return $this->order;
}
public function getUid()
{
return $this->uid;
}
public function getAmount()
{
return $this->amount;
}
public function getDividendId()
{
return $this->dividendId;
}
}

View File

@ -0,0 +1,14 @@
<?php
/**
* Author: 芸众商城 www.yunzshop.com
* Date: 2019-08-13
* Time: 22:48
*/
namespace Yunshop\AreaDividend\event;
class CreatedAreaDividendBonusEvent extends AreaDividendEvent
{
}

View File

@ -0,0 +1,28 @@
<?php
/**
* Author: 芸众商城 www.yunzshop.com
* Date: 2019-08-15
* Time: 19:57
*/
namespace Yunshop\AreaDividend\event;
use Yunshop\AreaDividend\models\AreaDividend;
class SettleAreaDividendBonusEvent
{
protected $settleDividend;
public function __construct($settleDividend)
{
$this->settleDividend = $settleDividend;
}
/**
* @return AreaDividend
*/
public function getSettleDividend()
{
return $this->settleDividend;
}
}

View File

@ -0,0 +1,18 @@
<?php
/**
* Author: 芸众商城 www.yunzshop.com
* Date: 2019-04-18
* Time: 22:05
*/
namespace Yunshop\AreaDividend\models;
use app\common\models\BaseModel;
class AgentOrder extends BaseModel
{
public $table = 'yz_area_dividend_order';
public $timestamps = true;
protected $guarded = [''];
}

View File

@ -0,0 +1,367 @@
<?php
/**
* Created by PhpStorm.
* User: yanglei
* Date: 2017/4/27
* Time: 上午9:16
*/
namespace Yunshop\AreaDividend\models;
use app\common\models\BaseModel;
use app\common\models\Income;
use app\framework\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Yunshop\AreaDividend\event\SettleAreaDividendBonusEvent;
use Yunshop\AreaDividend\services\AgentService;
use Yunshop\TeamDividend\models\ErrorTeamDividend;
/**
* Class AreaDividend
* @package Yunshop\AreaDividend\models
* @property Income income
* @property int status
* @property float dividend_amount
* @property float amount
* @property float order_amount
* @property AreaDividendAgent hasOneAgent
*/
class AreaDividend extends BaseModel
{
use SoftDeletes;
public $table = 'yz_area_dividend';
public $timestamps = true;
protected $guarded = [''];
public $StatusService;
public $LevelService;
protected $appends = ['status_name', 'level_name'];
public static function getDividends($search)
{
$model = self::uniacid();
if (!empty($search['member'])) {
$model->whereHas('hasOneMember', function ($query) use ($search) {
return $query->searchLike($search['member']);
});
}
if (!empty($search['area_name'])) {
$model->where('agent_area', 'like', '%' . $search['area_name'] . '%');
}
if($search['is_pay'] == 1){
$model->whereHas('hasOneOrder',function($query){
$query->where('status','>=',1);
});
}
if($search['is_pay'] == 2){
$model->whereHas('hasOneOrder',function($query){
$query->where('status','<',1);
});
}
if (!empty($search['area_level'])) {
$model->where('area_level', $search['area_level']);
}
if (!empty($search['order_sn'])) {
$model->where('order_sn', $search['order_sn']);
}
if ($search['status'] != '') {
$model->where('status', $search['status']);
}
if ($search['is_time']) {
if ($search['time']) {
$range = [strtotime($search['time']['start']), strtotime($search['time']['end'])];
$model->whereBetween('created_at', $range);
}
}
$model->where('dividend_amount' , '>', 0);
$model->with([
'hasOneMember' => function ($query) {
$query->select(['uid', 'avatar', 'nickname', 'realname', 'mobile'])->uniacid();
},
'hasOneOrder' => function ($query) {
$query->select(['id', 'order_sn'])->uniacid();
}
]);
return $model;
}
public static function getDataByOrderSn($order_sn)
{
return self::uniacid()->where('order_sn', $order_sn)->with('hasOneMember')->first();
}
public static function getDetailById($id)
{
$model = self::uniacid()
->with('hasOneMember')
->where('id', $id);
return $model;
}
/**
* @return mixed
* 获取可结算数据
*/
public static function getStatement()
{
return self::uniacid()
->with('hasOneAgent')
->with('hasOneOrder')
->where(function ($query) {
return $query->where(DB::raw('`recrive_at` + (`settle_days` * 86400)'), '<=', time())
->orWhere('settle_days', '=', '0');
})
->whereNotNull('recrive_at')
->where('status', '0');
}
/*
* 手动结算:可结算的数据
* */
public static function getNotSettleInfo($where)
{
$model = self::uniacid()
->where($where)
->with('hasOneAgent')
->with('hasOneOrder')
->whereNotNull('recrive_at')
->where('status', '0');
return $model;
}
/*
* 获取未结算总金额
* */
public static function getNotSettleAmount($uid)
{
return self::uniacid()
->where('member_id', $uid)
->where('status', 0)
->whereNotNull('recrive_at')
->sum('dividend_amount');
}
public static function updatedAreaDividend($data, $where)
{
return self::uniacid()
->where($where)
->update($data);
}
public function scopeAgent(Builder $query, $agent)
{
return $query->where('member_id', $agent['member_id']);
// $model = $query;
// if (empty($agent['agent_level'])) {
// return $model;
// }
//
//
// return $model->where('agent_area','like',$agent['area_name'].'%');
//
// return $model;
}
public function hasOneMember()
{
return $this->hasOne('app\common\models\Member', 'uid', 'member_id');
}
public function hasOneAgent()
{
return $this->hasOne('Yunshop\AreaDividend\models\AreaDividendAgent', 'member_id', 'member_id');
}
public function hasOneOrder()
{
return $this->hasOne('\app\common\models\Order', 'id', 'order_id');
}
public static function getStatistic($start, $end)
{
return self::uniacid()
->where('status', 1)
->where('member_id', \YunShop::app()->getMemberId())
->whereBetween('created_at', [$start, $end]);
}
public function hasManyDividend()
{
return $this->hasMany(self::class, "create_month", "create_month");
}
public static function getDividendList($status)
{
$model = self::select('create_month');
$model->uniacid();
// $model->where('status',$status);
// $model->with(['hasManyDividend' => function ($query) use ($search) {
// if ($search['status'] != '') {
// $query->where('status', $search['status']);
// }
// $query->where('member_id', \YunShop::app()->getMemberId());
// $query->orderBy('id', 'desc');
// return $query->get();
// }]);
// $model->whereHas('hasOneOrder',function($query){
// $query->where('status','>=',1)->orWhere('status',-1);
// });
$model->where('dividend_amount', '>', 0);
$model->groupBy('create_month');
$model->orderBy('create_month', 'desc');
return $model;
}
public static function getStatusDividendList($create_month,$status)
{
$model = self::uniacid();
if ($create_month){
$model->where('create_month',$create_month);
}
if (!empty($status) || $status == "0"){
$model->where('status',$status);
}
// $model->whereHas('hasOneOrder',function($query){
// $query->where('status','>=',1)->orWhere('status',-1);
// });
$model->where('dividend_amount', '>', 0);
$model->orderBy('created_at', 'desc');
$model->orderBy('create_month', 'desc');
return $model;
}
public static function getDividendListNew($create_month,$status = 0)
{
$model = self::uniacid()
->where('member_id', \YunShop::app()->getMemberId());
if ($create_month){
$model->where('create_month',$create_month);
}
if ($status){
$model->where('status',$status);
}
$model->orderBy('id', 'desc');
return $model;
}
public function getStatusNameAttribute()
{
if (!isset($this->StatusService)) {
switch ($this->status) {
case 0:
$this->StatusService = '未结算';
break;
case 1:
$this->StatusService = '已结算';
break;
case -1:
$this->StatusService = '已失效';
break;
}
}
return $this->StatusService;
}
public function getLevelNameAttribute()
{
if (!isset($this->LevelService)) {
$this->agent_level = $this->area_level;
$this->LevelService = AgentService::createLevelService($this);
}
return $this->LevelService;
}
public function income()
{
return $this->hasOne(Income::class,'incometable_id','id')->where('incometable_type',self::class);
}
public function logError($msg){
Log::info("订单{$this->dividend->order_sn}用户{$this->dividend->member_id}:", $msg);
}
/**
* 删除并操作对应的收入记录和提现记录
* @throws \Exception
*/
public function rollback(){
// 将区域代理记录 减去分红记录的金额
$this->hasOneAgent->count_order_amount -= $this->order_amount;
if ($this->status == 1) {
$this->hasOneAgent->count_settle_amount -= $this->amount;
} elseif ($this->status == -1) {
$this->hasOneAgent->unsettled_dividend_amount -= $this->dividend_amount;
}
$this->hasOneAgent->save();
//已结算
if($this->status == 1){
if($this->income && $this->income->status == 1){
// 收入已提现
if (!$this->income->withdraw()) {
$this->logError('提现记录未找到');
}else{
if ($this->income->withdraw()->status == 2) {
$this->logError('分红已提现,无法处理');
ErrorTeamDividend::create(['team_dividend_id' => $this->id, 'order_sn' => $this->order_sn, 'member_id' => $this->member_id, 'dividend_amount' => $this->dividend_amount, 'note' => "用户{$this->member_id}的分红已提现,无法处理"]);
}
$this->income->withdraw()->amounts -= $this->amount;
if ($this->income->withdraw()->amounts <= 0) {
// 提现记录的对应收入记录全部删除,则提现记录也删除
$this->income->withdraw()->delete();
} else {
// 还有其他收入记录的时候,修改时删除对应id并保存 todo 表结构不合理
$ids = explode(',', $this->income->withdraw()->type_id);
unset($ids[array_search($this->id, $ids)]);
$ids = implode(',', $ids);
$this->income->withdraw()->type_id = $ids;
$this->income->withdraw()->save();
$this->logError("分红提现状态为{$this->income->withdraw()->status},已修改");
}
}
$this->logError("分红记录的收入状态为{$this->status},收入记录已删除");
$this->income->delete();
}
}
// 删除对应分红日志
$this->delete();
}
public static function getAreaDividendByMemberId($status = '')
{
$model = self::uniacid();
$model->where('member_id', \YunShop::app()->getMemberId());
// 取消查询分红时要寻找订单状态
// $model->whereHas('hasOneOrder',function($query){
// $query->where('status','>=',1);
// });
if ($status !== '') {
$model->where('status', $status);
}
return $model;
}
}

View File

@ -0,0 +1,261 @@
<?php
/**
* Created by PhpStorm.
* User: yanglei
* Date: 2017/4/27
* Time: 上午9:16
*/
namespace Yunshop\AreaDividend\models;
use app\common\facades\Setting;
use app\common\models\BaseModel;
use app\common\services\finance\PointService;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\DB;
use Yunshop\AreaDividend\services\AgentService;
use Yunshop\Commission\models\AgentLevel;
/**
* Class AreaDividendAgent
* @package Yunshop\AreaDividend\models
* @property float count_order_amount
* @property float count_settle_amount
* @property float unsettled_dividend_amount
*/
class AreaDividendAgent extends BaseModel
{
use SoftDeletes;
public $table = 'yz_area_dividend_agent';
public $timestamps = true;
protected $guarded = [''];
public $StatusService;
public $LevelService;
public $Rate;
protected $appends = ['status_name', 'level_name', 'rate'];
protected $search_fields = ['province_name', 'city_name', 'district_name', 'street_name'];
public static function getAgents($search)
{
$agentModel = self::uniacid();
if (!empty($search['member'])) {
$agentModel->whereHas('hasOneMember', function ($query) use ($search) {
return $query->searchLike($search['member']);
});
}
$agentModel->with(['hasOneMember']);
$agentModel->where('status', '1');
if (!empty($search['area_name'])) {
$agentModel->searchLike($search['area_name']);
}
if (!empty($search['agent_level'])) {
$agentModel->where('agent_level', $search['agent_level']);
}
if ($search['is_time']) {
if ($search['time']) {
$range = [strtotime($search['time']['start']), strtotime($search['time']['end'])];
$agentModel->whereBetween('created_at', $range);
}
}
$agentModel->with(['hasOneDividend' => function ($query) {
$query->selectRaw('member_id, sum(amount) as total_amount')
->selectRaw('sum(if(status = 0 ,dividend_amount, 0)) as unsettled')
->selectRaw('sum(if(status = 1 ,dividend_amount, 0)) as settle')
->selectRaw('sum(order_amount) as total_order_amount')->groupBy('member_id');
}]);
return $agentModel;
}
public static function getApplyAgents()
{
return self::uniacid()
->with(['hasOneMember'])
->where('status', '0');
}
public static function getApplyAgentsBySearch($search)
{
$model = self::uniacid()
->with(['hasOneMember'])
->where('status', '0');
if (!empty($search['member'])) {
$model->whereHas('hasOneMember', function ($q) use ($search) {
$q->searchLike($search['member']);
});
}
return $model;
}
public function hasOneDividend()
{
return $this->hasOne(AreaDividend::class,'member_id', 'member_id');
}
public function getStatusNameAttribute()
{
if (!isset($this->StatusService)) {
$this->StatusService = AgentService::createStatusService($this);
}
return $this->StatusService;
}
public function getLevelNameAttribute()
{
if (!isset($this->LevelService)) {
$this->LevelService = AgentService::createLevelService($this);
}
return $this->LevelService;
}
/**
* Common: 获取器 —— 分润比例
* Author: wu-hui
* Time: 2022/09/27 17:38
* @return mixed|void
*/
public function getRateAttribute(){
if (!isset($this->Rate)) return AgentLevel::getUserRate($this->member_id,$this->agent_level,FALSE);
if ($this->has_ratio == 1) $this->Rate = $this->ratio;
return $this->Rate;
}
public function hasOneMember()
{
return $this->hasOne('app\common\models\Member', 'uid', 'member_id');
}
public static function getAreaAgentByAddressId($id, $level)
{
return self::uniacid()
->where('status', '1')
->where('agent_level', $level)
->where(function ($query) use ($id) {
return $query->where('province_id', $id)
->orWhere('city_id', $id)
->orWhere('district_id', $id)
->orWhere('street_id', $id);
});
}
public static function updatedAgentById($data, $id)
{
return self::uniacid()
->where('id', $id)
->update($data);
}
public static function getAgentByUserId($uid)
{
return self::uniacid()->where('user_id', $uid);
}
public static function getAgentByMemberId($membeId)
{
return self::uniacid()
->where('member_id',$membeId);
}
public static function daletedAgency($id)
{
return self::where('id', $id)
->delete();
}
public static function getLevelList()
{
return $level = [
'0' => [
'level' => '0',
'level_name' => '无效',
],
'1' => [
'level' => '1',
'level_name' => '省代理',
],
'2' => [
'level' => '2',
'level_name' => '市代理',
],
'3' => [
'level' => '3',
'level_name' => '区代理',
],
'4' => [
'level' => '4',
'level_name' => '街道代理',
],
];
}
public static function awardPoint($dividendRate, $level, $member_id, $order, $set)
{
$ratio = $dividendRate['rate_' . $level]['point_ratio'];
if ($ratio < 0) {
$ratio = 0;
}
// dump($dividendRate);
$calculatePrice = $order->price;
// dump('order_price:'.$calculatePrice);
if ($set['calculate_type'] == 1) {
// dump('利润');
$costPrice = $order->dispatch_price;
foreach ($order->hasManyOrderGoods as $orderGoods) {
$costPrice += $orderGoods->goods_cost_price;
}
// dump('costPrice:'.$costPrice);
$calculatePrice = $order->price - $costPrice;
}
// dump($calculatePrice);
// dump('ratio:'.$ratio);
if ($set['award_point_type'] == 1) {
// dump('固定');
$point = $ratio;
if ($set['calculate_type'] == 1) {
$point = 0;
foreach ($order->hasManyOrderGoods as $orderGoods) {
$point += $orderGoods->total * $ratio;
}
}
} else {
// dump('比例');
$point = $calculatePrice * $ratio / 100;
}
// dump($point);
$point_data = [
'point_income_type' => PointService::POINT_INCOME_GET,
'point_mode' => PointService::POINT_MODE_TEAM,
'member_id' => $member_id,
'point' => $point,
'remark' => '区域分红奖励'
];
// dump($point_data);
$point_service = new PointService($point_data);
$point_service->changePoint();
}
public static function getSpecifiedAgent($agnetAddressId, $column, $level)
{
return AreaDividendAgent::uniacid()
->where($column, $agnetAddressId)
->where('agent_level', $level)
->where('status', 1)
->where('manage', 1)
->first();
}
}

View File

@ -0,0 +1,88 @@
<?php
/**
* Created by PhpStorm.
* User: yanglei
* Date: 2017/4/27
* Time: 上午9:16
*/
namespace Yunshop\AreaDividend\models;
use app\common\facades\Setting;
use app\common\models\BaseModel;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\DB;
class AreaDividendGoods extends BaseModel
{
use SoftDeletes;
public $table = 'yz_goods_area_dividend';
public $timestamps = true;
protected $guarded = [''];
public $attributes = [
'is_dividend' => 1,
'has_dividend' => 0,
'has_dividend_price' => 0,
'has_dividend_rate' => 0,
];
public static function relationSave($goodsId, $data, $operate)
{
if (!$goodsId) {
return false;
}
// edit 2018-06-01 by Yy
// content 门店编辑商品没有区域分红选项, admin保存之后门店再保存widget没值,取默认.
if (!$data) {
return false;
}
$dividendModel = self::getModel($goodsId, $operate);
//判断deleted
if ($operate == 'deleted') {
return $dividendModel->delete();
}
$data['goods_id'] = $goodsId;
if(!$data['has_dividend']){
$data['has_dividend'] = 0;
}
$data['has_dividend_price'] = $data['has_dividend_price'] ?$data['has_dividend_price'] : 0;
$data['has_dividend_rate'] = $data['has_dividend_rate'] ?$data['has_dividend_rate'] : 0;
//开启了第一个独立规则,第二个就不能开启
if ($data['has_dividend']) {
$data['alone_rule'] = 0;
} else {
$data['alone_rule'] = $data['alone_rule'] ? $data['alone_rule'] : 0;
}
$data['province_rate'] = $data['province_rate'] ?$data['province_rate'] : 0;
$data['city_rate'] = $data['city_rate'] ?$data['city_rate'] : 0;
$data['area_rate'] = $data['area_rate'] ?$data['area_rate'] : 0;
$data['street_rate'] = $data['street_rate'] ?$data['street_rate'] : 0;
$dividendModel->setRawAttributes($data);
return $dividendModel->save();
}
public static function getModel($goodsId, $operate)
{
$model = false;
if ($operate != 'created') {
$model = static::where(['goods_id' => $goodsId])->first();
}
!$model && $model = new static;
return $model;
}
public static function getGoodsByGoodsId($goodsId)
{
return self::where('goods_id',$goodsId)
->where('is_dividend','1');
}
public static function getGoodsSet($goodsId)
{
$model = $goodsId ? static::where(['goods_id' => $goodsId])->first() : new static;
!$model && $model = ['is_dividend' => 0] ;
return $model;
}
}

View File

@ -0,0 +1,104 @@
<?php
/**
* Author: 芸众商城 www.yunzshop.com
* Date: 2019-08-13
* Time: 22:32
*/
namespace Yunshop\AreaDividend\models;
use app\common\models\Address;
use app\common\models\BaseModel;
use app\common\models\Street;
use Illuminate\Database\Eloquent\Builder;
class Lock extends BaseModel
{
public $table = 'yz_area_dividend_lock';
public $timestamps = true;
protected $guarded = [''];
protected $appends = [
'province_name', 'city_name', 'district_name', 'street_name'
];
public function getProvinceNameAttribute()
{
$name = '';
if ($this->province_id) {
$address = Address::select()
->where('id', $this->province_id)
->where('level', 1)
->first();
$name = $address->areaname;
}
return $name;
}
public function getCityNameAttribute()
{
$name = '';
if ($this->city_id) {
$address = Address::select()
->where('id', $this->city_id)
->where('level', 2)
->first();
$name = $address->areaname;
}
return $name;
}
public function getDistrictNameAttribute()
{
$name = '';
if ($this->district_id) {
$address = Address::select()
->where('id', $this->district_id)
->where('level', 3)
->first();
$name = $address->areaname;
}
return $name;
}
public function getStreetNameAttribute()
{
$name = '';
if ($this->street_id) {
$address = Street::find($this->street_id);
$name = $address->areaname;
}
return $name;
}
public static function verify($address)
{
$level = 1;
$build = self::select();
if ($address['province_id']) {
$build->where('province_id', $address['province_id']);
}
if ($address['city_id']) {
$build->where('city_id', $address['city_id']);
$level = 2;
}
if ($address['district_id']) {
$build->where('district_id', $address['district_id']);
$level = 3;
}
if ($address['street_id']) {
$build->where('street_id', $address['street_id']);
$level = 4;
}
$build->where('level', $level);
return $build->first();
}
public static function boot()
{
parent::boot();
static::addGlobalScope(function (Builder $builder) {
$builder->uniacid();
});
}
}

View File

@ -0,0 +1,182 @@
<?php
/**
* Created by PhpStorm.
* User: shenyang
* Date: 2018/11/5
* Time: 11:39 AM
*/
namespace Yunshop\AreaDividend\models;
use app\common\models\PayTypeGroup;
/**
* Class Order
* @package Yunshop\AreaDividend\models
* @property AreaDividend areaDividend
*/
class Order extends \app\backend\modules\order\models\Order
{
public function areaDividend()
{
return $this->hasMany(AreaDividend::class,'order_sn','order_sn');
}
public function hasOneAgentOrder()
{
return $this->hasOne(AgentOrder::class, 'order_id', 'id');
}
public function scopeSearch($order_builder,$params){
if ($params['shop_name'] != '') {
$order_builder->where('shop_name', 'like', '%' . $params['shop_name'] . '%');
}
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'] == 'address') {
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('address', function ($query) use ($params) {
return $query->where('address','like', '%' . $params['ambiguous']['string'] . '%')
->orWhere('mobile','like','%' . $params['ambiguous']['string'] . '%')
->orWhere('realname','like','%' . $params['ambiguous']['string'] . '%');
});
}
});
}
//增加根据优惠券名称搜索订单
if($params['ambiguous']['field'] == 'coupon'){
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('coupons', function ($query) use ($params) {
return $query->where('name','like','%' . $params['ambiguous']['string'] . '%');
});
}
});
}
//订单商品
if ($params['ambiguous']['field'] == 'order_goods') {
$order_builder->whereHas('hasManyOrderGoods', function ($query) use ($params) {
$query->searchLike($params['ambiguous']['string']);
});
}
//商品id
if ($params['ambiguous']['field'] == 'goods_id') {
// print_r($order_builder->whereHas('hasManyOrderGoods', function ($query) use ($params) {
// $query->where('goods_id',$params['ambiguous']['string']);
// })->toSql());exit;
$order_builder->whereHas('hasManyOrderGoods', function ($query) use ($params) {
$query->where('goods_id',$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']);
*/
//改为支付分组查询前端传入支付分组id在该处通过分组id获取组中所有成员这些成员就是确切的支付方式
//如前端传入的分组id为2对应的是支付宝支付分组然后查找属于支付宝支付组的支付方式找到如支付宝支付宝-yz这些具体支付方式
//获取到确切的支付方式后,对查询条件进行拼接
$payTypeGroup = PayTypeGroup::with('hasManyPayType')->find($params['pay_type']);
if($payTypeGroup)
{
$payTypes = $payTypeGroup->toArray();
if($payTypes['has_many_pay_type']) {
$pay_type_ids = array_column($payTypes['has_many_pay_type'], 'id');
$order_builder->whereIn('yz_order.pay_type_id', $pay_type_ids);
}
}
}
//操作时间范围
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 agentOrder($orderModel)
{
$orderAgent = self::getOrderAgent($orderModel->address);
if (!$orderAgent) {
return;
}
AgentOrder::create([
'order_id' => $orderModel->id,
'agent_id' => $orderAgent->id,
'plugin_id' => $orderModel->plugin_id
]);
}
private static function getOrderAgent($orderAddress)
{
if ($orderAddress->street_id) {
$agent = AreaDividendAgent::getSpecifiedAgent($orderAddress->street_id, 'street_id', 4);
}
if ($orderAddress->district_id && !$agent) {
$agent = AreaDividendAgent::getSpecifiedAgent($orderAddress->district_id, 'district_id', 3);
}
if ($orderAddress->city_id && !$agent) {
$agent = AreaDividendAgent::getSpecifiedAgent($orderAddress->city_id, 'city_id', 2);
}
if ($orderAddress->province_id && !$agent) {
$agent = AreaDividendAgent::getSpecifiedAgent($orderAddress->province_id, 'province_id', 1);
}
return $agent;
}
}

View File

@ -0,0 +1,45 @@
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/10/30
* Time: 10:05
*/
namespace Yunshop\AreaDividend\models\area;
use app\framework\Database\Eloquent\Builder;
use Yunshop\StoreCashier\common\models\Store;
use Yunshop\StoreCashier\common\models\StoreOrder;
use Yunshop\StoreCashier\common\models\CashierOrder;
class AreaStoreShop extends Store
{
public function scopeAreaShop(Builder $query, $params)
{
$model = $query->with(['hasManyStoreOrder', 'hasManyCashierOrder']);
if($params['is_time']){
if($params['time']){
$range = [strtotime($params['time']['start']), strtotime($params['time']['end'])];
$model->whereBetween('created_at', $range);
}
}
return $model;
}
public function hasManyStoreOrder()
{
return $this->hasMany(StoreOrder::class, 'store_id', 'id');
}
public function hasManyCashierOrder()
{
return $this->hasMany(CashierOrder::class, 'cashier_id', 'cashier_id');
}
}

View File

@ -0,0 +1,182 @@
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/10/29
* Time: 14:44
*/
namespace Yunshop\AreaDividend\models\area;
use app\common\models\OrderAddress;
use app\framework\Database\Eloquent\Builder;
use Yunshop\AreaDividend\models\area\SupplierOrder;
use Yunshop\AreaDividend\models\AreaDividend;
use Yunshop\StoreCashier\common\models\StoreOrder;
use Yunshop\StoreCashier\common\models\CashierOrder;
class Order extends \app\common\models\Order
{
protected $appends = ['plugin_name'];
public static function getOrderList($search)
{
return self::Search($search);
}
public function scopeSearch(Builder $query, $params)
{
$orders = $query->select('yz_order_address.id as address_id', 'yz_order.*');
$orders->with([
'belongsToMember' => self::memberBuilder(),
'hasOneSupplierOrder' => self::supplierBuilder(),
'hasOneStoreOrder' => self::storeCashier(),
'address',
'hasOneCashierOrder'=> self::storeCashier(),
'hasOneAreaDividend',
]);
/*$orders->whereHas('address', function ($address) use ($params) {
if ($params['province_id']) {
$address_where = $address->where('province_id', $params['province_id']);
}
if ($params['city_id']) {
$address_where->where('city_id', $params['city_id']);
}
if ($params['district_id']) {
$address_where->where('district_id', $params['district_id']);
}
if ($params['street_id']) {
$address_where->where('street_id', $params['street_id']);
}
return $address_where;
});*/
$orders->leftJoin('yz_order_address', 'yz_order.id', '=', 'yz_order_address.order_id')->where(function ($address_where) use ($params) {
if ($params['street_id']) {
return $address_where->where('street_id', $params['street_id']);
}
if ($params['district_id']) {
return $address_where->where('district_id', $params['district_id']);
}
if ($params['city_id']) {
return $address_where->where('city_id', $params['city_id']);
}
if ($params['province_id']) {
return $address_where->where('province_id', $params['province_id']);
}
return $address_where;
});
if (isset($params['plugin_id'])) {
$orders->where(function($where) use ($params) {
switch ($params['plugin_id']) {
case 0:
$where->where('plugin_id', 0);
break;
case 1:
$where->where('is_plugin', 1);
break;
case 32:
$where->where('plugin_id', 32)->orWhere('plugin_id', 31);
break;
default:
break;
}
});
}
if (isset($params['name'])) {
$orders->whereHas('hasOneSupplierOrder', function ($supp_order) use ($params) {
$supp_order->whereHas('beLongsToSupplier', function ($supp) use ($params) {
$supp->where('realname', 'like', '%' . $params['name'] . '%');
});
});
}
if($params['is_time']){
if($params['time']){
$range = [strtotime($params['time']['start']), strtotime($params['time']['end'])];
$orders->whereBetween('yz_order.created_at', $range);
}
}
//$orders->where('status', self::COMPLETE);
return $orders;
}
private static function memberBuilder()
{
return function ($query) {
return $query->select(['uid', 'mobile', 'nickname', 'realname','avatar']);
};
}
private static function supplierBuilder()
{
return function ($query) {
return $query->select('order_id')->with(['beLongsToSupplier' => function ($supp) {
$supp->select('id', 'realname');
}]);
};
}
private static function storeCashier()
{
return function ($query) {
return $query->with('hasOneStore');
};
}
public function getPluginNameAttribute()
{
if ($this->plugin_id == 32 || $this->plugin_id == 31) {
return '门店';
}
if ($this->is_plugin == 1 && empty($this->plugin_id)) {
return '供应商';
}
return '自营';
}
public function hasOneStoreOrder()
{
return $this->hasOne(StoreOrder::class, 'order_id', 'id');
}
public function hasOneCashierOrder()
{
return $this->hasOne(CashierOrder::class, 'order_id', 'id');
}
public function hasOneSupplierOrder()
{
return $this->hasOne(SupplierOrder::class, 'order_id', 'id');
}
public function hasOneAreaDividend()
{
return $this->hasOne(AreaDividend::class, 'order_sn', 'order_sn');
}
}

View File

@ -0,0 +1,29 @@
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/10/29
* Time: 15:46
*/
namespace Yunshop\AreaDividend\models\area;
use app\common\models\BaseModel;
use Yunshop\Supplier\common\models\Supplier;
class SupplierOrder extends BaseModel
{
public $table = 'yz_supplier_order';
protected $guarded = [''];
/**
* @name 关联供应商表
* @author yangyang
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function beLongsToSupplier()
{
return $this->belongsTo(Supplier::class, 'supplier_id', 'id');
}
}

View File

@ -0,0 +1,19 @@
<?php
/**
* Created by PhpStorm.
* User: shenyang
* Date: 2018/9/21
* Time: 上午9:53
*/
namespace Yunshop\AreaDividend\models\expansions;
use app\common\models\ModelExpansion;
use Yunshop\AreaDividend\models\AreaDividendGoods;
class GoodsExpansions extends ModelExpansion
{
public function areaDividendGoods($model){
// dd($model->hasOne(AreaDividendGoods::class,'goods_id'));
return $model->hasOne(AreaDividendGoods::class,'goods_id');
}
}

View File

@ -0,0 +1,28 @@
<?php
/**
* Author: 芸众商城 www.yunzshop.com
* Date: 2017/9/1
* Time: 下午5:42
*/
namespace Yunshop\AreaDividend\models\weiqing;
use app\common\models\BaseModel;
class UsersPermission extends BaseModel
{
public $table = 'users_permission';
protected $guarded = [''];
public $timestamps = false;
protected $attributes = [
'url' => ''
];
public function __construct()
{
if (config('APP_Framework') == 'platform') {
$this->table = 'yz_users_permission';
}
}
}

View File

@ -0,0 +1,164 @@
<?php
/**
* Author: 芸众商城 www.yunzshop.com
* Date: 2017/6/12
* Time: 下午2:01
*/
namespace Yunshop\AreaDividend\models\weiqing;
use app\common\models\BaseModel;
use app\common\models\user\UniAccountUser;
use app\common\services\Utils;
class WeiQingUsers extends BaseModel
{
public $table = 'users';
protected $guarded = [''];
protected $primaryKey = 'uid';
public $timestamps = false;
public function __construct()
{
if (config('APP_Framework') == 'platform') {
$this->table = 'yz_admin_users';
$this->timestamps = true;
}
}
public static function delUser($uid)
{
$user_model = self::getUserByUid($uid)->first();
if ($user_model) {
$user_model->delete();
}
}
public static function updatePermission($uid)
{
WeiQingUsers::updateType($uid);
//todo 公众号权限
$uni_model = new UniAccountUser();
$uni_model->fill([
'uid' => $uid,
'uniacid' => \YunShop::app()->uniacid,
'role' => 'clerk'
]);
$uni_model->save();
// todo 模块权限
$perm_model = new UsersPermission();
$perm_model->fill([
'uniacid' => \YunShop::app()->uniacid,
'uid' => $uid,
'type' => 'yun_shop',
'permission' => 'yun_shop_cover_shop|yun_shop_rule|yun_shop_menu_shop',
'url' => 'www.yunzshop.com'
]);
$perm_model->save();
}
public static function getUserByUserName($username)
{
return self::select()->byUserName($username);
}
public static function getUserByUid($uid)
{
return self::select()->byUid($uid);
}
public static function editPwd($new_pwd, $user)
{
$password = user_hash($new_pwd, $user->salt);
$user->password = $password;
$user->save();
}
public function scopeByUserName($query, $username)
{
return $query->where('username', $username);
}
public function scopeByUid($query, $uid)
{
return $query->where('uid', $uid);
}
public static function updateType($uid)
{
$user = self::getUserByUid($uid)->first();
if ($user) {
$user->type = 3;
$user->save();
}
}
public static function registerBySalt($username, $password, $salt)
{
$data = [
'username' => $username,
'password' => $password,
'salt' => $salt,
'lastvisit' => time(),
'lastip' => Utils::getClientIp(),
'joinip' => Utils::getClientIp(),
'status' => 2,
'remark' => '',
'owner_uid' => 0
];
$users_model = new WeiQingUsers;
$users_model->fill($data);
$users_model->save();
$user_uid = $users_model['uid'];
WeiQingUsers::updatePermission($user_uid);
return $user_uid;
}
public static function register($username, $password)
{
$salt = randNum(8);
$password = user_hash($password, $salt);
$data = [
'username' => $username,
'password' => $password,
'salt' => $salt,
'lastvisit' => time(),
'lastip' => Utils::getClientIp(),
'joinip' => Utils::getClientIp(),
'status' => 2,
'remark' => '',
'owner_uid' => 0
];
$users_model = new WeiQingUsers;
$users_model->fill($data);
$users_model->save();
WeiQingUsers::updatePermission($users_model->uid);
$data = [
'user_id' => $users_model->uid,
'password' => $users_model->password,
'salt' => $users_model->salt,
'username' => $users_model->username,
];
return $data;
}
public function atributeNames()
{
return [
'username' => '账号',
'password' => '密码'
];
}
public function rules()
{
$rules = [
'username' => 'required',
'password' => 'required'
];
return $rules;
}
}

View File

@ -0,0 +1,82 @@
<?php
namespace Yunshop\AreaDividend\services;
use app\common\models\Address;
use app\common\models\Street;
/**
* Created by PhpStorm.
* User: yanglei
* Date: 2017/5/4
* Time: 下午3:05
*/
class AgentService
{
public static function setAgentData($agentData)
{
$agentData['agent_level'] = 0;
if(!empty($agentData['province_id'])){
$province = Address::find($agentData['province_id']);
$agentData['province_name'] = $province->areaname;
$agentData['agent_level'] = 1;
}
if(!empty($agentData['city_id'])){
$province = Address::find($agentData['city_id']);
$agentData['city_name'] = $province->areaname;
$agentData['agent_level'] = 2;
}else{
$agentData['city_name'] = '';
}
if(!empty($agentData['district_id'])){
$province = Address::find($agentData['district_id']);
$agentData['district_name'] = $province->areaname;
$agentData['agent_level'] = 3;
}else{
$agentData['district_name'] = '';
}
if(!empty($agentData['street_id'])){
$province = Street::find($agentData['street_id']);
$agentData['street_name'] = $province->areaname;
$agentData['agent_level'] = 4;
}else{
$agentData['street_name'] = '';
}
return $agentData;
}
public static function createStatusService($data)
{
switch ($data->status) {
case -1:
return '驳回';
break;
case 0:
return '待审核';
break;
case 1:
return '通过';
break;
}
}
public static function createLevelService($data)
{
switch ($data->agent_level) {
case 0:
return '无效';
break;
case 1:
return '省代理';
break;
case 2:
return '市代理';
break;
case 3:
return '区代理';
break;
case 4:
return '街道代理';
break;
}
}
}

View File

@ -0,0 +1,33 @@
<?php
/**
* Created by PhpStorm.
* User: weifeng
* Date: 2019-04-15
* Time: 12:04
*/
namespace Yunshop\AreaDividend\services;
use Yunshop\AreaDividend\models\Order;
class AreaDividendGetService
{
public $member_id;
public function __construct($member_id)
{
$this->member_id = $member_id;
}
public function getOrdersByMemberId()
{
$result = [];
$order_models = Order::whereHas('areaDividend')->where('uid', $this->member_id)->where('status', 3);
$result['count'] = $order_models->count();
$result['amount'] = $order_models->sum('price');
return $result;
}
}

View File

@ -0,0 +1,110 @@
<?php
/**
* Created by PhpStorm.
* User: yanglei
* Date: 2017/4/15
* Time: 下午2:49
*/
namespace Yunshop\AreaDividend\services;
use app\common\facades\Setting;
use app\common\models\notice\MessageTemp;
use Illuminate\Support\Facades\Log;
use EasyWeChat\Foundation\Application;
use app\common\models\Member;
class MessageService
{
public static function notice($templateId, $data, $openId)
{
$app = app('wechat');
$notice = $app->notice;
$notice->uses($templateId)->andData($data)->andReceiver($openId)->send();
}
public static function becomeAgent($data, $member)
{
$areaDividendNotice = Setting::get('plugin.area_dividend');
$temp_id = $areaDividendNotice['area_agent'];
if (!$temp_id) {
return;
}
static::messageNotice($temp_id, $member, $data);
// if ($areaDividendNotice['template_id']) {
// $message = $areaDividendNotice['area_agent'];
// $message = str_replace('[昵称]', $member['nickname'], $message);
// $message = str_replace('[时间]', date('Y-m-d H:i:s', time()), $message);
// $message = str_replace('[省]', $data->province_name, $message);
// $message = str_replace('[市]', $data->city_name, $message);
// $message = str_replace('[区/县]', $data->district_name, $message);
// $message = str_replace('[街道/乡镇]', $data->street_name, $message);
//
// $msg = [
// "first" => '您好',
// "keyword1" => "成为区域代理通知",
// "keyword2" => $message,
// "remark" => "",
// ];
// $result = \app\common\services\MessageService::notice($areaDividendNotice['template_id'], $msg, $member->uid);
// if ($result) {
// Log::info($member->nickname . "成为区域代理. OPENID:" . $member->openid);
// }
// }
// return;
}
public static function statementNotice($data)
{
$areaDividendNotice = Setting::get('plugin.area_dividend');
$temp_id = $areaDividendNotice['area_dividend'];
if (!$temp_id) {
return;
}
$member = Member::getMemberByUid($data->member_id)->with('hasOneFans')->first();
static::messageNotice($temp_id, $member, $data);
// if ($areaDividendNotice['template_id'] ) {
// $message = $areaDividendNotice['dividend'];
// $message = str_replace('[昵称]', $member['nickname'], $message);
// $message = str_replace('[时间]', date('Y-m-d H:i:s', time()), $message);
// $message = str_replace('[等级]', $data->level_name, $message);
// $message = str_replace('[金额]', $data->dividend_amount, $message);
// $msg = [
// "first" => '您好',
// "keyword1" => "分红结算通知",
// "keyword2" => $message,
// "remark" => "",
// ];
// $result = \app\common\services\MessageService::notice($areaDividendNotice['template_id'], $msg, $member->uid);
// if ($result) {
// Log::info($member->nickname . "分红结算. OPENID:" . $member->openid);
// }
// }
// return;
}
public static function messageNotice($temp_id, $member, $data = [], $uniacid = '')
{
$params = [
['name' => '昵称', 'value' => $member['nickname']],
['name' => '时间', 'value' => date('Y-m-d H:i:s', time())],
['name' => '省', 'value' => $data['province_name']],
['name' => '市', 'value' => $data['city_name']],
['name' => '区/县', 'value' => $data['district_name']],
['name' => '街道/乡镇', 'value' => $data['street_name']],
['name' => '等级', 'value' => $data['level_name']],
['name' => '金额', 'value' => $data['dividend_amount']],
];
$msg = MessageTemp::getSendMsg($temp_id, $params);
if (!$msg) {
return;
}
\app\common\services\MessageService::notice(MessageTemp::$template_id, $msg, $member->uid, $uniacid);
}
}

View File

@ -0,0 +1,497 @@
<?php
namespace Yunshop\AreaDividend\services;
use app\common\facades\Setting;
use Yunshop\AreaDividend\event\CreatedAreaDividendBonusEvent;
use Yunshop\AreaDividend\models\AreaDividend;
use Yunshop\AreaDividend\models\AreaDividendAgent;
use Yunshop\AreaDividend\models\AreaDividendGoods;
use Yunshop\Commission\models\AgentLevel;
use Yunshop\Hotel\common\models\HotelGoods;
use Yunshop\Hotel\common\models\HotelSetting;
use Yunshop\StoreCashier\common\models\CashierGoods;
use Yunshop\StoreCashier\common\models\StoreSetting;
use Yunshop\StoreCashier\store\models\StoreGoods;
class OrderCreatedNewService
{
public $order;
public $dividendRate;
public $areaLevel;
public $areaDividendGoods;
public $amount;
public $is_fix;
public $commission;
public $alone_dividend_rate = false;
public $lower_level_rate = false;
public function __construct($order,$areaLevel,$is_fix,$commission=false)
{
$this->order = $order;
$this->areaLevel = $areaLevel;
$this->is_fix = $is_fix;
$this->commission = $commission;
}
protected function getSet()
{
if (!isset($this->set)) {
$this->set = Setting::get('plugin.area_dividend');
}
return $this->set;
}
protected function getDividendRate()
{
if (!isset($this->dividendRate)) {
$set = $this->getSet();
// 获取分红设置
$uid = $this->order['uid'] > 0 ? $this->order['uid'] : \YunShop::app()->getMemberId();
\Log::debug("用户分红比例 - uid",$uid);
if($uid > 0){
$originalStreetRate = AgentLevel::getUserRate($uid,4);
$originalAreaRate = AgentLevel::getUserRate($uid,3);
$originalCityRate = AgentLevel::getUserRate($uid,2);
$originalProvinceRate = AgentLevel::getUserRate($uid,1);
}else{
$originalStreetRate = $set['street_rate'] ? : 0;
$originalAreaRate = $set['area_rate'] ? : 0;
$originalCityRate = $set['city_rate'] ? : 0;
$originalProvinceRate = $set['province_rate'] ? : 0;
}
\Log::debug("用户分红比例 - 全部比例:",[$originalStreetRate,$originalAreaRate,$originalCityRate,$originalProvinceRate]);
// 分红配置
if ($set['is_distinction']) {
//开启极差
$street_rate = $this->areaLevel['level_4'] ? $originalStreetRate : 0;
$area_rate = $this->areaLevel['level_3'] ? $originalAreaRate : $street_rate;
$city_rate = $this->areaLevel['level_2'] ? $originalCityRate : $area_rate;
$province_rate = $this->areaLevel['level_1'] ? $originalProvinceRate : $city_rate;
$rates = [
'province_rate' => $province_rate - $city_rate,
'city_rate' => $city_rate - $area_rate,
'area_rate' => $area_rate - $street_rate,
];
// 分销极差
if ($this->commission !== false) {
$rates = [
'province_rate' => $province_rate,
'city_rate' => $city_rate,
'area_rate' => $area_rate,
];
}
$this->dividendRate = [
'rate_1' => [
'rate' => $rates['province_rate'] > 0 ? $rates['province_rate'] : 0,
'lower_level_rate' => $rates['city_rate'],
'point_ratio' => $set['province_point']
],
'rate_2' => [
'rate' => $rates['city_rate'] > 0 ? $rates['city_rate'] : 0,
'lower_level_rate' => $rates['area_rate'],
'point_ratio' => $set['city_point']
],
'rate_3' => [
'rate' => $rates['area_rate'] > 0 ? $rates['area_rate'] : 0,
'lower_level_rate' => $originalStreetRate ? $originalStreetRate : 0,
'point_ratio' => $set['area_point']
],
'rate_4' => [
'rate' => $originalStreetRate ? $originalStreetRate : 0,
'lower_level_rate' => '0',
'point_ratio' => $set['street_point']
]
];
} else {
$this->dividendRate = [
'rate_1' => [
'rate' => $originalProvinceRate,
'lower_level_rate' => $originalCityRate,
'point_ratio' => $set['province_point']
],
'rate_2' => [
'rate' => $originalCityRate,
'lower_level_rate' => $originalAreaRate,
'point_ratio' => $set['city_point']
],
'rate_3' => [
'rate' => $originalAreaRate,
'lower_level_rate' => $originalStreetRate,
'point_ratio' => $set['area_point']
],
'rate_4' => [
'rate' => $originalStreetRate,
'lower_level_rate' => '',
'point_ratio' => $set['street_point']
]
];
}
}
\Log::debug("用户分红比例 - 最终比例:",$this->dividendRate);
return $this->dividendRate;
}
public function addAreaDividendData($area_agents,$areaLevel)
{
if ($area_agents->isEmpty()) {
\Log::debug('区域分红' . $this->order->id .$areaLevel.'团队为空');
return ;
}
$same_level_num = $area_agents->count('id'); //同级人数
\Log::debug('区域分红' . $this->order->id .$areaLevel.'同级人数'.$same_level_num);
$areaDividendData = [
'uniacid' => \YunShop::app()->uniacid,
'order_sn' => $this->order->order_sn,
'order_id' => $this->order->id,
// 'amount' => $amount,
'order_amount' => $this->order->price,
'settle_days' => $this->getSet()['settle_days'] ? : 0,
'create_month' => date('Y-m'),
'same_level_number' => $same_level_num,
'created_at' => $this->order->create_time->timestamp,
];
foreach ($area_agents as $agent) {
if($agent['agent_at'] > $areaDividendData['created_at']){
\Log::debug("区域分红{$this->order->id}: {$areaLevel}{$agent['id']}成为区域代理的时间大于下单时间");
continue;
}
$exist = AreaDividend::where([
'member_id' => $agent['member_id'],
'area_level' => $agent['agent_level'],
'order_sn' => $areaDividendData['order_sn'],
])->count();
if ($exist) {
\Log::info("订单{$areaDividendData['order_sn']}:", "{$agent['member_id']}的分红记录已存在");
continue;
}
$areaDividendData['member_id'] = $agent['member_id'];
$areaDividendData['area_level'] = $agent['agent_level'];
$areaDividendData['agent_area'] = $this->getAreaName($agent);
$areaDividendData['dividend_rate'] = $this->dividendRate($agent);
$areaDividendData['lower_level_rate'] = $this->lowerLevelRate($agent);
$dividend_amount = $this->getDividendAmount($areaDividendData,$agent);
if ($dividend_amount <= 0) {
continue;
}
if ($this->alone_dividend_rate !== false) {
$areaDividendData['dividend_rate'] = $this->alone_dividend_rate;
$areaDividendData['lower_level_rate'] = $this->lower_level_rate;
}
$areaDividendData['dividend_amount'] = $dividend_amount;
$areaDividendData['amount'] = $this->amount;
//todo 防止多队列支付先走
$order = \app\common\models\Order::find($this->order->id);
if ($order->status >= 3) {
$areaDividendData['recrive_at'] = strtotime($order->finish_time);
}
$dividendModel = AreaDividend::create($areaDividendData);
if ($this->is_fix) {
continue;
}
event(new CreatedAreaDividendBonusEvent($this->order, $agent['member_id'], $areaDividendData['dividend_amount'], $dividendModel->id));
OrderCreatedService::setAareaDividend($areaDividendData, $agent);
\Log::info("订单{$areaDividendData['order_sn']}:", "{$agent['member_id']}的分红记录生成成功");
}
if ($this->commission !== false) {
//$this->commission = (!empty($dividend_amount) && $dividend_amount>0) ? $dividend_amount : $this->commission;
// 区级 3(分红a1) - 1(分销) = 2(分红a2)
// 市级 10(分红b1) - (1(分销) + 2(分红a2) = 7(分红b2))
// 省级 40(分红c1) - (7(分红b2) + 3(分红a1)) = 30
$this->commission += $dividend_amount;
}
}
protected function getAreaName($agent)
{
$areaName = $agent->province_name;
$areaName .= $agent->city_name ? "-" . $agent->city_name : '';
$areaName .= $agent->district_name ? "-" . $agent->district_name : '';
$areaName .= $agent->street_name ? "-" . $agent->street_name : '';
return $areaName;
}
/**
* @param $agent
* @return int
*/
protected function dividendRate($agent)
{
$ratio = $this->getDividendRate()['rate_' . $agent['agent_level']]['rate'] ? : 0;
if ($agent->has_ratio == 1) {
$ratio = $agent->ratio;
}
return $ratio;
}
/**
* @param $agent
* @return int
*/
protected function lowerLevelRate($agent)
{
$ratio = $this->getDividendRate()['rate_' . $agent['agent_level']]['lower_level_rate'] ? : 0;
if ($agent->has_ratio == 1) {
$ratio = $agent->ratio;
}
return $ratio;
}
protected function getAreaDividendGoods()
{
if (!isset($this->areaDividendGoods)) {
foreach ($this->order['goods'] as $goods) {
$this->areaDividendGoods[$goods->goods_id] = AreaDividendGoods::getGoodsByGoodsId($goods->goods_id)->first();
}
}
return $this->areaDividendGoods;
}
//计算分红金额
protected function getDividendAmount($areaDividendData,$agent)
{
$dividendAmount = 0;
$amount = 0;
$pt_price = 0;
foreach ($this->order['goods'] as $goods) {
if (app('plugins')->isEnabled('special-settlement') && \Setting::get('plugin.special-settlement.profit-rule')["area_dividend"]==1) {
if (in_array($this->order->plugin_id,[31,32])) {
$goods->payment_amount = $goods->goods_price;
}
}
$areaDividendGoods = $this->getAreaDividendGoods()[$goods->goods_id];
if (!$areaDividendGoods || $areaDividendGoods->is_dividend <> 1) {//商品没开启区域分红
continue;
}
if ($areaDividendGoods['alone_rule'] == 1) {//开启独立分红设置
$price = $this->setDividendPrice($goods); //根据设置获取利润或者售价
$rates = $this->getAloneRate($areaDividendGoods,$agent);
$rate = $rates['rate'];
$amount += $price;
if (count($this->order['goods']) == 1) {
$this->alone_dividend_rate = $rates['rate'];
$this->lower_level_rate = $rates['lower_level_rate'];
}
$dividendAmount += proportionMath($price , $rate);
\Log::debug('区域分红独立规则分红',[$price,$rate,$dividendAmount,$goods->goods_id]);
} else {
if ($areaDividendGoods->has_dividend) { //开启独立分红金额
$price = $this->hasDividendPrice($areaDividendGoods, $goods);
\Log::debug('区域分红计算金额1',$price);
} else {
$price = static::setDividendPrice($goods);
\Log::debug('区域分红计算金额2',$price);
if ($this->order->plugin_id == 32) {
$set = $this->order->getSetting('plugin.area-dividend');
// 门店设置
if ($set['has_dividend_rate']) {
$price = proportionMath($price , $set['has_dividend_rate']);
}
}
if ($this->order->plugin_id == 33) {
$set = $this->order->getSetting('plugin.area_dividend');
// 酒店设置
if ($set['has_dividend_rate']) {
$price = proportionMath($price , $set['has_dividend_rate']);
}
}
}
$amount += $price;
$pt_price += $price;
}
}
if ($pt_price > 0) {//加上普通非独立规则的商品分红计算
$dividendAmount += proportionMath($pt_price,$areaDividendData['dividend_rate']);
}
//是否开启同等级平均分红
if ($this->getSet()['is_average']) {
$dividendAmount = bcdiv($dividendAmount,$areaDividendData['same_level_number'],2);
}
//分销极差
if ($this->commission !== false) {
if ($dividendAmount - $this->commission <= 0) {
$dividendAmount = 0;
} else {
$dividendAmount -= $this->commission;
}
}
\Log::debug('区域分红+++++++++++',[$agent['agent_level'],$dividendAmount,$areaDividendData['dividend_rate']]);
$this->amount = $amount; // 给获取预计分红计算
return $dividendAmount;
}
protected function getAloneRate($areaDividendGoods,$agent){
$set = $this->getSet();
if ($set['is_distinction']) {
//开启极差
$street_rate = $this->areaLevel['level_4'] ? $areaDividendGoods['street_rate'] : 0;
$area_rate = $this->areaLevel['level_3'] ? $areaDividendGoods['area_rate'] : $street_rate;
$city_rate = $this->areaLevel['level_2'] ? $areaDividendGoods['city_rate'] : $area_rate;
$province_rate = $this->areaLevel['level_1'] ? $areaDividendGoods['province_rate'] : $city_rate;
$rate = [
'province_rate' => $province_rate - $city_rate,
'city_rate' => $city_rate - $area_rate,
'area_rate' => $area_rate - $street_rate,
];
// 分销极差
if ($this->commission !== false) {
$rate = [
'province_rate' => $province_rate,
'city_rate' => $city_rate,
'area_rate' => $area_rate,
];
}
$rates = [
'rate_1' => [
'rate' => $rate['province_rate'] > 0 ? $rate['province_rate'] : 0,
'lower_level_rate' => $rate['city_rate'],
],
'rate_2' => [
'rate' => $rate['city_rate'] > 0 ? $rate['city_rate'] : 0,
'lower_level_rate' => $rate['area_rate'],
],
'rate_3' => [
'rate' => $rate['area_rate'] > 0 ? $rate['area_rate'] : 0,
'lower_level_rate' => $areaDividendGoods['street_rate'] ? $areaDividendGoods['street_rate'] : 0,
],
'rate_4' => [
'rate' => $areaDividendGoods['street_rate'] ? $areaDividendGoods['street_rate'] : 0,
'lower_level_rate' => '0',
]
];
} else {
$rates = [
'rate_1' => [
'rate' => $areaDividendGoods['province_rate'] ? : 0,
'lower_level_rate' => $areaDividendGoods['city_rate'],
],
'rate_2' => [
'rate' => $areaDividendGoods['city_rate'] ? : 0,
'lower_level_rate' => $areaDividendGoods['area_rate'],
],
'rate_3' => [
'rate' => $areaDividendGoods['area_rate'] ? : 0,
'lower_level_rate' => $areaDividendGoods['street_rate'],
],
'rate_4' => [
'rate' => $areaDividendGoods['street_rate'] ? $areaDividendGoods['street_rate'] : 0,
'lower_level_rate' => '0',
]
];
}
return $rates['rate_'.$agent['agent_level']];
}
protected function hasDividendPrice($areaDividendGoods, $goods)
{
if ($areaDividendGoods->has_dividend_rate > 0) {
$price = proportionMath($goods->payment_amount, $areaDividendGoods->has_dividend_rate);
} elseif ($areaDividendGoods->has_dividend_price > 0) {
$price = $areaDividendGoods->has_dividend_price * $goods->total;
} else {
$price = static::setDividendPrice($goods);
}
return $price;
}
protected function setDividendPrice($goods)
{
if ($this->getSet()['culate_method']) {
//利润
$price = $goods->payment_amount - $goods->goods_cost_price;
if (app('plugins')->isEnabled('store-cashier')) {
$cashier_good = CashierGoods::select('id', 'goods_id', 'shop_commission')->where('goods_id', $goods->goods_id)->first();
$store_good = StoreGoods::select('id', 'store_id', 'goods_id')->where('goods_id', $goods->goods_id)->first();
if ($cashier_good) {
$price = proportionMath($goods->payment_amount , $cashier_good->shop_commission);
if (app('plugins')->isEnabled('consumer-reward') && \Setting::get('plugin.consumer_reward.is_open')==1) {
if (\Setting::get('plugin.consumer_reward.cashier_profit')) {
$price = proportionMath($goods->goods_price , $cashier_good->shop_commission);
$price = \Yunshop\ConsumerReward\common\services\AmountDividendService::amountPrice($goods->order_id, $price);
}
}
} elseif ($store_good) {
$store_setting = StoreSetting::where('store_id', $store_good->store_id)->where('key', 'store')->first();
$shop_commission = (integer)$store_setting->value['shop_commission'];
$price = proportionMath($goods->payment_amount , $shop_commission);
if (app('plugins')->isEnabled('consumer-reward') && \Setting::get('plugin.consumer_reward.is_open')==1) {
if (\Setting::get('plugin.consumer_reward.store_profit')) {
$amount_price = $goods->payment_amount - $goods->goods_cost_price;
$price = \Yunshop\ConsumerReward\common\services\AmountDividendService::amountPrice($goods->order_id, $amount_price);
}
}
}
}
if (app('plugins')->isEnabled('hotel')) {
$hotel_good = HotelGoods::select('id', 'hotel_id', 'goods_id')->where('goods_id', $goods->goods_id)->first();
if ($hotel_good) {
$hotel_setting = HotelSetting::where('hotel_id', $hotel_good->hotel_id)->where('key', 'hotel')->first();
$shop_commission = (integer)$hotel_setting->value['shop_commission'];
$price = proportionMath($goods->payment_amount , $shop_commission);
}
}
} else {
//订单金额
$price = $goods->payment_amount;
}
return $price;
}
protected function getAmount()
{
return $this->amount;
}
/**
* 预计分红
* @return float|int
*/
public function expectedDividend()
{
$set = $this->order->getSetting('plugin.area_dividend');
$totalDividend = 0.00;
$rates['province_rate'] = $set['province_rate'];
$rates['city_rate'] = $set['city_rate'];
$rates['area_rate'] = $set['area_rate'];
$rates['street_rate'] = $set['street_rate'];
if ($set['is_distinction']) {
$totalDividend = round(max($rates) / 100 * $this->amount, 2);
} else {
foreach ($rates as $rate) {
$totalDividend += round($rate / 100 * $this->amount, 2);
}
}
return $totalDividend;
}
}

View File

@ -0,0 +1,316 @@
<?php
namespace Yunshop\AreaDividend\services;
use app\common\facades\Setting;
use Yunshop\AreaDividend\models\AreaDividendAgent;
use Yunshop\AreaDividend\models\AreaDividendGoods;
use Yunshop\Commission\models\AgentLevel;
use Yunshop\Hotel\common\models\HotelGoods;
use Yunshop\Hotel\common\models\HotelSetting;
use Yunshop\StoreCashier\common\models\CashierGoods;
use Yunshop\StoreCashier\common\models\StoreSetting;
use Yunshop\StoreCashier\store\models\StoreGoods;
/**
* Created by PhpStorm.
* User: yanglei
* Date: 2017/5/8
* Time: 上午10:04
*/
class OrderCreatedService
{
/**
* @param $order
* @param $set
* @return float|int|mixed
*/
public static function gerAmount($order, $set)
{
$price = 0;
foreach ($order['goods'] as $goods) {
if (app('plugins')->isEnabled('special-settlement') && \Setting::get('plugin.special-settlement.profit-rule')["area_dividend"]==1) {
if ($order->plugin_id == 31 || $order->plugin_id == 32) {
$goods->payment_amount = $goods->goods_price;
}
}
$areaDividendGoods = AreaDividendGoods::getGoodsByGoodsId($goods->goods_id)->first();
if ($areaDividendGoods) {
$price += static::gerPrice($price, $areaDividendGoods, $goods, $set, $order);
}
}
return $price;
}
/**
* @param $price
* @param $areaDividendGoods
* @param $goods
* @param $set
* @param $order
* @return float|int|mixed
*/
public static function gerPrice($price, $areaDividendGoods, $goods, $set, $order)
{
if ($areaDividendGoods->has_dividend) {
$price = static::hasDividendPrice($price, $areaDividendGoods, $goods);
} else {
$price = static::setDividendPrice($price, $goods);
if ($order->plugin_id == 32) {
$set = $order->getSetting('plugin.area-dividend');
// 门店设置
if ($set['has_dividend_rate']) {
$price = proportionMath($price , $set['has_dividend_rate']);
}
}
if ($order->plugin_id == 33) {
$set = $order->getSetting('plugin.area_dividend');
// 酒店设置
if ($set['has_dividend_rate']) {
$price = proportionMath($price , $set['has_dividend_rate']);
}
}
}
return $price;
}
/**
* @param $price
* @param $areaDividendGoods
* @param $goods
* @return float|int|mixed
*/
public static function hasDividendPrice($price, $areaDividendGoods, $goods)
{
if ($areaDividendGoods->has_dividend_rate > 0) {
$price = proportionMath($goods->payment_amount, $areaDividendGoods->has_dividend_rate);
} elseif ($areaDividendGoods->has_dividend_price > 0) {
$price = $areaDividendGoods->has_dividend_price * $goods->total;
} else {
$price = static::setDividendPrice($price, $goods);
}
return $price;
}
/**
* @param $price
* @param $goods
* @return mixed
*/
public static function setDividendPrice($price, $goods)
{
$set = Setting::get('plugin.area_dividend');
if ($set['culate_method']) {
//利润
$price = $goods->payment_amount - $goods->goods_cost_price;
if (app('plugins')->isEnabled('store-cashier')) {
$cashier_good = CashierGoods::select('id', 'goods_id', 'shop_commission')->where('goods_id', $goods->goods_id)->first();
$store_good = StoreGoods::select('id', 'store_id', 'goods_id')->where('goods_id', $goods->goods_id)->first();
if ($cashier_good) {
$price = proportionMath($goods->payment_amount , $cashier_good->shop_commission);
if (app('plugins')->isEnabled('consumer-reward') && \Setting::get('plugin.consumer_reward.is_open')==1) {
if (\Setting::get('plugin.consumer_reward.cashier_profit')) {
$price = proportionMath($goods->goods_price , $cashier_good->shop_commission);
$price = \Yunshop\ConsumerReward\common\services\AmountDividendService::amountPrice($goods->order_id, $price);
}
}
} elseif ($store_good) {
$store_setting = StoreSetting::where('store_id', $store_good->store_id)->where('key', 'store')->first();
$shop_commission = (integer)$store_setting->value['shop_commission'];
$price = proportionMath($goods->payment_amount , $shop_commission);
if (app('plugins')->isEnabled('consumer-reward') && \Setting::get('plugin.consumer_reward.is_open')==1) {
if (\Setting::get('plugin.consumer_reward.store_profit')) {
$amount_price = $goods->payment_amount - $goods->goods_cost_price;
$price = \Yunshop\ConsumerReward\common\services\AmountDividendService::amountPrice($goods->order_id, $amount_price);
}
}
}
}
if (app('plugins')->isEnabled('hotel')) {
$hotel_good = HotelGoods::select('id', 'hotel_id', 'goods_id')->where('goods_id', $goods->goods_id)->first();
if ($hotel_good) {
$hotel_setting = HotelSetting::where('hotel_id', $hotel_good->hotel_id)->where('key', 'hotel')->first();
$shop_commission = (integer)$hotel_setting->value['shop_commission'];
$price = proportionMath($goods->payment_amount , $shop_commission);
}
}
} else {
//订单金额
$price = $goods->payment_amount;
}
return $price;
}
/**
* @param $set
* @param $areaLevel
* @return array
*/
public static function getRateByAgent($set, $areaLevel){
// 获取分红设置
$uid = \YunShop::app()->getMemberId();
if($uid > 0){
$originalStreetRate = AgentLevel::getUserRate($uid,4);
$originalAreaRate = AgentLevel::getUserRate($uid,3);
$originalCityRate = AgentLevel::getUserRate($uid,2);
$originalProvinceRate = AgentLevel::getUserRate($uid,1);
}else{
$originalStreetRate = $set['street_rate'] ? : 0;
$originalAreaRate = $set['area_rate'] ? : 0;
$originalCityRate = $set['city_rate'] ? : 0;
$originalProvinceRate = $set['province_rate'] ? : 0;
}
// 其他操作
$rateData = [];
if ($areaLevel['level_4']) $street_rate = $originalStreetRate;
else $street_rate = 0;
if ($areaLevel['level_3']) $area_rate = $originalAreaRate;
else $area_rate = $street_rate;
if ($areaLevel['level_2']) $city_rate = $originalCityRate;
else $city_rate = $area_rate;
if ($areaLevel['level_1']) $province_rate = $originalProvinceRate;
else $province_rate = $city_rate;
$street_point = $set['street_point'];
$area_point = $set['area_point'];
$city_point = $set['city_point'];
$province_point = $set['province_point'];
$rateData = [
'province_rate' => $province_rate - $city_rate,
'city_rate' => $city_rate - $area_rate,
'area_rate' => $area_rate - $street_rate,
'province_point' => $province_point - $city_point,
'city_point' => $city_point - $area_point,
'area_point' => $area_point - $street_point,
'street_point' => $street_point
];
return $rateData;
}
/**
* @param $areaLevel
* @return array
*/
public static function gerDividendRate($areaLevel)
{
$set = Setting::get('plugin.area_dividend');
$dividendRate = [];
// 获取分红设置
$uid = \YunShop::app()->getMemberId();
if($uid > 0){
$originalStreetRate = AgentLevel::getUserRate($uid,4);
$originalAreaRate = AgentLevel::getUserRate($uid,3);
$originalCityRate = AgentLevel::getUserRate($uid,2);
$originalProvinceRate = AgentLevel::getUserRate($uid,1);
}else{
$originalStreetRate = $set['street_rate'] ? : 0;
$originalAreaRate = $set['area_rate'] ? : 0;
$originalCityRate = $set['city_rate'] ? : 0;
$originalProvinceRate = $set['province_rate'] ? : 0;
}
if ($set['is_distinction']) {
$rates = static::getRateByAgent($set, $areaLevel);
$province_rate = $rates['province_rate'];
$city_rate = $rates['city_rate'];
$area_rate = $rates['area_rate'];
$dividendRate = [
'rate_1' => [
'rate' => $province_rate > 0 ? $province_rate : 0,
'lower_level_rate' => $city_rate,
'point_ratio' => $set['province_point']
],
'rate_2' => [
'rate' => $city_rate > 0 ? $city_rate : 0,
'lower_level_rate' => $area_rate,
'point_ratio' => $set['city_point']
],
'rate_3' => [
'rate' => $area_rate > 0 ? $area_rate : 0,
'lower_level_rate' => $originalStreetRate ? $originalStreetRate : 0,
'point_ratio' => $set['area_point']
],
'rate_4' => [
'rate' => $originalStreetRate ? $originalStreetRate : 0,
'lower_level_rate' => '0',
'point_ratio' => $set['street_point']
]
];
} else {
$dividendRate = [
'rate_1' => [
'rate' => $originalProvinceRate,
'lower_level_rate' => $originalCityRate,
'point_ratio' => $set['province_point']
],
'rate_2' => [
'rate' => $originalCityRate,
'lower_level_rate' => $originalAreaRate,
'point_ratio' => $set['city_point']
],
'rate_3' => [
'rate' => $originalAreaRate,
'lower_level_rate' => $originalStreetRate,
'point_ratio' => $set['area_point']
],
'rate_4' => [
'rate' => $originalStreetRate,
'lower_level_rate' => '',
'point_ratio' => $set['street_point']
]
];
}
return $dividendRate;
}
/**
* @param $data
* @param $agent
*/
public static function setAareaDividend($data, $agent)
{
$agentData = [
'count_order_amount' => $data['order_amount'] + $agent['count_order_amount'],
'count_settle_amount' => $data['amount'] + $agent['count_settle_amount'],
'unsettled_dividend_amount' => $data['dividend_amount'] + $agent['unsettled_dividend_amount'],
];
AreaDividendAgent::updatedAgentById($agentData, $agent['id']);
}
/**
* 预计分红
* @param $amount
* @param $set
* @return float|int
*/
public static function expectedDividend($amount, $set)
{
$totalDividend = 0.00;
$rates['province_rate'] = $set['province_rate'];
$rates['city_rate'] = $set['city_rate'];
$rates['area_rate'] = $set['area_rate'];
$rates['street_rate'] = $set['street_rate'];
if ($set['is_distinction']) {
$totalDividend = round(max($rates) / 100 * $amount, 2);
} else {
foreach ($rates as $rate) {
$totalDividend += round($rate / 100 * $amount, 2);
}
}
return $totalDividend;
}
}

View File

@ -0,0 +1,60 @@
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/10/11
* Time: 17:52
*/
namespace Yunshop\AreaDividend\services;
use Yunshop\AreaDividend\event\SettleAreaDividendBonusEvent;
use Yunshop\AreaDividend\models\AreaDividend;
class ReturnFormatService
{
//处理数量 返回相同格式
public function sameFormat($model)
{
foreach ($model as $item) {
$data[] = $this->defaultFormat($item);
}
return $data;
}
protected function defaultFormat($data)
{
return [
'id' => $data->id,
'order_sn' => $data->order_sn,
'amount' => $data->dividend_amount,
'order' => $data->hasOneOrder ? $data->hasOneOrder->toArray() : [],
];
}
//统一格式化数据返回
public function getAdvFormat($result)
{
//加入到收入
$this->setSettlement($result);
return $this->defaultFormat($result);
}
public function setSettlement($result)
{
$data = ['status'=>'1','statement_at'=>time()];
AreaDividend::where('id', $result->id)->update($data);
$areaDividend = collect([])->push($result);
(new TimedTaskService())->setStatement($areaDividend);
$dividend = AreaDividend::where('id', $result->id)->get();
event(new SettleAreaDividendBonusEvent($dividend));
}
}

View File

@ -0,0 +1,216 @@
<?php
namespace Yunshop\AreaDividend\services;
use app\common\facades\Setting;
use app\common\models\Member;
use app\common\models\UniAccount;
use app\common\services\income\IncomeService;
use Illuminate\Support\Facades\Log;
use Yunshop\AreaDividend\event\SettleAreaDividendBonusEvent;
use Yunshop\AreaDividend\models\AreaDividend;
use Yunshop\AreaDividend\models\AreaDividendAgent;
use app\common\models\Income;
use app\common\events\ProfitEvent;
/**
* Created by PhpStorm.
* User: yanglei
* Date: 2017/5/12
* Time: 下午09:52
*/
class TimedTaskService
{
public function handle()
{
$uniAccount = UniAccount::getEnable();
\Log::info('区域分红');
foreach ($uniAccount as $u) {
\YunShop::app()->uniacid = $u->uniacid;
Setting::$uniqueAccountId = $u->uniacid;
$set = Setting::get('plugin.area_dividend');
//结算类型为手动结算 跳过
if (isset($set['settlement_model']) && $set['settlement_model'] == 1) {
\Log::info($u.'区域分红结算设置',$set['settlement_model']);
continue;
}
$request = AreaDividend::getStatement()->get();
if(!$request->isEmpty()){
//修改分红佣金状态-已结算
$this->updatedStatement($request);
$this->setStatement($request);
event(new SettleAreaDividendBonusEvent($request));
}else{
\Log::info($u.'区域分红结算记录为空');
}
}
}
/**
* @param $areaDividend
*/
public function setStatement($areaDividend)
{
foreach ($areaDividend as $item)
{
//增加区域代理已结算金额
$this->addAgentDividend($item);
//加入分红收入
$this->addAreaDividendIncome($item);
//招商专员插件分红
if(app('plugins')->isEnabled('invest-people')) {
(new \Yunshop\InvestPeople\services\IncomeWithdrawService())->areaDividend($item);
}
if ($item->dividend_amount > 0) {
MessageService::statementNotice($item);
}
if (app('plugins')->isEnabled('instation-message')) {
//开启了站内消息插件
event(new \Yunshop\InstationMessage\event\AreaDividendSettlementEvent([
'changeTime'=>date('Y-m-d H:i:s', time()),
'order_sn'=>$item->hasOneOrder->order_sn,
'order_amount'=>$item->hasOneOrder->price,
'amount'=>$item->amount,
'dividend_amount'=>$item->dividend_amount,
'member_id'=>$item->member_id,
'uniacid'=>\YunShop::app()->uniacid
]));
}
}
}
/**
* @param AreaDividend $dividendData
* @return bool
*/
public function updatedStatement($dividendData)
{
$data = ['status'=>'1','statement_at'=>time()];
$ids = $dividendData->pluck('id');
return AreaDividend::whereIn('id', $ids)->update($data);
}
/**
* @param $dividendData
*/
public function addAgentDividend($dividendData)
{
$data = [
'settle_dividend_amount' => $dividendData->hasOneAgent->settle_dividend_amount + $dividendData->dividend_amount,
'unsettled_dividend_amount' => $dividendData->hasOneAgent->unsettled_dividend_amount - $dividendData->dividend_amount,
];
return AreaDividendAgent::updatedAgentById($data,$dividendData->hasOneAgent->id);
}
public function addAreaDividendIncome($dividendData)
{
$order = $dividendData->hasOneOrder;
$data = [
'area_dividend' => [
'title' => '区域分红',
'data' => [
'0' => [
'title' => '订单分红结算金额',
'value' => $dividendData->amount . "",
],
'1' => [
'title' => '分红比例',
'value' => $dividendData->dividend_rate . "%",
],
'2' => [
'title' => '下级分红比例',
'value' => $dividendData->lower_level_rate . "%",
],
'3' => [
'title' => '分红金额',
'value' => $dividendData->dividend_amount . "",
],
'4' => [
'title' => '结算时间',
'value' => date("Y-m-d H:i:s", time())
],
'5' => [
'title' => '分红区域',
'value' => $dividendData->agent_area
],
]
],
'order' => [
'title' => '订单',
'data' => [
'0' => [
'title' => '订单号',
'value' => $order->order_sn,
],
'1' => [
'title' => '订单金额',
'value' => $order->price,
],
'2' => [
'title' => '完成时间',
'value' => $order->finish_time->toDateTimeString(),
],
]
]
];
//收入明细数据
$incomeDetail = json_encode($data);
$config = \app\backend\modules\income\Income::current()->getItem('areaDividend');
//收入明细数据
$incomeDetail = json_encode($data);
$incomeData = [
'uniacid' => \YunShop::app()->uniacid,
'member_id' => $dividendData->member_id,
'amount' => $dividendData->dividend_amount,
'detail' => $incomeDetail,//收入明细数据
'dividend_table_id' => $dividendData->id,
'dividend_code' => IncomeService::AREA_DIVIDEND,
'order_sn' => $order['order_sn'],
];
\Log::info('收入插入数据:', $incomeData);
$result = IncomeService::insertIncome($incomeData);
if ($result) {
\Log::info("区域分红:收入统计插入数据!");
}
// //收入数据
// $incomeData = [
// 'uniacid' => \YunShop::app()->uniacid,
// 'member_id' => $dividendData->member_id,
// 'incometable_type' => $config['class'],
// 'incometable_id' => $dividendData->id,
// 'type_name' => $config['title'],
// 'amount' => $dividendData->dividend_amount,
// 'status' => '0',
// 'detail' => $incomeDetail,
// 'create_month' => date("Y-m"),
// ];
// //插入收入
// $incomeModel = new Income();
// $incomeModel->separate = [
// 'mark' => $config['type'],
// 'order_sn' => $dividendData['order_sn']
// ];
// $incomeModel->fill($incomeData);
// $requestIncome = $incomeModel->save();
// if ($requestIncome) {
// \Log::info(time() . ":收入统计插入数据!");
// }
// return $requestIncome;
}
}

View File

@ -0,0 +1,22 @@
<?php
namespace Yunshop\AreaDividend\widgets;
/**
* Created by PhpStorm.
* User: yanglei
* Date: 2017/3/18
* Time: 下午5:36
*/
use app\common\components\Widget;
use app\common\facades\Setting;
class AreaDividendWithdrawWidget extends Widget
{
public function run()
{
$set = Setting::get('withdraw.areaDividend', ['roll_out_limit' => '', 'poundage_rate' => '']);
return view('Yunshop\AreaDividend::admin.withdraw-set', [
'set' => $set,
])->render();
}
}

View File

@ -0,0 +1,66 @@
<?php
/**
* Created by PhpStorm.
* Name: 芸众商城系统
* Author: 广州市芸众信息科技有限公司
* Profile: 广州市芸众信息科技有限公司位于国际商贸中心的广州,专注于移动电子商务生态系统打造,拥有芸众社交电商系统、区块链数字资产管理系统、供应链管理系统、电子合同等产品/服务。官网 www.yunzmall.com www.yunzshop.com
* Date: 2021/9/9
* Time: 17:39
*/
namespace Yunshop\AreaDividend\widgets;
use app\backend\modules\goods\widget\BaseGoodsWidget;
use app\common\facades\Setting;
use Yunshop\AreaDividend\models\AreaDividendGoods;
/**
* 区域分红(插件)
*/
class DividendVueWidget extends BaseGoodsWidget
{
public $group = 'profit';
public $widget_key = 'area_dividend';
public $code = 'areaDividend';
public function pluginFileName()
{
return 'area-dividend';
}
public function getData()
{
$goods_id = $this->goods->id;
// $set = Setting::get('plugin.area_dividend');
$item = AreaDividendGoods::where('goods_id',$goods_id)->first();
$data['item'] = [
'is_dividend'=>0, //是否开启 1是 0否
'has_dividend' => 0, //启用独立佣金比例 1启用
'has_dividend_rate'=>'', //独立分红金额 百分比
'has_dividend_price'=>'', //独立分红金额 固定值
'alone_rule' => 0,
'province_rate' => '',
'city_rate' => '',
'area_rate' => '',
'street_rate' => '',
];
if ($item) {
$data['item'] = $item->toArray();
}
return $data;
}
public function pagePath()
{
return plugin_assets('area-dividend','views/widget/');
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace Yunshop\AreaDividend\widgets;
/**
* Created by PhpStorm.
* User: yanglei
* Date: 2017/5/15
* Time: 下午4:06
*/
use app\common\components\Widget;
use app\common\facades\Setting;
use Yunshop\AreaDividend\models\AreaDividendGoods;
class DividendWidget extends Widget
{
public function run()
{
$set = Setting::get('plugin.area_dividend');
$item = AreaDividendGoods::getGoodsSet($this->goods_id);
return view('Yunshop\AreaDividend::admin.goods', [
'set' => $set,
'item' => $item,
])->render();
}
}

View File

@ -0,0 +1,104 @@
@extends('layouts.base')
@section('content')
@section('title', trans('区域代理申请'))
<div class="right-titpos">
<ul class="add-snav">
<li class="active"><a href="#">区域代理申请</a></li>
</ul>
</div>
<form action="" method="post" class="form-horizontal" id="form1">
<div class="right-addbox">
<div class="panel panel-info">
<div class="panel-body">
<div class="form-group col-xs-12 col-sm-3">
<input class="form-control" name="search[member]" id="" type="text"
value="{{$search['member']}}" placeholder="会员ID/昵称/姓名/手机">
</div>
<div class="form-group col-xs-12 col-sm-4">
<input type="hidden" name="token" value="{{$var['token']}}" id="search"/>
<button class="btn btn-success "><i class="fa fa-search"></i> 搜索</button>
</div>
</div>
</div>
</div>
</form>
<div class='panel panel-default'>
<div class='panel-body'>
<table class="table table-hover" style="overflow:visible;">
<thead>
<tr>
<th style='width:10%;'>ID</th>
<th style='width:15%;'>会员</th>
<th style='width:15%;'>姓名</br>手机</th>
<th style='width:15%;'>申请区域</th>
<th style='width:15%;'>申请时间</th>
<th style='width:10%;'>状态</th>
<th style='width:10%;'>审核</th>
</tr>
</thead>
<tbody>
@foreach($list['data'] as $row)
<tr>
<td>{{$row['id']}}</td>
<td>
<img src="{{tomedia($row['has_one_member']['avatar'])}}"
style="width: 30px; height: 30px;border:1px solid #ccc;padding:1px;">
</br>
{{$row['has_one_member']['nickname']}}
</td>
<td>
{{$row['real_name']}}
</br>
{{$row['mobile']}}
</td>
<td>
@if($row['province_name'])
{{$row['province_name']}}
@endif
@if($row['city_name'])
-{{$row['city_name']}}
@endif
@if($row['district_name'])
-{{$row['district_name']}}
@endif
@if($row['street_name'])
-{{$row['street_name']}}
@endif
</td>
<td>
{{$row['created_at']}}
</td>
<td>
{{$row['status_name']}}
</td>
<td style="overflow:visible;">
<div class="btn-group btn-group-sm " data-type="1">
<a class="btn btn-default dropdown" data-expanded="1"
href="{{yzWebUrl('plugin.area-dividend.admin.agent.cope-apply',['id'=>$row['id'],'status'=>'1'])}}">通过 <span class="caret"></span></a>
<a class="btn btn-default dropdown" data-expanded="1"
href="{{yzWebUrl('plugin.area-dividend.admin.agent.cope-apply',['id'=>$row['id'],'status'=>'-1'])}}">驳回 <span class="caret"></span></a>
</div>
</td>
</tr>
@endforeach
</tbody>
</table>
{!! $pager !!}
</div>
</div>
<div style="width:100%;height:150px;"></div>
@endsection

View File

@ -0,0 +1,224 @@
@extends('layouts.base')
@section('content')
@section('title', '编辑信息')
<div class="rightlist">
<div id="editAgentContent">
{{--表单内容--}}
<form action="" method='post' class='form-horizontal' id="editAgent" enctype="multipart/form-data">
<div class='panel panel-default'>
<el-tabs>
<el-tab-pane label="基本信息">
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">代理名称</label>
<div class="col-sm-9 col-xs-12">
<input type="text" name="title" class="form-control" value="{{$agency['title']}}" />
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">订单管理权限(唯一)</label>
<div class="col-sm-9 col-xs-12">
<label class="radio-inline">
<input type="radio" name="order_manage" value="0" @if(!$agency['manage']) checked="checked" @endif /> 关闭
</label>
<label class="radio-inline">
<input type="radio" name="order_manage" value="1" @if($agency['manage'] == 1) checked="checked" @endif /> 开启
</label>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">独立分红比例</label>
<div class="col-sm-9 col-xs-12">
<label class="radio-inline">
<input type="radio" name="has_ratio" value="0" @if(!$agency['has_ratio']) checked="checked" @endif /> 关闭</label>
<label class="radio-inline">
<input type="radio" name="has_ratio" value="1" @if($agency['has_ratio'] == 1) checked="checked" @endif/> 开启</label>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">分红比例</label>
<div class="col-sm-6 col-xs-6">
<div class='input-group'>
<input type='text' name='ratio' class="form-control discounts_value" onkeyup="this.value= this.value.match(/\d+(\.\d{0,2})?/) ? this.value.match(/\d+(\.\d{0,2})?/)[0] : ''" value="{{$agency['ratio']}}"/>
<div class='input-group-addon waytxt'>%</div>
</div>
</div>
</div>
{{--招商专员插件--}}
@if(app('plugins')->isEnabled('invest-people'))
{!! \Yunshop\InvestPeople\services\InvestMemberView::areaDividend($agency['investor_uid']) !!}
@endif
@if (!empty($username))
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">账号:</label>
<div class="col-sm-9 col-xs-12">
{{$username}}
</div>
</div>
@else
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">添加账号</label>
<div class="col-sm-9 col-xs-12">
<input type="text" name="wq[username]" placeholder="登录账号" class="form-control" value="" />
</div>
</div>
@endif
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">密码</label>
<div class="col-sm-9 col-xs-12">
<input type="text" name="wq[password]" class="form-control" value="" />
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">验证密码</label>
<div class="col-sm-9 col-xs-12">
<input type="text" name="wq[password_again]" class="form-control" value="" />
</div>
</div>
</el-tab-pane>
<el-tab-pane label="微信小程序">
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">小程序状态</label>
<div class="col-sm-9 col-xs-12">
<label class='radio-inline'>
<input type='radio' name='min_status' value='0' @if ($agency['min_status'] != 1) checked @endif/>关闭
</label>
<label class='radio-inline'>
<input type='radio' name='min_status' value='1' @if ($agency['min_status'] == 1) checked @endif />使用中
</label>
</div>
</div>
<div class="min-config-content" @if($agency['min_status'] != 1) style="display: none;" @endif>
{{--<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">App ID</label>
<div class="col-sm-9 col-xs-12">
<input type="text" name="min_app_id" class="form-control" value="{{ $agency['min_app_id'] }}"/>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">App Secret</label>
<div class="col-sm-9 col-xs-12">
<input type="text" name="min_app_secret" class="form-control @if($agency['min_app_secret']) hidden @endif " value="{{ $agency['min_app_secret'] }}" id="secret"/>
<span class='label label-success @if(!$agency['min_app_secret']) hidden @endif ' id="secret_label" >已上传</span>
<input type="button" name="" value="重设" onclick="removeHiddent1()" class="btn btn-danger @if(!$agency['min_app_secret']) hidden @endif" id="secret_btn" />
</div>
</div>--}}
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">支付商户号</label>
<div class="col-sm-9 col-xs-12">
<input type="text" name="min_mch_id" class="form-control" value="{{ $agency['min_mch_id'] }}"/>
</div>
</div>
{{--<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">支付密钥</label>
<div class="col-sm-9 col-xs-12">
<input type="text" name="min_api_secret" id="api_secret" class="form-control @if($agency['min_api_secret']) hidden @endif" value="{{ $agency['min_api_secret'] }}"/>
<span class='label label-success @if(!$agency['min_api_secret']) hidden @endif ' id="api_secret_label" >已上传</span>
<input type="button" name="" value="重设" onclick="removeHiddent()" class="btn btn-danger @if(!$agency['min_api_secret']) hidden @endif" id="api_secret_btn" />
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">CERT证书文件</label>
<div class="col-sm-9 col-xs-12">
<input type="hidden" name="min_apiclient_cert" value="{{ $agency['min_apiclient_cert'] }}"/>
<input type="file" name="apiclient_cert" class="form-control"/>
<span class="help-block">
@if (!empty($agency['min_apiclient_cert']))
<span class='label label-success'>已上传</span>
@else
<span class='label label-danger'>未上传</span>
@endif
下载证书 cert.zip 中的 apiclient_cert.pem 文件
</span>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">KEY密钥文件</label>
<div class="col-sm-9 col-xs-12">
<input type="hidden" name="min_apiclient_key" value="{{ $agency['min_apiclient_key'] }}"/>
<input type="file" name="apiclient_key" class="form-control"/>
<span class="help-block">
@if (!empty($agency['min_apiclient_key']))
<span class='label label-success'>已上传</span>
@else
<span class='label label-danger'>未上传</span>
@endif
下载证书 cert.zip 中的 apiclient_key.pem 文件
</span>
</div>
</div>--}}
</div>
</el-tab-pane>
</el-tabs>
{{--提交按钮--}}
<div class="form-group"></div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
<div class="col-sm-9 col-xs-12">
<input type="submit" name="submit" value="提交" class="btn btn-primary col-lg-1" />
<input type="button" name="back" onclick='history.back()' value="返回列表" class="btn btn-default" />
</div>
</div>
</div>
</form>
</div>
</div>
<script>
$(function () {
// 小程序状态改变
$("[name='min_status']").on('change',function () {
let val = parseInt($(this).val());
val = isNaN(val) ? parseInt(0) : parseInt(val);
if(val === 1) $(".min-config-content").show();
else $(".min-config-content").hide();
});
// 表单验证
$("#editAgent").submit(function(){
// 表单信息处理
let list = $("#editAgent").serializeArray();
let newList = {};
$.each(list,function (k,v) {
let name = v.name.replace(/data\[/g, "").replace(/]/g, "");
newList[name] = v.value;
});
console.log(newList);
// 内容校验列表
let defaultRule = [
{name: 'title', checkType: 'required', errorMsg: '请输入代理名称'},
];
if(newList['min_status'] == 1){
// defaultRule.push({name: 'min_app_id', checkType: 'required', errorMsg: '请输入App ID'});
// defaultRule.push({name: 'min_app_secret', checkType: 'required', errorMsg: '请输入App Secret'});
defaultRule.push({name: 'min_mch_id', checkType: 'required', errorMsg: '请输入支付商户号'});
// defaultRule.push({name: 'min_api_secret', checkType: 'required', errorMsg: '请输入支付密钥'});
}
let result = util.verify(newList,defaultRule);
return result === true;
})
})
// 重新设置支付秘钥
function removeHiddent(){
$("#api_secret").removeClass('hidden')
$("#api_secret").val('')
$("#api_secret_btn").addClass('hidden')
$("#api_secret_label").addClass('hidden')
}
// 重新设置app Secret
function removeHiddent1(){
$("#secret").removeClass('hidden')
$("#secret").val('')
$("#secret_btn").addClass('hidden')
$("#secret_label").addClass('hidden')
}
var vm = new Vue({
el: "#editAgentContent",
delimiters: ['[[', ']]'],
data() {
return {}
},
created () {},
methods: {},
});
</script>
@endsection

View File

@ -0,0 +1,295 @@
@extends('layouts.base')
@section('content')
@section('title', '添加区域代理')
<style>
select{width: 25%; height: 34px;}
#saleravatar img{width: 200px; height: 200px;}
</style>
<div class="w1200 ">
<div class="rightlist">
<div id="AddAgentContent">
{{--表单内容--}}
<form action="" method='post' class='form-horizontal' id="addAgent" enctype="multipart/form-data">
<div class='panel panel-default'>
<el-tabs>
<el-tab-pane label="基本信息">
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">代理名称</label>
<div class="col-sm-9 col-xs-12">
<input type="text" name="title" class="form-control"/>
</div>
</div>
<div class="form-group notice">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">微信角色</label>
<div class="col-xs-6">
<input type='hidden' id='uid' name='agent[member_id]' value=""/>
<div class='input-group'>
<input type="text" name="saler" maxlength="30"
value="" id="saler" class="form-control" readonly/>
<div class='input-group-btn'>
<button class="btn btn-default" type="button"
onclick="popwin = $('#modal-module-menus-notice').modal();">选择角色
</button>
<button class="btn btn-danger" type="button"
onclick="$('#uid').val('');$('#saler').val('');$('#saleravatar').hide()">
清除选择
</button>
</div>
</div>
<span id="saleravatar" class='help-block' style="display:none">
<img style="" src=""/></span>
<div id="modal-module-menus-notice" class="modal fade" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button aria-hidden="true" data-dismiss="modal" class="close" type="button">
×
</button>
<h3>选择角色</h3>
</div>
<div class="modal-body">
<div class="row">
<div class="input-group">
<input type="text" class="form-control" name="keyword" value=""
id="search-kwd-notice"
placeholder="请输入粉丝昵称/姓名/手机号"/>
<span class='input-group-btn'>
<button type="button" class="btn btn-default"
onclick="search_members();">搜索
</button>
</span>
</div>
</div>
<div id="module-menus-notice"></div>
</div>
<div class="modal-footer">
<a href="#" class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</a>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">独立分红比例</label>
<div class="col-sm-9 col-xs-12">
<label class="radio-inline">
<input type="radio" name="agent[has_ratio]" value="0" checked="checked" /> 关闭</label>
<label class="radio-inline">
<input type="radio" name="agent[has_ratio]" value="1"/> 开启</label>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">分红比例</label>
<div class="col-sm-6 col-xs-6">
<div class='input-group'>
<input type='text' name='agent[ratio]' class="form-control discounts_value" onkeyup="this.value= this.value.match(/\d+(\.\d{0,2})?/) ? this.value.match(/\d+(\.\d{0,2})?/)[0] : ''"
value=""/>
<div class='input-group-addon waytxt'>%</div>
</div>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">账号</label>
<div class="col-xs-6">
<input type="text" id="username" name="wq[username]" class="form-control" value="{{$wq_data['username']}}" placeholder="请输入账号" />
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">登录密码</label>
<div class="col-xs-6">
<input type="password" id="password" name="wq[password]" class="form-control" value="" placeholder="请输入密码" />
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">验证密码</label>
<div class="col-xs-6">
<input type="password" id="password_again" name="wq[password_again]" class="form-control" value="" placeholder="请输入密码" />
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">真实姓名</label>
<div class="col-xs-6">
<input type="text" name="agent[real_name]" class="form-control"
value=""/>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">联系方式</label>
<div class="col-xs-6">
<input type="text" name="agent[mobile]" class="form-control"
value=""/>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">代理区域</label>
<div class="col-xs-6">
{!! app\common\helpers\AddressHelper::tplLinkedAddress(['agent[province_id]','agent[city_id]','agent[district_id]','agent[street_id]'], [])!!}
</div>
</div>
{{--招商专员插件--}}
@if(app('plugins')->isEnabled('invest-people'))
{!! \Yunshop\InvestPeople\services\InvestMemberView::areaDividend() !!}
@endif
</el-tab-pane>
<el-tab-pane label="微信小程序">
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">小程序状态</label>
<div class="col-sm-9 col-xs-12">
<label class='radio-inline'>
<input type='radio' name='min_status' value='0' checked/>关闭
</label>
<label class='radio-inline'>
<input type='radio' name='min_status' value='1'/>使用中
</label>
</div>
</div>
<div class="min-config-content" style="display: none;">
{{-- <div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">App ID</label>
<div class="col-sm-9 col-xs-12">
<input type="text" name="min_app_id" class="form-control"/>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">App Secret</label>
<div class="col-sm-9 col-xs-12">
<input type="text" name="min_app_secret" class="form-control" id="secret"/>
</div>
</div>--}}
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">支付商户号</label>
<div class="col-sm-9 col-xs-12">
<input type="text" name="min_mch_id" class="form-control"/>
</div>
</div>
{{-- <div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">支付密钥</label>
<div class="col-sm-9 col-xs-12">
<input type="text" name="min_api_secret" id="api_secret" class="form-control"/>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">CERT证书文件</label>
<div class="col-sm-9 col-xs-12">
<input type="file" name="apiclient_cert" class="form-control"/>
<span class="help-block">
<span class='label label-danger'>未上传</span>
下载证书 cert.zip 中的 apiclient_cert.pem 文件
</span>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">KEY密钥文件</label>
<div class="col-sm-9 col-xs-12">
<input type="file" name="apiclient_key" class="form-control"/>
<span class="help-block">
<span class='label label-danger'>未上传</span>
下载证书 cert.zip 中的 apiclient_key.pem 文件
</span>
</div>
</div>--}}
</div>
</el-tab-pane>
</el-tabs>
{{--提交按钮--}}
<div class="form-group"></div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
<div class="col-sm-9 col-xs-12">
<input type="submit" name="submit" value="提交" class="btn btn-primary col-lg-1" />
<input type="button" name="back" onclick='history.back()' value="返回列表" class="btn btn-default" />
</div>
</div>
</div>
</form>
</div>
</div>
</div>
<script type="text/javascript" src="{{static_url('js/area/cascade_street.js')}}"></script>
<script>
cascdeInit();
function search_members() {
if ($('#search-kwd-notice').val() == '') {
Tip.focus('#search-kwd-notice', '请输入关键词');
return;
}
$("#module-menus-notice").html("正在搜索....");
$.get("{!! yzWebUrl('member.member.get-search-member') !!}", {
keyword: $.trim($('#search-kwd-notice').val())
}, function (dat) {
$('#module-menus-notice').html(dat);
});
}
function select_member(o) {
$("#uid").val(o.uid);
$("#saleravatar").show();
$("#saleravatar").find('img').attr('src', o.avatar);
$("#saler").val(o.nickname + "/" + o.realname + "/" + o.mobile);
$("#modal-module-menus-notice .close").click();
}
$(function () {
// 小程序状态改变
$("[name='min_status']").on('change',function () {
let val = parseInt($(this).val());
val = isNaN(val) ? parseInt(0) : parseInt(val);
if(val === 1) $(".min-config-content").show();
else $(".min-config-content").hide();
});
// 表单验证
$("#addAgent").submit(function(){
// 表单信息处理
let list = $("#addAgent").serializeArray();
let newList = {};
$.each(list,function (k,v) {
let name = v.name.replace(/data\[/g, "").replace(/]/g, "");
newList[name] = v.value;
});
console.log(newList);
// 内容校验列表
let defaultRule = [
{name: 'title', checkType: 'required', errorMsg: '请输入代理名称'},
{name: 'saler', checkType: 'required', errorMsg: '请选择微信角色'},
];
if(newList['min_status'] == 1){
// defaultRule.push({name: 'min_app_id', checkType: 'required', errorMsg: '请输入App ID'});
// defaultRule.push({name: 'min_app_secret', checkType: 'required', errorMsg: '请输入App Secret'});
defaultRule.push({name: 'min_mch_id', checkType: 'required', errorMsg: '请输入支付商户号'});
// defaultRule.push({name: 'min_api_secret', checkType: 'required', errorMsg: '请输入支付密钥'});
}
let result = util.verify(newList,defaultRule);
return result === true;
})
})
// 重新设置支付秘钥
function removeHiddent(){
$("#api_secret").removeClass('hidden')
$("#api_secret").val('')
$("#api_secret_btn").addClass('hidden')
$("#api_secret_label").addClass('hidden')
}
// 重新设置app Secret
function removeHiddent1(){
$("#secret").removeClass('hidden')
$("#secret").val('')
$("#secret_btn").addClass('hidden')
$("#secret_label").addClass('hidden')
}
var vm = new Vue({
el: "#AddAgentContent",
delimiters: ['[[', ']]'],
data() {
return {}
},
created () {},
methods: {},
});
</script>
@endsection

View File

@ -0,0 +1,155 @@
@extends('layouts.base')
@section('content')
@section('title', trans('区域分红详细信息'))
<link href="{{static_url('yunshop/css/member.css')}}" media="all" rel="stylesheet" type="text/css"/>
<div class="w1200 m0a">
<div class="rightlist">
<!-- 新增加右侧顶部三级菜单 -->
<div class="right-titpos">
<ul class="add-snav">
<li class="active"><a href="{{yzWebUrl('plugin.area-dividend.admin.dividend.get-list')}}">区域分红代理</a>
</li>
<li><a href="#">&nbsp;<i class="fa fa-angle-double-right"></i> &nbsp;区域分红详细信息</a></li>
</ul>
</div>
<!-- 新增加右侧顶部三级菜单结束 -->
<div class='form-horizontal'>
<div class='panel panel-default'>
<div class='panel-body'>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">ID</label>
<div class="col-sm-9 col-xs-12">
<div class='form-control-static'>
{{$info['id']}}
</div>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">区域代理</label>
<div class="col-sm-9 col-xs-12">
<img src='{{$info['has_one_member']['avatar']}}'
style='width:100px;height:100px;padding:1px;border:1px solid #ccc'/>
{{$info['has_one_member']['nickname']}}
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">会员ID</label>
<div class="col-sm-9 col-xs-12">
<div class='form-control-static'>
{{$info['has_one_member']['uid']}}
</div>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">区域等级</label>
<div class="col-sm-9 col-xs-12">
<div class='form-control-static'>
{{$info['level_name']}}
</div>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">代理区域</label>
<div class="col-sm-9 col-xs-12">
<div class='form-control-static'>
{{$info['agent_area']}}
</div>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">订单号</label>
<div class="col-sm-9 col-xs-12">
<div class='form-control-static'>
{{$info['order_sn']}}
</div>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">订单金额</label>
<div class="col-sm-9 col-xs-12">
<div class='form-control-static'>
{{$info['order_amount']}}
</div>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">分红结算金额</label>
<div class="col-sm-9 col-xs-12">
<div class='form-control-static'>
{{$info['amount']}}
</div>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">分红比例</label>
<div class="col-sm-9 col-xs-12">
<div class='form-control-static'>
{{$info['dividend_rate']}}
</div>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">同级分红人数</label>
<div class="col-sm-9 col-xs-12">
<div class='form-control-static'>
{{$info['same_level_number']}}
</div>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">下级分销比例</label>
<div class="col-sm-9 col-xs-12">
<div class='form-control-static'>
{{$info['lower_level_rate']}}
</div>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">分红金额</label>
<div class="col-sm-9 col-xs-12">
<div class='form-control-static'>
{{$info['dividend_amount']}}
</div>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">分红状态</label>
<div class="col-sm-9 col-xs-12">
<div class='form-control-static'>
<label class='label label-success'>{{$info['status_name']}}</label>
</div>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">分红时间</label>
<div class="col-sm-9 col-xs-12">
<div class='form-control-static'>
{{$info['created_at']}}
</div>
</div>
</div>
</div>
<div class='panel-body'>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
<div class="col-sm-9 col-xs-12">
<a href="{{yzWebUrl('order.list',['search'=>['ambiguous'=>['field'=>'order','string'=>$info['order_sn']]]])}}">
<input type="button" class="btn btn-default" value="查看订单" style='margin-left:10px;'/>
</a>
<input type="button" class="btn btn-default" name="submit" onclick="history.go(-1)"
value="返回列表" style='margin-left:10px;'/>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
@endsection

View File

@ -0,0 +1,211 @@
@extends('layouts.base')
@section('content')
@section('title', trans('区域分红列表'))
<div class="right-titpos">
<ul class="add-snav">
<li class="active"><a href="#">区域分红列表</a></li>
</ul>
</div>
<div class='panel panel-default'>
<form action="" method="post" class="form-horizontal" id="form1">
<div class="panel panel-info">
<div class="panel-body">
<div class="form-group col-xs-12 col-sm-2">
<!--<label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label">会员信息</label>-->
<!--<div class="col-xs-12 col-sm-8 col-lg-9">-->
<input class="form-control" name="search[member]" id="" type="text"
value="{{$search['member']}}" placeholder="会员ID/昵称/姓名/手机">
<!--</div>-->
</div>
<div class="form-group col-xs-12 col-sm-2">
<input class="form-control" name="search[area_name]" id="" type="text"
value="{{$search['area_name']}}" placeholder="区域名称">
</div>
<div class="form-group col-xs-12 col-sm-3">
<select name='search[area_level]' class='form-control'>
<option value=''>区域等级</option>
<option value='1' @if($search['area_level'] == '1') selected @endif></option>
<option value='2' @if($search['area_level'] == '2') selected @endif></option>
<option value='3' @if($search['area_level'] == '3') selected @endif>/</option>
<option value='4' @if($search['area_level'] == '4') selected @endif>街道/乡镇</option>
</select>
</div>
<div class="form-group col-xs-12 col-sm-2">
<input class="form-control" name="search[order_sn]" id="" type="text"
value="{{$search['order_sn']}}" placeholder="请输入订单编号">
</div>
<div class="form-group col-xs-12 col-sm-3">
<select name='search[status]' class='form-control'>
<option value=''>分红状态</option>
<option value='0' @if($search['status'] == '0') selected @endif>未结算</option>
<option value='1' @if($search['status'] == '1') selected @endif>已结算</option>
<option value='-1' @if($search['status'] == '-1') selected @endif>已失效</option>
</select>
</div>
<div class="form-group col-xs-12 col-sm-3">
<select name='search[statistics]' class='form-control'>
<option value='2' @if($search['statistics'] == '2') selected @endif>不统计</option>
<option value='1' @if($search['statistics'] == '1') selected @endif>统计</option>
</select>
</div>
<div class="form-group col-xs-12 col-sm-3">
<select name='search[is_pay]' class='form-control'>
<option value='0' @if($search['is_pay'] == '0') selected @endif>全部</option>
<option value='1' @if($search['is_pay'] == '1') selected @endif>已支付</option>
<option value='2' @if($search['is_pay'] == '2') selected @endif>未支付</option>
</select>
</div>
<div class="form-group col-xs-12 col-sm-8">
<div class="col-sm-3">
<label class='radio-inline'>
<input type='radio' value='0' name='search[is_time]'
@if($search['is_time'] == '0') checked @endif>不搜索
</label>
<label class='radio-inline'>
<input type='radio' value='1' name='search[is_time]'
@if($search['is_time'] == '1') checked @endif>搜索
</label>
</div>
{!! app\common\helpers\DateRange::tplFormFieldDateRange(
'search[time]',
[
'starttime'=>$search['time']['start'],
'endtime'=>$search['time']['end'],
'start'=>$search['time']['start'],
'end'=>$search['time']['end']
],
true
) !!}
</div>
<div class="form-group col-xs-12 col-sm-4">
<input type="button" class="btn btn-success" id="export" value="导出">
<input type="button" class="btn btn-success" id="search" value="搜索">
</div>
</div>
</div>
</form>
</div>
<div class='panel panel-default'>
<div class='panel-heading'>
<div @if ($search['statistics'] != 1) hidden="hidden" @endif>
分红统计 未结算分红:{{$statisti['unsettled']}} 已结算分红:{{$statisti['settled']}} 分红总金额:{{$statisti['total']}}
</div>
</div>
<div class='panel-body'>
<table class="table table-hover" style="overflow:visible;">
<thead>
<tr>
<th style='width:6%;'>ID</th>
<th style='width:15%;'>分红时间</th>
<th style='width:8%;'>区域代理</th>
<th style='width:10%;'>姓名<br>手机</th>
<th style='width:6%;'>区域等级</th>
<th style='width:15%;'>代理区域</th>
<th style='width:20%;'>订单号</th>
<th style='width:8%;'>订单金额</th>
<th style='width:10%;'>分红结算金额</th>
<th style='width:8%;'>分红比例</th>
<th style='width:10%;'>下级分红比例</th>
<th style='width:10%;'>分红金额</th>
<th style='width:10%;'>分红状态</th>
</tr>
</thead>
<tbody>
@foreach($list['data'] as $row)
<tr>
<td>{{$row['id']}}</td>
<td>{{$row['created_at']}}</td>
<td>
<a target="_blank"
href="{{yzWebUrl('member.member.detail',['id'=>$row['has_one_member']['uid']])}}">
<img src="{{tomedia($row['has_one_member']['avatar'])}}"
style="width: 30px; height: 30px;border:1px solid #ccc;padding:1px;">
</br>
{{$row['has_one_member']['nickname']}}
</a>
</td>
<td>
<a target="_blank"
href="{{yzWebUrl('member.member.detail',['id'=>$row['has_one_member']['uid']])}}">
{{$row['has_one_member']['realname']}}</br>
{{$row['has_one_member']['mobile']}}
</a>
</td>
<td>{{$row['level_name']}}</td>
<td>{{$row['agent_area']}}</td>
<td>
<a target="_blank"
href="{{yzWebUrl('order.detail.vue-index',['id' => $row['has_one_order']['id']])}}">
{{$row['order_sn']}}
</a>
</td>
<td>{{$row['order_amount']}}</td>
<td>{{$row['amount']}}</td>
<td>{{$row['dividend_rate']}}%</td>
<td>{{$row['lower_level_rate']}}%</td>
<td>
<a href="{{yzWebUrl('plugin.area-dividend.admin.dividend.get-detail',['id'=>$row['id']])}}">
{{$row['dividend_amount']}}
</a>
</td>
<td>{{$row['status_name']}}</td>
</tr>
@endforeach
</tbody>
</table>
{!! $pager !!}
</div>
</div>
<div style="width:100%;height:150px;"></div>
<script language='javascript'>
$(function () {
$('#export').click(function () {
$('#form1').attr('action', '{!! yzWebUrl('plugin.area-dividend.admin.dividend.export') !!}');
$('#form1').submit();
});
$('#search').click(function () {
$('#form1').attr('action', '{!! yzWebUrl('plugin.area-dividend.admin.dividend.get-list') !!}');
$('#form1').submit();
});
});
</script>
@endsection

View File

@ -0,0 +1,134 @@
<div class='panel panel-default'>
<div class='panel-heading'>
区域分红设置
</div>
<div class='panel-body'>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">开启区域分红</label>
<div class="col-sm-9 col-xs-12">
<label class="radio-inline">
<input type="radio" name="widgets[area_dividend][is_dividend]" value="0"
@if($item['is_dividend'] == '0') checked="checked" @endif /> 关闭</label>
<label class="radio-inline">
<input type="radio" name="widgets[area_dividend][is_dividend]" value="1"
@if($item['is_dividend'] == '1') checked="checked" @endif /> 开启</label>
<span class='help-block'>如果不开启区域分红,则不产生分红佣金</span>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">独立规则</label>
<div class="col-sm-9 col-xs-12">
<label class="radio-inline">
<input type="checkbox" id="hasarea" value="1" name="widgets[area_dividend][has_dividend]"
@if($item['has_dividend'] == '1') checked="checked" @endif /> 启用独立佣金比例
</label>
<span class='help-block'> 启用独立分红金额设置,此商品拥有独自的分红金额,不受默认设置限制</span>
</div>
</div>
<div id="area_div" @if($item['has_dividend'] != '1') style="display:none" @endif >
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">独立分红金额</label>
<div class="col-sm-6 col-xs-6">
<div class="input-group">
<input type="text" name="widgets[area_dividend][has_dividend_rate]"
class="form-control"
value="{{$item['has_dividend_rate']}}"/>
<div class="input-group-addon">% 固定</div>
<input type="text" name="widgets[area_dividend][has_dividend_price]"
class="form-control"
value="{{$item['has_dividend_price']}}"/>
<div class="input-group-addon"></div>
</div>
<span class="help-block">如果比例为空或等于0则使用固定规则如果都为空或等于0则使用默认规则</span>
</div>
</div>
</div>
<div class="form-group"></div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">独立设置</label>
<div class="col-sm-9 col-xs-12">
<label class="radio-inline">
<input type="checkbox" id="alone_rule" value="1" name="widgets[area_dividend][alone_rule]"
@if($item['alone_rule'] == '1') checked="checked" @endif /> 启用独立佣金比例
</label>
<span class='help-block'> 启用独立设置如果比例为空为0则无分红佣金开启了第一个独立规则独立设置就无法开启</span>
</div>
</div>
<div id="alone_rule_div" @if($item['alone_rule'] != '1') style="display:none" @endif>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
<div class="col-sm-6 col-xs-6">
<div class='input-group'>
<div class='input-group-addon'></div>
<input type='text' name='widgets[area_dividend][province_rate]' class="form-control discounts_value"
value="{{$item['province_rate']}}"/>
<div class='input-group-addon waytxt'>%</div>
</div>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
<div class="col-sm-6 col-xs-6">
<div class='input-group'>
<div class='input-group-addon'></div>
<input type='text' name='widgets[area_dividend][city_rate]' class="form-control discounts_value"
value="{{$item['city_rate']}}"/>
<div class='input-group-addon waytxt'>%</div>
</div>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
<div class="col-sm-6 col-xs-6">
<div class='input-group'>
<div class='input-group-addon'>/</div>
<input type='text' name='widgets[area_dividend][area_rate]' class="form-control discounts_value"
value="{{$item['area_rate']}}"/>
<div class='input-group-addon waytxt'>%</div>
</div>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
<div class="col-sm-6 col-xs-6">
<div class='input-group'>
<div class='input-group-addon'>街道/乡镇</div>
<input type='text' name='widgets[area_dividend][street_rate]' class="form-control discounts_value"
value="{{$item['street_rate']}}"/>
<div class='input-group-addon waytxt'>%</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script language="javascript">
$(function () {
$("#hasarea").click(function () {
var obj = $(this);
if (obj.get(0).checked) {
$("#area_div").show();
} else {
$("#area_div").hide();
}
});
})
$(function () {
$("#alone_rule").click(function () {
var obj = $(this);
if (obj.get(0).checked) {
$("#alone_rule_div").show();
} else {
$("#alone_rule_div").hide();
}
});
})
</script>

View File

@ -0,0 +1,308 @@
@extends('layouts.base')
@section('content')
@section('title', trans('区域代理列表'))
<style>
.user-info{
min-height: 80px;
min-width: 150px;
width: 100%;
display: inline-flex;
flex-direction: row;
flex-wrap: nowrap;
align-items: center;
justify-content: center;
}
.user-info .user-avatar{
height: 50px;
width: 50px;
margin-right: 10px;
}
.user-info .user-avatar .avatar{
width: 100% !important;
height: 100% !important;
border-radius: 50%;
}
.user-info .user-nickname{
font-size: 14px;
text-align: left;
height: 50px;
width: calc(100% - 50px - 10px);
line-height: 25px;
}
#info-list a{
color: #000000!important;
-webkit-tap-highlight-color: rgba(255, 255, 255, 0);
-webkit-user-select: none;
-moz-user-focus: none;
-moz-user-select: none;
border: none!important;
}
</style>
<div class="w1200 ">
<div class="rightlist">
<div class="right-titpos">
<ul class="add-snav">
{{--<li class="active"><a href="#">区域代理</a></li>--}}
<a class='btn btn-primary' href="{{yzWebUrl('plugin.area-dividend.admin.agent.create-agent')}}"
style="margin-bottom:5px;"><i class='fa fa-plus'></i> 增加区域代理</a>
</ul>
</div>
<form action="" method="post" class="form-horizontal" id="form1">
<div class="right-addbox">
<div class="panel panel-info">
<div class="panel-body" style="padding: 15px;">
<div> 区域代理概况 ( 区域代理总人数: {{$total}} )</div>
</div>
</div>
<div class="panel panel-info">
<div class="panel-body">
<div class="form-group col-xs-12 col-sm-3">
<!--<label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label">会员信息</label>-->
<!--<div class="">-->
<input class="form-control" name="search[member]" id="" type="text"
value="{{$search['member']}}" placeholder="会员ID/昵称/姓名/手机">
<!--</div>-->
</div>
<div class="form-group col-xs-12 col-sm-3">
<!--<label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label">区域名称</label>-->
<!--<div class="col-xs-12 col-sm-8 col-lg-9">-->
<input class="form-control" name="search[area_name]" id="" type="text"
value="{{$search['area_name']}}" placeholder="区域名称">
<!--</div>-->
</div>
<div class="form-group col-xs-12 col-sm-4">
<!--<label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label">区域等级</label>-->
<!--<div class="col-sm-8 col-lg-9 col-xs-12">-->
<select name='search[agent_level]' class='form-control'>
<option value=''>区域等级</option>
<option value='1' @if($search['agent_level'] == '1') selected @endif></option>
<option value='2' @if($search['agent_level'] == '2') selected @endif></option>
<option value='3' @if($search['agent_level'] == '3') selected @endif>/</option>
<option value='4' @if($search['agent_level'] == '4') selected @endif>街道/乡镇</option>
</select>
<!--</div>-->
</div>
<div class="form-group col-xs-12 col-sm-8">
<!--<label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label">成为代理商时间</label>-->
<!--<div class="col-sm-7 col-lg-9 col-xs-12">-->
<div class="col-sm-3">
<label class='radio-inline'>
<input type='radio' value='0' name='search[is_time]'
@if($search['is_time'] == '0') checked @endif>不搜索
</label>
<label class='radio-inline'>
<input type='radio' value='1' name='search[is_time]'
@if($search['is_time'] == '1') checked @endif>搜索
</label>
</div>
{!! app\common\helpers\DateRange::tplFormFieldDateRange('search[time]', [
'starttime'=>$search['time']['start'],
'endtime'=>$search['time']['end'],
'start'=>$search['time']['start'],
'end'=>$search['time']['end']
], true) !!}
<!--</div>-->
</div>
<div class="form-group col-xs-12 col-sm-4">
<!--<label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label"> </label>-->
<!--<div class="col-xs-12 col-sm-2 col-lg-2">-->
<!--<input type="button" class="btn btn-success pull-right" id="export" value="导出">
<input type="button" class="btn btn-success pull-right" id="search" value="搜索">-->
<button type="button" name="export" value="1" id="export"
class="btn btn-default excel back ">导出 Excel
</button>
<input type="hidden" name="token" value="{{$var['token']}}" id="search"/>
<button class="btn btn-success "><i class="fa fa-search"></i> 搜索</button>
<!--</div>-->
</div>
</div>
</div>
</div>
</form>
<div class="clearfix">
<div class='panel panel-default' id="info-list">
<div class='panel-body table-responsive'>
<table class="table table-hover" style="overflow:visible;">
<thead>
<tr>
<th style='text-align:center;width:50px;'>ID</th>
<th style='text-align:center;width:120px;'>代理名称</th>
<th style='text-align:center;width:180px;'>会员信息</th>
<th style='text-align:center;width:150px;'>成为代理时间</th>
<th style='text-align:center;width:200px;'>申请区域</th>
<th style='text-align:center'>申请等级</th>
<th style='text-align:center'>消费总额</th>
<th style='text-align:center'>分红比例</th>
<th style='text-align:center'>累计结算金额</th>
<th style='text-align:center'>已结算分红佣金</th>
<th style='text-align:center'>未结算分红佣金</th>
<th style='text-align:center'>操作</th>
</tr>
</thead>
<tbody>
@foreach($list['data'] as $row)
<tr>
<td style='text-align:center'>{{$row['id']}}</td>
<td style='text-align:center'>{{$row['title']}}</td>
<td style="text-align:center">
<a target="_blank" href="{{yzWebUrl('member.member.detail',['id'=>$row['has_one_member']['uid']])}}">
<div class="user-info" title="{{ $row['has_one_member']['nickname'] }}">
<div class="user-avatar">
<img class="avatar" src="{{ $row['has_one_member']['avatar_image'] }}" />
</div>
<div class="user-nickname">
{{ $row['has_one_member']['nickname'] }} <br />
ID{{ $row['has_one_member']['uid'] }}
</div>
</div>
</a>
</td>
<td style="text-align:center">{{date("Y-m-d H:i",$row['agent_at'])}}</td>
<td style="text-align:center" class='tdedit'>
<span class='fa-edit-item' style='cursor:pointer' data-agentid="{{$row['id']}}">
<span class="title">
@if($row['province_name']){{$row['province_name']}}@endif
@if($row['city_name']){{$row['city_name']}}@endif
@if($row['district_name']){{$row['district_name']}}@endif
@if($row['street_name']){{$row['street_name']}}@endif
</span>
<i class='fa fa-pencil' style="display:none"></i>
</span>
</td>
<td style='text-align:center'>{{$row['level_name']}}</td>
<td style='text-align:center'>{{$row['has_one_dividend']['total_order_amount'] ?: '0.00'}}</td>
<td style='text-align:center'>{{$row['ratio']}}%</td>
<td style='text-align:center'>{{$row['has_one_dividend']['total_amount'] ?: '0.00'}}</td>
<td style='text-align:center'>{{$row['has_one_dividend']['settle'] ?: '0.00'}}</td>
<td style='text-align:center'>{{$row['has_one_dividend']['unsettled'] ?: '0.00'}}</td>
<td style="position:relative; overflow:visible;">
<a href="{{yzWebUrl('plugin.area-dividend.admin.agent.daletedAgency',['id'=>$row['id']])}}"
onclick="return confirm('是否确认删除?');
return false;" class="btn btn-default btn-sm"
title="删除"><i
class="fa fa-trash"></i></a>
<a href="{{yzWebUrl('plugin.area-dividend.admin.agent.editAgency',['id'=>$row['id']])}}"
class="btn btn-default btn-sm" title="编辑账号"><i class="fa fa-edit"></i></a>
</td>
</tr>
@endforeach
</tbody>
</table>
{!! $pager !!}
</div>
</div>
</div>
<div style="width:100%;height:150px;"></div>
<div id="modal-module-menus-notice" class="modal fade" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button aria-hidden="true" data-dismiss="modal" class="close" type="button">
×
</button>
<h3>变更区域</h3>
</div>
<div class="modal-body">
<div class="row">
<div class="input-group">
原代理区域:
<span class="area-text"></span>
</div>
<div class="input-group">
变更区域:
{!! app\common\helpers\AddressHelper::tplLinkedAddress(['province_id','city_id','district_id','street_id'], [])!!}
</div>
</div>
<div id="module-menus-notice"></div>
</div>
<div class="modal-footer">
<input type="hidden" value="" name="areaAgentId" class="area-agent-id">
<a href="javascript:;" class="btn btn-default" id="submit">提交</a>
<a href="#" class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</a>
</div>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript" src="{{static_url('js/area/cascade_street.js')}}"></script>
<script language='javascript'>
$('.tdedit').mouseover(function () {
$(this).find('.fa-pencil').show();
}).mouseout(function () {
$(this).find('.fa-pencil').hide();
});
$('.fa-edit-item').click(function () {
var areaData = $(this).closest('span').find('span').html();
var agentid = $(this).data('agentid');
popwin = $('#modal-module-menus-notice').modal();
$('.area-text').text(areaData);
$('.area-agent-id').val(agentid);
cascdeInit();
});
$('#submit').click(function () {
var agentid = $('.area-agent-id').val();
var provanceId = $('#sel-provance').val();
var cityId = $('#sel-city').val();
var districtId = $('#sel-area').val();
var streetId = $('#sel-street').val();
var obg = {
province_id: provanceId,
city_id: cityId,
district_id: districtId,
street_id: streetId
};
fastChange(agentid, obg);
});
function fastChange(id, value) {
$.ajax({
url: "{!! yzWebUrl('plugin.area-dividend.admin.agent.change') !!}",
type: "post",
data: {id: id, value: value},
cache: false,
success: function ($data) {
//console.log($data);return;
if ($data.result == 0) {
confirm($data.msg);
}
location.reload();
}
})
}
$(function () {
$('#export').click(function () {
$('#form1').attr('action', '{!! yzWebUrl('plugin.area-dividend.admin.agent.export') !!}');
$('#form1').submit();
});
$('#search').click(function () {
$('#form1').attr('action', '{!! yzWebUrl('plugin.area-dividend.admin.agent') !!}');
$('#form1').submit();
});
});
</script>
@endsection

View File

@ -0,0 +1,59 @@
@extends('layouts.base')
@section('content')
@section('title', trans('区域分红设置'))
<script type="text/javascript">
window.optionchanged = false;
require(['bootstrap'], function () {
$('#myTab a').click(function (e) {
e.preventDefault();
$(this).tab('show');
})
});
</script>
<div class="w1200 m0a">
<div class="rightlist">
<!-- 新增加右侧顶部三级菜单 -->
<div class="right-titpos">
<ul class="add-snav">
<li class="active"><a href="#">区域分红设置</a></li>
</ul>
</div>
@include('Yunshop\AreaDividend::admin.tabs')
<section>
<form id="setform" action="" method="post" class="form-horizontal form">
<div class="panel panel-default">
<div class="panel-body">
<div class="tab-content">
<div class="tab-pane active"
id="tab_area_dividend">@include('Yunshop\AreaDividend::admin.tpl.area_dividend')</div>
<div class="tab-pane" id="tab_settle">@include('Yunshop\AreaDividend::admin.tpl.settle')</div>
<div class="tab-pane" id="tab_notice">@include('Yunshop\AreaDividend::admin.tpl.notice')</div>
<div class="tab-pane" id="tab_agreement">@include('Yunshop\AreaDividend::admin.tpl.agreement')</div>
<div class="tab-pane" id="tab_rangecommission">@include('Yunshop\AreaDividend::admin.tpl.range_commission')</div>
<div class="tab-pane" id="tab_apply_background">@include('Yunshop\AreaDividend::admin.tpl.apply_background')</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
<div class="col-xs-12 col-sm-9 col-md-10">
<input type="submit" name="submit" value="提交" class="btn btn-success"
onclick="return formcheck()"/>
</div>
</div>
</div>
</div>
</form>
</section>
</div>
</div>
<script language='javascript'>
$('.diy-notice').select2();
</script>
@endsection

View File

@ -0,0 +1,16 @@
{{--<div class="right-titpos">--}}
{{--<ul class="add-snav">--}}
{{--<li class="active"><a href="#">区域分红设置</a></li>--}}
{{--</ul>--}}
{{--</div>--}}
<div class="panel panel-info">
<ul class="add-shopnav" id="myTab">
<li class="active" ><a href="#tab_area_dividend">区域分红设置</a></li>
<li><a href="#tab_settle">结算设置</a></li>
<li><a href="#tab_notice">消息</a></li>
<li><a href="#tab_agreement">申请协议</a></li>
<li><a href="#tab_rangecommission">分销极差</a></li>
<li><a href="#tab_apply_background">申请页面背景图</a></li>
</ul>
</div>

View File

@ -0,0 +1,17 @@
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">是否开启:</label>
<div class="col-sm-9 col-xs-12">
<label class="radio-inline">
<input type="radio" name="setdata[is_open]" value="1"
@if($set['is_open'] == 1) checked="checked" @endif /> 开启</label>
<label class="radio-inline">
<input type="radio" name="setdata[is_open]" value="0"
@if($set['is_open'] == 0) checked="checked" @endif /> 禁用</label>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">申请协议</label>
<div class="col-sm-9 col-xs-12">
{!! tpl_ueditor('setdata[agreement]', $agreement) !!}
</div>
</div>

View File

@ -0,0 +1,7 @@
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">申请页面背景图:</label>
<div class="col-sm-9 col-xs-12">
{!! app\common\helpers\ImageHelper::tplFormFieldImage('setdata[apply_background]',$set['apply_background']) !!}
<p style="font-size:12px;">建议尺寸750*306</p>
</div>
</div>

View File

@ -0,0 +1,66 @@
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">区域分红</label>
<div class="col-sm-9 col-xs-12">
<label class="radio-inline">
<input type="radio" name="setdata[is_area_dividend]" value="0"
@if($set['is_area_dividend'] == 0) checked="checked" @endif /> 关闭</label>
<label class="radio-inline">
<input type="radio" name="setdata[is_area_dividend]" value="1"
@if($set['is_area_dividend'] == 1) checked="checked" @endif /> 开启</label>
</div>
</div>
{{--<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">成为区域代理</label>
<div class="col-sm-9 col-xs-12">
<label class="radio-inline">
<input type="radio" name="setdata[become_agent]" value="0"
@if($set['become_agent'] == 0) checked="checked" @endif /> 无条件</label>
<label class="radio-inline">
<input type="radio" name="setdata[become_agent]" value="1"
@if($set['become_agent'] == 1) checked="checked" @endif /> 申请</label>
</div>
</div>--}}
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">是否需要审核</label>
<div class="col-sm-9 col-xs-12">
<label class="radio-inline">
<input type="radio" name="setdata[become_check]" value="0"
@if($set['become_check'] == 0) checked="checked" @endif /> 不需要</label>
<label class="radio-inline">
<input type="radio" name="setdata[become_check]" value="1"
@if($set['become_check'] == 1) checked="checked" @endif /> 需要</label>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">申请驳回后可再次申请</label>
<div class="col-sm-9 col-xs-12">
<label class="radio-inline">
<input type="radio" name="setdata[apply_again]" value="0"
@if($set['apply_again'] == 0) checked="checked" @endif /> </label>
<label class="radio-inline">
<input type="radio" name="setdata[apply_again]" value="1"
@if($set['apply_again'] == 1) checked="checked" @endif /> </label>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">一个人代理多个区域</label>
<div class="col-sm-9 col-xs-12">
<label class="radio-inline">
<input type="radio" name="setdata[agent_many]" value="0"
@if($set['agent_many'] == 0) checked="checked" @endif />关闭</label>
<label class="radio-inline">
<input type="radio" name="setdata[agent_many]" value="1"
@if($set['agent_many'] == 1) checked="checked" @endif />开启</label>
<span style="" class='help-block'>
开启后一个人可以有多个区域代理,若存在一人代理多个区域则不允许关闭
</span>
</div>
</div>

View File

@ -0,0 +1,96 @@
<div class='panel-body'>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">成为区域代理通知</label>
<div class="col-sm-8 col-xs-12">
<select name='setdata[area_agent]' class='form-control diy-notice'>
<option @if(\app\common\models\notice\MessageTemp::getIsDefaultById($set['area_agent'])) value="{{$set['area_agent']}}"
selected @else value="" @endif>
默认消息模板
</option>
@foreach ($temp_list as $item)
<option value="{{$item['id']}}"
@if($set['area_agent'] == $item['id'])
selected
@endif>{{$item['title']}}</option>
@endforeach
</select>
</div>
<div class="col-sm-2 col-xs-6">
<input class="mui-switch mui-switch-animbg" id="area_agent" type="checkbox"
@if(\app\common\models\notice\MessageTemp::getIsDefaultById($set['area_agent']))
checked
@endif
onclick="message_default(this.id)"/>
</div>
</div>
</div>
<div class='panel-body'>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">分红结算通知</label>
<div class="col-sm-8 col-xs-12">
<select name='setdata[area_dividend]' class='form-control diy-notice'>
<option @if(\app\common\models\notice\MessageTemp::getIsDefaultById($set['area_dividend'])) value="{{$set['area_dividend']}}"
selected @else value="" @endif>
默认消息模板
</option>
@foreach ($temp_list as $item)
<option value="{{$item['id']}}"
@if($set['area_dividend'] == $item['id'])
selected
@endif>{{$item['title']}}</option>
@endforeach
</select>
</div>
<div class="col-sm-2 col-xs-6">
<input class="mui-switch mui-switch-animbg" id="area_dividend" type="checkbox"
@if(\app\common\models\notice\MessageTemp::getIsDefaultById($set['area_dividend']))
checked
@endif
onclick="message_default(this.id)"/>
</div>
</div>
</div>
<script>
function message_default(name) {
var id = "#" + name;
var setting_name = "plugin.area_dividend";
var select_name = "select[name='setdata[" + name + "]']"
var url_open = "{!! yzWebUrl('setting.default-notice.index') !!}"
var url_close = "{!! yzWebUrl('setting.default-notice.cancel') !!}"
var postdata = {
notice_name: name,
setting_name: setting_name
};
if ($(id).is(':checked')) {
//开
$.post(url_open,postdata,function(data){
if (data.result == 1) {
$(select_name).find("option:selected").val(data.id)
showPopover($(id),"开启成功")
} else {
showPopover($(id),"开启失败,请检查微信模版")
$(id).attr("checked",false);
}
}, "json");
} else {
//关
$.post(url_close,postdata,function(data){
$(select_name).val('');
showPopover($(id),"关闭成功")
}, "json");
}
}
function showPopover(target, msg) {
target.attr("data-original-title", msg);
$('[data-toggle="tooltip"]').tooltip();
target.tooltip('show');
target.focus();
//2秒后消失提示框
setTimeout(function () {
target.attr("data-original-title", "");
target.tooltip('hide');
}, 2000
);
}
</script>

View File

@ -0,0 +1,16 @@
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">分销极差</label>
<div class="col-sm-9 col-xs-12">
<label class="radio-inline">
<input type="radio" name="setdata[is_range_commission]" value="0"
@if($set['is_range_commission'] == 0) checked="checked" @endif /> 关闭</label>
<label class="radio-inline">
<input type="radio" name="setdata[is_range_commission]" value="1"
@if($set['is_range_commission'] == 1) checked="checked" @endif /> 开启</label>
</div>
</div>

View File

@ -0,0 +1,223 @@
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">结算方式</label>
<div class="col-sm-9 col-xs-12">
<label class="radio-inline">
<input type="radio" name="setdata[culate_method]" value="0"
@if($set['culate_method'] == 0) checked="checked" @endif /> 订单价格:(不包括运费及抵扣金额)</label>
<label class="radio-inline">
<input type="radio" name="setdata[culate_method]" value="1"
@if($set['culate_method'] == 1) checked="checked" @endif /> 利润:(订单最终价格-成本负数取0)</label>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">是否开启平均分红</label>
<div class="col-sm-9 col-xs-12">
<label class="radio-inline">
<input type="radio" name="setdata[is_average]" value="0"
@if($set['is_average'] == 0) checked="checked" @endif /> </label>
<label class="radio-inline">
<input type="radio" name="setdata[is_average]" value="1"
@if($set['is_average'] == 1) checked="checked" @endif /> </label>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">是否开启极差分红</label>
<div class="col-sm-9 col-xs-12">
<label class="radio-inline">
<input type="radio" name="setdata[is_distinction]" value="0"
@if($set['is_distinction'] == 0) checked="checked" @endif /> </label>
<label class="radio-inline">
<input type="radio" name="setdata[is_distinction]" value="1"
@if($set['is_distinction'] == 1) checked="checked" @endif /> </label>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">默认分红比例</label>
<div class="col-sm-6 col-xs-6">
<div class='input-group'>
<div class='input-group-addon'></div>
<input type='text' name='setdata[province_rate]' class="form-control discounts_value"
value="{{$set['province_rate']}}"/>
<div class='input-group-addon waytxt'>%</div>
</div>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
<div class="col-sm-6 col-xs-6">
<div class='input-group'>
<div class='input-group-addon'></div>
<input type='text' name='setdata[city_rate]' class="form-control discounts_value"
value="{{$set['city_rate']}}"/>
<div class='input-group-addon waytxt'>%</div>
</div>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
<div class="col-sm-6 col-xs-6">
<div class='input-group'>
<div class='input-group-addon'>/</div>
<input type='text' name='setdata[area_rate]' class="form-control discounts_value"
value="{{$set['area_rate']}}"/>
<div class='input-group-addon waytxt'>%</div>
</div>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
<div class="col-sm-6 col-xs-6">
<div class='input-group'>
<div class='input-group-addon'>街道/乡镇</div>
<input type='text' name='setdata[street_rate]' class="form-control discounts_value"
value="{{$set['street_rate']}}"/>
<div class='input-group-addon waytxt'>%</div>
</div>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">订单计算方式</label>
<div class="col-sm-6 col-xs-6">
<div class='input-group'>
<label class="radio-inline">
<input type="radio" name="setdata[calculate_type]" value="0" @if(!$set['calculate_type']) checked @endif />
实付金额
</label>
<label class="radio-inline">
<input type="radio" name="setdata[calculate_type]" value="1" @if($set['calculate_type'] == '1') checked @endif />
利润
</label>
</div>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">赠送积分计算方式</label>
<div class="col-sm-6 col-xs-6">
<div class='input-group'>
<label class="radio-inline">
<input type="radio" name="setdata[award_point_type]" value="0" @if(!$set['award_point_type']) checked @endif /> 赠送比例
</label>
<label class="radio-inline">
<input type="radio" name="setdata[award_point_type]" value="1" @if($set['award_point_type'] == '1') checked @endif />
固定积分
</label>
</div>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
<div class="col-sm-6 col-xs-6">
<div class='input-group col-md-6'>
<div class='input-group-addon'></div>
<input type='text' name='setdata[province_point]'
class="form-control discounts_value"
value="{{ $set['province_point'] }}"/>
<div class='input-group-addon staff_waytxt'>
%/
</div>
</div>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
<div class="col-sm-6 col-xs-6">
<div class='input-group col-md-6'>
<div class='input-group-addon'></div>
<input type='text' name='setdata[city_point]'
class="form-control discounts_value"
value="{{ $set['city_point'] }}"/>
<div class='input-group-addon staff_waytxt'>
%/
</div>
</div>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
<div class="col-sm-6 col-xs-6">
<div class='input-group col-md-6'>
<div class='input-group-addon'>/</div>
<input type='text' name='setdata[area_point]'
class="form-control discounts_value"
value="{{ $set['area_point'] }}"/>
<div class='input-group-addon staff_waytxt'>
%/
</div>
</div>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
<div class="col-sm-6 col-xs-6">
<div class='input-group col-md-6'>
<div class='input-group-addon'>街道/乡镇</div>
<input type='text' name='setdata[street_point]'
class="form-control discounts_value"
value="{{ $set['street_point'] }}"/>
<div class='input-group-addon staff_waytxt'>
%/
</div>
</div>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">结算类型</label>
<div class="col-sm-9 col-xs-12">
<label class="radio-inline">
<input type="radio" name="setdata[settlement_model]" value="0"
@if($set['settlement_model'] == 0) checked="checked" @endif />自动结算</label>
<label class="radio-inline" style="margin-left: 35px">
<input type="radio" name="setdata[settlement_model]" value="1"
@if($set['settlement_model'] == 1) checked="checked" @endif /> 手动结算</label>
<span style="" class='help-block'>
自动结算:订单完成后,根据结算期时间来加入到提现<br />
手动结算:订单完成后,需要进入推广中心手动领取才可以提现
</span>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">结算期</label>
<div class="col-sm-6 col-xs-6">
<div class='input-group'>
<input type='text' name='setdata[settle_days]' class="form-control discounts_value"
value="{{$set['settle_days']}}"/>
<div class='input-group-addon waytxt'></div>
</div>
</div>
</div>
<script language='javascript'>
$('input[name="setdata[award_merchant][staff][type]"]').click(function () {
var type = $('input:radio[name="setdata[award_merchant][staff][type]"]:checked').val();
if (type == 1) {
$('.staff_waytxt').html('%');
} else {
$('.staff_waytxt').html('个');
}
});
$('input[name="setdata[award_merchant][center][type]"]').click(function () {
var type = $('input:radio[name="setdata[award_merchant][center][type]"]:checked').val();
if (type == 1) {
$('.center_waytxt').html('%');
} else {
$('.center_waytxt').html('个');
}
});
</script>

View File

@ -0,0 +1,17 @@
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">额外奖励</label>
<div class="col-sm-9 col-xs-12">
<label class="radio-inline">
<input type="radio" name="setdata[is_supplier_award]" value="0"
@if($set['is_supplier_award'] == 0) checked="checked" @endif /> 关闭</label>
<label class="radio-inline">
<input type="radio" name="setdata[is_supplier_award]" value="1"
@if($set['is_supplier_award'] == 1) checked="checked" @endif /> 开启</label>
<span class='help-block'>开启分销极差时,不执行供应商额外奖励</span>
</div>
</div>

View File

@ -0,0 +1,61 @@
<div class='panel panel-default'>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">提现额度</label>
<div class="col-sm-9 col-xs-12">
<input type="text" name="withdraw[areaDividend][roll_out_limit]" class="form-control"
value="{{$set['roll_out_limit']}}"/>
<span class="help-block">当前代理的佣金达到此额度时才能提现</span>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">提现手续费</label>
<div class="col-sm-9 col-xs-12">
<div class="switch">
<label class='radio-inline'>
<input type='radio' name='withdraw[areaDividend][poundage_type]' value='1'
@if($set['poundage_type'] == 1) checked @endif />
固定金额
</label>
<label class='radio-inline'>
<input type='radio' name='withdraw[areaDividend][poundage_type]' value='0'
@if(empty($set['poundage_type'])) checked @endif />
手续费比例
</label>
</div>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
<div class="col-sm-9 col-xs-12">
<div class="cost">
<label class='radio-inline'>
<div class="input-group">
<div class="input-group-addon" id="areaDividend_poundage_hint"
style="width: 120px;">@if($set['poundage_type'] == 1) 固定金额 @else
手续费比例 @endif</div>
<input type="text" name="withdraw[areaDividend][poundage_rate]"
class="form-control" value="{{ $set['poundage_rate'] ?? '' }}"
placeholder="请输入提现手续费计算值"/>
<div class="input-group-addon" id="areaDividend_poundage_unit">@if($set['poundage_type'] == 1) @else
% @endif</div>
</div>
</label>
</div>
</div>
</div>
</div>
<script language="javascript">
$(function () {
$(":radio[name='withdraw[areaDividend][poundage_type]']").click(function () {
if ($(this).val() == 1) {
$("#areaDividend_poundage_unit").html('元');
$("#areaDividend_poundage_hint").html('固定金额');
}
else {
$("#areaDividend_poundage_unit").html('%');
$("#areaDividend_poundage_hint").html('手续费比例')
}
});
})
</script>

View File

@ -0,0 +1,152 @@
@extends('layouts.base')
@section('content')
@section('title', trans('区域商家'))
<div class="right-titpos">
<ul class="add-snav">
<li class="active"><a href="#">区域商家</a></li>
</ul>
</div>
<div class='panel panel-default'>
<form action="" method="post" class="form-horizontal" id="form1">
<div class="panel panel-info">
<div class="panel-body">
<div class="form-group col-xs-12 col-sm-2 col-md-2 col-lg-2">
{{--<label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label">微店名称</label>--}}
<div class="">
<input type="text" class="form-control" name="search[store_name]" value="{{$search['store_name']?$search['store_name']:''}}" placeholder="门店名称"/>
</div>
</div>
<div class="form-group col-xs-6 col-sm-2">
<select name='search[statistics]' class='form-control'>
<option value='2' @if($search['statistics'] == '2') selected @endif>不统计</option>
<option value='1' @if($search['statistics'] == '1') selected @endif>统计</option>
</select>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">区域</label>
<div class="col-xs-6">
<input type="hidden" id="province_id" value="{{ $search['province_id']?:0 }}"/>
<input type="hidden" id="city_id" value="{{ $search['city_id']?:0 }}"/>
<input type="hidden" id="district_id" value="{{ $search['district_id']?:0 }}"/>
<input type="hidden" id="street_id" value="{{ $search['street_id']?:0 }}"/>
{!! app\common\helpers\AddressHelper::tplLinkedAddress(['search[province_id]','search[city_id]','search[district_id]','search[street_id]'], [])!!}
</div>
</div>
<div class="form-group col-xs-12 col-sm-8">
<div class="col-sm-3">
<label class='radio-inline'>
<input type='radio' value='0' name='search[is_time]'
@if(empty($search['is_time']) || $search['is_time'] == '0') checked @endif>不搜索
</label>
<label class='radio-inline'>
<input type='radio' value='1' name='search[is_time]'
@if($search['is_time'] == '1') checked @endif>搜索
</label>
</div>
{!! app\common\helpers\DateRange::tplFormFieldDateRange(
'search[time]',
[
'starttime'=>$search['time']['start'],
'endtime'=>$search['time']['end'],
'start'=>$search['time']['start'],
'end'=>$search['time']['end']
],
true
) !!}
</div>
<div class="form-group col-xs-12 col-sm-4">
<input type="button" class="btn btn-success" id="export" value="导出">
<input type="button" class="btn btn-success" id="search" value="搜索">
</div>
</div>
</div>
</form>
</div>
<div class='panel panel-default'>
<div class='panel-heading'>
<div @if ($search['statistics'] != 1) hidden="hidden" @endif>
数量:{{$tou['total']}} &nbsp&nbsp 累计收款金额: 门店:{{$tou['store_amount']}} / 收银台:{{$tou['cashier_amount']}}
</div>
</div>
<div class='panel-body'>
<table class="table table-hover" style="overflow:visible;">
<thead>
<tr>
<th style='width:6%;'>商家ID</th>
<th style='width:10%;'>入驻时间</th>
<th style='width:13%;'>所在区域</th>
<th style='width:6%;text-align: center;'>店长信息</th>
<th style='width:6%;text-align: center;'>店铺名称</th>
<th style='width:8%;text-align: center;'>门店分类</th>
<th style='width:10%;'>累计收款金额()</th>
</tr>
</thead>
<tbody>
@foreach($list as $row)
<tr>
<td>{{$row['id']}}</td>
<td>{{$row['created_at']}}</td>
<td>
{{$row['full_address']}}
</td>
<td style="text-align: center;">
<img src='{{$row->hasOneMember->avatar}}' style='width:30px;height:30px;padding:1px;border:1px solid #ccc' />
<br/>
<a href="">@if ($row->hasOneMember->nickname) {{$row->hasOneMember->nickname}} @else {{$row->hasOneMember->mobile}} @endif</a>
</td>
<td style="text-align: center;">
<img src='{{tomedia($row->thumb)}}' style='width:30px;height:30px;padding:1px;border:1px solid #ccc' />
<br/>
{{$row->store_name}}
</td>
<td style="text-align: center;">{{$row->hasOneCategory->name}}</td>
<td>
门店:{{$row->hasManyStoreOrder->sum('amount')}}
<br />
收银台:{{$row->hasManyCashierOrder->sum('amount')}}
</td>
</tr>
@endforeach
</tbody>
</table>
{!! $pager !!}
</div>
</div>
<div style="width:100%;height:150px;"></div>
<script type="text/javascript" src="{{static_url('js/area/cascade_street.js')}}"></script>
<script language='javascript'>
var province_id = $('#province_id').val();
var city_id = $('#city_id').val();
var district_id = $('#district_id').val();
var street_id = $('#street_id').val();
cascdeInit(province_id, city_id, district_id, street_id);
$(function () {
$('#export').click(function () {
$('#form1').attr('action', '{!! yzWebUrl('plugin.area-dividend.area.area-shop.export') !!}');
$('#form1').submit();
});
$('#search').click(function () {
$('#form1').attr('action', '{!! yzWebUrl('plugin.area-dividend.area.area-shop.index') !!}');
$('#form1').submit();
});
});
</script>
@endsection

View File

@ -0,0 +1,130 @@
@extends('layouts.base')
@section('content')
@section('title', trans('区域分红'))
<div class="right-titpos">
<ul class="add-snav">
<li class="active"><a href="#">区域分红</a></li>
</ul>
</div>
<div class='panel panel-default'>
<form action="" method="post" class="form-horizontal" id="form1">
<div class="panel panel-info">
<div class="panel-body">
<div class="form-group col-xs-12 col-sm-2">
<!--<label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label">会员信息</label>-->
<!--<div class="col-xs-12 col-sm-8 col-lg-9">-->
<input class="form-control" name="search[order_sn]" id="" type="text"
value="{{$search['order_sn']}}" placeholder="请输入订单号">
<!--</div>-->
</div>
<div class="form-group col-xs-9 col-sm-2">
<select name='search[statistics]' class='form-control'>
<option value='2' @if($search['statistics'] == '2') selected @endif>不统计</option>
<option value='1' @if($search['statistics'] == '1') selected @endif>统计</option>
</select>
</div>
<div class="form-group col-xs-12 col-sm-8">
<div class="col-sm-3">
<label class='radio-inline'>
<input type='radio' value='0' name='search[is_time]'
@if(empty($search['is_time']) || $search['is_time'] == '0') checked @endif>不搜索
</label>
<label class='radio-inline'>
<input type='radio' value='1' name='search[is_time]'
@if($search['is_time'] == '1') checked @endif>搜索
</label>
</div>
{!! app\common\helpers\DateRange::tplFormFieldDateRange(
'search[time]',
[
'starttime'=>$search['time']['start'],
'endtime'=>$search['time']['end'],
'start'=>$search['time']['start'],
'end'=>$search['time']['end']
],
true
) !!}
</div>
<div class="form-group col-xs-12 col-sm-4">
<input type="button" class="btn btn-success" id="export" value="导出">
<input type="button" class="btn btn-success" id="search" value="搜索">
</div>
</div>
</div>
</form>
</div>
<div class='panel panel-default'>
<div class='panel-heading'>
<div @if ($search['statistics'] != 1) hidden="hidden" @endif>
<div style="float: left;">总数:{{$list->total()}}</div>
<div style="float: left;margin-left: 80px;">分红总数:{{$statisti['total']}}</div>
<div style="float: left;margin-left: 120px;">代理区域:{{$statisti['agent_area']}}</div>
{{-- <div style="float: left;margin-left: 200px;">当前分红比例:{{$statisti['agent_area']}}%</div>--}}
<div style="clear: both;"></div>
</div>
</div>
<div class='panel-body'>
<table class="table table-hover" style="overflow:visible;">
<thead>
<tr>
<th style='width:6%;'>ID</th>
<th style='width:10%;'>分红时间</th>
<th style='width:10%;'>订单号</th>
<th style='width:8%;'>订单金额(元)</th>
<th style='width:10%;'>分红结算金额</th>
<th style='width:8%;'>分红比例</th>
<th style='width:10%;'>下级分红比例</th>
<th style='width:10%;'>分红金额</th>
<th style='width:10%;'>分红金额</th>
</tr>
</thead>
<tbody>
@foreach($list as $row)
<tr>
<td>{{$row->id}}</td>
<td>{{$row->created_at }}</td>
<td>{{$row->order_sn}}</td>
<td>{{$row->order_amount}}</td>
<td>{{$row->amount}}</td>
<td>{{$row->dividend_rate}}%</td>
<td>{{$row->lower_level_rate}}%</td>
<td>{{$row->dividend_amount}}</td>
<td>{{$row->status_name}}</td>
</tr>
@endforeach
</tbody>
</table>
{!! $pager !!}
</div>
</div>
<div style="width:100%;height:150px;"></div>
<script language='javascript'>
$(function () {
$('#export').click(function () {
$('#form1').attr('action', '{!! yzWebUrl('plugin.area-dividend.area.dividend-log.export') !!}');
$('#form1').submit();
});
$('#search').click(function () {
$('#form1').attr('action', '{!! yzWebUrl('plugin.area-dividend.area.dividend-log.index') !!}');
$('#form1').submit();
});
});
</script>
@endsection

View File

@ -0,0 +1,171 @@
@extends('layouts.base')
@section('content')
@section('title', trans('区域订单'))
<div class="right-titpos">
<ul class="add-snav">
<li class="active"><a href="#">区域订单</a></li>
</ul>
</div>
<div class='panel panel-default'>
<form action="" method="post" class="form-horizontal" id="form1">
<div class="panel panel-info">
<div class="panel-body">
{{--<div class="form-group col-xs-12 col-sm-2">--}}
{{--<input class="form-control" name="search[name]" id="" type="text"--}}
{{--value="{{$search['name']}}" placeholder="店铺名称">--}}
{{--</div>--}}
<div class="form-group col-xs-6 col-sm-2">
<select name='search[plugin_id]' class='form-control'>
<option value=''>订单类型</option>
<option value='0' @if($search['plugin_id'] == '0') selected @endif>自营</option>
<option value='1' @if($search['plugin_id'] == '1') selected @endif>供应商</option>
<option value='32' @if($search['plugin_id'] == '32') selected @endif>门店</option>
</select>
</div>
<div class="form-group col-xs-6 col-sm-2">
<select name='search[statistics]' class='form-control'>
<option value='2' @if($search['statistics'] == '2') selected @endif>不统计</option>
<option value='1' @if($search['statistics'] == '1') selected @endif>统计</option>
</select>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">区域</label>
<div class="col-xs-6">
<input type="hidden" id="province_id" value="{{ $search['province_id']?:0 }}"/>
<input type="hidden" id="city_id" value="{{ $search['city_id']?:0 }}"/>
<input type="hidden" id="district_id" value="{{ $search['district_id']?:0 }}"/>
<input type="hidden" id="street_id" value="{{ $search['street_id']?:0 }}"/>
{!! app\common\helpers\AddressHelper::tplLinkedAddress(['search[province_id]','search[city_id]','search[district_id]','search[street_id]'], [])!!}
</div>
</div>
<div class="form-group col-xs-12 col-sm-8">
<div class="col-sm-3">
<label class='radio-inline'>
<input type='radio' value='0' name='search[is_time]'
@if(empty($search['is_time']) || $search['is_time'] == '0') checked @endif>不搜索
</label>
<label class='radio-inline'>
<input type='radio' value='1' name='search[is_time]'
@if($search['is_time'] == '1') checked @endif>搜索
</label>
</div>
{!! app\common\helpers\DateRange::tplFormFieldDateRange(
'search[time]',
[
'starttime'=>$search['time']['start'],
'endtime'=>$search['time']['end'],
'start'=>$search['time']['start'],
'end'=>$search['time']['end']
],
true
) !!}
</div>
<div class="form-group col-xs-12 col-sm-4">
<input type="button" class="btn btn-success" id="export" value="导出">
<input type="button" class="btn btn-success" id="search" value="搜索">
</div>
</div>
</div>
</form>
</div>
<div class='panel panel-default'>
<div class='panel-heading'>
<div @if ($search['statistics'] != 1) hidden="hidden" @endif>
数量:{{$statisti['total']}} 总金额:{{$statisti['amount']}}
</div>
</div>
<div class='panel-body'>
<table class="table table-hover" style="overflow:visible;">
<thead>
<tr>
<th style='width:10%;'>时间</th>
<th style='width:12%;'>订单号</th>
<th style='width:12%;'>收货人<br/>手机号码</th>
<th style='width:15%;'>订单地址</th>
<th style='width:6%;'>订单类型</th>
<th style='width:6%;'>店铺名称</th>
<th style='width:8%;'>订单金额(元)</th>
<th style='width:10%;'>区域代理结算金额</th>
</tr>
</thead>
<tbody>
@foreach($list['data'] as $row)
<tr>
{{--<td>{{$row['id']}}</td>--}}
<td>{{ date('Y-m-d H:i:s', $row['created_at'])}}</td>
<td>{{$row['order_sn']}}</td>
<td>{{$row['address']['realname']}}<br/>{{$row['address']['mobile']}}</td>
<td>
{{$row['address']['address']}}
</td>
<td>{{$row['plugin_name']}}</td>
<td>
@if ($row['plugin_id'] == 32)
{{$row['has_one_store_order']['has_one_store']['store_name']}}
@elseif($row['plugin_id'] == 31)
{{$row['has_one_cashier_order']['has_one_store']['store_name']}}
@elseif($row['is_plugin'] == 1)
{{$row['has_one_supplier_order']['beLongs_to_supplier']['realname']}}
@else
自营
@endif
</td>
<td>{{$row['price']}}</td>
<td>
@if ($row['has_one_area_dividend'])
{{$row['has_one_area_dividend']['amount']}}
@else
无分红
@endif
</td>
</tr>
@endforeach
</tbody>
</table>
{!! $pager !!}
</div>
</div>
<div style="width:100%;height:150px;"></div>
<script type="text/javascript" src="{{static_url('js/area/cascade_street.js')}}"></script>
<script language='javascript'>
var province_id = $('#province_id').val();
var city_id = $('#city_id').val();
var district_id = $('#district_id').val();
var street_id = $('#street_id').val();
cascdeInit(province_id, city_id, district_id, street_id);
$(function () {
$('#export').click(function () {
$('#form1').attr('action', '{!! yzWebUrl('plugin.area-dividend.area.area-order.export') !!}');
$('#form1').submit();
});
$('#search').click(function () {
$('#form1').attr('action', '{!! yzWebUrl('plugin.area-dividend.area.area-order.index') !!}');
$('#form1').submit();
});
});
</script>
@endsection

View File

@ -0,0 +1,326 @@
<style>
.form-group {
overflow: hidden;
margin-bottom: 0 !important;
}
.line {
margin: 10px;
border-bottom: 1px solid #ddd
}
</style>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">粉丝 :</label>
<div class="col-sm-9 col-xs-12">
<img src='{{$order['belongs_to_member']['avatar']}}'
style='width:100px;height:100px;padding:1px;border:1px solid #ccc'/>
{{--<a href="{!! yzWebUrl('member.member.detail',array('id'=>$order['belongs_to_member']['uid'])) !!}"> {{$order['belongs_to_member']['nickname']}}</a>--}}
{{$order['belongs_to_member']['nickname']}}
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">会员信息 :</label>
<div class="col-sm-9 col-xs-12">
<div class='form-control-static'>ID: {{$order['belongs_to_member']['uid']}}
姓名: {{$order['belongs_to_member']['realname']}} /
手机号: {{$order['belongs_to_member']['mobile']}}</div>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">订单编号 :</label>
<div class="col-sm-9 col-xs-12">
<p class="form-control-static">{{$order['order_sn']}} </p>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">订单金额 :</label>
<div class="col-sm-9 col-xs-12">
<div class="form-control-static">
<table cellspacing="0" cellpadding="0">
<tr>
<td style='border:none;text-align:right;'>商品小计:</td>
<td style='border:none;text-align:right;;'>
{{number_format( $order['order_goods_price'] ,2)}}</td>
</tr>
<tr>
<td style='border:none;text-align:right;'>优惠:</td>
<td style='border:none;text-align:right;'>
{{number_format( $order['discount_price'] ,2)}}</td>
</tr>
<tr>
<td style='border:none;text-align:right;'>抵扣:</td>
<td style='border:none;text-align:right;'>
- {{number_format( $order['deduction_price'] ,2)}}</td>
</tr>
<tr>
<td style='border:none;text-align:right;'>运费:</td>
<td style='border:none;text-align:right;'>
{{number_format( $order['dispatch_price'] ,2)}}</td>
</tr>
<tr>
<td style='border:none;text-align:right;'>应收款:</td>
<td style='border:none;text-align:right;color:green;'>
{{number_format($order['price'],2)}}</td>
</tr>
</table>
</div>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">订单状态 :</label>
<div class="col-sm-9 col-xs-12">
<p class="form-control-static">
<span class="label
@if ($order['status'] == 3) label-success
@elseif ($order['status'] == -1) label-default
@else label-info
@endif">{{$order['status_name']}}</span>
</p>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">支付方式 :</label>
<div class="col-sm-9 col-xs-12">
<p class="form-control-static">
<span class="label label-info">{{$order['pay_type_name']}}</span>
{{--@if(count($order['order_pays']))
<a target="_blank" href="{{yzWebUrl('order.orderPay', array('order_id' => $order['id']))}}" class='btn btn-default'>查看支付记录</a>
@endif--}}
</p>
</div>
</div>
{{--<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">上传发票</label>
<div class="col-sm-9 col-xs-12">
{!! app\common\helpers\ImageHelper::tplFormFieldImage('basic-detail[invoice]', $order['invoice']) !!}
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
<div class="col-sm-9 col-xs-12">
<br/>
<button name='saveremark' onclick="sub()" class='btn btn-default'>保存发票</button>
</div>
</div>--}}
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">用户备注 :</label>
<div class="col-sm-9 col-xs-12" class="form-control" style="height:150px;" cols="70" >
<textarea style="height:140px;" class="form-control" cols="70" disabled>{{$order['note']}}</textarea>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">商户备注 :</label>
<div class="col-sm-9 col-xs-12">
<textarea style="height:150px;" class="form-control" id="remark" name="remark" cols="70">{{$order['has_one_order_remark']['remark']}}</textarea>
</div>
</div>
{{--<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
<div class="col-sm-9 col-xs-12">
<br/>
<button name='saveremark' onclick="sub()" class='btn btn-default'>保存备注</button>
</div>
</div>--}}
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">下单日期 :</label>
<div class="col-sm-9 col-xs-12">
<p class="form-control-static">{{$order['create_time']}}</p>
</div>
</div>
@if ($order['status'] >= 1)
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">付款时间 :</label>
<div class="col-sm-9 col-xs-12">
<p class="form-control-static">{{$order['pay_time']}}</p>
</div>
</div>
@endif
@if ($order['status'] >= 2)
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">发货时间 :</label>
<div class="col-sm-9 col-xs-12">
<p class="form-control-static">{{$order['send_time']}}</p>
</div>
</div>
@endif
@if ($order['status'] == 3)
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">完成时间 :</label>
<div class="col-sm-9 col-xs-12">
<p class="form-control-static">{{$order['finish_time']}}</p>
</div>
</div>
@endif
@if (!empty($order['address']))
@include('dispatch.detail')
@endif
@if (!empty($order['has_one_refund_apply']))
@include('Yunshop\AreaDividend::area.refund.index')
@endif
@if(!empty($order['call']))
@include('invoice.display')
@endif
@if (count($order['discounts']))
<div class="panel panel-default">
<div class="panel-heading">
优惠信息
</div>
<div class="panel-body table-responsive">
<table class="table table-hover">
<thead class="navbar-inner">
<tr>
<th class="col-md-5 col-lg-3">优惠名称</th>
<th class="col-md-5 col-lg-3">优惠金额</th>
</tr>
</thead>
@foreach ($order['discounts'] as $discount)
<tr>
<td>{{$discount['name']}}</td>
<td>¥{{$discount['amount']}}</td>
</tr>
@endforeach
</table>
</div>
</div>
@endif
@if (count($order['deductions']))
<div class="panel panel-default">
<div class="panel-heading">
抵扣信息
</div>
<div class="panel-body table-responsive">
<table class="table table-hover">
<thead class="navbar-inner">
<tr>
<th class="col-md-5 col-lg-3">名称</th>
<th class="col-md-5 col-lg-1">抵扣值</th>
<th class="col-md-5 col-lg-3">抵扣金额</th>
</tr>
</thead>
@foreach ($order['deductions'] as $deduction)
<tr>
<td>{{$deduction['name']}}</td>
<td>{{$deduction['coin']}}</td>
<td>¥{{$deduction['amount']}}</td>
</tr>
@endforeach
</table>
</div>
</div>
@endif
@if (count($order['coupons']))
<div class="panel panel-default">
<div class="panel-heading">
优惠券信息
</div>
<div class="panel-body table-responsive">
<table class="table table-hover">
<thead class="navbar-inner">
<tr>
<th class="col-md-5 col-lg-3">名称</th>
<th class="col-md-5 col-lg-3">优惠金额</th>
</tr>
</thead>
@foreach ($order['coupons'] as $coupon)
<tr>
<td>{{$coupon['name']}}</td>
<td>¥{{$coupon['amount']}}</td>
</tr>
@endforeach
</table>
</div>
</div>
@endif
@if($div_from['status'])
<div class="panel panel-default">
<div class="panel-heading">
个人表单信息
</div>
<div class="panel-body">
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">真实姓名 :</label>
<div class="col-sm-9 col-xs-12">
<p class="form-control-static">
{{ $div_from['member_name'] }}
</p>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">身份证 :</label>
<div class="col-sm-9 col-xs-12">
<p class="form-control-static">
{{ $div_from['member_card'] }}
</p>
</div>
</div>
</div>
</div>
@endif
<div class="panel panel-default">
<div class="panel-heading">
商品信息
</div>
<div class="panel-body table-responsive">
<table class="table table-hover">
<thead class="navbar-inner">
<tr>
<th class="col-md-5 col-lg-1">ID</th>
<th class="col-md-5 col-lg-3">商品标题</th>
<th class="col-md-5 col-lg-3">商品规格</th>
<th class="col-md-5 col-lg-3">现价/原价/成本价</th>
<th class="col-md-5 col-lg-1">购买数量</th>
{{--<th class="col-md-5 col-lg-1" style="color:red;">折扣前<br/>折扣后</th>--}}
<th class="col-md-5 col-lg-1">操作</th>
</tr>
</thead>
@foreach ($order['has_many_order_goods'] as $order_goods)
<tr>
<td>{{$order_goods['goods_id']}}</td>
<td>
{{--<a href="{{yzWebUrl($edit_goods, array('id' => $order_goods['goods_id']))}}">{{$order_goods['title']}}</a>--}}
{{$order_goods['title']}}
</td>
<td>{{$order_goods['goods_option_title']}}</td>
<td>{{$order_goods['goods_price']}}
/{{$order_goods['goods_market_price']}}
/{{$order_goods['goods_cost_price']}}
</td>
<td>{{$order_goods['total']}}</td>
{{--<td style='color:red;font-weight:bold;'>{{sprintf('%.2f', $order_goods['goods_price']/$order_goods['total'])}}--}}
{{--<br/>{{sprintf('%.2f', $order_goods['payment_amount']/$order_goods['total'])}}--}}
{{--</td>--}}
<td>
{{--<a href="{!! yzWebUrl($edit_goods, array('id' => $order_goods['goods']['id'])) !!}"
class="btn btn-default btn-sm" title="编辑"><i
class="fa fa-edit"></i></a>&nbsp;&nbsp;--}}
无权限
</td>
</tr>
@endforeach
@include('Yunshop\AreaDividend::area.refund.modal')
<tr>
<td colspan="2">
@include('Yunshop\AreaDividend::area.order.modals')
@include($ops)
</td>
<td colspan="8">
</td>
</tr>
</table>
</div>
</div>
<script></script>

View File

@ -0,0 +1,72 @@
@extends('layouts.base')
@section('title','批量发货')
@section('content')
<div class="page-heading">
<h2>批量发货</h2>
</div>
<div class="alert alert-info">
功能介绍: 使用excel快速导入进行订单发货, 文件格式<b style="color:red;">[xls]</b>
<span style="padding-left: 60px;">如重复导入数据将以最新导入数据为准,请谨慎使用</span>
<span style="padding-left: 60px;">数据导入订单状态自动修改为已发货</span>
<span style="padding-left: 60px;">一次导入的数据不要太多,大量数据请分批导入,建议在服务器负载低的时候进行</span>
<br>
使用方法: <span style="padding-left: 60px;">1. 下载Excel模板文件并录入信息</span>
<span style="padding-left: 60px;">2. 选择快递公司</span>
<span style="padding-left: 60px;">3. 上传Excel导入</span>
<br>
格式要求: Excel第一列必须为订单编号第二列必须为快递单号请确认订单编号与快递单号的备注
</div>
<form id="importform" class="form-horizontal form" action="" method="post" enctype="multipart/form-data">
<div class='form-group'>
<div class="form-group">
<label class="col-sm-2 control-label must">快递公司</label>
<div class="col-sm-5 goodsname" style="padding-right:0;" >
<select class="form-control" name="send[express_code]" id="express">
@include('express.companies')
</select>
<input type="hidden" name='send[express_company_name]' id='expresscom' value="顺丰"/>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label must">EXCEL</label>
<div class="col-sm-5 goodsname" style="padding-right:0;" >
<input type="file" name="send[excelfile]" class="form-control" />
<span class="help-block">如果遇到数据重复则将进行数据更新</span>
</div>
</div>
</div>
<div class='form-group'>
<div class="col-sm-12">
<div class="modal-footer">
<button type="submit" class="btn btn-primary" name="cancelsend" value="yes">确认导入</button>
<a class="btn btn-primary" href="{{yzWebUrl('order.batch-send.get-example')}}" style="margin-right: 10px;" ><i class="fa fa-download" title=""></i> 下载Excel模板文件</a>
</div>
</div>
</div>
</div>
</form>
<script language='javascript'>
$("#express").change(function () {
var sel = $(this).find("option:selected").text();
// var sel = $(this).find("option:selected").attr("data-name");
$("#expresscom").val(sel);
});
$('#express').select2();
</script>
@endsection('content')

View File

@ -0,0 +1,130 @@
@extends('layouts.base')
@section('title','订单详情')
@section('js')
<link href="{{static_url('yunshop/css/order.css')}}" media="all" rel="stylesheet" type="text/css"/>
<script language="javascript">
$(function(){
$("#myTab li.active>a").css("background","#f15353");
})
window.optionchanged = false;
require(['bootstrap'], function () {
$('#myTab a').click(function (e) {
e.preventDefault();
$(this).tab('show');
$(this).css("background","#f15353").parent().siblings().children().css("background","none")
})
});
function sub() {
var order_id = $('.order_id').val();
var remark = $('#remark').val();
var invoice = $("[name='basic-detail[invoice]']").val();//获取发票
// $.post("{!! yzWebUrl('order.edit') !!}", {
$.post("{!! yzWebUrl('order.operation.remark') !!}", {
order_id: order_id,
remark: remark,
invoice: invoice,
}, function (json) {
var json = $.parseJSON(json);
if (json.result == 1) {
window.location.reload();
}
});
}
function showDiyInfo(obj) {
var hide = $(obj).attr('hide');
if (hide == '1') {
$(obj).next().slideDown();
}
else {
$(obj).next().slideUp();
}
$(obj).attr('hide', hide == '1' ? '0' : '1');
}
//cascdeInit("{!! isset($user['province'])?$user['province']:'' !!}", "{!! isset($user['city'])?$user['city']:'' !!}", "{!! isset($user['area'])?$user['area']:'' !!}");
$('#editaddress').click(function () {
show_address(1);
});
$('#backaddress').click(function () {
show_address(0);
});
$('#editexpress').click(function () {
show_express(1);
});
$('#backexpress').click(function () {
show_express(0);
});
function show_address(flag) {
if (flag == 1) {
$('.ad1').hide();
$('.ad2').show();
} else {
$('.ad1').show();
$('.ad2').hide();
}
}
function show_express(flag) {
if (flag == 1) {
$('.ex1').hide();
$('.ex2').show();
} else {
$('.ex1').show();
$('.ex2').hide();
}
}
</script>
@stop
@section('content')
<div class="w1200 m0a">
<div class="rightlist">
<!-- 新增加右侧顶部三级菜单 -->
<div class="right-titpos">
<ul class="add-snav">
<li class="active"><a href="#">订单管理 &nbsp; <i class="fa fa-angle-double-right"></i> &nbsp; 订单详情</a>
</li>
</ul>
</div>
<!-- 新增加右侧顶部三级菜单结束 -->
<div class="main">
<input type="hidden" class="order_id" value="{{$order['id']}}"/>
<input type="hidden" name="token" value="{{$var['token']}}"/>
<input type="hidden" name="dispatchid" value="{{$dispatch['id']}}"/>
<div class="panel panel-default">
{{--<div class="top">
<ul class="add-shopnav" id="myTab">
<li class="active"><a href="#tab_basic">基本信息</a></li>
@foreach(\app\backend\modules\income\Income::current()->getItem('order') as $key=>$value)
<li><a href="#{{$key}}">{{$value['title']}}</a></li>
@endforeach
</ul>
</div>--}}
<div class="info">
<div class="panel-body">
<div class="tab-content">
<div class="tab-pane active" id="tab_basic">@include('Yunshop\AreaDividend::area.order.basicDetail')</div>
@foreach(\app\backend\modules\income\Income::current()->getItem('order') as $key=>$value)
<div class="tab-pane"
id="{{$key}}">{!! widget($value['class'], ['goods_id'=> $goods->id])!!}</div>
@endforeach
</div>
</div>
</div>
</div>
</div>
@endsection('content')

View File

@ -0,0 +1,435 @@
@extends('layouts.base')
@section('title','订单列表')
@section('content')
<link href="{{static_url('yunshop/css/order.css')}}" media="all" rel="stylesheet" type="text/css"/>
<div class="w1200 m0a">
<script type="text/javascript" src="{{static_url('js/dist/jquery.gcjs.js')}}"></script>
<script type="text/javascript" src="{{static_url('js/dist/jquery.form.js')}}"></script>
<script type="text/javascript" src="{{static_url('js/dist/tooltipbox.js')}}"></script>
<div class="rightlist">
<div class="panel panel-info">
<div class="panel-body">
<div class="card">
<div class="card-header card-header-icon" data-background-color="rose">
<i class="fa fa-bars" style="font-size: 24px;" aria-hidden="true"></i>
</div>
<div class="card-content">
<h4 class="card-title">订单管理</h4>
<form action="" method="get" class="form-horizontal" id="form1">
@section('form')
<input type="hidden" name="c" value="site"/>
<input type="hidden" name="a" value="entry"/>
<input type="hidden" name="m" value="yun_shop"/>
<input type="hidden" name="do" value="order" id="form_do"/>
<input type="hidden" name="route" value="{{$url}}" id="form_p"/>
@show
<div>
@section('search_bar')
@if($route == 'order.list.waitSend')
<div class="form-group col-md-2 col-sm-6">
<select name="search[sort]" class="form-control">
<option value="" @if(!$requestSearch['sort']) selected="selected"@endif>
时间排序
</option>
<option value="1" @if($requestSearch['sort'] == 1) selected="selected"@endif>
会员排序
</option>
</select>
</div>
@endif
<div class="form-group col-md-2 col-sm-6">
<select name="search[ambiguous][field]" id="ambiguous-field"
class="form-control">
<option value="order"
@if(array_get($requestSearch,'ambiguous.field','') =='order') selected="selected"@endif >
订单号/支付号
</option>
<option value="member"
@if( array_get($requestSearch,'ambiguous.field','')=='member') selected="selected"@endif>
用户姓名/ID/昵称/手机号
</option>
<option value="address"
@if( array_get($requestSearch,'ambiguous.field','')=='address') selected="selected"@endif>
收货地址/姓名/手机号
</option>
<option value="goods_id"{{--order_goods--}}
@if( array_get($requestSearch,'ambiguous.field','')=='goods_id') selected="selected"@endif>
商品名称/ID
</option>
{{--<option value="goods_id"--}}
{{--@if( array_get($requestSearch,'ambiguous.field','')=='goods_id') selected="selected"@endif>--}}
{{--商品ID--}}
{{--</option>--}}
<option value="dispatch"
@if( array_get($requestSearch,'ambiguous.field','')=='dispatch') selected="selected"@endif>
快递单号
</option>
</select>
</div>
<div class='form-group col-sm-4 col-lg-3 col-xs-12'>
<input class="form-control" name="search[ambiguous][string]" type="text"
value="{{array_get($requestSearch,'ambiguous.string','')}}"
placeholder="订单号/支付单号" id="string">
<div class="form-group notice" id="goods_name">
<div >
<div class='input-group'>
<input type="hidden" id="plugin_id" name="plugin_id" value="@if(!empty($list['plugin_id'])) {{$list['plugin_id']}} @else 0 @endif">
<input type="text" name="search[ambiguous][name]" maxlength="30" value="{{array_get($requestSearch,'ambiguous.name','')}}" id="saler" class="form-control" readonly />
<div class='input-group-btn'>
<button class="btn btn-default" type="button" onclick="popwin = $('#modal-module-menus-notice').modal();">选择商品</button>
<button class="btn btn-danger" type="button" onclick="$('#noticeopenid').val('');$('#saler').val('');$('#saleravatar').hide()">清除选择</button>
</div>
</div>
<div id="modal-module-menus-notice" class="modal fade" tabindex="-1">
<div class="modal-dialog" style='width: 920px;'>
<div class="modal-content">
<div class="modal-header"><button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button><h3>选择商品名称</h3></div>
<div class="modal-body" >
<div class="row">
<div class="input-group">
<input type="text" class="form-control" name="keyword" value="" id="search-kwd-notice" placeholder="请输入商品名称" />
<span class='input-group-btn'><button type="button" class="btn btn-default" onclick="search_members();">搜索</button></span>
</div>
</div>
<div id="module-menus-notice" style="padding-top:5px;"></div>
</div>
<div class="modal-footer"><a href="#" class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</a></div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="form-group form-group col-sm-8 col-lg-2 col-xs-12">
<!-- 注意由于属于支付宝支付的支付方式有好几种包括app支付宝支付方式支付宝-YZ方式
等,所以进行了分组,支付选项传入的支付方式是支付方式组的id并不是支付方式的id -->
<select name="search[pay_type]" class="form-control">
<option value=""
@if( array_get($requestSearch,'pay_type','')) selected="selected"@endif>
全部支付方式
</option>
<option value="1"
@if( array_get($requestSearch,'pay_type','') == '1') selected="selected"@endif>
微信支付
</option>
<option value="2"
@if( array_get($requestSearch,'pay_type','') == '2') selected="selected"@endif>
支付宝支付
</option>
<option value="3"
@if( array_get($requestSearch,'pay_type','') == '3') selected="selected"@endif>
余额支付
</option>
<option value="4"
@if( array_get($requestSearch,'pay_type','') == '4') selected="selected"@endif>
后台付款
</option>
</select>
</div>
<div class="form-group col-sm-12 col-lg-12 col-xs-12"></div>
<div class="form-group col-sm-8 col-lg-5 col-xs-12">
<select name="search[time_range][field]" class="form-control form-time" >
<option value=""
@if( array_get($requestSearch,'time_range.field',''))selected="selected"@endif >
操作时间
</option>
<option value="create_time"
@if( array_get($requestSearch,'time_range.field','')=='create_time') selected="selected"@endif >
下单
</option>
<option value="pay_time"
@if( array_get($requestSearch,'time_range.field','')=='pay_time') selected="selected"@endif>
付款
</option>
<option value="send_time"
@if( array_get($requestSearch,'time_range.field','')=='send_time') selected="selected"@endif>
发货
</option>
<option value="finish_time"
@if( array_get($requestSearch,'time_range.field','')=='finish_time') selected="selected"@endif>
完成
</option>
</select>
{!!
app\common\helpers\DateRange::tplFormFieldDateRange('search[time_range]', [
'starttime'=>array_get($requestSearch,'time_range.start',0),
'endtime'=>array_get($requestSearch,'time_range.end',0),
'start'=>0,
'end'=>0
], true)!!}
</div>
@show
</div>
<div class="form-group">
<div class="col-sm-7 col-lg-9 col-xs-12">
<button class="btn btn-success"><i class="fa fa-search"></i> 搜索</button>
<button type="submit" name="export" value="1" id="export" class="btn btn-info">导出
Excel
</button>
<button type="submit" name="export" value="2" id="export" class="btn btn-info">导出
Excel
</button>
{{--<input type="hidden" name="token" value="{{$var['token']}}"/>
@section('export')
<button type="submit" name="export" value="1" id="export" class="btn btn-info">导出
Excel
</button>
@if(app('plugins')->isEnabled('team-dividend'))
<button type="submit" name="direct_export" value="1" id="direct-export" class="btn btn-info">导出
直推 Excel经销商
</button>
@endif
@show
@if( $requestSearch['plugin'] != "fund")
<a class="btn btn-warning"
href="{!! yzWebUrl('order.export') !!}">自定义导出</a>
@endif--}}
</div>
</div>
</form>
</div>
</div>
{{--<form action="" method="get" class="form-horizontal" id="form1">--}}
{{--</form>--}}
</div>
</div>
<div class="panel panel-default">
<table class='table'
style='float:left;margin-bottom:0;table-layout: fixed;line-height: 40px;height: 40px'>
<tr class='trhead'>
<td colspan='8' style="text-align: left;">
订单数: <span id="total">{{$list['total']}}</span>
订单金额: <span id="totalmoney" style="color:red">{{$total_price}}</span>&nbsp;
@section('supplier_apply')
@show
</td>
</tr>
</table>
@section('is_plugin')
@foreach ($list['data'] as $order_index => $order)
<div class="order-info">
<table class='table order-title'>
<tr>
<td class="left" colspan='8'>
<b>订单编号:</b> {{$order['order_sn']}}
@if($order['status']>\app\common\models\Order::WAIT_PAY && isset($order['has_one_order_pay']))
<b>支付单号:</b> {{$order['has_one_order_pay']['pay_sn']}}
@endif
<b>下单时间: </b>{{$order['create_time']}}
@if( $order['has_one_refund_apply'] == \app\common\models\refund\RefundApply::WAIT_RECEIVE_RETURN_GOODS)
<label class='label label-primary'>客户已经寄出快递</label>@endif
<label class="label label-info">{{$order['shop_name']}}</label>
@if(!empty($order['has_one_refund_apply']))
<label class="label label-danger">{{$order['has_one_refund_apply']['refund_type_name']}}
:{{$order['has_one_refund_apply']['status_name']}}</label>
@endif
<td class="right">
{{--@if(empty($order['status']))
<a class="btn btn-default btn-sm" href="javascript:;"
onclick="$('#modal-close').find(':input[name=order_id]').val('{{$order['id']}}')"
data-toggle="modal" data-target="#modal-close">关闭订单</a>
@endif--}}
</td>
</tr>
</table>
<table class='table order-main'>
@foreach( $order['has_many_order_goods'] as $order_goods_index => $order_goods)
<tr class='trbody'>
<td class="goods_info">
<img src="{{tomedia($order_goods['thumb'])}}">
</td>
<td class="top" valign='top' style="font-size: 16px;color: #AEB9C0">
{{--<a href="{{yzWebUrl('goods.goods.edit', array('id' => $order_goods['goods_id']))}}">{{$order_goods['title']}}</a>--}}
{{$order_goods['title']}}
@if( !empty($order_goods['goods_option_title']))<br/>
<span style="font-size: 15px;color: #AEB9C0">{{$order_goods['goods_option_title']}}</span>
@endif
<br/><span style="font-size: 15px;color: #AEB9C0">{{$order_goods['goods_sn']}}</span>
</td>
<td class="price">
原价: {{ number_format($order_goods['goods_price']/$order_goods['total'],2)}}
<br/>应付: {{ number_format($order_goods['price']/$order_goods['total'],2) }}
<br/>数量: {{$order_goods['total']}}
</td>
@if( $order_goods_index == 0)
<td rowspan="{{count($order['has_many_order_goods'])}}">
{{--<a href="{!! yzWebUrl('member.member.detail',array('id'=>$order['belongs_to_member']['uid'])) !!}"> {{$order['belongs_to_member']['nickname']}}</a>--}}
{{$order['belongs_to_member']['nickname']}}
<br/>
{{$order['belongs_to_member']['realname']}}
<br/>{{$order['belongs_to_member']['mobile']}}
</td>
<td rowspan="{{count($order['has_many_order_goods'])}}">
<label class='label label-info'>{{$order['pay_type_name']}}</label>
<br/>
{{$order['has_one_dispatch_type']['name']}}
</td>
<td rowspan="{{count($order['has_many_order_goods'])}}" style='width:18%;'>
<table class="goods-price">
<tr>
<td style=''>商品小计:</td>
<td style=''>{!! number_format(
$order['goods_price'] ,2) !!}
</td>
</tr>
<tr>
<td style=''>运费:</td>
<td style=''>{!! number_format(
$order['dispatch_price'],2) !!}
</td>
</tr>
@if($order['change_price'] != 0)
<tr>
<td style=''>卖家改价:</td>
<td style='color:green'>{!! number_format(
$order['change_price'] ,2) !!}
</td>
</tr>
@endif
@if($order['change_dispatch_price'] != 0)
<tr>
<td style=''>卖家改运费:</td>
<td style='color:green'>{{ number_format(
$order['change_dispatch_price'] ,2) }}
</td>
</tr>
@endif
<tr>
<td style=''>应收款:</td>
<td style='color:green'>{!! number_format(
$order['price'] ,2) !!}
</td>
</tr>
{{--@if($order['status'] == 0)
<tr>
<td></td>
<td style='color:green;'>
<a href="javascript:;" class="btn btn-link "
onclick="changePrice('{{$order['id']}}')">修改价格</a>
</td>
</tr>
@endif--}}
</table>
</td>
<td rowspan="{{count($order['has_many_order_goods'])}}"><label
class='label label-info'>{{$order['status_name']}}</label>
<br/>
<a href="{!! yzWebUrl($detail_url,['id'=>$order['id']])!!}">查看详情</a>
</td>
<td rowspan="{{count($order['has_many_order_goods'])}}" width="10%">
@include($include_ops)
</td>
@endif
</tr>
@endforeach
</table>
</div>
@endforeach
@show
@include('Yunshop\AreaDividend::area.order.modals')
<div id="pager">{!! $pager !!}</div>
</div>
</div>
</div>
<script>
$(function () {
// $("#goods_name").hide();//页面加载,隐藏选择商品名称控件
$("#ambiguous-field").on('change', function () {
$(this).next('input').attr('placeholder', $(this).find(':selected').text().trim())
if ($(this).val()=='goods_id'){//选择商品名称搜索
$("#string").hide();
$("#goods_name").show();
}else {
$('input[name="search[ambiguous][string]"]').val("");
$("#goods_name").hide();
$("#string").show();
}
});
})
if ($("#ambiguous-field").val()=='goods_id'){//选择商品名称搜索
$("#string").hide();
$("#goods_name").show();
}else {
$("#goods_name").hide();
$("#string").show();
}
function search_members() {
if ($('#search-kwd-notice').val() == '') {
Tip.focus('#search-kwd-notice', '请输入关键词');
return;
}
$("#module-menus-notice").html("正在搜索....");
$.get("{!! yzWebUrl('goods.goods.search-order') !!}", {
keyword: $.trim($('#search-kwd-notice').val()),
plugin_id : $.trim($('#plugin_id').val()),
}, function (dat) {
$('#module-menus-notice').html(dat);
});
}
function select_good (o) {
console.log(o.id)
$('input[name="search[ambiguous][string]"]').val(o.id);
$('input[name="search[ambiguous][name]"]').val(o.title);
$("#saleravatar").show();
$("#saleravatar").find('img').attr('src', o.thumb);
$("#saler").val(o.title);
$("#modal-module-menus-notice .close").click();
}
</script>
@section('plugin_js')
@show
@endsection('content')

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