-
+
- 基本信息 + + @foreach(\app\backend\modules\income\Income::current()->getItem('order') as $key=>$value) +
- {{$value['title']}} + @endforeach + +
From 3fc6fca7fbdea17a7e75f7e5fb8beff1a3ab4b8c Mon Sep 17 00:00:00 2001
From: wuhui_zzw <1760308791@qq.com>
Date: Tue, 24 Oct 2023 15:11:27 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=EF=BC=9A=E5=8C=BA=E5=9F=9F?=
=?UTF-8?q?=E4=BB=A3=E7=90=86=E6=8F=92=E4=BB=B6=20=E4=BC=98=E5=8C=96?=
=?UTF-8?q?=EF=BC=9A=E8=B4=AD=E4=B9=B0=E5=95=86=E5=93=81=E8=B5=A0=E9=80=81?=
=?UTF-8?q?=E6=9D=83=E9=87=8D=E5=80=BC=20-=20=E7=BB=8F=E7=BA=AA=E4=BA=BA?=
=?UTF-8?q?=E8=B5=A0=E9=80=81=20=E4=BF=AE=E5=A4=8D=EF=BC=9A=E8=B4=AD?=
=?UTF-8?q?=E4=B9=B0=E5=95=86=E5=93=81=E7=BB=8F=E7=BA=AA=E4=BA=BA=E4=BA=8C?=
=?UTF-8?q?=E7=BA=A7=E8=B5=A0=E9=80=81=E8=AE=BE=E7=BD=AE=E6=97=A0=E6=95=88?=
=?UTF-8?q?=20=E4=BF=AE=E5=A4=8D=EF=BC=9A=E4=BB=A3=E7=90=86=E5=95=86?=
=?UTF-8?q?=E5=8D=87=E7=BA=A7=E5=A5=96=E5=8A=B1=E6=9D=83=E9=87=8D=E5=80=BC?=
=?UTF-8?q?=E6=9C=AA=E6=8C=89=E7=85=A7=E9=98=B6=E6=A2=AF=E8=B5=A0=E9=80=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
plugins/area-dividend/callbacks.php | 10 +
plugins/area-dividend/lang/en/locale.js | 8 +
plugins/area-dividend/lang/en/test.php | 5 +
plugins/area-dividend/lang/zh-CN/index.php | 9 +
plugins/area-dividend/lang/zh-CN/locale.js | 6 +
plugins/area-dividend/lang/zh-CN/test.php | 6 +
...reate_ims_yz_goods_area_dividend_table.php | 41 ++
...reate_ims_yz_area_dividend_agent_table.php | 57 ++
...2752_create_ims_yz_area_dividend_table.php | 54 ++
...has_dividend_to_yz_goods_area_dividend.php | 39 ++
...ividend_rate_to_yz_goods_area_dividend.php | 36 +
...edit_dividend_rate_to_yz_area_dividend.php | 42 ++
...dd_plugin_id_to_yz_area_dividend_order.php | 40 ++
...023_add_user_to_yz_area_dividend_agent.php | 46 ++
...2018_10_30_104524_repair_dividend_data.php | 29 +
...reate_ims_yz_error_team_dividend_table.php | 46 ++
...ge_to_ims_yz_area_dividend_agent_table.php | 36 +
...io_to_ims_yz_area_dividend_agent_table.php | 40 ++
...reate_ims_yz_area_dividend_order_table.php | 38 ++
...create_ims_yz_area_dividend_lock_table.php | 50 ++
...lt_to_ims_yz_area_dividend_agent_table.php | 56 ++
...order_id_to_ims_yz_area_dividend_table.php | 48 ++
...3023_add_pid_to_yz_area_dividend_order.php | 41 ++
...or_uid_to_yz_area_dividend_agent_table.php | 34 +
...e_yz_goods_area_dividend_table20211015.php | 65 ++
plugins/area-dividend/package.json | 11 +
.../Frontend/Services/IncomePageService.php | 146 ++++
.../Listener/CreatedCommissionListener.php | 203 ++++++
.../Listener/OrderCreatedListener--old.php | 397 +++++++++++
.../src/Listener/OrderCreatedListener.php | 179 +++++
.../src/Listener/OrderCreatedOldListener.php | 397 +++++++++++
.../src/Listener/OrderFailureListener.php | 42 ++
.../src/Listener/OrderReceiveListener.php | 75 +++
.../area-dividend/src/PluginApplication.php | 530 +++++++++++++++
.../src/admin/AgentController.php | 467 +++++++++++++
.../src/admin/AreaDividendSetController.php | 56 ++
.../src/admin/DividendController.php | 110 +++
.../area-dividend/src/admin/FixController.php | 55 ++
.../src/admin/modules/dividend/Repair.php | 37 +
.../modules/dividend/WrongDataRepair.php | 36 +
.../src/api/AreaDividendController.php | 369 ++++++++++
.../src/api/PaymentCodeController.php | 125 ++++
.../src/area/AreaOrderController.php | 169 +++++
.../src/area/AreaShopController.php | 185 +++++
.../src/area/BatchSendController.php | 210 ++++++
.../src/area/CommonController.php | 29 +
.../src/area/DividendLogController.php | 134 ++++
.../src/area/OrderDetailController.php | 129 ++++
.../src/area/OrderManageController.php | 260 +++++++
.../src/area/ReturnAddressController.php | 184 +++++
.../src/area/StoreOrderManageController.php | 258 +++++++
.../src/event/AreaDividendEvent.php | 47 ++
.../event/CreatedAreaDividendBonusEvent.php | 14 +
.../event/SettleAreaDividendBonusEvent.php | 28 +
.../area-dividend/src/models/AgentOrder.php | 18 +
.../area-dividend/src/models/AreaDividend.php | 367 ++++++++++
.../src/models/AreaDividendAgent.php | 261 ++++++++
.../src/models/AreaDividendGoods.php | 88 +++
plugins/area-dividend/src/models/Lock.php | 104 +++
plugins/area-dividend/src/models/Order.php | 182 +++++
.../src/models/area/AreaStoreShop.php | 45 ++
.../area-dividend/src/models/area/Order.php | 182 +++++
.../src/models/area/SupplierOrder.php | 29 +
.../src/models/expansions/GoodsExpansions.php | 19 +
.../src/models/weiqing/UsersPermission.php | 28 +
.../src/models/weiqing/WeiQingUsers.php | 164 +++++
.../src/services/AgentService.php | 82 +++
.../src/services/AreaDividendGetService.php | 33 +
.../src/services/MessageService.php | 110 +++
.../src/services/OrderCreatedNewService.php | 497 ++++++++++++++
.../src/services/OrderCreatedService.php | 316 +++++++++
.../src/services/ReturnFormatService.php | 60 ++
.../src/services/TimedTaskService.php | 216 ++++++
.../widgets/AreaDividendWithdrawWidget.php | 22 +
.../src/widgets/DividendVueWidget.php | 66 ++
.../src/widgets/DividendWidget.php | 25 +
.../area-dividend/views/admin/apply.blade.php | 104 +++
.../views/admin/change-pwd.blade.php | 224 +++++++
.../views/admin/create-agent.blade.php | 295 ++++++++
.../views/admin/dividend-detail.blade.php | 155 +++++
.../views/admin/dividend-list.blade.php | 211 ++++++
.../area-dividend/views/admin/goods.blade.php | 134 ++++
.../area-dividend/views/admin/list.blade.php | 308 +++++++++
.../area-dividend/views/admin/set.blade.php | 59 ++
.../area-dividend/views/admin/tabs.blade.php | 16 +
.../views/admin/tpl/agreement.blade.php | 17 +
.../admin/tpl/apply_background.blade.php | 7 +
.../views/admin/tpl/area_dividend.blade.php | 66 ++
.../views/admin/tpl/notice.blade.php | 96 +++
.../admin/tpl/range_commission.blade.php | 16 +
.../views/admin/tpl/settle.blade.php | 223 ++++++
.../views/admin/tpl/supplier.blade.php | 17 +
.../views/admin/withdraw-set.blade.php | 61 ++
.../views/area/area-shop.blade.php | 152 +++++
.../views/area/dividend-list.blade.php | 130 ++++
.../views/area/order-list.blade.php | 171 +++++
.../views/area/order/basicDetail.blade.php | 326 +++++++++
.../views/area/order/batch_send.blade.php | 72 ++
.../views/area/order/detail.blade.php | 130 ++++
.../views/area/order/list.blade.php | 435 ++++++++++++
.../views/area/order/modals.blade.php | 633 ++++++++++++++++++
.../views/area/order/ops.blade.php | 38 ++
.../views/area/order/store-detail.blade.php | 130 ++++
.../views/area/order/store-list.blade.php | 438 ++++++++++++
.../area/order/storeBasicDetail.blade.php | 326 +++++++++
.../views/area/refund/index.blade.php | 206 ++++++
.../views/area/refund/modal.blade.php | 7 +
.../views/area/refund/modal_base.blade.php | 157 +++++
.../refund/modal_exchange_goods.blade.php | 27 +
.../area/refund/modal_refund_money.blade.php | 24 +
.../area/refund/modal_return_goods.blade.php | 40 ++
.../views/area/return/info.blade.php | 147 ++++
.../views/area/return/list.blade.php | 66 ++
.../views/widget/profit/areaDividend.js | 147 ++++
.../src/services/TimedTaskService.php | 4 +-
plugins/team-dividend/src/models/Uplog.php | 10 +
.../src/observers/DealerObserver.php | 16 -
.../src/admin/IndexController.php | 6 +-
.../weight-value/src/models/WeightValue.php | 19 +-
.../views/widget/marketing/weight_value.js | 12 +-
120 files changed, 14517 insertions(+), 39 deletions(-)
create mode 100644 plugins/area-dividend/callbacks.php
create mode 100644 plugins/area-dividend/lang/en/locale.js
create mode 100644 plugins/area-dividend/lang/en/test.php
create mode 100644 plugins/area-dividend/lang/zh-CN/index.php
create mode 100644 plugins/area-dividend/lang/zh-CN/locale.js
create mode 100644 plugins/area-dividend/lang/zh-CN/test.php
create mode 100644 plugins/area-dividend/migrations/2017_05_17_091956_create_ims_yz_goods_area_dividend_table.php
create mode 100644 plugins/area-dividend/migrations/2017_05_17_092418_create_ims_yz_area_dividend_agent_table.php
create mode 100644 plugins/area-dividend/migrations/2017_05_17_092752_create_ims_yz_area_dividend_table.php
create mode 100644 plugins/area-dividend/migrations/2017_07_27_155310_add_has_dividend_to_yz_goods_area_dividend.php
create mode 100644 plugins/area-dividend/migrations/2017_08_11_112810_add_has_dividend_rate_to_yz_goods_area_dividend.php
create mode 100644 plugins/area-dividend/migrations/2017_08_30_104524_edit_dividend_rate_to_yz_area_dividend.php
create mode 100644 plugins/area-dividend/migrations/2018_10_29_113023_add_plugin_id_to_yz_area_dividend_order.php
create mode 100644 plugins/area-dividend/migrations/2018_10_29_113023_add_user_to_yz_area_dividend_agent.php
create mode 100644 plugins/area-dividend/migrations/2018_10_30_104524_repair_dividend_data.php
create mode 100644 plugins/area-dividend/migrations/2018_11_05_134514_create_ims_yz_error_team_dividend_table.php
create mode 100644 plugins/area-dividend/migrations/2019_04_17_134500_add_manage_to_ims_yz_area_dividend_agent_table.php
create mode 100644 plugins/area-dividend/migrations/2019_04_17_134501_add_ratio_to_ims_yz_area_dividend_agent_table.php
create mode 100644 plugins/area-dividend/migrations/2019_04_17_134511_create_ims_yz_area_dividend_order_table.php
create mode 100644 plugins/area-dividend/migrations/2019_08_11_114007_create_ims_yz_area_dividend_lock_table.php
create mode 100644 plugins/area-dividend/migrations/2020_05_21_134500_add_salt_to_ims_yz_area_dividend_agent_table.php
create mode 100644 plugins/area-dividend/migrations/2020_10_27_134500_add_order_id_to_ims_yz_area_dividend_table.php
create mode 100644 plugins/area-dividend/migrations/2021_03_01_113023_add_pid_to_yz_area_dividend_order.php
create mode 100644 plugins/area-dividend/migrations/2021_05_10_115850_add_investor_uid_to_yz_area_dividend_agent_table.php
create mode 100644 plugins/area-dividend/migrations/2021_10_15_104444_update_yz_goods_area_dividend_table20211015.php
create mode 100644 plugins/area-dividend/package.json
create mode 100644 plugins/area-dividend/src/Frontend/Services/IncomePageService.php
create mode 100644 plugins/area-dividend/src/Listener/CreatedCommissionListener.php
create mode 100644 plugins/area-dividend/src/Listener/OrderCreatedListener--old.php
create mode 100644 plugins/area-dividend/src/Listener/OrderCreatedListener.php
create mode 100644 plugins/area-dividend/src/Listener/OrderCreatedOldListener.php
create mode 100644 plugins/area-dividend/src/Listener/OrderFailureListener.php
create mode 100644 plugins/area-dividend/src/Listener/OrderReceiveListener.php
create mode 100644 plugins/area-dividend/src/PluginApplication.php
create mode 100644 plugins/area-dividend/src/admin/AgentController.php
create mode 100644 plugins/area-dividend/src/admin/AreaDividendSetController.php
create mode 100644 plugins/area-dividend/src/admin/DividendController.php
create mode 100644 plugins/area-dividend/src/admin/FixController.php
create mode 100644 plugins/area-dividend/src/admin/modules/dividend/Repair.php
create mode 100644 plugins/area-dividend/src/admin/modules/dividend/WrongDataRepair.php
create mode 100644 plugins/area-dividend/src/api/AreaDividendController.php
create mode 100644 plugins/area-dividend/src/api/PaymentCodeController.php
create mode 100644 plugins/area-dividend/src/area/AreaOrderController.php
create mode 100644 plugins/area-dividend/src/area/AreaShopController.php
create mode 100644 plugins/area-dividend/src/area/BatchSendController.php
create mode 100644 plugins/area-dividend/src/area/CommonController.php
create mode 100644 plugins/area-dividend/src/area/DividendLogController.php
create mode 100644 plugins/area-dividend/src/area/OrderDetailController.php
create mode 100644 plugins/area-dividend/src/area/OrderManageController.php
create mode 100644 plugins/area-dividend/src/area/ReturnAddressController.php
create mode 100644 plugins/area-dividend/src/area/StoreOrderManageController.php
create mode 100644 plugins/area-dividend/src/event/AreaDividendEvent.php
create mode 100644 plugins/area-dividend/src/event/CreatedAreaDividendBonusEvent.php
create mode 100644 plugins/area-dividend/src/event/SettleAreaDividendBonusEvent.php
create mode 100644 plugins/area-dividend/src/models/AgentOrder.php
create mode 100644 plugins/area-dividend/src/models/AreaDividend.php
create mode 100644 plugins/area-dividend/src/models/AreaDividendAgent.php
create mode 100644 plugins/area-dividend/src/models/AreaDividendGoods.php
create mode 100644 plugins/area-dividend/src/models/Lock.php
create mode 100644 plugins/area-dividend/src/models/Order.php
create mode 100644 plugins/area-dividend/src/models/area/AreaStoreShop.php
create mode 100644 plugins/area-dividend/src/models/area/Order.php
create mode 100644 plugins/area-dividend/src/models/area/SupplierOrder.php
create mode 100644 plugins/area-dividend/src/models/expansions/GoodsExpansions.php
create mode 100644 plugins/area-dividend/src/models/weiqing/UsersPermission.php
create mode 100644 plugins/area-dividend/src/models/weiqing/WeiQingUsers.php
create mode 100644 plugins/area-dividend/src/services/AgentService.php
create mode 100644 plugins/area-dividend/src/services/AreaDividendGetService.php
create mode 100644 plugins/area-dividend/src/services/MessageService.php
create mode 100644 plugins/area-dividend/src/services/OrderCreatedNewService.php
create mode 100644 plugins/area-dividend/src/services/OrderCreatedService.php
create mode 100644 plugins/area-dividend/src/services/ReturnFormatService.php
create mode 100644 plugins/area-dividend/src/services/TimedTaskService.php
create mode 100644 plugins/area-dividend/src/widgets/AreaDividendWithdrawWidget.php
create mode 100644 plugins/area-dividend/src/widgets/DividendVueWidget.php
create mode 100644 plugins/area-dividend/src/widgets/DividendWidget.php
create mode 100644 plugins/area-dividend/views/admin/apply.blade.php
create mode 100644 plugins/area-dividend/views/admin/change-pwd.blade.php
create mode 100644 plugins/area-dividend/views/admin/create-agent.blade.php
create mode 100644 plugins/area-dividend/views/admin/dividend-detail.blade.php
create mode 100644 plugins/area-dividend/views/admin/dividend-list.blade.php
create mode 100644 plugins/area-dividend/views/admin/goods.blade.php
create mode 100644 plugins/area-dividend/views/admin/list.blade.php
create mode 100644 plugins/area-dividend/views/admin/set.blade.php
create mode 100644 plugins/area-dividend/views/admin/tabs.blade.php
create mode 100644 plugins/area-dividend/views/admin/tpl/agreement.blade.php
create mode 100644 plugins/area-dividend/views/admin/tpl/apply_background.blade.php
create mode 100644 plugins/area-dividend/views/admin/tpl/area_dividend.blade.php
create mode 100644 plugins/area-dividend/views/admin/tpl/notice.blade.php
create mode 100644 plugins/area-dividend/views/admin/tpl/range_commission.blade.php
create mode 100644 plugins/area-dividend/views/admin/tpl/settle.blade.php
create mode 100644 plugins/area-dividend/views/admin/tpl/supplier.blade.php
create mode 100644 plugins/area-dividend/views/admin/withdraw-set.blade.php
create mode 100644 plugins/area-dividend/views/area/area-shop.blade.php
create mode 100644 plugins/area-dividend/views/area/dividend-list.blade.php
create mode 100644 plugins/area-dividend/views/area/order-list.blade.php
create mode 100644 plugins/area-dividend/views/area/order/basicDetail.blade.php
create mode 100644 plugins/area-dividend/views/area/order/batch_send.blade.php
create mode 100644 plugins/area-dividend/views/area/order/detail.blade.php
create mode 100644 plugins/area-dividend/views/area/order/list.blade.php
create mode 100644 plugins/area-dividend/views/area/order/modals.blade.php
create mode 100644 plugins/area-dividend/views/area/order/ops.blade.php
create mode 100644 plugins/area-dividend/views/area/order/store-detail.blade.php
create mode 100644 plugins/area-dividend/views/area/order/store-list.blade.php
create mode 100644 plugins/area-dividend/views/area/order/storeBasicDetail.blade.php
create mode 100644 plugins/area-dividend/views/area/refund/index.blade.php
create mode 100644 plugins/area-dividend/views/area/refund/modal.blade.php
create mode 100644 plugins/area-dividend/views/area/refund/modal_base.blade.php
create mode 100644 plugins/area-dividend/views/area/refund/modal_exchange_goods.blade.php
create mode 100644 plugins/area-dividend/views/area/refund/modal_refund_money.blade.php
create mode 100644 plugins/area-dividend/views/area/refund/modal_return_goods.blade.php
create mode 100644 plugins/area-dividend/views/area/return/info.blade.php
create mode 100644 plugins/area-dividend/views/area/return/list.blade.php
create mode 100644 plugins/area-dividend/views/widget/profit/areaDividend.js
diff --git a/plugins/area-dividend/callbacks.php b/plugins/area-dividend/callbacks.php
new file mode 100644
index 00000000..c71f3e90
--- /dev/null
+++ b/plugins/area-dividend/callbacks.php
@@ -0,0 +1,10 @@
+ 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']);
+ },
+];
\ No newline at end of file
diff --git a/plugins/area-dividend/lang/en/locale.js b/plugins/area-dividend/lang/en/locale.js
new file mode 100644
index 00000000..c552f50f
--- /dev/null
+++ b/plugins/area-dividend/lang/en/locale.js
@@ -0,0 +1,8 @@
+
+"use strict";
+
+$.extend($.locales['en'], {
+ 'examplePlugin': {
+ test: "JavaScript i18n test: English"
+ }
+});
diff --git a/plugins/area-dividend/lang/en/test.php b/plugins/area-dividend/lang/en/test.php
new file mode 100644
index 00000000..8999558a
--- /dev/null
+++ b/plugins/area-dividend/lang/en/test.php
@@ -0,0 +1,5 @@
+'this is test title'
+];
\ No newline at end of file
diff --git a/plugins/area-dividend/lang/zh-CN/index.php b/plugins/area-dividend/lang/zh-CN/index.php
new file mode 100644
index 00000000..a9d6fa57
--- /dev/null
+++ b/plugins/area-dividend/lang/zh-CN/index.php
@@ -0,0 +1,9 @@
+'区域分红',
+];
\ No newline at end of file
diff --git a/plugins/area-dividend/lang/zh-CN/locale.js b/plugins/area-dividend/lang/zh-CN/locale.js
new file mode 100644
index 00000000..2e54008e
--- /dev/null
+++ b/plugins/area-dividend/lang/zh-CN/locale.js
@@ -0,0 +1,6 @@
+
+$.extend($.locales['zh-CN'], {
+ 'examplePlugin': {
+ test: "JavaScript i18n test: 简体中文"
+ }
+});
diff --git a/plugins/area-dividend/lang/zh-CN/test.php b/plugins/area-dividend/lang/zh-CN/test.php
new file mode 100644
index 00000000..8c4c6823
--- /dev/null
+++ b/plugins/area-dividend/lang/zh-CN/test.php
@@ -0,0 +1,6 @@
+'测试标题',
+ 'name'=>'测试名字'
+];
\ No newline at end of file
diff --git a/plugins/area-dividend/migrations/2017_05_17_091956_create_ims_yz_goods_area_dividend_table.php b/plugins/area-dividend/migrations/2017_05_17_091956_create_ims_yz_goods_area_dividend_table.php
new file mode 100644
index 00000000..c71d2602
--- /dev/null
+++ b/plugins/area-dividend/migrations/2017_05_17_091956_create_ims_yz_goods_area_dividend_table.php
@@ -0,0 +1,41 @@
+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');
+ }
+
+}
diff --git a/plugins/area-dividend/migrations/2017_05_17_092418_create_ims_yz_area_dividend_agent_table.php b/plugins/area-dividend/migrations/2017_05_17_092418_create_ims_yz_area_dividend_agent_table.php
new file mode 100644
index 00000000..08711d5e
--- /dev/null
+++ b/plugins/area-dividend/migrations/2017_05_17_092418_create_ims_yz_area_dividend_agent_table.php
@@ -0,0 +1,57 @@
+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');
+ }
+
+}
diff --git a/plugins/area-dividend/migrations/2017_05_17_092752_create_ims_yz_area_dividend_table.php b/plugins/area-dividend/migrations/2017_05_17_092752_create_ims_yz_area_dividend_table.php
new file mode 100644
index 00000000..445bafed
--- /dev/null
+++ b/plugins/area-dividend/migrations/2017_05_17_092752_create_ims_yz_area_dividend_table.php
@@ -0,0 +1,54 @@
+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');
+ }
+
+}
diff --git a/plugins/area-dividend/migrations/2017_07_27_155310_add_has_dividend_to_yz_goods_area_dividend.php b/plugins/area-dividend/migrations/2017_07_27_155310_add_has_dividend_to_yz_goods_area_dividend.php
new file mode 100644
index 00000000..d2e8353d
--- /dev/null
+++ b/plugins/area-dividend/migrations/2017_07_27_155310_add_has_dividend_to_yz_goods_area_dividend.php
@@ -0,0 +1,39 @@
+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()
+ {
+ //
+ }
+}
diff --git a/plugins/area-dividend/migrations/2017_08_11_112810_add_has_dividend_rate_to_yz_goods_area_dividend.php b/plugins/area-dividend/migrations/2017_08_11_112810_add_has_dividend_rate_to_yz_goods_area_dividend.php
new file mode 100644
index 00000000..95195787
--- /dev/null
+++ b/plugins/area-dividend/migrations/2017_08_11_112810_add_has_dividend_rate_to_yz_goods_area_dividend.php
@@ -0,0 +1,36 @@
+decimal('has_dividend_rate', 10)->nullable()->default(0.00);
+ }
+ });
+ }
+
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ //
+ }
+}
diff --git a/plugins/area-dividend/migrations/2017_08_30_104524_edit_dividend_rate_to_yz_area_dividend.php b/plugins/area-dividend/migrations/2017_08_30_104524_edit_dividend_rate_to_yz_area_dividend.php
new file mode 100644
index 00000000..ff3786de
--- /dev/null
+++ b/plugins/area-dividend/migrations/2017_08_30_104524_edit_dividend_rate_to_yz_area_dividend.php
@@ -0,0 +1,42 @@
+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()
+ {
+ //
+ }
+}
diff --git a/plugins/area-dividend/migrations/2018_10_29_113023_add_plugin_id_to_yz_area_dividend_order.php b/plugins/area-dividend/migrations/2018_10_29_113023_add_plugin_id_to_yz_area_dividend_order.php
new file mode 100644
index 00000000..73b9979f
--- /dev/null
+++ b/plugins/area-dividend/migrations/2018_10_29_113023_add_plugin_id_to_yz_area_dividend_order.php
@@ -0,0 +1,40 @@
+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');
+ }
+ });
+ }
+ }
+}
diff --git a/plugins/area-dividend/migrations/2018_10_29_113023_add_user_to_yz_area_dividend_agent.php b/plugins/area-dividend/migrations/2018_10_29_113023_add_user_to_yz_area_dividend_agent.php
new file mode 100644
index 00000000..48949fdc
--- /dev/null
+++ b/plugins/area-dividend/migrations/2018_10_29_113023_add_user_to_yz_area_dividend_agent.php
@@ -0,0 +1,46 @@
+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');
+ }
+ });
+ }
+ }
+}
diff --git a/plugins/area-dividend/migrations/2018_10_30_104524_repair_dividend_data.php b/plugins/area-dividend/migrations/2018_10_30_104524_repair_dividend_data.php
new file mode 100644
index 00000000..2274549f
--- /dev/null
+++ b/plugins/area-dividend/migrations/2018_10_30_104524_repair_dividend_data.php
@@ -0,0 +1,29 @@
+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');
+ }
+
+}
diff --git a/plugins/area-dividend/migrations/2019_04_17_134500_add_manage_to_ims_yz_area_dividend_agent_table.php b/plugins/area-dividend/migrations/2019_04_17_134500_add_manage_to_ims_yz_area_dividend_agent_table.php
new file mode 100644
index 00000000..4769384b
--- /dev/null
+++ b/plugins/area-dividend/migrations/2019_04_17_134500_add_manage_to_ims_yz_area_dividend_agent_table.php
@@ -0,0 +1,36 @@
+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');
+ });
+ }
+}
diff --git a/plugins/area-dividend/migrations/2019_04_17_134501_add_ratio_to_ims_yz_area_dividend_agent_table.php b/plugins/area-dividend/migrations/2019_04_17_134501_add_ratio_to_ims_yz_area_dividend_agent_table.php
new file mode 100644
index 00000000..4930be40
--- /dev/null
+++ b/plugins/area-dividend/migrations/2019_04_17_134501_add_ratio_to_ims_yz_area_dividend_agent_table.php
@@ -0,0 +1,40 @@
+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();
+ });
+ }
+}
diff --git a/plugins/area-dividend/migrations/2019_04_17_134511_create_ims_yz_area_dividend_order_table.php b/plugins/area-dividend/migrations/2019_04_17_134511_create_ims_yz_area_dividend_order_table.php
new file mode 100644
index 00000000..894b34bc
--- /dev/null
+++ b/plugins/area-dividend/migrations/2019_04_17_134511_create_ims_yz_area_dividend_order_table.php
@@ -0,0 +1,38 @@
+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');
+ }
+}
diff --git a/plugins/area-dividend/migrations/2019_08_11_114007_create_ims_yz_area_dividend_lock_table.php b/plugins/area-dividend/migrations/2019_08_11_114007_create_ims_yz_area_dividend_lock_table.php
new file mode 100644
index 00000000..86fdde61
--- /dev/null
+++ b/plugins/area-dividend/migrations/2019_08_11_114007_create_ims_yz_area_dividend_lock_table.php
@@ -0,0 +1,50 @@
+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');
+ }
+
+}
diff --git a/plugins/area-dividend/migrations/2020_05_21_134500_add_salt_to_ims_yz_area_dividend_agent_table.php b/plugins/area-dividend/migrations/2020_05_21_134500_add_salt_to_ims_yz_area_dividend_agent_table.php
new file mode 100644
index 00000000..27932e9d
--- /dev/null
+++ b/plugins/area-dividend/migrations/2020_05_21_134500_add_salt_to_ims_yz_area_dividend_agent_table.php
@@ -0,0 +1,56 @@
+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');
+ });
+ }
+}
diff --git a/plugins/area-dividend/migrations/2020_10_27_134500_add_order_id_to_ims_yz_area_dividend_table.php b/plugins/area-dividend/migrations/2020_10_27_134500_add_order_id_to_ims_yz_area_dividend_table.php
new file mode 100644
index 00000000..c2f44a41
--- /dev/null
+++ b/plugins/area-dividend/migrations/2020_10_27_134500_add_order_id_to_ims_yz_area_dividend_table.php
@@ -0,0 +1,48 @@
+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');
+ });
+ }
+}
diff --git a/plugins/area-dividend/migrations/2021_03_01_113023_add_pid_to_yz_area_dividend_order.php b/plugins/area-dividend/migrations/2021_03_01_113023_add_pid_to_yz_area_dividend_order.php
new file mode 100644
index 00000000..e4cd1cac
--- /dev/null
+++ b/plugins/area-dividend/migrations/2021_03_01_113023_add_pid_to_yz_area_dividend_order.php
@@ -0,0 +1,41 @@
+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');
+ }
+ });
+ }
+ }
+}
diff --git a/plugins/area-dividend/migrations/2021_05_10_115850_add_investor_uid_to_yz_area_dividend_agent_table.php b/plugins/area-dividend/migrations/2021_05_10_115850_add_investor_uid_to_yz_area_dividend_agent_table.php
new file mode 100644
index 00000000..be7d95d5
--- /dev/null
+++ b/plugins/area-dividend/migrations/2021_05_10_115850_add_investor_uid_to_yz_area_dividend_agent_table.php
@@ -0,0 +1,34 @@
+integer('investor_uid')->default(0)->comment('招商专员会员ID');
+ }
+ });
+ }
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ //
+ }
+}
diff --git a/plugins/area-dividend/migrations/2021_10_15_104444_update_yz_goods_area_dividend_table20211015.php b/plugins/area-dividend/migrations/2021_10_15_104444_update_yz_goods_area_dividend_table20211015.php
new file mode 100644
index 00000000..3dce48c2
--- /dev/null
+++ b/plugins/area-dividend/migrations/2021_10_15_104444_update_yz_goods_area_dividend_table20211015.php
@@ -0,0 +1,65 @@
+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');
+ }
+ });
+ }
+ }
+}
diff --git a/plugins/area-dividend/package.json b/plugins/area-dividend/package.json
new file mode 100644
index 00000000..f0fd5fec
--- /dev/null
+++ b/plugins/area-dividend/package.json
@@ -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"
+}
\ No newline at end of file
diff --git a/plugins/area-dividend/src/Frontend/Services/IncomePageService.php b/plugins/area-dividend/src/Frontend/Services/IncomePageService.php
new file mode 100644
index 00000000..03a873d9
--- /dev/null
+++ b/plugins/area-dividend/src/Frontend/Services/IncomePageService.php
@@ -0,0 +1,146 @@
+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;
+ }
+}
diff --git a/plugins/area-dividend/src/Listener/CreatedCommissionListener.php b/plugins/area-dividend/src/Listener/CreatedCommissionListener.php
new file mode 100644
index 00000000..ee13ea19
--- /dev/null
+++ b/plugins/area-dividend/src/Listener/CreatedCommissionListener.php
@@ -0,0 +1,203 @@
+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();
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/plugins/area-dividend/src/Listener/OrderCreatedListener--old.php b/plugins/area-dividend/src/Listener/OrderCreatedListener--old.php
new file mode 100644
index 00000000..f1715d5f
--- /dev/null
+++ b/plugins/area-dividend/src/Listener/OrderCreatedListener--old.php
@@ -0,0 +1,397 @@
+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();
+ }
+
+
+}
diff --git a/plugins/area-dividend/src/Listener/OrderCreatedListener.php b/plugins/area-dividend/src/Listener/OrderCreatedListener.php
new file mode 100644
index 00000000..d345758c
--- /dev/null
+++ b/plugins/area-dividend/src/Listener/OrderCreatedListener.php
@@ -0,0 +1,179 @@
+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();
+ }
+
+
+}
diff --git a/plugins/area-dividend/src/Listener/OrderCreatedOldListener.php b/plugins/area-dividend/src/Listener/OrderCreatedOldListener.php
new file mode 100644
index 00000000..3f69394c
--- /dev/null
+++ b/plugins/area-dividend/src/Listener/OrderCreatedOldListener.php
@@ -0,0 +1,397 @@
+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();
+ }
+
+
+}
diff --git a/plugins/area-dividend/src/Listener/OrderFailureListener.php b/plugins/area-dividend/src/Listener/OrderFailureListener.php
new file mode 100644
index 00000000..6b68c5d0
--- /dev/null
+++ b/plugins/area-dividend/src/Listener/OrderFailureListener.php
@@ -0,0 +1,42 @@
+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);
+ }
+}
\ No newline at end of file
diff --git a/plugins/area-dividend/src/Listener/OrderReceiveListener.php b/plugins/area-dividend/src/Listener/OrderReceiveListener.php
new file mode 100644
index 00000000..278d667f
--- /dev/null
+++ b/plugins/area-dividend/src/Listener/OrderReceiveListener.php
@@ -0,0 +1,75 @@
+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);
+ }
+ }
+}
diff --git a/plugins/area-dividend/src/PluginApplication.php b/plugins/area-dividend/src/PluginApplication.php
new file mode 100644
index 00000000..054c5762
--- /dev/null
+++ b/plugins/area-dividend/src/PluginApplication.php
@@ -0,0 +1,530 @@
+ [
+ '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]);
+ });
+ }
+}
+
diff --git a/plugins/area-dividend/src/admin/AgentController.php b/plugins/area-dividend/src/admin/AgentController.php
new file mode 100644
index 00000000..fbed41d7
--- /dev/null
+++ b/plugins/area-dividend/src/admin/AgentController.php
@@ -0,0 +1,467 @@
+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文件上传错误");
+ }
+
+}
\ No newline at end of file
diff --git a/plugins/area-dividend/src/admin/AreaDividendSetController.php b/plugins/area-dividend/src/admin/AreaDividendSetController.php
new file mode 100644
index 00000000..824e74e8
--- /dev/null
+++ b/plugins/area-dividend/src/admin/AreaDividendSetController.php
@@ -0,0 +1,56 @@
+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();
+
+ }
+}
\ No newline at end of file
diff --git a/plugins/area-dividend/src/admin/DividendController.php b/plugins/area-dividend/src/admin/DividendController.php
new file mode 100644
index 00000000..d08798de
--- /dev/null
+++ b/plugins/area-dividend/src/admin/DividendController.php
@@ -0,0 +1,110 @@
+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'));
+ }
+
+
+}
\ No newline at end of file
diff --git a/plugins/area-dividend/src/admin/FixController.php b/plugins/area-dividend/src/admin/FixController.php
new file mode 100644
index 00000000..37785195
--- /dev/null
+++ b/plugins/area-dividend/src/admin/FixController.php
@@ -0,0 +1,55 @@
+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;
+ }
+}
\ No newline at end of file
diff --git a/plugins/area-dividend/src/admin/modules/dividend/Repair.php b/plugins/area-dividend/src/admin/modules/dividend/Repair.php
new file mode 100644
index 00000000..e9f02f32
--- /dev/null
+++ b/plugins/area-dividend/src/admin/modules/dividend/Repair.php
@@ -0,0 +1,37 @@
+',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);
+ });
+ }
+}
\ No newline at end of file
diff --git a/plugins/area-dividend/src/admin/modules/dividend/WrongDataRepair.php b/plugins/area-dividend/src/admin/modules/dividend/WrongDataRepair.php
new file mode 100644
index 00000000..6cbde560
--- /dev/null
+++ b/plugins/area-dividend/src/admin/modules/dividend/WrongDataRepair.php
@@ -0,0 +1,36 @@
+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 删除订单对应的分红日志
+ }
+}
\ No newline at end of file
diff --git a/plugins/area-dividend/src/api/AreaDividendController.php b/plugins/area-dividend/src/api/AreaDividendController.php
new file mode 100644
index 00000000..e56410da
--- /dev/null
+++ b/plugins/area-dividend/src/api/AreaDividendController.php
@@ -0,0 +1,369 @@
+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);
+ }
+
+
+}
diff --git a/plugins/area-dividend/src/api/PaymentCodeController.php b/plugins/area-dividend/src/api/PaymentCodeController.php
new file mode 100644
index 00000000..6fc68418
--- /dev/null
+++ b/plugins/area-dividend/src/api/PaymentCodeController.php
@@ -0,0 +1,125 @@
+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));
+ }
+ }
+
+
+}
diff --git a/plugins/area-dividend/src/area/AreaOrderController.php b/plugins/area-dividend/src/area/AreaOrderController.php
new file mode 100644
index 00000000..bb9a0963
--- /dev/null
+++ b/plugins/area-dividend/src/area/AreaOrderController.php
@@ -0,0 +1,169 @@
+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');
+ }
+}
\ No newline at end of file
diff --git a/plugins/area-dividend/src/area/AreaShopController.php b/plugins/area-dividend/src/area/AreaShopController.php
new file mode 100644
index 00000000..7356f2d7
--- /dev/null
+++ b/plugins/area-dividend/src/area/AreaShopController.php
@@ -0,0 +1,185 @@
+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;
+ }
+}
\ No newline at end of file
diff --git a/plugins/area-dividend/src/area/BatchSendController.php b/plugins/area-dividend/src/area/BatchSendController.php
new file mode 100644
index 00000000..d6355c8d
--- /dev/null
+++ b/plugins/area-dividend/src/area/BatchSendController.php
@@ -0,0 +1,210 @@
+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 = '
' . count($this->err_array) . '个订单发货失败,失败的订单编号:
';
+ foreach ($this->err_array as $k => $v )
+ {
+ $this->error_msg .= $v . ' ';
+ if (($num % 2) == 0)
+ {
+ $this->error_msg .= '
';
+ }
+ ++$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');
+ }
+}
\ No newline at end of file
diff --git a/plugins/area-dividend/src/area/CommonController.php b/plugins/area-dividend/src/area/CommonController.php
new file mode 100644
index 00000000..f933c633
--- /dev/null
+++ b/plugins/area-dividend/src/area/CommonController.php
@@ -0,0 +1,29 @@
+uid)->first();
+ if ($agent_model) {
+
+ $this->agent_model = $agent_model;
+ } else {
+ exit($this->message('您不是该区域管理者', '', 'error'));
+ }
+ }
+}
\ No newline at end of file
diff --git a/plugins/area-dividend/src/area/DividendLogController.php b/plugins/area-dividend/src/area/DividendLogController.php
new file mode 100644
index 00000000..caa64f29
--- /dev/null
+++ b/plugins/area-dividend/src/area/DividendLogController.php
@@ -0,0 +1,134 @@
+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');
+ }
+}
\ No newline at end of file
diff --git a/plugins/area-dividend/src/area/OrderDetailController.php b/plugins/area-dividend/src/area/OrderDetailController.php
new file mode 100644
index 00000000..bcf8bb3f
--- /dev/null
+++ b/plugins/area-dividend/src/area/OrderDetailController.php
@@ -0,0 +1,129 @@
+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();
+ }
+}
\ No newline at end of file
diff --git a/plugins/area-dividend/src/area/OrderManageController.php b/plugins/area-dividend/src/area/OrderManageController.php
new file mode 100644
index 00000000..09c70630
--- /dev/null
+++ b/plugins/area-dividend/src/area/OrderManageController.php
@@ -0,0 +1,260 @@
+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;
+ }
+}
\ No newline at end of file
diff --git a/plugins/area-dividend/src/area/ReturnAddressController.php b/plugins/area-dividend/src/area/ReturnAddressController.php
new file mode 100644
index 00000000..5d4dfd0b
--- /dev/null
+++ b/plugins/area-dividend/src/area/ReturnAddressController.php
@@ -0,0 +1,184 @@
+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');
+ }
+ }
+}
\ No newline at end of file
diff --git a/plugins/area-dividend/src/area/StoreOrderManageController.php b/plugins/area-dividend/src/area/StoreOrderManageController.php
new file mode 100644
index 00000000..ee532dd9
--- /dev/null
+++ b/plugins/area-dividend/src/area/StoreOrderManageController.php
@@ -0,0 +1,258 @@
+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;
+ }
+}
\ No newline at end of file
diff --git a/plugins/area-dividend/src/event/AreaDividendEvent.php b/plugins/area-dividend/src/event/AreaDividendEvent.php
new file mode 100644
index 00000000..7228df0c
--- /dev/null
+++ b/plugins/area-dividend/src/event/AreaDividendEvent.php
@@ -0,0 +1,47 @@
+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;
+ }
+}
\ No newline at end of file
diff --git a/plugins/area-dividend/src/event/CreatedAreaDividendBonusEvent.php b/plugins/area-dividend/src/event/CreatedAreaDividendBonusEvent.php
new file mode 100644
index 00000000..d1b03ffc
--- /dev/null
+++ b/plugins/area-dividend/src/event/CreatedAreaDividendBonusEvent.php
@@ -0,0 +1,14 @@
+settleDividend = $settleDividend;
+ }
+
+ /**
+ * @return AreaDividend
+ */
+ public function getSettleDividend()
+ {
+ return $this->settleDividend;
+ }
+
+}
\ No newline at end of file
diff --git a/plugins/area-dividend/src/models/AgentOrder.php b/plugins/area-dividend/src/models/AgentOrder.php
new file mode 100644
index 00000000..4ee9a5f8
--- /dev/null
+++ b/plugins/area-dividend/src/models/AgentOrder.php
@@ -0,0 +1,18 @@
+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;
+ }
+}
\ No newline at end of file
diff --git a/plugins/area-dividend/src/models/AreaDividendAgent.php b/plugins/area-dividend/src/models/AreaDividendAgent.php
new file mode 100644
index 00000000..2b2b1071
--- /dev/null
+++ b/plugins/area-dividend/src/models/AreaDividendAgent.php
@@ -0,0 +1,261 @@
+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();
+ }
+}
\ No newline at end of file
diff --git a/plugins/area-dividend/src/models/AreaDividendGoods.php b/plugins/area-dividend/src/models/AreaDividendGoods.php
new file mode 100644
index 00000000..4ebe74b8
--- /dev/null
+++ b/plugins/area-dividend/src/models/AreaDividendGoods.php
@@ -0,0 +1,88 @@
+ 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;
+ }
+}
\ No newline at end of file
diff --git a/plugins/area-dividend/src/models/Lock.php b/plugins/area-dividend/src/models/Lock.php
new file mode 100644
index 00000000..0e3866f4
--- /dev/null
+++ b/plugins/area-dividend/src/models/Lock.php
@@ -0,0 +1,104 @@
+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();
+ });
+ }
+}
\ No newline at end of file
diff --git a/plugins/area-dividend/src/models/Order.php b/plugins/area-dividend/src/models/Order.php
new file mode 100644
index 00000000..02fb97f8
--- /dev/null
+++ b/plugins/area-dividend/src/models/Order.php
@@ -0,0 +1,182 @@
+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;
+ }
+}
\ No newline at end of file
diff --git a/plugins/area-dividend/src/models/area/AreaStoreShop.php b/plugins/area-dividend/src/models/area/AreaStoreShop.php
new file mode 100644
index 00000000..63bc1b15
--- /dev/null
+++ b/plugins/area-dividend/src/models/area/AreaStoreShop.php
@@ -0,0 +1,45 @@
+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');
+ }
+}
\ No newline at end of file
diff --git a/plugins/area-dividend/src/models/area/Order.php b/plugins/area-dividend/src/models/area/Order.php
new file mode 100644
index 00000000..3a57e808
--- /dev/null
+++ b/plugins/area-dividend/src/models/area/Order.php
@@ -0,0 +1,182 @@
+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');
+ }
+
+}
\ No newline at end of file
diff --git a/plugins/area-dividend/src/models/area/SupplierOrder.php b/plugins/area-dividend/src/models/area/SupplierOrder.php
new file mode 100644
index 00000000..c030e341
--- /dev/null
+++ b/plugins/area-dividend/src/models/area/SupplierOrder.php
@@ -0,0 +1,29 @@
+belongsTo(Supplier::class, 'supplier_id', 'id');
+ }
+}
\ No newline at end of file
diff --git a/plugins/area-dividend/src/models/expansions/GoodsExpansions.php b/plugins/area-dividend/src/models/expansions/GoodsExpansions.php
new file mode 100644
index 00000000..d792f9de
--- /dev/null
+++ b/plugins/area-dividend/src/models/expansions/GoodsExpansions.php
@@ -0,0 +1,19 @@
+hasOne(AreaDividendGoods::class,'goods_id'));
+ return $model->hasOne(AreaDividendGoods::class,'goods_id');
+ }
+}
\ No newline at end of file
diff --git a/plugins/area-dividend/src/models/weiqing/UsersPermission.php b/plugins/area-dividend/src/models/weiqing/UsersPermission.php
new file mode 100644
index 00000000..e73f13ec
--- /dev/null
+++ b/plugins/area-dividend/src/models/weiqing/UsersPermission.php
@@ -0,0 +1,28 @@
+ ''
+ ];
+
+ public function __construct()
+ {
+ if (config('APP_Framework') == 'platform') {
+ $this->table = 'yz_users_permission';
+ }
+ }
+}
\ No newline at end of file
diff --git a/plugins/area-dividend/src/models/weiqing/WeiQingUsers.php b/plugins/area-dividend/src/models/weiqing/WeiQingUsers.php
new file mode 100644
index 00000000..849efdd5
--- /dev/null
+++ b/plugins/area-dividend/src/models/weiqing/WeiQingUsers.php
@@ -0,0 +1,164 @@
+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;
+ }
+}
\ No newline at end of file
diff --git a/plugins/area-dividend/src/services/AgentService.php b/plugins/area-dividend/src/services/AgentService.php
new file mode 100644
index 00000000..0160e73b
--- /dev/null
+++ b/plugins/area-dividend/src/services/AgentService.php
@@ -0,0 +1,82 @@
+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;
+ }
+ }
+}
\ No newline at end of file
diff --git a/plugins/area-dividend/src/services/AreaDividendGetService.php b/plugins/area-dividend/src/services/AreaDividendGetService.php
new file mode 100644
index 00000000..a32a1727
--- /dev/null
+++ b/plugins/area-dividend/src/services/AreaDividendGetService.php
@@ -0,0 +1,33 @@
+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;
+ }
+}
\ No newline at end of file
diff --git a/plugins/area-dividend/src/services/MessageService.php b/plugins/area-dividend/src/services/MessageService.php
new file mode 100644
index 00000000..edf17688
--- /dev/null
+++ b/plugins/area-dividend/src/services/MessageService.php
@@ -0,0 +1,110 @@
+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);
+ }
+
+}
\ No newline at end of file
diff --git a/plugins/area-dividend/src/services/OrderCreatedNewService.php b/plugins/area-dividend/src/services/OrderCreatedNewService.php
new file mode 100644
index 00000000..d664fe1b
--- /dev/null
+++ b/plugins/area-dividend/src/services/OrderCreatedNewService.php
@@ -0,0 +1,497 @@
+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;
+ }
+}
\ No newline at end of file
diff --git a/plugins/area-dividend/src/services/OrderCreatedService.php b/plugins/area-dividend/src/services/OrderCreatedService.php
new file mode 100644
index 00000000..7075d415
--- /dev/null
+++ b/plugins/area-dividend/src/services/OrderCreatedService.php
@@ -0,0 +1,316 @@
+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;
+ }
+
+}
\ No newline at end of file
diff --git a/plugins/area-dividend/src/services/ReturnFormatService.php b/plugins/area-dividend/src/services/ReturnFormatService.php
new file mode 100644
index 00000000..01f115e4
--- /dev/null
+++ b/plugins/area-dividend/src/services/ReturnFormatService.php
@@ -0,0 +1,60 @@
+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));
+ }
+}
\ No newline at end of file
diff --git a/plugins/area-dividend/src/services/TimedTaskService.php b/plugins/area-dividend/src/services/TimedTaskService.php
new file mode 100644
index 00000000..d9da90fb
--- /dev/null
+++ b/plugins/area-dividend/src/services/TimedTaskService.php
@@ -0,0 +1,216 @@
+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;
+ }
+}
\ No newline at end of file
diff --git a/plugins/area-dividend/src/widgets/AreaDividendWithdrawWidget.php b/plugins/area-dividend/src/widgets/AreaDividendWithdrawWidget.php
new file mode 100644
index 00000000..809d897c
--- /dev/null
+++ b/plugins/area-dividend/src/widgets/AreaDividendWithdrawWidget.php
@@ -0,0 +1,22 @@
+ '', 'poundage_rate' => '']);
+ return view('Yunshop\AreaDividend::admin.withdraw-set', [
+ 'set' => $set,
+ ])->render();
+ }
+}
\ No newline at end of file
diff --git a/plugins/area-dividend/src/widgets/DividendVueWidget.php b/plugins/area-dividend/src/widgets/DividendVueWidget.php
new file mode 100644
index 00000000..6a523746
--- /dev/null
+++ b/plugins/area-dividend/src/widgets/DividendVueWidget.php
@@ -0,0 +1,66 @@
+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/');
+ }
+
+
+}
\ No newline at end of file
diff --git a/plugins/area-dividend/src/widgets/DividendWidget.php b/plugins/area-dividend/src/widgets/DividendWidget.php
new file mode 100644
index 00000000..40e920f8
--- /dev/null
+++ b/plugins/area-dividend/src/widgets/DividendWidget.php
@@ -0,0 +1,25 @@
+goods_id);
+ return view('Yunshop\AreaDividend::admin.goods', [
+ 'set' => $set,
+ 'item' => $item,
+ ])->render();
+ }
+}
\ No newline at end of file
diff --git a/plugins/area-dividend/views/admin/apply.blade.php b/plugins/area-dividend/views/admin/apply.blade.php
new file mode 100644
index 00000000..d0f50169
--- /dev/null
+++ b/plugins/area-dividend/views/admin/apply.blade.php
@@ -0,0 +1,104 @@
+@extends('layouts.base')
+
+@section('content')
+@section('title', trans('区域代理申请'))
+
| ID | +会员 | +姓名手机 | +申请区域 | +申请时间 | +状态 | +审核 | +
|---|---|---|---|---|---|---|
| {{$row['id']}} | + +
+ |
+
+ + {{$row['real_name']}} + + {{$row['mobile']}} + | + ++ @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 + | + ++ {{$row['created_at']}} + | ++ {{$row['status_name']}} + | + ++ + | +
| ID | +分红时间 | +区域代理 | +姓名 手机 |
+ 区域等级 | +代理区域 | +订单号 | +订单金额 | +分红结算金额 | +分红比例 | +下级分红比例 | +分红金额 | +分红状态 | + +
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| {{$row['id']}} | +{{$row['created_at']}} | +
+
+ |
+ + + {{$row['has_one_member']['realname']}} + {{$row['has_one_member']['mobile']}} + + | +{{$row['level_name']}} | +{{$row['agent_area']}} | ++ + {{$row['order_sn']}} + + | + +{{$row['order_amount']}} | +{{$row['amount']}} | + +{{$row['dividend_rate']}}% | +{{$row['lower_level_rate']}}% | + ++ + {{$row['dividend_amount']}} + + | +{{$row['status_name']}} | +
| ID | +代理名称 | +会员信息 | +成为代理时间 | +申请区域 | +申请等级 | +消费总额 | +分红比例 | +累计结算金额 | +已结算分红佣金 | +未结算分红佣金 | +操作 | +
|---|---|---|---|---|---|---|---|---|---|---|---|
| {{$row['id']}} | +{{$row['title']}} | ++ + + + | +{{date("Y-m-d H:i",$row['agent_at'])}} | ++ + + @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 + + + + | +{{$row['level_name']}} | +{{$row['has_one_dividend']['total_order_amount'] ?: '0.00'}} | +{{$row['ratio']}}% | +{{$row['has_one_dividend']['total_amount'] ?: '0.00'}} | +{{$row['has_one_dividend']['settle'] ?: '0.00'}} | +{{$row['has_one_dividend']['unsettled'] ?: '0.00'}} | ++ + + | +
建议尺寸750*306
+| 商家ID | +入驻时间 | +所在区域 | +店长信息 | +店铺名称 | +门店分类 | +累计收款金额(元) | + + +
|---|---|---|---|---|---|---|
| {{$row['id']}} | +{{$row['created_at']}} | ++ {{$row['full_address']}} + | +
+ + @if ($row->hasOneMember->nickname) {{$row->hasOneMember->nickname}} @else {{$row->hasOneMember->mobile}} @endif + |
+
+ + {{$row->store_name}} + |
+ {{$row->hasOneCategory->name}} | +
+ 门店:{{$row->hasManyStoreOrder->sum('amount')}}
+ + 收银台:{{$row->hasManyCashierOrder->sum('amount')}} + |
+
| ID | +分红时间 | +订单号 | +订单金额(元) | +分红结算金额 | +分红比例 | +下级分红比例 | +分红金额 | +分红金额 | + + +
|---|---|---|---|---|---|---|---|---|
| {{$row->id}} | +{{$row->created_at }} | +{{$row->order_sn}} | +{{$row->order_amount}} | +{{$row->amount}} | +{{$row->dividend_rate}}% | +{{$row->lower_level_rate}}% | +{{$row->dividend_amount}} | +{{$row->status_name}} | +
| 时间 | +订单号 | +收货人 手机号码 |
+ 订单地址 | +订单类型 | +店铺名称 | +订单金额(元) | +区域代理结算金额 | + + +|
|---|---|---|---|---|---|---|---|---|
| {{$row['id']}} | --}} +{{ date('Y-m-d H:i:s', $row['created_at'])}} | +{{$row['order_sn']}} | +{{$row['address']['realname']}} {{$row['address']['mobile']}} |
+ + {{$row['address']['address']}} + | +{{$row['plugin_name']}} | ++ @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 + + | +{{$row['price']}} | ++ @if ($row['has_one_area_dividend']) + {{$row['has_one_area_dividend']['amount']}} + @else + 无分红 + @endif + | +
{{$order['order_sn']}}
+| 商品小计: | ++ ¥{{number_format( $order['order_goods_price'] ,2)}} | +
| 优惠: | ++ ¥{{number_format( $order['discount_price'] ,2)}} | +
| 抵扣: | ++ - ¥{{number_format( $order['deduction_price'] ,2)}} | +
| 运费: | ++ ¥{{number_format( $order['dispatch_price'] ,2)}} | +
| 应收款: | ++ ¥{{number_format($order['price'],2)}} | +
+ {{$order['status_name']}} +
++ + {{$order['pay_type_name']}} + {{--@if(count($order['order_pays'])) + 查看支付记录 + @endif--}} +
+ +{{$order['create_time']}}
+{{$order['pay_time']}}
+{{$order['send_time']}}
+{{$order['finish_time']}}
+| 优惠名称 | +优惠金额 | +
|---|---|
| {{$discount['name']}} | +¥{{$discount['amount']}} | +
| 名称 | +抵扣值 | +抵扣金额 | +
|---|---|---|
| {{$deduction['name']}} | +{{$deduction['coin']}} | +¥{{$deduction['amount']}} | +
| 名称 | +优惠金额 | +
|---|---|
| {{$coupon['name']}} | +¥{{$coupon['amount']}} | +
+ {{ $div_from['member_name'] }} +
++ {{ $div_from['member_card'] }} +
+| ID | +商品标题 | +商品规格 | +现价/原价/成本价 | +购买数量 | + {{--折扣前 折扣后 | --}}
+ 操作 | +|||
|---|---|---|---|---|---|---|---|---|---|
| {{$order_goods['goods_id']}} | ++ {{--{{$order_goods['title']}}--}} + {{$order_goods['title']}} + | +{{$order_goods['goods_option_title']}} | +{{$order_goods['goods_price']}} + /{{$order_goods['goods_market_price']}} + /{{$order_goods['goods_cost_price']}}元 + | +{{$order_goods['total']}} | + {{--{{sprintf('%.2f', $order_goods['goods_price']/$order_goods['total'])}}--}}
+ {{-- {{sprintf('%.2f', $order_goods['payment_amount']/$order_goods['total'])}}--}} + {{-- | --}}
+ + {{-- --}} + 无权限 + | +|||
| + @include('Yunshop\AreaDividend::area.order.modals') + @include($ops) + | ++ | +||||||||
| + 订单数: {{$list['total']}} + 订单金额: {{$total_price}}元 + @section('supplier_apply') + + @show + | +
| + 订单编号: {{$order['order_sn']}} + @if($order['status']>\app\common\models\Order::WAIT_PAY && isset($order['has_one_order_pay'])) + 支付单号: {{$order['has_one_order_pay']['pay_sn']}} + @endif + 下单时间: {{$order['create_time']}} + @if( $order['has_one_refund_apply'] == \app\common\models\refund\RefundApply::WAIT_RECEIVE_RETURN_GOODS) + @endif + + + + @if(!empty($order['has_one_refund_apply'])) + + @endif + + + | + {{--@if(empty($order['status'])) + 关闭订单 + @endif--}} + + | + + +|||||||
|
+ |
+
+ {{--{{$order_goods['title']}}--}}
+ {{$order_goods['title']}}
+ @if( !empty($order_goods['goods_option_title'])) + {{$order_goods['goods_option_title']}} + + @endif + {{$order_goods['goods_sn']}} + + |
+
+ 原价: {{ number_format($order_goods['goods_price']/$order_goods['total'],2)}}
+ 应付: {{ number_format($order_goods['price']/$order_goods['total'],2) }} + 数量: {{$order_goods['total']}} + |
+
+
+ @if( $order_goods_index == 0)
+
+ {{-- {{$order['belongs_to_member']['nickname']}}--}}
+ {{$order['belongs_to_member']['nickname']}}
+ + {{$order['belongs_to_member']['realname']}} + {{$order['belongs_to_member']['mobile']}} + |
+
+
+
+ + + {{$order['has_one_dispatch_type']['name']}} + |
+
+
|
+
+ + 查看详情 + |
+ + + @include($include_ops) + | + @endif +
| + 订单数: {{$list['total']}} + 订单金额: {{$total_price}}元 + @section('supplier_apply') + + @show + | +
| + 订单编号: {{$order['order_sn']}} + @if($order['status']>\app\common\models\Order::WAIT_PAY && isset($order['has_one_order_pay'])) + 支付单号: {{$order['has_one_order_pay']['pay_sn']}} + @endif + 下单时间: {{$order['create_time']}} + @if( $order['has_one_refund_apply'] == \app\common\models\refund\RefundApply::WAIT_RECEIVE_RETURN_GOODS) + @endif + + + + @if(!empty($order['has_one_refund_apply'])) + + @endif + + + | + {{--@if(empty($order['status'])) + 关闭订单 + @endif--}} + + | + + +|||||||
|
+ |
+
+ {{--{{$order_goods['title']}}--}}
+ {{$order_goods['title']}}
+ @if( !empty($order_goods['goods_option_title'])) + {{$order_goods['goods_option_title']}} + + @endif + {{$order_goods['goods_sn']}} + + |
+
+ 原价: {{ number_format($order_goods['goods_price']/$order_goods['total'],2)}}
+ 应付: {{ number_format($order_goods['price']/$order_goods['total'],2) }} + 数量: {{$order_goods['total']}} + |
+
+
+ @if( $order_goods_index == 0)
+
+ {{-- {{$order['belongs_to_member']['nickname']}}--}}
+ {{$order['belongs_to_member']['nickname']}}
+ + {{$order['belongs_to_member']['realname']}} + {{$order['belongs_to_member']['mobile']}} + |
+
+
+
+ + + {{$order['has_one_dispatch_type']['name']}} + |
+
+
|
+
+ + 查看详情 + |
+ + + {{--@include($include_ops)--}} + | + @endif +
{{$order['order_sn']}}
+| 商品小计: | ++ ¥{{number_format( $order['order_goods_price'] ,2)}} | +
| 优惠: | ++ ¥{{number_format( $order['discount_price'] ,2)}} | +
| 抵扣: | ++ - ¥{{number_format( $order['deduction_price'] ,2)}} | +
| 运费: | ++ ¥{{number_format( $order['dispatch_price'] ,2)}} | +
| 应收款: | ++ ¥{{number_format($order['price'],2)}} | +
+ {{$order['status_name']}} +
++ + {{$order['pay_type_name']}} + {{--@if(count($order['order_pays'])) + 查看支付记录 + @endif--}} +
+ +{{$order['create_time']}}
+{{$order['pay_time']}}
+{{$order['send_time']}}
+{{$order['finish_time']}}
+| 优惠名称 | +优惠金额 | +
|---|---|
| {{$discount['name']}} | +¥{{$discount['amount']}} | +
| 名称 | +抵扣值 | +抵扣金额 | +
|---|---|---|
| {{$deduction['name']}} | +{{$deduction['coin']}} | +¥{{$deduction['amount']}} | +
| 名称 | +优惠金额 | +
|---|---|
| {{$coupon['name']}} | +¥{{$coupon['amount']}} | +
+ {{ $div_from['member_name'] }} +
++ {{ $div_from['member_card'] }} +
+| ID | +商品标题 | +商品规格 | +现价/原价/成本价 | +购买数量 | + {{--折扣前 折扣后 | --}}
+ 操作 | +|||
|---|---|---|---|---|---|---|---|---|---|
| {{$order_goods['goods_id']}} | ++ {{--{{$order_goods['title']}}--}} + {{$order_goods['title']}} + | +{{$order_goods['goods_option_title']}} | +{{$order_goods['goods_price']}} + /{{$order_goods['goods_market_price']}} + /{{$order_goods['goods_cost_price']}}元 + | +{{$order_goods['total']}} | + {{--{{sprintf('%.2f', $order_goods['goods_price']/$order_goods['total'])}}--}}
+ {{-- {{sprintf('%.2f', $order_goods['payment_amount']/$order_goods['total'])}}--}} + {{-- | --}}
+ + {{-- --}} + 无权限 + | +|||
| --}} + {{--@include('order.modals')--}} + {{--@include($ops)--}} + {{-- | --}} + {{----}} + {{-- | --}} + {{--||||||||
@if ($order['has_one_refund_apply']['is_refunding']) + {{$order['has_one_refund_apply']['status_name']}} + @elseif ($order['has_one_refund_apply']['is_refund_fail']) + {{$order['has_one_refund_apply']['status_name']}} + + @elseif($order['has_one_refund_apply']['is_refunded']) + {{$order['has_one_refund_apply']['status_name']}} + @endif
+{{$order['has_one_refund_apply']['create_time']}} +
+{{$order['has_one_refund_apply']['refund_type_name']}}
+{{$order['has_one_refund_apply']['price']}}
+{{$order['has_one_refund_apply']['reason']}}
++ {!! empty($order['has_one_refund_apply']['content'])?'无':$order['has_one_refund_apply']['content'] !!}
++ @if($order['has_one_refund_apply']['refund_type'] != 0) + + 处理{{$order['has_one_refund_apply']['refund_type_name']}}申请 + + @else + + 无权处理订单退款 + + @endif +
+