diff --git a/addon/activity/api/controller/Goods.php b/addon/activity/api/controller/Goods.php
deleted file mode 100644
index a2903e2..0000000
--- a/addon/activity/api/controller/Goods.php
+++ /dev/null
@@ -1,139 +0,0 @@
-params[ 'id' ]) ? $this->params[ 'id' ] : 0;
- if (empty($activity_id)) {
- return $this->response($this->error('', '活动不存在活已过期'));
- }
- $groupbuy_model = new ActivityModel();
- $condition = [
- [ 'activity_id', '=', $activity_id ],
- [ 'site_id', '=', $this->site_id ],
- ];
- $goods_sku_detail = $groupbuy_model->getActivityInfo($condition)[ 'data' ];
-
- if (empty($goods_sku_detail)) return $this->response($this->error());
- $goods_sku_detail['goods_name']='这个超级优惠券';
- $goods_sku_detail['sku_images']=$goods_sku_detail['activity_image'];
- $goods_sku_detail['goods_service_ids']=[];
- $goods_sku_detail['goods_content']=$goods_sku_detail['content'];
- $goods_sku_detail['goods_stock']=9999;
- $goods_sku_detail['goods_state']=1;
- $res[ 'goods_sku_detail' ] = $goods_sku_detail;
- // 处理公共数据
- $goods_sku_api = new Goodssku();
- $goods_sku_api->handleGoodsDetailData($res[ 'goods_sku_detail' ]);
- return $this->response($this->success($res));
- }
-
- /**
- * 查询商品SKU集合
- * @return false|string
- */
- public function goodsSku()
- {
- $goods_id = isset($this->params[ 'goods_id' ]) ? $this->params[ 'goods_id' ] : 0;
- $groupbuy_id = isset($this->params[ 'groupbuy_id' ]) ? $this->params[ 'groupbuy_id' ] : 0;
- if (empty($goods_id)) {
- return $this->response($this->error('', 'REQUEST_ID'));
- }
- if (empty($groupbuy_id)) {
- return $this->response($this->error('', 'REQUEST_GROUPBUY_ID'));
- }
- $groupbuy_model = new GroupbuyModel();
- $condition = [
- [ 'pg.groupbuy_id', '=', $groupbuy_id ],
- [ 'pg.site_id', '=', $this->site_id ],
- [ 'g.goods_id', '=', $goods_id ],
- [ 'g.goods_state', '=', 1 ],
- [ 'g.is_delete', '=', 0 ]
- ];
- $list = $groupbuy_model->getGroupbuyGoodsSkuList($condition, null);
- return $this->response($list);
- }
-
- public function page()
- {
- $page = isset($this->params[ 'page' ]) ? $this->params[ 'page' ] : 1;
- $page_size = isset($this->params[ 'page_size' ]) ? $this->params[ 'page_size' ] : PAGE_LIST_ROWS;
- $goods_id_arr = isset($this->params[ 'goods_id_arr' ]) ? $this->params[ 'goods_id_arr' ] : '';//goods_id数组
-
- $condition = [
- [ 'pg.status', '=', 2 ],// 状态(1未开始 2进行中 3已结束)
- [ 'g.goods_stock', '>', 0 ],
- [ 'g.goods_state', '=', 1 ],
- [ 'g.is_delete', '=', 0 ],
- [ 'sku.site_id', '=', $this->site_id ]
- ];
-
- if (!empty($goods_id_arr)) {
- $condition[] = [ 'sku.goods_id', 'in', $goods_id_arr ];
- }
-
- $groupbuy_model = new GroupbuyModel();
- $list = $groupbuy_model->getGroupbuyGoodsPageList($condition, $page, $page_size, 'pg.groupbuy_id desc');
-
- return $this->response($list);
- }
-
- public function lists()
- {
- $num = isset($this->params[ 'num' ]) ? $this->params[ 'num' ] : 0;
-
- $condition = [
- [ 'pg.status', '=', 2 ],// 状态(1未开始 2进行中 3已结束)
- [ 'g.goods_stock', '>', 0 ],
- [ 'g.goods_state', '=', 1 ],
- [ 'g.is_delete', '=', 0 ],
- [ 'sku.site_id', '=', $this->site_id ]
- ];
-
- if (!empty($goods_id_arr)) {
- $condition[] = [ 'sku.goods_id', 'in', $goods_id_arr ];
- }
-
- $groupbuy_model = new GroupbuyModel();
- $list = $groupbuy_model->getGroupbuyGoodsList($condition, '', 'pg.groupbuy_id desc', $num);
-
- return $this->response($list);
- }
-
- /**
- * 获取商品海报
- */
- public function poster()
- {
- $this->checkToken();
-
- $promotion_type = 'groupbuy';
- $qrcode_param = json_decode($this->params[ 'qrcode_param' ], true);
- $qrcode_param[ 'source_member' ] = $this->member_id;
- $qrcode_param[ 'id' ] = $qrcode_param[ 'groupbuy_id' ] ?? 0;
- unset($qrcode_param[ 'groupbuy_id' ]);
- $poster = new Poster();
- $res = $poster->goods($this->params[ 'app_type' ], $this->params[ 'page' ], $qrcode_param, $promotion_type, $this->site_id);
- return $this->response($res);
- }
-}
diff --git a/addon/activity/api/controller/Ordercreate.php b/addon/activity/api/controller/Ordercreate.php
deleted file mode 100644
index df74088..0000000
--- a/addon/activity/api/controller/Ordercreate.php
+++ /dev/null
@@ -1,189 +0,0 @@
-checkToken();
- if ($token[ 'code' ] < 0) return $this->response($token);
- $order_create = new OrderCreateModel();
- $data = [
- 'groupbuy_id' => isset($this->params[ 'groupbuy_id' ]) ? $this->params[ 'groupbuy_id' ] : '',//团购id
- 'num' => isset($this->params[ 'num' ]) ? $this->params[ 'num' ] : 1,//商品数量(买几套)
- 'sku_id' => isset($this->params[ 'sku_id' ]) ? $this->params[ 'sku_id' ] : 0,//sku_id
- 'site_id' => $this->site_id,//站点id
- 'member_id' => $this->member_id,
- 'is_balance' => isset($this->params[ 'is_balance' ]) ? $this->params[ 'is_balance' ] : 0,//是否使用余额
- 'pay_password' => isset($this->params[ 'pay_password' ]) ? $this->params[ 'pay_password' ] : '',//支付密码
- 'order_from' => $this->params[ 'app_type' ],
- 'order_from_name' => $this->params[ 'app_type_name' ],
- 'buyer_message' => $this->params[ 'buyer_message' ] ?? '',
- 'delivery' => isset($this->params[ "delivery" ]) && !empty($this->params[ "delivery" ]) ? json_decode($this->params[ "delivery" ], true) : [],
- 'member_address' => isset($this->params[ "member_address" ]) && !empty($this->params[ "member_address" ]) ? json_decode($this->params[ "member_address" ], true) : [],
-
- 'latitude' => $this->params[ "latitude" ] ?? '',
- 'longitude' => $this->params[ "longitude" ] ?? '',
-
- 'is_invoice' => $this->params[ "is_invoice" ] ?? 0,
- 'invoice_type' => $this->params[ "invoice_type" ] ?? 0,
- 'invoice_title' => $this->params[ "invoice_title" ] ?? '',
- 'taxpayer_number' => $this->params[ "taxpayer_number" ] ?? '',
- 'invoice_content' => $this->params[ "invoice_content" ] ?? '',
- 'invoice_full_address' => $this->params[ "invoice_full_address" ] ?? '',
- 'is_tax_invoice' => $this->params[ "is_tax_invoice" ] ?? 0,
- 'invoice_email' => $this->params[ "invoice_email" ] ?? '',
- 'invoice_title_type' => $this->params[ "invoice_title_type" ] ?? 0,
- 'buyer_ask_delivery_time' => $this->params[ "buyer_ask_delivery_time" ] ?? '',
- 'form_data' => isset($this->params[ "form_data" ]) && !empty($this->params[ "form_data" ]) ? json_decode($this->params[ "form_data" ], true) : [],
- ];
- if (empty($data[ 'sku_id' ]) || empty($data[ 'groupbuy_id' ])) {
- return $this->response($this->error('', '缺少必填参数商品数据'));
- }
- if ($data[ 'num' ] < 1) {
- return $this->response($this->error('', '购买数量不能小于1'));
- }
- $res = $order_create->create($data);
- return $this->response($res);
- }
-
- /**
- * 门店自提情况下提交订单验证地址和门店库存
- */
- public function verifyAreaOrStock()
- {
- $token = $this->checkToken();
- if ($token[ 'code' ] < 0) return $this->response($token);
- $order_create = new OrderCreateModel();
- $data = [
- 'groupbuy_id' => isset($this->params[ 'groupbuy_id' ]) ? $this->params[ 'groupbuy_id' ] : '',//团购id
- 'num' => isset($this->params[ 'num' ]) ? $this->params[ 'num' ] : 1,//商品数量(买几套)
- 'sku_id' => isset($this->params[ 'sku_id' ]) ? $this->params[ 'sku_id' ] : 0,//sku_id
- 'site_id' => $this->site_id,//站点id
- 'member_id' => $this->member_id,
- 'is_balance' => isset($this->params[ 'is_balance' ]) ? $this->params[ 'is_balance' ] : 0,//是否使用余额
- 'pay_password' => isset($this->params[ 'pay_password' ]) ? $this->params[ 'pay_password' ] : '',//支付密码
- 'order_from' => $this->params[ 'app_type' ],
- 'order_from_name' => $this->params[ 'app_type_name' ],
- 'buyer_message' => $this->params[ 'buyer_message' ] ?? '',
- 'delivery' => isset($this->params[ "delivery" ]) && !empty($this->params[ "delivery" ]) ? json_decode($this->params[ "delivery" ], true) : [],
- 'member_address' => isset($this->params[ "member_address" ]) && !empty($this->params[ "member_address" ]) ? json_decode($this->params[ "member_address" ], true) : [],
-
- 'latitude' => $this->params[ "latitude" ] ?? '',
- 'longitude' => $this->params[ "longitude" ] ?? '',
-
- 'is_invoice' => $this->params[ "is_invoice" ] ?? 0,
- 'invoice_type' => $this->params[ "invoice_type" ] ?? 0,
- 'invoice_title' => $this->params[ "invoice_title" ] ?? '',
- 'taxpayer_number' => $this->params[ "taxpayer_number" ] ?? '',
- 'invoice_content' => $this->params[ "invoice_content" ] ?? '',
- 'invoice_full_address' => $this->params[ "invoice_full_address" ] ?? '',
- 'is_tax_invoice' => $this->params[ "is_tax_invoice" ] ?? 0,
- 'invoice_email' => $this->params[ "invoice_email" ] ?? '',
- 'invoice_title_type' => $this->params[ "invoice_title_type" ] ?? 0,
- 'buyer_ask_delivery_time' => $this->params[ "buyer_ask_delivery_time" ] ?? '',
- ];
- if (empty($data[ 'sku_id' ]) || empty($data[ 'groupbuy_id' ])) {
- return $this->response($this->error('', '缺少必填参数商品数据'));
- }
- $res = $order_create->verifyAreaOrStock($data);
- return $this->response($res);
- }
-
- /**
- * 计算信息
- */
- public function calculate()
- {
- $token = $this->checkToken();
- if ($token[ 'code' ] < 0) return $this->response($token);
- $order_create = new OrderCreateModel();
- $data = [
- 'groupbuy_id' => isset($this->params[ 'groupbuy_id' ]) ? $this->params[ 'groupbuy_id' ] : '',//团购id
- 'num' => isset($this->params[ 'num' ]) ? $this->params[ 'num' ] : 1,//商品数量(买几套)
- 'sku_id' => isset($this->params[ 'sku_id' ]) ? $this->params[ 'sku_id' ] : 0,//sku_id
- 'member_id' => $this->member_id,
- 'site_id' => $this->site_id,//站点id
- 'is_balance' => isset($this->params[ 'is_balance' ]) ? $this->params[ 'is_balance' ] : 0,//是否使用余额
- 'order_from' => $this->params[ 'app_type' ],
- 'order_from_name' => $this->params[ 'app_type_name' ],
- 'delivery' => isset($this->params[ "delivery" ]) && !empty($this->params[ "delivery" ]) ? json_decode($this->params[ "delivery" ], true) : [],
- 'member_address' => isset($this->params[ "member_address" ]) && !empty($this->params[ "member_address" ]) ? json_decode($this->params[ "member_address" ], true) : [],
-
- 'latitude' => $this->params[ "latitude" ] ?? '',
- 'longitude' => $this->params[ "longitude" ] ?? '',
-
- 'is_invoice' => $this->params[ "is_invoice" ] ?? 0,
- 'invoice_type' => $this->params[ "invoice_type" ] ?? 0,
- 'invoice_title' => $this->params[ "invoice_title" ] ?? '',
- 'taxpayer_number' => $this->params[ "taxpayer_number" ] ?? '',
- 'invoice_content' => $this->params[ "invoice_content" ] ?? '',
- 'invoice_full_address' => $this->params[ "invoice_full_address" ] ?? '',
- 'is_tax_invoice' => $this->params[ "is_tax_invoice" ] ?? 0,
- 'invoice_email' => $this->params[ "invoice_email" ] ?? '',
- 'invoice_title_type' => $this->params[ "invoice_title_type" ] ?? 0,
- 'buyer_ask_delivery_time' => $this->params[ "buyer_ask_delivery_time" ] ?? '',
- ];
- if (empty($data[ 'sku_id' ]) || empty($data[ 'groupbuy_id' ])) {
- return $this->response($this->error('', '缺少必填参数商品数据'));
- }
- $res = $order_create->calculate($data);
- return $this->response($this->success($res));
- }
-
- /**
- * 待支付订单 数据初始化
- * @return string
- */
- public function payment()
- {
- $token = $this->checkToken();
- if ($token[ 'code' ] < 0) return $this->response($token);
- $order_create = new OrderCreateModel();
- $data = [
- 'groupbuy_id' => isset($this->params[ 'groupbuy_id' ]) ? $this->params[ 'groupbuy_id' ] : '',//团购id
- 'num' => isset($this->params[ 'num' ]) ? $this->params[ 'num' ] : 1,//商品数量(买几套)
- 'sku_id' => isset($this->params[ 'sku_id' ]) ? $this->params[ 'sku_id' ] : 0,//sku_id
- 'member_id' => $this->member_id,
- 'site_id' => $this->site_id,//站点id
- 'is_balance' => isset($this->params[ 'is_balance' ]) ? $this->params[ 'is_balance' ] : 0,//是否使用余额
- 'order_from' => $this->params[ 'app_type' ],
- 'order_from_name' => $this->params[ 'app_type_name' ],
-
- 'latitude' => $this->params[ "latitude" ] ?? '',
- 'longitude' => $this->params[ "longitude" ] ?? '',
- 'default_store_id' => $this->params[ "default_store_id" ] ?? 0,
-
- ];
- if (empty($data[ 'sku_id' ]) || empty($data[ 'groupbuy_id' ])) {
- return $this->response($this->error('', '缺少必填参数商品数据'));
- }
- $res = $order_create->orderPayment($data);
- return $this->response($this->success($res));
- }
-
-}
\ No newline at end of file
diff --git a/addon/activity/component/controller/Groupbuy.php b/addon/activity/component/controller/Groupbuy.php
deleted file mode 100644
index a7282d4..0000000
--- a/addon/activity/component/controller/Groupbuy.php
+++ /dev/null
@@ -1,21 +0,0 @@
-fetch("groupbuy/design.html");
- }
-}
\ No newline at end of file
diff --git a/addon/activity/component/view/groupbuy/css/design.css b/addon/activity/component/view/groupbuy/css/design.css
deleted file mode 100644
index 44f8acb..0000000
--- a/addon/activity/component/view/groupbuy/css/design.css
+++ /dev/null
@@ -1,29 +0,0 @@
-@CHARSET "UTF-8";
-
-/* 样式:单列 */
-.component-groupbuy .groupbuy-list .row1-of1{}
-.component-groupbuy .groupbuy-list .row1-of1 .item{display: flex;margin-bottom: 10px;padding: 8px;}
-.component-groupbuy .groupbuy-list .row1-of1 .item:last-child{margin-bottom: 0;}
-.component-groupbuy .groupbuy-list .row1-of1 .item .img-wrap {width: 100px;height: 100px;}
-.component-groupbuy .groupbuy-list .row1-of1 .item .img-wrap > img{width: 100%;}
-.component-groupbuy .groupbuy-list .row1-of1 .item .img-wrap .bg{display: none;}
-.component-groupbuy .groupbuy-list .row1-of1 .item .content{flex:1;margin-left: 10px;position: relative;}
-.component-groupbuy .groupbuy-list .row1-of1 .item .content .goods-name{margin-top: 3px;}
-.component-groupbuy .groupbuy-list .row1-of1 .item .content .discount-price{font-weight: bold;font-size: 0;position: absolute;bottom: 3px;left: 0;}
-.component-groupbuy .groupbuy-list .row1-of1 .item .content .discount-price .unit{font-size: 12px;}
-.component-groupbuy .groupbuy-list .row1-of1 .item .content .discount-price .price{font-size: 16px;}
-.component-groupbuy .groupbuy-list .row1-of1 .item .content button{position: absolute;bottom: 3px;right: 10px;padding: 0 8px;height: 26px;font-size: 12px;line-height: 26px;}
-
-/* 样式:横向滑动 */
-.component-groupbuy .groupbuy-list .horizontal-slide{display: flex;margin: 10px;overflow: hidden;}
-.component-groupbuy .groupbuy-list .horizontal-slide .item {width: 97px;}
-.component-groupbuy .groupbuy-list .horizontal-slide .item .img-wrap {width: 97px;height: 97px;overflow: hidden;position: relative;}
-.component-groupbuy .groupbuy-list .horizontal-slide .item .img-wrap > img{width: calc(100% + 1px);}
-.component-groupbuy .groupbuy-list .horizontal-slide .item .img-wrap .bg {position: absolute;width: 100%;height: 30px;bottom: 0;}
-.component-groupbuy .groupbuy-list .horizontal-slide .item .img-wrap .bg img {width: 100%;}
-.component-groupbuy .groupbuy-list .horizontal-slide .item .img-wrap .num {width: 90px;position: absolute;bottom: 5px;padding-left: 10px;font-size: 12px;line-height: 1;}
-.component-groupbuy .groupbuy-list .horizontal-slide .item .content {padding: 5px 10px;}
-.component-groupbuy .groupbuy-list .horizontal-slide .item .content .discount-price{margin-top: 5px;font-weight: bold;}
-.component-groupbuy .groupbuy-list .horizontal-slide .item .content .discount-price .unit{font-size: 12px; height: 16px;}
-.component-groupbuy .groupbuy-list .horizontal-slide .item .content .discount-price .price{font-size: 16px;}
-.component-groupbuy .groupbuy-list .horizontal-slide .item .content .original-price {font-size: 12px;line-height: 1;margin-top: 5px;text-decoration: line-through;}
\ No newline at end of file
diff --git a/addon/activity/component/view/groupbuy/design.html b/addon/activity/component/view/groupbuy/design.html
deleted file mode 100644
index 7ed6b32..0000000
--- a/addon/activity/component/view/groupbuy/design.html
+++ /dev/null
@@ -1,290 +0,0 @@
-
-
-
-
-
-
-
-
-
-
![]()
-
-
已团128件
-
-
-
{{ item.goods_name }}
-
- ¥
- {{item.discount_price.split(".")[0]}}
- {{"."+item.discount_price.split(".")[1]}}
-
-
¥{{item.line_price}}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
商品样式
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
购买按钮
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- var groupBuyResourcePath = "{$resource_path}"; // http路径
- var groupBuyRelativePath = "{$relative_path}"; // 相对路径
-
-
-
-
-
-
\ No newline at end of file
diff --git a/addon/activity/component/view/groupbuy/img/bg.png b/addon/activity/component/view/groupbuy/img/bg.png
deleted file mode 100644
index 53d2d79..0000000
Binary files a/addon/activity/component/view/groupbuy/img/bg.png and /dev/null differ
diff --git a/addon/activity/component/view/groupbuy/img/blue.png b/addon/activity/component/view/groupbuy/img/blue.png
deleted file mode 100644
index 3404173..0000000
Binary files a/addon/activity/component/view/groupbuy/img/blue.png and /dev/null differ
diff --git a/addon/activity/component/view/groupbuy/img/goods.png b/addon/activity/component/view/groupbuy/img/goods.png
deleted file mode 100644
index 5f1c884..0000000
Binary files a/addon/activity/component/view/groupbuy/img/goods.png and /dev/null differ
diff --git a/addon/activity/component/view/groupbuy/img/goods_1.png b/addon/activity/component/view/groupbuy/img/goods_1.png
deleted file mode 100644
index 37e6624..0000000
Binary files a/addon/activity/component/view/groupbuy/img/goods_1.png and /dev/null differ
diff --git a/addon/activity/component/view/groupbuy/img/icon/groupbuy.png b/addon/activity/component/view/groupbuy/img/icon/groupbuy.png
deleted file mode 100644
index 52fe098..0000000
Binary files a/addon/activity/component/view/groupbuy/img/icon/groupbuy.png and /dev/null differ
diff --git a/addon/activity/component/view/groupbuy/img/icon/groupbuy_selected.png b/addon/activity/component/view/groupbuy/img/icon/groupbuy_selected.png
deleted file mode 100644
index 9bbd7dd..0000000
Binary files a/addon/activity/component/view/groupbuy/img/icon/groupbuy_selected.png and /dev/null differ
diff --git a/addon/activity/component/view/groupbuy/img/manual.png b/addon/activity/component/view/groupbuy/img/manual.png
deleted file mode 100644
index d22f765..0000000
Binary files a/addon/activity/component/view/groupbuy/img/manual.png and /dev/null differ
diff --git a/addon/activity/component/view/groupbuy/img/manual_1.png b/addon/activity/component/view/groupbuy/img/manual_1.png
deleted file mode 100644
index 0d283ba..0000000
Binary files a/addon/activity/component/view/groupbuy/img/manual_1.png and /dev/null differ
diff --git a/addon/activity/component/view/groupbuy/img/red.png b/addon/activity/component/view/groupbuy/img/red.png
deleted file mode 100644
index 76bd1ec..0000000
Binary files a/addon/activity/component/view/groupbuy/img/red.png and /dev/null differ
diff --git a/addon/activity/component/view/groupbuy/img/style1.png b/addon/activity/component/view/groupbuy/img/style1.png
deleted file mode 100644
index 2464149..0000000
Binary files a/addon/activity/component/view/groupbuy/img/style1.png and /dev/null differ
diff --git a/addon/activity/component/view/groupbuy/img/style2 - ╕▒▒╛.png b/addon/activity/component/view/groupbuy/img/style2 - ╕▒▒╛.png
deleted file mode 100644
index e69de29..0000000
diff --git a/addon/activity/component/view/groupbuy/img/style2 - .png b/addon/activity/component/view/groupbuy/img/style2 - .png
deleted file mode 100644
index af4ac50..0000000
Binary files a/addon/activity/component/view/groupbuy/img/style2 - .png and /dev/null differ
diff --git a/addon/activity/component/view/groupbuy/img/style2.png b/addon/activity/component/view/groupbuy/img/style2.png
deleted file mode 100644
index 13924e8..0000000
Binary files a/addon/activity/component/view/groupbuy/img/style2.png and /dev/null differ
diff --git a/addon/activity/component/view/groupbuy/img/style2_title.png b/addon/activity/component/view/groupbuy/img/style2_title.png
deleted file mode 100644
index 8deb43e..0000000
Binary files a/addon/activity/component/view/groupbuy/img/style2_title.png and /dev/null differ
diff --git a/addon/activity/component/view/groupbuy/img/style3 - ╕▒▒╛.png b/addon/activity/component/view/groupbuy/img/style3 - ╕▒▒╛.png
deleted file mode 100644
index e69de29..0000000
diff --git a/addon/activity/component/view/groupbuy/img/style3 - .png b/addon/activity/component/view/groupbuy/img/style3 - .png
deleted file mode 100644
index b3f754e..0000000
Binary files a/addon/activity/component/view/groupbuy/img/style3 - .png and /dev/null differ
diff --git a/addon/activity/component/view/groupbuy/img/style3.png b/addon/activity/component/view/groupbuy/img/style3.png
deleted file mode 100644
index 3f6aad5..0000000
Binary files a/addon/activity/component/view/groupbuy/img/style3.png and /dev/null differ
diff --git a/addon/activity/component/view/groupbuy/img/style3_title.png b/addon/activity/component/view/groupbuy/img/style3_title.png
deleted file mode 100644
index 8c82f51..0000000
Binary files a/addon/activity/component/view/groupbuy/img/style3_title.png and /dev/null differ
diff --git a/addon/activity/component/view/groupbuy/img/violet.png b/addon/activity/component/view/groupbuy/img/violet.png
deleted file mode 100644
index 195bcdf..0000000
Binary files a/addon/activity/component/view/groupbuy/img/violet.png and /dev/null differ
diff --git a/addon/activity/component/view/groupbuy/img/yellow.png b/addon/activity/component/view/groupbuy/img/yellow.png
deleted file mode 100644
index 530d028..0000000
Binary files a/addon/activity/component/view/groupbuy/img/yellow.png and /dev/null differ
diff --git a/addon/activity/component/view/groupbuy/js/design.js b/addon/activity/component/view/groupbuy/js/design.js
deleted file mode 100644
index a3fffb4..0000000
--- a/addon/activity/component/view/groupbuy/js/design.js
+++ /dev/null
@@ -1,131 +0,0 @@
-var groupbuyListHtml = '
-
-
-{/block}
- {block name="script"}
-
- {/block}
\ No newline at end of file
diff --git a/addon/aliapp/shop/view/aliapp/setting.html b/addon/aliapp/shop/view/aliapp/setting.html
deleted file mode 100644
index bc949ad..0000000
--- a/addon/aliapp/shop/view/aliapp/setting.html
+++ /dev/null
@@ -1,225 +0,0 @@
-{extend name="app/shop/view/base.html" /}
-{block name="resources"}
-
-
-
-
-
-
授权接入
-
(授权接入无需复杂参数配置)
-
-
-
-
-
-
参数设置
-
(手动接入需要录入开发相关数据)
-
-
-
-{/block}
-{block name="main"}
-
-
-
-
- -
-
-

-
- 注册小程序应用
-
- -
-
-
- -
-
-

-
- 信息完善
-
- -
-
-
- -
-
-

-
- 开发
-
- -
-
-
- -
-
-

-
- 提交审核
-
- -
-
-
- -
-
-

-
- 发布
-
-
-
-
-
-
-{/block}
-{block name="script"}
-
-{/block}
\ No newline at end of file
diff --git a/addon/aliapp/shop/view/aliapp/success.html b/addon/aliapp/shop/view/aliapp/success.html
deleted file mode 100644
index 7c832f3..0000000
--- a/addon/aliapp/shop/view/aliapp/success.html
+++ /dev/null
@@ -1,52 +0,0 @@
-
-
-
-
-
支付宝扫码授权
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/addon/aliapp/shop/view/member/add.html b/addon/aliapp/shop/view/member/add.html
deleted file mode 100644
index c85a6ab..0000000
--- a/addon/aliapp/shop/view/member/add.html
+++ /dev/null
@@ -1,78 +0,0 @@
-{extend name="app/shop/view/base.html"/}
-{block name="resources"}
-
-{/block}
-
-{block name="body"}
-
-{/block}
-{block name="script"}
-
-{/block}
\ No newline at end of file
diff --git a/addon/aliapp/shop/view/member/index.html b/addon/aliapp/shop/view/member/index.html
deleted file mode 100644
index 9c55991..0000000
--- a/addon/aliapp/shop/view/member/index.html
+++ /dev/null
@@ -1,156 +0,0 @@
-{extend name="app/shop/view/base.html"/}
-{block name="resources"}
-
-{/block}
-
-{block name="main"}
-
-
-
-
-
-
-
-
-
-
-
-
-
-{/block}
-
-{block name="script"}
-
-{/block}
\ No newline at end of file
diff --git a/addon/aliapp/shop/view/message/config.html b/addon/aliapp/shop/view/message/config.html
deleted file mode 100644
index fbc6b1b..0000000
--- a/addon/aliapp/shop/view/message/config.html
+++ /dev/null
@@ -1,221 +0,0 @@
-{extend name="app/shop/view/base.html" /}
-{block name="resources"}
-
-{/block}
-{block name="main"}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-{/block}
-{block name="script"}
-
-{/block}
\ No newline at end of file
diff --git a/addon/aliapp/shop/view/message/edit.html b/addon/aliapp/shop/view/message/edit.html
deleted file mode 100644
index be87ee5..0000000
--- a/addon/aliapp/shop/view/message/edit.html
+++ /dev/null
@@ -1,87 +0,0 @@
-{extend name="app/shop/view/base.html" /}
-{block name="main"}
-
-{/block}
-{block name="script"}
-
-{/block}
\ No newline at end of file
diff --git a/addon/aliapp/shop/view/order/tradecomplain.html b/addon/aliapp/shop/view/order/tradecomplain.html
deleted file mode 100644
index 0fd61bf..0000000
--- a/addon/aliapp/shop/view/order/tradecomplain.html
+++ /dev/null
@@ -1,332 +0,0 @@
-{extend name="app/shop/view/base.html"/}
-{block name="resources"}
-
-{/block}
-{block name="main"}
-
-
-
操作提示
-
- - 支付宝交易订单投诉维权
- - 请在12小时完成售后维权
-
-
-
-
-
-
-
-
-
-
-
-
-{/block}
-{block name="script"}
-
-{/block}
\ No newline at end of file
diff --git a/addon/aliapp/shop/view/public/fail.png b/addon/aliapp/shop/view/public/fail.png
deleted file mode 100644
index 5ca1925..0000000
Binary files a/addon/aliapp/shop/view/public/fail.png and /dev/null differ
diff --git a/addon/aliapp/shop/view/public/img/alipay_app_new.png b/addon/aliapp/shop/view/public/img/alipay_app_new.png
deleted file mode 100644
index 9180086..0000000
Binary files a/addon/aliapp/shop/view/public/img/alipay_app_new.png and /dev/null differ
diff --git a/addon/aliapp/shop/view/public/img/alipay_app_select.png b/addon/aliapp/shop/view/public/img/alipay_app_select.png
deleted file mode 100644
index c83241a..0000000
Binary files a/addon/aliapp/shop/view/public/img/alipay_app_select.png and /dev/null differ
diff --git a/addon/aliapp/shop/view/public/success.png b/addon/aliapp/shop/view/public/success.png
deleted file mode 100644
index da3943d..0000000
Binary files a/addon/aliapp/shop/view/public/success.png and /dev/null differ
diff --git a/addon/aliapp/shop/view/release/index.html b/addon/aliapp/shop/view/release/index.html
deleted file mode 100644
index 6dcdec0..0000000
--- a/addon/aliapp/shop/view/release/index.html
+++ /dev/null
@@ -1,407 +0,0 @@
-{extend name="app/shop/view/base.html"/}
-{block name="resources"}
-
-{/block}
-{block name="main"}
-
-
-
操作提示
-
- - 通过平台注册小程序需要完善基础信息
- {if $is_baseinfo==0}
- - 未完善基础信息将无法通过审核去完善
- {/if}
-
-
-
-
-
-
- {if $isNewest}
-
- {else/}
-
- {/if}
-
-
-
-
-
-
-
-
-
-
-{/block}
-{block name="script"}
-
-{/block}
\ No newline at end of file
diff --git a/addon/aliapp/storeapi/controller/AppletRelease.php b/addon/aliapp/storeapi/controller/AppletRelease.php
deleted file mode 100644
index bc7fdc0..0000000
--- a/addon/aliapp/storeapi/controller/AppletRelease.php
+++ /dev/null
@@ -1,200 +0,0 @@
-checkToken();
- if ($token[ 'code' ] < 0) {
- echo $this->response($token);
- exit;
- }
- }
- /**
- * Common: 进入发布小程序
- * Author: wu-hui
- * Time: 2023/01/03 17:05
- * @return array|mixed
- * @throws \think\db\exception\DbException
- */
- public function index(){
- $config = new Config();
- $config_info = $config->getAppConfig($this->site_id)['data']['value'];
- $baseinfo=[];
- $is_baseinfo=1;
- if(!empty($config_info['line_type'])&&$config_info['line_type']=='auth'){
- $app = new MinCode();
- $app->appAuthToken = $config_info['app_auth_token'];
- $baseinfo = cache($app->appAuthToken . '_baseinfo');
- if (empty($baseinfo)) {
- $baseinfo = $app->requestApi('alipay.open.mini.baseinfo.query')['alipay_open_mini_baseinfo_query_response'];
- cache($app->appAuthToken . '_baseinfo', $baseinfo);
- }
- if(!isset($baseinfo['category_names'])){
- $is_baseinfo=0;
- }
- }
- return $this->response($this->success([
- 'is_baseinfo' => $is_baseinfo,
- 'baseinfo' => $baseinfo,
- 'isNewest' => (new AliPayApplet($this->site_id))->isNewestVersion(),
- ]));
- }
-
- /**
- * 编辑小程序基础信息
- * 已商上架小程序无法再次修改
- * @return array|mixed
- */
- public function appinfo()
- {
- $site_id = $this->site_id;
- $app = new MinCode();
- $config = new Config();
- $config_info = $config->getAppConfig($site_id)['data']['value'];
- $app->appAuthToken = $config_info['app_auth_token'];
-
- $baseinfo = cache($app->appAuthToken . '_baseinfo');
- if (empty($baseinfo)) {
- $baseinfo = $app->requestApi('alipay.open.mini.baseinfo.query')['alipay_open_mini_baseinfo_query_response'];
- cache($app->appAuthToken . '_baseinfo', $baseinfo);
- }
- $one_category = cache($app->appAuthToken . '_category');
- $category_all = cache($app->appAuthToken . '_alls_category');
- if (empty($one_category)) {
- $category = $app->requestApi('alipay.open.mini.category.query', ['is_filter' => true])['alipay_open_mini_category_query_response'];
- if ($category['mini_category_list']) {
- $category_all = array_column($category['mini_category_list'], null, 'category_id');
- $one_category = [];
- foreach ($category_all as $key => $item) {
- if ($item['parent_category_id'] == '0') {
- $one_category[] = $item;
- }
- }
- cache($app->appAuthToken . '_category', $one_category);
- cache($app->appAuthToken . '_alls_category', $category_all);
- }
- }
-
- $original = [];
- $mini_category_ids = [];
- if(isset($baseinfo['category_names'])){
- $category_names = $baseinfo['category_names'];
- $category_ids = explode(';', $category_names);
- $category_all_name = array_column($category_all, null, 'category_name');
- foreach ($category_ids as $key => $val) {
- if ($val) {
- $text = explode('_', $val);
- foreach ($text as $category_namet) {
- $d=$category_all_name[$category_namet]??[];
- if($d){
- $d['checked']=true;
- $category_all[$d['category_id']]['checked']=true;
- $original[$key][] = $d;
- }
- }
- }
- }
- }
- if ($original) { //已设置分类
- foreach ($original as $value) {
- $category_ids = array_column($value, 'category_id');
- $mini_category_ids[] = implode('_', $category_ids);
- }
- }
- if (isset($baseinfo['app_logo'])&&strpos($baseinfo['app_logo'], 'http')===0){
- $upload=new UploadModel($site_id);
- $pic_img=$upload->setPath("common/images/" . date("Ymd") . '/')->remotePullToLocal($baseinfo['app_logo']);
- $baseinfo['app_logo']=$pic_img['data']['path'];
- }
- $res = [
- 'original' => $original,
- 'allCategory' => $this->getTreeCategory($category_all),
- 'info' => $baseinfo,
- 'mini_category_ids' => implode(';', $mini_category_ids),
- 'app_id_info' => model('uni_account')->getInfo([['site_id', '=', $this->site_id]],'appid'),
- 'isNewest' => (new AliPayApplet($this->site_id))->isNewestVersion(),
- ];
- return $this->response($this->success($res));
- }
-
- public function list(){
- $list = (new appletReleaseModel($this->site_id))->getList();
- return $this->response($list);
- }
-
- public function getTreeCategory($category){
- $category_all=$category;
- $res = [];
- //遍历寻父 O(n)
- foreach ($category_all as &$item) {
- if (isset($category_all[$item['parent_category_id']])){
- //注意下面有一个引用符 & !
- $category_all[$item['parent_category_id']]['child'] []= &$item;
- }elseif(!$item['parent_category_id']){ // 此处判断是否加入到结果集 $item['pid'] === null 或者 $item['pid'] == -1 之类的
- $res []= &$item;
- }
- }
- unset($item);
- return $res;
- }
-
- /**
- * Common: 小程序发布流程处理
- * Author: wu-hui
- * Time: 2023/01/04 11:05
- * @return array|false|string
- */
- public function publishingProcessProcessing(){
- // 参数获取
- $type = (string)input('type');
- $id = (int)input('id');
- return $this->response((new AliPayApplet($this->site_id))->publishingInit($type,$id));
- }
- /**
- * Common: 版本管理 —— 版本同步
- * Author: wu-hui
- * Time: 2022/12/30 10:08
- * @return array|false|string
- * @throws \Exception
- */
- public function versionSynchronization(){
- return $this->response((new AliPayApplet($this->site_id))->versionSynchronization());
- }
- /**
- * Common: 生成小程序推广二维码
- * Author: wu-hui
- * Time: 2023/01/03 14:13
- * @return array|false|string
- */
- public function qrcodeCreate(){
- $version=config('alipay.templateInfo.template_version');
- return $this->response((new AliPayApplet($this->site_id))->queryTestQrcode($version));
- }
-
-}
\ No newline at end of file
diff --git a/addon/alilife/config/diy_view.php b/addon/alilife/config/diy_view.php
deleted file mode 100644
index 917ab1e..0000000
--- a/addon/alilife/config/diy_view.php
+++ /dev/null
@@ -1,30 +0,0 @@
- '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
- 'template' => [],
- // 后台自定义组件——装修
- 'util' => [],
- // 自定义页面路径
- 'link' => [ ],
- // 自定义图标库
- 'icon_library' => [],
- // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
- 'component' => [],
- // uni-app 页面,多个逗号隔开
- 'pages' => [],
- // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
- 'info' => [],
- // 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
- 'theme' => [],
- // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
- 'data' => []
-];
\ No newline at end of file
diff --git a/addon/alilife/config/event.php b/addon/alilife/config/event.php
deleted file mode 100644
index 82d358b..0000000
--- a/addon/alilife/config/event.php
+++ /dev/null
@@ -1,44 +0,0 @@
- [],
- 'listen' => [
- //展示活动
- 'ShowPromotion' => [
- 'addon\alilife\event\ShowPromotion',
- ],
- // 订单发货
- 'OrderDelivery' => [
- 'addon\alilife\event\OrderDelivery'
- ],
- // 订单收货
- 'OrderTakeDelivery' => [
- 'addon\alilife\event\OrderTakeDelivery'
- ],
- 'AliGatewayNotify' => [//网关通知
- 'addon\alilife\event\AliGoodsStatusNotify'
- ],
- 'AutoPushOrderDelivery' => [ //验证自动发货
- 'addon\alilife\event\AutoPushOrderDelivery'
- ],
- 'GoodsEdit' => [
- 'addon\alilife\event\GoodsEdit'
- ],
- 'AddGoods' => [
- 'addon\alilife\event\AddGoods'
- ],
- 'editGoodsInfo'=>[//获取编辑信息
- 'addon\alilife\event\editGoodsInfo'
- ],
- 'AoutSyncGoodsAlipay'=>[//同步支付宝商品
- 'addon\alilife\event\AoutSyncGoodsAlipay'
- ],
- 'SyncImageGoodsAlipay'=>[
- 'addon\alilife\event\SyncImageGoodsAlipay'
- ],
- 'AlbumUpload'=>[//相册图形上传事件
- 'addon\alilife\event\AlbumUpload'
- ]
- ],
- 'subscribe' => [],
-];
diff --git a/addon/alilife/config/info.php b/addon/alilife/config/info.php
deleted file mode 100644
index 1771faa..0000000
--- a/addon/alilife/config/info.php
+++ /dev/null
@@ -1,21 +0,0 @@
- 'alilife',
- 'title' => '支付宝生活号',
- 'description' => '支付宝本地生活,生活号,支付宝直播带货',
- 'type' => 'tool', //插件类型 system :系统插件(自动安装), business:业务插件 promotion:扩展营销插件 tool:工具插件
- 'status' => 1,
- 'author' => '',
- 'version' => '1.0.0',
- 'version_no' => '520230316001',
- 'content' => '',
-];
\ No newline at end of file
diff --git a/addon/alilife/config/menu_shop.php b/addon/alilife/config/menu_shop.php
deleted file mode 100644
index ab51358..0000000
--- a/addon/alilife/config/menu_shop.php
+++ /dev/null
@@ -1,66 +0,0 @@
- 'SHOP_ALILIFE_ROOT',
- 'title' => '生活号',
- 'url' => 'alilife://shop/goods/lists',
- 'picture' => 'addon/shopcomponent/shop/view/public/img/live_new.png',
- 'picture_selected' => 'addon/shopcomponent/shop/view/public/img/live_select.png',
- 'parent' => 'SHOP_ALIAPP_ROOT',
- 'is_show' => 0,
- 'sort' => 1,
- 'child_list' => [
- [
- 'name' => 'SHOP_ALILIFE_GOODS',
- 'title' => '普通商品',
- 'url' => 'alilife://shop/goods/lists',
- 'is_show' => 1,
- 'sort' => 1,
- 'child_list' => []
- ],
- [
- 'name' => 'SHOP_LIFEGROUP_GOODS',
- 'title' => '本地团购',
- 'url' => 'alilife://shop/goods/lifelists',
- 'is_show' => 1,
- 'sort' => 2,
- 'child_list' => [
- [
- 'name' => 'SHOP_LIFEGROUP_ADDGOODS',
- 'title' => '添加商品',
- 'url' => 'alilife://shop/goods/add',
- 'is_show' => 0,
- ],
- [
- 'name' => 'SHOP_LIFEGROUP_EDITGOODS',
- 'title' => '编辑商品',
- 'url' => 'alilife://shop/goods/edit',
- 'is_show' => 0,
- ]
- ]
- ],
- [
- 'name' => 'SHOP_ALILIFE_CATEGORY',
- 'title' => '类目管理',
- 'url' => 'alilife://shop/category/lists',
- 'is_show' => 1,
- 'sort' => 3,
- 'child_list' => []
- ],
- ]
- ],
- [
- 'title' => '支付宝对账',
- 'name' => 'PROMOTION_Alipay',
- 'url' => 'alilife://shop/order/miniOrderItembill',
- 'parent' => 'ACCOUNT_MANAGE',
- 'picture' => 'app/shop/view/public/img/icon_new/member_withdraw_new.png',
- 'picture_selected' => 'app/shop/view/public/img/icon_new/member_withdraw_select.png',
- 'is_show' => 1,
- 'is_control' => 1,
- 'sort' => 6
- ]
-];
diff --git a/addon/alilife/event/AddGoods.php b/addon/alilife/event/AddGoods.php
deleted file mode 100644
index e36cb41..0000000
--- a/addon/alilife/event/AddGoods.php
+++ /dev/null
@@ -1,17 +0,0 @@
-newAddGoods($data);
- }
-}
\ No newline at end of file
diff --git a/addon/alilife/event/AlbumUpload.php b/addon/alilife/event/AlbumUpload.php
deleted file mode 100644
index f37d562..0000000
--- a/addon/alilife/event/AlbumUpload.php
+++ /dev/null
@@ -1,14 +0,0 @@
-UploadImage($data['relate_id']);
- }
- return error(-1, '任务数据错误');
- }
-}
\ No newline at end of file
diff --git a/addon/alilife/event/AliGoodsStatusNotify.php b/addon/alilife/event/AliGoodsStatusNotify.php
deleted file mode 100644
index e4f6a3f..0000000
--- a/addon/alilife/event/AliGoodsStatusNotify.php
+++ /dev/null
@@ -1,27 +0,0 @@
-StatusNotify($param);
- break;
- case 'alipay.open.mini.order.changed'://订单通知
- $json = $param['biz_content'];
- (new Order())->OrderStatus($json);
- break;
- }
- }
- }
-}
\ No newline at end of file
diff --git a/addon/alilife/event/AoutSyncGoodsAlipay.php b/addon/alilife/event/AoutSyncGoodsAlipay.php
deleted file mode 100644
index 6479a6a..0000000
--- a/addon/alilife/event/AoutSyncGoodsAlipay.php
+++ /dev/null
@@ -1,14 +0,0 @@
-AoutSyncGoodsAlipay();
- }
-}
\ No newline at end of file
diff --git a/addon/alilife/event/AutoPushOrderDelivery.php b/addon/alilife/event/AutoPushOrderDelivery.php
deleted file mode 100644
index b593bd7..0000000
--- a/addon/alilife/event/AutoPushOrderDelivery.php
+++ /dev/null
@@ -1,74 +0,0 @@
-getList([
- ['is_video_number', '=', 1],
- ['is_sync_order', 'in', [0, 2]],
- ['order_status', '=', 3],
- ], $field, '', 'o', $join, '', 30);
- if ($orderInfo) {
- foreach ($orderInfo as $item) {
- if (in_array($item['pay_type'], ['alipay', 'zmgopay', 'zmxxpay', 'huabie'])) {
- $this->pushOrder($item);
- }
- }
- }
- return success();
- }
-
- /***
- * 推送订单
- * @param $item
- * @return void
- */
- public function pushOrder($item)
- {
- $temp = [
- 'TRADE_CREATED' => '订单创建',
- 'WAIT_PAY' => '等待支付',
- 'PAID' => '支付成功',
- 'INIT' => '冻结',
- 'PARTIAL_DELIVERED' => '部分发货',
- 'DELIVERED' => '全部发货',
- 'RECEIVED_CONFIRM' => '确认收货',
- 'TIMEOUT_CLOSED' => '超时取消',
- 'REFUND_CLOSED' => '全部退款'
- ];
- $apiApp = new MinCode($item['site_id']);
- $info = $apiApp->miniOrderQuery($item['out_trade_no'], $item['ali_openid']);
- if ($info && $info['code'] == 10000 && $info['status'] == 'DELIVERED') { //已发货同步
- model('order')->update(['is_sync_order' => 1, 'sync_msg' => ''], ['order_id' => $item['order_id']]);
- } else if ($info['code'] == 10000 && $info['status'] == 'PAID') {
- $res = event('OrderDelivery', ['order_id' => $item['order_id']]);//设置发货同步
- if ($res[0]['code'] == 0) {
- model('order')->update(['is_sync_order' => 1], ['order_id' => $item['order_id']]);
- } else {
- model('order')->update(['is_sync_order' => 2, 'sync_msg' => $res[0]['message']], ['order_id' => $item['order_id']]);
- }
- } else if ($info['code'] != 10000) {
- model('order')->update(['is_sync_order' => 3, 'sync_msg' => $info['sub_msg']], ['order_id' => $item['order_id']]);
- } else if ($info['code'] == 10000) {
- $is_sync_order = 2;
- if (in_array($info['status'], ['RECEIVED_CONFIRM', 'REFUND_CLOSED', 'TIMEOUT_CLOSED'])) {
- $is_sync_order = 1;
- }
- model('order')->update(['is_sync_order' => $is_sync_order, 'sync_msg' => $temp[$info['status']]], ['order_id' => $item['order_id']]);
- }
- }
-}
\ No newline at end of file
diff --git a/addon/alilife/event/GoodsEdit.php b/addon/alilife/event/GoodsEdit.php
deleted file mode 100644
index 084f941..0000000
--- a/addon/alilife/event/GoodsEdit.php
+++ /dev/null
@@ -1,20 +0,0 @@
-GoodsEditupdate($data);
- }
-}
\ No newline at end of file
diff --git a/addon/alilife/event/Install.php b/addon/alilife/event/Install.php
deleted file mode 100644
index 259ea45..0000000
--- a/addon/alilife/event/Install.php
+++ /dev/null
@@ -1,26 +0,0 @@
-delivery($param['order_id']);
- return $res;
- }
-}
\ No newline at end of file
diff --git a/addon/alilife/event/OrderTakeDelivery.php b/addon/alilife/event/OrderTakeDelivery.php
deleted file mode 100644
index c6d51f9..0000000
--- a/addon/alilife/event/OrderTakeDelivery.php
+++ /dev/null
@@ -1,16 +0,0 @@
-takeDelivery($param['order_id']);
- return $res;
- }
-
-}
\ No newline at end of file
diff --git a/addon/alilife/event/ShowPromotion.php b/addon/alilife/event/ShowPromotion.php
deleted file mode 100644
index b5924e0..0000000
--- a/addon/alilife/event/ShowPromotion.php
+++ /dev/null
@@ -1,46 +0,0 @@
- [
- [
- //插件名称
- 'name' => 'alilife',
- //店铺端展示分类 shop:营销活动 member:互动营销
- 'show_type' => 'tool',
- //展示主题
- 'title' => '支付宝生活号',
- //展示介绍
- 'description' => '生活直播,本地生活开启线上带货新模式',
- //展示图标
- 'icon' => 'addon/shopcomponent/icon.png',
- //跳转链接
- 'url' => 'alilife://shop/goods/lists',
- ]
- ]
- ];
- return $data;
- }
-}
\ No newline at end of file
diff --git a/addon/alilife/event/SyncImageGoodsAlipay.php b/addon/alilife/event/SyncImageGoodsAlipay.php
deleted file mode 100644
index 3900760..0000000
--- a/addon/alilife/event/SyncImageGoodsAlipay.php
+++ /dev/null
@@ -1,15 +0,0 @@
-SyncGoodsImage();
- }
-}
\ No newline at end of file
diff --git a/addon/alilife/event/UnInstall.php b/addon/alilife/event/UnInstall.php
deleted file mode 100644
index 4f5aaba..0000000
--- a/addon/alilife/event/UnInstall.php
+++ /dev/null
@@ -1,24 +0,0 @@
-getGoodsInfo($data);
- }
-}
\ No newline at end of file
diff --git a/addon/alilife/icon.png b/addon/alilife/icon.png
deleted file mode 100644
index dc14f10..0000000
Binary files a/addon/alilife/icon.png and /dev/null differ
diff --git a/addon/alilife/model/Category.php b/addon/alilife/model/Category.php
deleted file mode 100644
index 3ccbbd4..0000000
--- a/addon/alilife/model/Category.php
+++ /dev/null
@@ -1,159 +0,0 @@
-pageList($condition, $field, $order, $page, $list_rows, $alias, $join);
- return $this->success($data);
- }
-
- /**
- * 获取类目通过上级类目ID
- * @param $level
- * @param int $pid
- * @return array
- */
- public function getCategoryByParent($site_id,$level,$pid = 0,$cat_type=1,$type='allcategory')
- {
- $condition=[
- ['site_id','=',$site_id],
- ['cat_level','=',$level],
- ['api_type','=',$type]
- ];
- if($pid){
- $condition[]=['cat_pid','=',$pid];
- }
- if($cat_type){
- $condition[]=['cat_type','=',$cat_type];
- }
- $list = model('shopalilife_category')->getList($condition, '*', '', '', null, 'cat_id');
- $data = $this->success($list);
- Cache::tag('aliCategory')->set("aliCategory_{$level}_{$pid}", $data);
- return $data;
- }
-
- public function getCategory($site_id,$type='allcategory',$cat_type=1){
- $condition=[
- ['site_id','=',$site_id],
- ['api_type','=',$type],
- ['cat_type','=',$cat_type],
- ];
- $items = model('shopalilife_category')->getColumn($condition, '*', 'cat_id', '', null, 'cat_id');
- $config=[
- 'id' => 'cat_id', // id名称
- 'pid' => 'cat_pid', // pid名称
- 'title' => 'cat_name', // 标题名称
- 'child' => 'children', // 子元素键名
- 'step' => 3,
- ];
- $tree =new Tree($config);
- $lists=$tree::toLayer($items);
- $temp=[];
- foreach ($lists as $item) {
- if ($item['cat_level'] == 1) {
- $temp[] = $item;
- }
- }
- return $temp;
- }
- /**
- * 同步商品类目
- */
- public function syncCategory($site_id,$item_type=1,$type='allcategory')
- {
- if($type=='allcategory'){
- $api='alipay.open.app.item.allcategory.query';
- $key='alipay_open_app_item_allcategory_query_response';
- }else{
- $api='alipay.open.app.localitem.allcategory.query';
- $key='alipay_open_app_localitem_allcategory_query_response';
- }
- $res = ( new MinCode($site_id) )->requestApi($api,['item_type'=>$item_type]);
- $res=$res[$key];
- if ($res[ 'code' ] != 10000) return $res;
- if (!empty($res[ 'cats' ])) {
- model('shopalilife_category')->delete([['site_id','=',$site_id],['api_type','=',$type],['cat_type','=',$item_type]]);
- $data = [];
- foreach ($res[ 'cats' ] as $item) {
- foreach ($item['cat_and_parent'] as $value){
- $data[$value['cat_id']]=[
- 'site_id' => $site_id,
- 'cat_id' => $value['cat_id'],
- 'cat_pid' => $value['f_cat_id']??'',
- 'cat_name' => $value['cat_name'],
- 'cat_level' => $value['cat_level'],
- 'qualification_status' => $value['qualification_status']??'',
- 'cat_type' => $item_type,
- 'api_type' => $type,
- 'create_time' => time(),
- ];
- }
- }
- model('shopalilife_category')->addList(array_values($data));
- return $this->success(1);
- }else{
- return $this->error(-1,'未发现有可用分类信息');
- }
- }
-
-
- /***
- * 获取模版信息
- * @param $site_id
- * @param $cat_id
- * @param $type
- * @return void
- */
- public function getCatTemplate($site_id,$cat_id,$type='allcategory',$item_type=''){
- $data=['category_id'=>$cat_id];
- if($type=='allcategory'){
- $api='alipay.open.app.item.template.query';
- $key='alipay_open_app_item_template_query_response';
- }else{
- $api='alipay.open.app.localitem.template.query';
- $key='alipay_open_app_localitem_template_query_response';
- $data['item_type']=$item_type;
- }
- $res = ( new MinCode($site_id) )->requestApi($api,$data);
- $res=$res[$key];
- return $res;
- }
-
- /**
- * 获取分类信息
- * @param $third_cat_id
- * @param $site_id
- */
- public function getCategoryInfo($third_cat_id, $site_id=0)
- {
- $info = model('shopalilife_category')->getInfo([['site_id','=',$site_id],[ 'cat_id', '=', $third_cat_id ] ]);
- if (empty($info)) return $info;
- return $info;
- }
-}
\ No newline at end of file
diff --git a/addon/alilife/model/Goods.php b/addon/alilife/model/Goods.php
deleted file mode 100644
index 3274001..0000000
--- a/addon/alilife/model/Goods.php
+++ /dev/null
@@ -1,1739 +0,0 @@
- '未上架',
- 5 => '上架中',
- 11 => '已下架',
- 13 => '违规下架'
- ];
-
- /**
- * 审核状态
- * @var string[]
- */
- private $editStatus = [
- 0 => '审核中',
- 1 => '编辑中',
- 2 => '审核中',
- 3 => '审核失败',
- 4 => '审核成功',
- ];
- private $mime = [
- 'image/jpeg' => '.jpg',
- 'image/png' => '.png',
- 'image/gif' => '.gif',
- 'image/bmp' => '.bmp',
- 'image/webp' => '.webp',
- ];
- public $image_service;
- public $driver;
-
- public function getBillList($condition = [], $page = 1, $site_id)
- {
- $aliapp = new MinCode($site_id);
- $config = new Config();
- $config_info = $config->getAppConfig($site_id)['data']['value'];
- $data = [
- 'mini_app_id' => $config_info['appid'],
- 'page_num' => 1,
- 'page_size' => 10,
- 'order_status' => 'PAID',
- ];
- $res = $aliapp->requestApi('alipay.open.mini.order.itembill.batchquery', array_merge($data, $condition))['alipay_open_mini_order_itembill_batchquery_response'];
- if ($res['code'] != 10000 || !isset($res['order_list'])) {
- $res = [
- 'code' => 1,
- 'msg' => '暂无数据',
- 'page_num' => 1,
- 'page_size' => 10,
- 'total' => 0,
- 'order_list' => []
- ];
- } else {
- if (count($res['order_list'])) {
- $out_trade_no = array_column($res['order_list'], 'out_trade_no');
- $pay_out_trade_no = model('pay', 0)->getColumn([['out_trade_no', 'in', $out_trade_no]], '*', 'out_trade_no');
- $order_info = model('order', 0)->getColumn([['out_trade_no', 'in', $out_trade_no]], '*', 'out_trade_no');
- foreach ($res['order_list'] as &$item) {
- if (isset($pay_out_trade_no[$item['out_trade_no']]) && isset($order_info[$item['out_trade_no']]) && $order_info[$item['out_trade_no']]['order_status'] != -1) {
- $item['out_order_id'] = $order_info[$item['out_trade_no']]['order_id'];
- $item['is_sync_bill'] = 1;
- $item['out_order_status'] = $order_info[$item['out_trade_no']]['order_status'];
- $item['is_sync_delivery'] = $order_info[$item['out_trade_no']]['order_status'];
- } else {
- $item['is_sync_bill'] = 0;
- $item['is_sync_delivery'] = 0;
- $item['out_order_id'] = 0;
- $item['out_order_status'] = '';
- }
- }
- }
- $res['code'] = 0;
- }
- return $res;
- }
-
- /**
- * 获取商品列表
- * @param array $condition
- * @param bool $field
- * @param string $order
- * @param int $page
- * @param int $list_rows
- * @param string $alias
- * @param array $join
- * @return array
- */
- public function getGoodsPageList($condition = [], $field = true, $order = '', $page = 1, $list_rows = PAGE_LIST_ROWS, $alias = 'a', $join = [])
- {
- $field = 'sg.*,g.goods_name,g.goods_image,g.price,g.goods_stock,g.recommend_way';
- $alias = 'sg';
- $join = [
- ['goods g', 'g.goods_id = sg.out_item_id', 'inner'],
- ];
- $data = model('shopalilife_goods')->pageList($condition, $field, $order, $page, $list_rows, $alias, $join);
- if (!empty($data['list'])) {
- foreach ($data['list'] as $k => $item) {
- $data['list'][$k]['goods_stock'] = numberFormat($data['list'][$k]['goods_stock']);
- $arr_img = explode(',', $item['goods_image']);
- $data['list'][$k]['cover_img'] = $arr_img[0] ?? '';
- $data['list'][$k]['create_time'] = $item['create_time'] > 0 ? time_to_date($item['create_time']) : '--';
- $data['list'][$k]['audit_time'] = $item['audit_time'] > 0 ? time_to_date($item['audit_time']) : '--';
- if ($item['reject_reason']) {
- $reject_reason = json_decode($item['reject_reason'], true);
- if ($reject_reason) {
- $data['list'][$k]['reject_reason'] = implode('', array_column($reject_reason, 'remark'));
- }
- }
- }
- }
- return $this->success($data);
- }
-
- /***
- * 推送普通商品
- * @return void
- */
- public function PushPTSyncGoodsInfo($goods_id, $data)
- {
- $join = [
- ['goods g', 'g.goods_id=a.goods_id', 'right']
- ];
- $where = [
- ['g.goods_id', '=', $goods_id]
- ];
- $goods_info = $this->getGoodsInfo($where, 'g.*,a.goods_id as gid,a.spu_data,a.spu_status,a.item_type,a.api_type,a.category_id,a.skus', 'a', $join);
- $sku_list = model('goods_sku')->getList([['goods_id', '=', $goods_id]], 'sku_id,sku_name,sku_no,sku_image,discount_price,market_price,stock,sku_spec_format');
- if (!empty($goods_info['gid'])) {
- $skus = json_decode($goods_info['skus'], true);
- $spu_data = json_decode($goods_info['spu_data'], true);
- $spu_data_names = [];
- if ($spu_data) {
- $spu_data_names = array_column($spu_data, 'sku_name');
- }
- $out_sku_ids = array_column($skus, 'out_sku_id');
- $sku_ids = array_column($sku_list, 'sku_id');
- $sku_names = array_column($sku_list, 'sku_name');
- if (array_diff($out_sku_ids, $sku_ids) || array_diff($sku_names, $spu_data_names)) {
- $param['goods_id'] = $goods_id;
- $param['site_id'] = $goods_info['site_id'];
- $api = 'alipay.open.app.item.modify';
- $response = 'alipay_open_app_item_modify_response';
- return $this->SyncAlipayGoods($param, $api, $response, $data['alipaycategory_id'] ?? '');
- } else {
- return $this->syncDtockPrice($goods_id, $goods_info['site_id']);
- }
- } else {
- $api = 'alipay.open.app.item.create';
- $key = 'alipay_open_app_item_create_response';
- $data['site_id'] = $goods_info['site_id'];
- $data['goods_id'] = $goods_id;
- $data['goods_name'] = $goods_info['goods_name'];
- return $this->SyncAlipayGoods($data, $api, $key, $data['alipaycategory_id']);
- }
- }
-
- public function PushLocaSyncGoodsInfo($goods_id, $data)
- {
-
- }
-
- /**
- * 同步商品库商品
- */
- public function syncGoods($start = 1, $limit = 20, $site_id, $type = 'allcategory')
- {
- if ($type == 'allcategory') {
- $api = 'alipay.open.app.item.list.query';
- $key = 'alipay_open_app_item_list_query_response';
- } else {
- $api = 'alipay.open.app.localitem.allcategory.query';
- $key = 'alipay_open_app_localitem_allcategory_query_response';
- }
- $aliapp = new MinCode($site_id);
- $res = $aliapp->requestApi($api, ['page_num' => $start, 'page_size' => $limit]);
- $sync_res = $res[$key];
- if ($sync_res['code'] != 10000) return $sync_res;
- if (!empty($sync_res['items'])) {
- foreach ($sync_res['items'] as $goods_item) {
- $count = model('shopalilife_goods')->getCount([['out_item_id', '=', $goods_item['out_item_id']], ['site_id', '=', $site_id]]);
- $is_sync = model('goods')->getCount([['goods_id', '=', $goods_item['out_item_id']], ['site_id', '=', $site_id]]);
- if ($count) {
- model('shopalilife_goods')->update(
- [
- 'spu_status' => $goods_item['spu_status'],
- 'stock_num' => $goods_item['stock_num'],
- 'category_id' => $goods_item['category_id'],
- 'item_id' => $goods_item['item_id']
- ],
- [
- ['out_item_id', '=', $goods_item['out_item_id']]
- ]
- );
- } else {
- $category = (new Category())->getCategoryInfo($goods_item['category_id'], $site_id);
- $temp = [
- 'site_id' => $site_id,
- 'is_sync' => $is_sync,
- 'out_item_id' => $goods_item['out_item_id'],
- 'item_id' => $goods_item['item_id'],
- 'stock_num' => $goods_item['stock_num'],
- 'category_id' => $goods_item['category_id'],
- 'api_type' => $type,
- 'spu_status' => $goods_item['spu_status'],
- 'create_time' => time(),
- 'update_time' => time(),
- 'cat_name' => $category['cat_name']
- ];
- model('shopalilife_goods')->add($temp);
- }
- }
- $total_page = ceil($sync_res['total'] / $limit);
- return $this->success(['page' => $start, 'total_page' => $total_page]);
- } else {
- return $this->success(['page' => $start, 'total_page' => 1]);
- }
- }
-
- /***
- * 支付宝状态更新
- * @param $param
- * @return array
- */
- public function StatusNotify($param)
- {
- $biz_content = $param['biz_content'] ?? '';
- if ($biz_content) {
- $goods_data = [
- 'spu_status' => $biz_content['spu_status'],
- 'is_sync' => 1,
- 'reject_reason' => json_encode($biz_content['reasons'] ?? '') ?? ''
- ];
- model('shopalilife_goods')->update($goods_data, [['out_item_id', '=', $biz_content['out_item_id']]]);
- }
- return $this->success();
- }
-
- /***
- * 同步线上价格
- * @param $goods_id
- * @param $site_id
- * @param $type
- * @return array
- */
- public function syncDtockPrice($goods_id, $site_id)
- {
- $api = 'alipay.open.app.item.direct.modify';
- $key = 'alipay_open_app_item_direct_modify_response';
- $goods_info = model('goods')->getInfo([['goods_id', '=', $goods_id], ['site_id', '=', $site_id]], 'goods_id,goods_name,goods_image,sku_id,goods_content');
- $miniapp = new MinCode($site_id);
- // 同步商品所需数据
- $spu_data = [
- 'out_item_id' => $goods_info['goods_id'],
- 'skus' => []
- ];
- $sku_list = model('goods_sku')->getList([['goods_id', '=', $goods_info['goods_id']]], 'sku_id,sku_no,sku_image,discount_price,market_price,stock,sku_spec_format');
- if (count($sku_list) > 1) {
- foreach ($sku_list as $sku_item) {
- if ($sku_item['market_price'] <= $sku_item['discount_price']) {
- $sku_item['market_price'] = $sku_item['discount_price'] + $sku_item['discount_price'] * 0.5;
- }
- $sku_data = [
- 'out_sku_id' => $sku_item['sku_id'],
- 'sale_status' => 'AVAILABLE',
- 'stock_num' => numberFormat($sku_item['stock']),
- 'sale_price' => $sku_item['discount_price'] * 100,
- 'original_price' => $sku_item['market_price'] * 100,
- ];
- array_push($spu_data['skus'], $sku_data);
- }
- } else {
- $sku_item = $sku_list[0];
- $spu_data['sale_price'] = $sku_item['discount_price'] * 100;
- $spu_data['original_price'] = $sku_item['market_price'] * 100;
- $spu_data['stock_num'] = numberFormat($sku_item['stock']);
- $spu_data['sale_status'] = 'AVAILABLE';
- unset($spu_data['skus']);
- if ($spu_data['original_price'] <= $spu_data['sale_price']) {
- $spu_data['original_price'] = $spu_data['sale_price'] + $spu_data['sale_price'] * 0.5;
- }
- }
- $add_res = $miniapp->requestApi($api, $spu_data)[$key];
- if ($add_res['code'] != 10000) return $this->error('', $add_res['sub_msg']);
- $goods_data['item_id'] = $add_res['item_id'];
- $goods_data['update_time'] = time();
- model('shopalilife_goods')->update($goods_data, [['out_item_id', '=', $goods_id], ['site_id', '=', $site_id]]);
- return $this->success();
- }
-
- /***
- * 同步本地商品价格
- * @param $goods_id
- * @param $site_id
- * @param $type
- * @return array|void
- */
- public function syncLocalitemPrice($goods_id, $site_id)
- {
-
- $api = 'alipay.open.app.localitem.direct.modify';
- $key = 'alipay_open_app_localitem_direct_modify_response';
- $goods_info = model('goods')->getInfo([['goods_id', '=', $goods_id], ['site_id', '=', $site_id]], 'goods_id,goods_name,goods_image,sku_id,goods_content');
- $miniapp = new MinCode($site_id);
- // 同步商品所需数据
- $groupboy = new \addon\groupbuy\model\Groupbuy();
- $gwhere = [
- ['g.goods_id', '=', $goods_id]
- ];
- $groupboyInfo = $groupboy->getGroupbuyInfo($gwhere)['data'];
- $spu_data = [
- 'out_item_id' => $goods_info['goods_id'],
- 'sold_time' => [
- 'start_time' => date('Y-m-d H:i:s', $groupboyInfo['start_time']),
- 'end_time' => date('Y-m-d H:i:s', $groupboyInfo['end_time']),
- ],
- 'skus' => [
- [
- 'sale_price' => $groupboyInfo['groupbuy_price'] * 100,
- 'original_price' => $groupboyInfo['price'] * 100,
- 'sale_status' => 'AVAILABLE',
- 'stock_num' => numberFormat($groupboyInfo['goods_stock']),
- ]
- ]
- ];
- $add_res = $miniapp->requestApi($api, $spu_data)[$key];
- if ($add_res['code'] != 10000) return $this->error('', $add_res['sub_msg']);
- $goods_data['item_id'] = $add_res['item_id'];
- $goods_data['update_time'] = time();
- model('shopalilife_goods')->update($goods_data, [['out_item_id', '=', $goods_id], ['site_id', '=', $site_id]]);
- return $this->success();
- }
-
- /***
- * 查询商品信息
- * @param $site_id
- * @param $item_id
- * @param $type
- * @return mixed
- */
- public function goodsQuery($site_id, $item_id, $type = 'allcategory')
- {
- $aliapp = new MinCode($site_id);
- if ($type == 'allcategory') {
- $api = 'alipay.open.app.item.query';
- $key = 'alipay_open_app_item_modify_response';
- } else {
- $api = 'alipay.open.app.localitem.modify';
- $key = 'alipay_open_app_localitem_modify_response';
- }
- $res = $aliapp->requestApi('alipay.open.app.item.query', ['item_id' => $item_id]);
- $query = $res['alipay_open_app_item_query_response'];
- return $query;
- }
-
- /***
- * 获取单品信息
- * @param $param
- * @return mixed
- */
- public function getGoodsInfo($param, $field = '*', $alias = 'a', $join = null, $data = null)
- {
- $goodsInfo = model('shopalilife_goods')->getInfo($param, $field, $alias, $join);
- $goodsInfo['apptype'] = 'aliapp';
- return $goodsInfo;
- }
-
- /**
- * 添加商品
- * @param $param
- */
- public function addGoods($param, $type = 'allcategory')
- {
- $goods_list = model('goods')->getList([['goods_id', 'in', explode(',', $param['goods_ids'])], ['site_id', '=', $param['site_id']]], 'goods_id,goods_name,goods_image,sku_id,goods_content');
- if (!empty($goods_list)) {
- $category = (new Category())->getCategoryInfo($param['cat_id'], $param['site_id']);
- $miniapp = new MinCode($param['site_id']);
- if ($type == 'allcategory') {
- $api = 'alipay.open.app.item.create';
- $key = 'alipay_open_app_item_create_response';
- } else {
- $api = 'alipay.open.app.localitem.create';
- $key = 'alipay_open_app_localitem_create_response';
- }
- $miniConfig = $miniapp->getConfig();
- foreach ($goods_list as $goods_item) {
- // 需加到库中的商品数据
- $goods_data = [
- 'out_item_id' => $goods_item['goods_id'],
- 'category_id' => $param['cat_id']
- ];
- //处理图片
- $goods_image_arr = $this->handleImg($goods_item['goods_image'], 'BIG');
- $image_list = [];
- $image_urls = [];
- $this->driver = config('upload')['driver'] ?? 'gd';
- $this->image_service = new ImageService($this->driver);
- foreach ($goods_image_arr as $img_k => $img_y) {
- if (strpos($img_y, 'http://') !== false || strpos($img_y, 'https://') !== false) {
- $image = $this->image_service->open(img($img_y))->thumb(750, 750);
- $file = root_path() . 'runtime/temp/' . $goods_item['goods_id'] . $this->mime[$image->image->mime];
- $image->save($file, 100);
- $image = $miniapp->imageUpload($img_k . $goods_item['goods_name'], $file, true);
- $res = $image['alipay_offline_material_image_upload_response'];
- if ($res['code'] == 10000) {
- if (count($image_list) < 3) {
- $image_list[] = $res['image_id'];
- $image_urls[] = $res['image_url'];
- }
- }
- } else {
- $image_urls[] = 'https://oalipay-dl-django.alicdn.com/rest/1.0/image?fileIds=' . $img_y;
- if (count($image_list) < 3) {
- $image_list[] = $img_y;
- }
- }
- }
- $url = urlencode("pages_market/goods/detail?goods_id={$goods_item[ 'goods_id' ]}");
- // 同步商品所需数据
- $spu_data = [
- 'title' => $goods_item['goods_name'],
- 'path' => "alipays://platformapi/startApp?appId={$miniConfig['appid']}&page={$url}",
- 'head_img' => $image_list[0],
- 'image_list' => $image_list,
- 'desc_info' => [
- 'desc' => $goods_item['goods_name']
- ],
- 'skus' => []
- ];
- $sku_list = model('goods_sku')->getList([['goods_id', '=', $goods_item['goods_id']]], 'sku_id,sku_no,sku_image,discount_price,market_price,stock,sku_spec_format');
- if (count($sku_list) > 1) {
- foreach ($sku_list as $keys => $sku_item) {
- if ($keys >= 50) {
- continue;
- }
- if ($sku_item['market_price'] <= $sku_item['discount_price']) {
- $sku_item['market_price'] = $sku_item['discount_price'] + $sku_item['discount_price'] * 0.5;
- }
- $sku_image = $this->handleImg($sku_item['sku_image'], 'MID')[0];
- if (strpos($img_y, 'http://') !== false || strpos($img_y, 'https://') !== false) {
- //图片处理
- $image = $this->image_service->open(img($this->handleImg($sku_item['sku_image'])[0]))->thumb(400, 400);
- $file = root_path() . 'runtime/temp/' . $sku_item['sku_id'] . $this->mime[$image->image->mime];
- $image->save($file, 100);
- $sku_res = $miniapp->imageUpload($sku_item['sku_id'], $file, true)['alipay_offline_material_image_upload_response'];
- if ($sku_res['code'] == 10000) {
- $sku_image = $sku_res['image_id'];
- }
- }
- $sku_data = [
- 'out_sku_id' => $sku_item['sku_id'],
- 'thumb_img' => $sku_image,
- 'sale_status' => 'AVAILABLE',
- 'stock_num' => numberFormat($sku_item['stock']),
- 'sale_price' => $sku_item['discount_price'] * 100,
- 'original_price' => $sku_item['market_price'] * 100,
- 'item_details_page_model' => 0,
- 'sku_attrs' => [],
- ];
- if (!empty($sku_item['sku_spec_format'])) {
- foreach (json_decode($sku_item['sku_spec_format'], true) as $spec_item) {
- array_push($sku_data['sku_attrs'], [
- 'attr_key' => $spec_item['spec_name'],
- 'attr_value' => $spec_item['spec_value_name']
- ]);
- }
- } else {
- $sku_data['sku_attrs'] = [
- [
- 'attr_key' => $sku_item['sku_id'],
- 'attr_value' => $sku_item['sku_id']
- ]
- ];
- }
- array_push($spu_data['skus'], $sku_data);
- }
- } else {
- $sku_item = $sku_list[0];
- $spu_data['sale_price'] = $sku_item['discount_price'] * 100;
- $spu_data['original_price'] = $sku_item['market_price'] * 100;
- $spu_data['stock_num'] = numberFormat($sku_item['stock']);
- $spu_data['sale_status'] = 'AVAILABLE';
- $spu_data['item_details_page_model'] = 0;
- unset($spu_data['skus']);
- if ($spu_data['original_price'] <= $spu_data['sale_price']) {
- return $this->error('', '销售价格必须小于划线价');
- }
- }
- $add_res = $miniapp->requestApi($api, array_merge($goods_data, $spu_data))[$key];
- if ($add_res['code'] != 10000) return $this->error('', $add_res['sub_msg']);
- $goods_data['is_sync'] = 1;
- $goods_data['api_type'] = $type;
- $goods_data['spu_status'] = 'AUDITING';
- $goods_data['goods_id'] = $goods_item['goods_id'];
- $goods_data['item_id'] = $add_res['item_id'];
- $goods_data['goods_image'] = implode(',', $image_urls);
- $goods_data['goods_content'] = $this->getGoodsContent($param['site_id'], $goods_item);
- $goods_data['skus'] = json_encode($add_res['skus']);
- $goods_data['spu_data'] = json_encode($spu_data);
- $goods_data['create_time'] = time();
- $goods_data['site_id'] = $param['site_id'];
- $goods_data['cat_name'] = $category['cat_name'];
- model('shopalilife_goods')->add($goods_data);
- }
- return $this->success();
- } else {
- return $this->error('', '未获取到要添加的商品');
- }
- }
-
- /****
- * 添加新商品任务
- * @param $param
- * @param $type
- * @return array|void
- */
- public function newAddGoods($param, $type = 'allcategory', $item_type = 1)
- {
- if (isset($param['alipay_cat_id']) && !$param['alipay_cat_id']) return $this->error();
- $category = (new Category())->getCategoryInfo($param['alipay_cat_id'], $param['site_id']);
- if ($category) {
- $goods_data['is_sync'] = 0;
- $goods_data['out_item_id'] = $param['goods_id'];
- $goods_data['goods_id'] = $param['goods_id'];
- $goods_data['goods_name'] = $param['goods_name'];
- $goods_data['item_id'] = 0;
- $goods_data['item_type'] = $item_type;
- $goods_data['edit_status'] = 1;
- $goods_data['api_type'] = $type;
- $goods_data['category_id'] = $param['alipay_cat_id'];
- $goods_data['spu_status'] = 'NOTSYNC';
- $goods_data['skus'] = '{}';
- $goods_data['create_time'] = time();
- $goods_data['site_id'] = $param['site_id'];
- $goods_data['cat_name'] = $category['cat_name'];
- $res = model('shopalilife_goods')->add($goods_data);
- return $this->success($res);
- }
- return $this->error();
- }
-
- /***
- * 自动同步同步商品支付宝
- * @return void
- */
- public function AoutSyncGoodsAlipay()
- {
- $where = [
- ['l.is_sync', '=', 0]
- ];
- $join = [
- ['goods g', 'l.goods_id=g.goods_id', 'inner']
- ];
- $field = 'l.*';
- $goodsList = model('shopalilife_goods')->getList($where, $field, 'create_time desc', 'l', $join, '', 1);
- if ($goodsList) {
- foreach ($goodsList as $item) {
- $item['cat_id'] = $item['category_id'];
- if ($item['spu_status'] == 'NOTSYNC' && $item['api_type'] == 'allcategory') {
- $api = 'alipay.open.app.item.create';
- $key = 'alipay_open_app_item_create_response';
- $this->SyncAlipayGoods($item, $api, $key);
- } else if ($item['edit_status'] == 1 && $item['api_type'] == 'allcategory') {
- $this->SyncAlipayGoods($item);
- } else if ($item['spu_status'] == 'NOTSYNC' && $item['api_type'] != 'allcategory') {
- $this->localitemAddGoods($item, $item['item_type']);
- } else if ($item['edit_status'] == 0 && $item['api_type'] != 'allcategory') {
- $this->updateGoodslocalitemGoods($item['goods_id'], $item, $item['item_type']);
- } else {
- echo date('Y-m-d', time());
- }
- }
- }
- return $this->success();
- }
-
- /***
- * 同步支付宝修改支付宝
- * @param $param
- * @param $api
- * @param $response
- * @return array
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function SyncAlipayGoods($param, $api = 'alipay.open.app.item.modify', $response = 'alipay_open_app_item_modify_response', $category_id = '')
- {
- $field = 'sg.*,g.goods_id,g.goods_name,g.goods_image,g.sku_id,g.goods_content';
- $alias = 'sg';
- $join = [
- ['goods g', 'g.goods_id = sg.out_item_id', 'inner'],
- ];
- $condition = [
- ['g.goods_id', '=', $param['goods_id']],
- ['g.site_id', '=', $param['site_id']],
- ];
- $goods_info = model('shopalilife_goods')->getInfo($condition, $field, $alias, $join);
- $error = '';
- if (!empty($goods_info)) {
- $cat_id = $category_id ?: $goods_info['category_id'];
- $category = (new Category())->getCategoryInfo($cat_id, $param['site_id']);
- $miniapp = new MinCode($param['site_id']);
- //处理图片
- $goods_image_arr = $this->handleImg($goods_info['goods_image'], 'BIG');
- $image_list = [];
- $image_urls = [];
- $this->driver = config('upload')['driver'] ?? 'gd';
- $this->image_service = new ImageService($this->driver);
- foreach ($goods_image_arr as $img_k => $img_y) {
- if (strpos($img_y, 'http://') !== false || strpos($img_y, 'https://') !== false) {
- $image = $this->image_service->open(img($img_y))->thumb(750, 750);
- $file = root_path() . 'runtime/temp/' . $goods_info['goods_id'] . $this->mime[$image->image->mime];
- $image->save($file, 100);
- $image = $miniapp->imageUpload($goods_info['goods_id'], $file, true);
- $res = $image['alipay_offline_material_image_upload_response'];
- if ($res['code'] == 10000) {
- if (count($image_list) < 3) {
- $image_list[] = $res['image_id'];
- }
- $image_urls[] = $res['image_url'];
- }
- } else {
- if (count($image_list) < 3) {
- $image_list[] = $res['image_id'];
- }
- }
- }
- $url = urlencode("pages_market/goods/detail?goods_id={$goods_info[ 'goods_id' ]}");
- $miniConfig = $miniapp->getConfig();
- // 同步商品所需数据
- $spu_data = [
- 'out_item_id' => $goods_info['goods_id'],
- 'category_id' => $cat_id,
- 'title' => $goods_info['goods_name'],
- 'path' => "alipays://platformapi/startApp?appId={$miniConfig['appid']}&page={$url}",
- 'head_img' => $image_list[0],
- 'desc_info' => [
- 'desc' => $goods_info['goods_name']
- ],
- 'skus' => []
- ];
- $sku_list = Db::name('goods_sku')->where([['goods_id', '=', $goods_info['goods_id']]])->field('sku_id,sku_no,sku_image,discount_price,market_price,stock,sku_spec_format')->select();
- if (count($sku_list) > 1) {
- foreach ($sku_list as $keys => $sku_item) {
- if ($keys > 50) {
- $error = 'SKU大于50个部分属性丢失';
- continue;
- }
- if ($sku_item['market_price'] <= $sku_item['discount_price']) {
- $sku_item['market_price'] = $sku_item['discount_price'] + $sku_item['discount_price'] * 0.5;
- }
- $sku_image = $this->handleImg($sku_item['sku_image'], 'MID')[0];
- //图片处理
- if (strpos($sku_image, 'http://') || strpos($sku_image, 'https://')) {
- $image = $this->image_service->open(img($this->handleImg($sku_item['sku_image'])[0]))->thumb(400, 400);
- $file = root_path() . 'runtime/temp/' . $sku_item['sku_id'] . $this->mime[$image->image->mime];
- $image->save($file, 100);
- $sku_res = $miniapp->imageUpload($sku_item['sku_id'], $file, true)['alipay_offline_material_image_upload_response'];
- $sku_image = "";
- if ($sku_res['code'] == 10000) {
- $sku_image = $sku_res['image_id'];
- }
- }
- $sku_data = [
- 'out_sku_id' => $sku_item['sku_id'],
- 'thumb_img' => $sku_image,
- 'sale_status' => 'AVAILABLE',
- 'stock_num' => numberFormat($sku_item['stock']),
- 'sale_price' => $sku_item['discount_price'] * 100,
- 'original_price' => $sku_item['market_price'] * 100,
- 'item_details_page_model' => 0,
- 'sku_attrs' => [],
- ];
- if (!empty($sku_item['sku_spec_format'])) {
- foreach (json_decode($sku_item['sku_spec_format'], true) as $spec_item) {
- array_push($sku_data['sku_attrs'], [
- 'attr_key' => $spec_item['spec_name'],
- 'attr_value' => $spec_item['spec_value_name']
- ]);
- }
- }
- array_push($spu_data['skus'], $sku_data);
- }
- } else {
- $sku_item = $sku_list[0];
- $spu_data['sale_price'] = $sku_item['discount_price'] * 100;
- $spu_data['original_price'] = $sku_item['market_price'] * 100;
- $spu_data['stock_num'] = numberFormat($sku_item['stock']);
- $spu_data['image_list'] = $image_list;
- $spu_data['sale_status'] = 'AVAILABLE';
- $spu_data['item_details_page_model'] = 0;
- if ($spu_data['original_price'] <= $spu_data['sale_price']) {
- $spu_data['original_price'] = $spu_data['sale_price'] + $spu_data['sale_price'] * 0.5;
- }
- unset($spu_data['skus']);
- }
- $add_res = $miniapp->requestApi($api, $spu_data)[$response];
- if ($add_res['code'] != 10000) {
- $error = $add_res['sub_msg'];
- } else {
- $goods_data['item_id'] = $add_res['item_id'];
- $goods_data['skus'] = json_encode($add_res['skus']);
- $goods_data['spu_status'] = 'AUDITING';
- }
- $goods_data['goods_image'] = implode(',', $image_urls);
- $goods_data['goods_content'] = $this->getGoodsContent($param['site_id'], $goods_info);
- $goods_data['update_time'] = time();
- $goods_data['edit_status'] = 2;
- $goods_data['reject_reason'] = $error;
- $goods_data['cat_name'] = $category['cat_name'];
- $goods_data['spu_data'] = json_encode($spu_data);
- model('shopalilife_goods')->update($goods_data, [['out_item_id', '=', $param['goods_id']], ['site_id', '=', $param['site_id']]]);
- if ($error) return $this->error($error);
- return $this->success();
- } else {
- model('shopalilife_goods')->delete([['out_item_id', '=', $param['goods_id']], ['site_id', '=', $param['site_id']]]);
- $param['alipay_cat_id'] = $category_id;
- return $this->newAddGoods($param);
- }
- }
-
-
- /***
- * 同步商城图片
- * @return void
- * @throws \think\db\exception\DbException
- */
- public function SyncGoodsImage()
- {
- $field = 'sg.id,sg.site_id,sg.item_id,sg.api_type,sg.out_item_id,sg.goods_image as image,g.goods_id,g.goods_image,g.goods_content';
- $alias = 'sg';
- $join = [
- ['goods g', 'g.goods_id = sg.out_item_id', 'inner']
- ];
- $condition = [
- ['sg.reject_reason', '<>', 'imgerr'],
- ['sg.spu_status', '<>', 'NOTSYNC'],
- ['sg.goods_id', '>', 0],
- ['sg.goods_image', '=', '']
- ];
- $goods_info = model('shopalilife_goods')->getList($condition, $field, '', $alias, $join, '', 10);
- if ($goods_info) {
- foreach ($goods_info as $item) {
- $goodsInfo = $this->goodsQuery($item['site_id'], $item['item_id'], $item['api_type']);
- if ($goodsInfo['code'] == '10000' && isset($goodsInfo['image_list'])) {
- $data['goods_image'] = implode(',', $goodsInfo['image_list']);
- $data['goods_content'] = $this->getGoodsContent($item['site_id'], $item);
- model('shopalilife_goods')->update($data, ['goods_id' => $item['goods_id'], 'site_id' => $item['site_id']]);
- } else {
- $data['reject_reason'] = 'imgerr';
- }
- model('shopalilife_goods')->update($data, ['goods_id' => $item['goods_id'], 'site_id' => $item['site_id']]);
- }
- return $this->success('成功');
- }
- return $this->error('无数据');
- }
-
-
- /***
- * 上传产品图片到支付宝
- * @param $id
- * @return array|void
- */
- public function UploadImage($id = '')
- {
- try {
- $albumInfo = Db::name('album_pic')->where('pic_id', '=', $id)->field('pic_id,pic_path,site_id,thumb_value')->find();
- if ($albumInfo && !$albumInfo['thumb_value']) {
- $config_model = new Config();
- $config_info = $config_model->getAppConfig($albumInfo['site_id'])['data']['value'];
- if (isset($config_info['account'])) {
- $this->driver = config('upload')['driver'] ?? 'gd';
- $this->image_service = new ImageService($this->driver);
- $miniapp = new MinCode($albumInfo['site_id']);
- $ali_pic_value = [];
- $ali_pic_path = '';
- //图片处理
- $image = $this->image_service->open(img($albumInfo['pic_path']));
- $file1 = root_path() . 'runtime/temp/' . md5($albumInfo['pic_path']) . $this->mime[$image->image->mime];
- if (strpos($albumInfo['pic_path'], 'alicdn.com') !== false && (strpos($albumInfo['pic_path'], 'http://') !== false || strpos($albumInfo['pic_path'], 'https://') !== false)) {
- $image->save($file1, 100);
- $pic_path = $miniapp->imageUpload(md5($albumInfo['pic_path']), $file1, true)['alipay_offline_material_image_upload_response'];
- if ($pic_path['code'] == 10000) {
- $ali_pic_path = $pic_path['image_url'];
- }
- }
- $image = $this->image_service->open($file1)->thumb(400, 400);
- $file = root_path() . 'runtime/temp/' . md5($albumInfo['pic_path']) . '_400' . $this->mime[$image->image->mime];
- $image->save($file, 100);
- $img_400 = $miniapp->imageUpload(md5($albumInfo['pic_path']) . '_400', $file, true)['alipay_offline_material_image_upload_response'];
- if ($img_400['code'] == 10000) {
- $ali_pic_value['MID'] = [
- 'size' => 'BIG',
- "width" => 400,
- "height" => 400,
- 'image_id' => $img_400['image_id'],
- 'thumb_name' => $img_400['image_url'],
- ];
- }
- $image = $this->image_service->open($file1)->thumb(750, 750);
- $file = root_path() . 'runtime/temp/' . md5($albumInfo['pic_path']) . '_750' . $this->mime[$image->image->mime];
- $image->save($file, 100);
- $img_750 = $miniapp->imageUpload(md5($albumInfo['pic_path']) . '_750', $file, true)['alipay_offline_material_image_upload_response'];
- if ($img_750['code'] == 10000) {
- $ali_pic_value['BIG'] = [
- 'size' => 'BIG',
- "width" => 750,
- "height" => 750,
- 'image_id' => $img_750['image_id'],
- 'thumb_name' => $img_750['image_url'],
- ];
- }
- $data = [];
- if ($ali_pic_path) {
- $data['ali_pic_path'] = $ali_pic_path;
- }
- if ($ali_pic_value) {
- $data['thumb_value'] = json_encode($ali_pic_value);
- }
- if ($data) {
- $res = Db::name('album_pic')->where('pic_id', '=', $id)->update($data);
- return $this->success($res);
- }
- }
- }
- return $this->success();
- } catch (\Exception $e) {
- return $this->error($e->getMessage());
- }
- }
-
- /***
- * 添加团购商品
- * @return void
- */
- public function localitemAddGoods($param, $item_type = '', $merchant_name = '', $phone_number = '')
- {
- $goods_ids = $param['goods_ids'];
- $goods_list = model('goods')->getList([['goods_id', 'in', $goods_ids], ['site_id', '=', $param['site_id']]], 'goods_id,goods_name,goods_image,sku_id,goods_content,unit');
- //保存本地团购信息获取商品信息
- $groupbuy_data = [
- 'site_id' => $param['site_id'],
- 'start_time' => strtotime($param['start_time']),
- 'end_time' => strtotime($param['end_time']),
- 'rule' => $param['notification']
- ];
- $groupbuy_model = new GroupbuyModel();
- $groupbuy_model->addGroupbuy($groupbuy_data, $param['goods_list'], $goods_ids);
- if (!empty($goods_list)) {
- $category = (new Category())->getCategoryInfo($param['cat_id'], $param['site_id']);
- $miniapp = new MinCode($param['site_id']);
- $api = 'alipay.open.app.localitem.create';
- $key = 'alipay_open_app_localitem_create_response';
- $miniConfig = $miniapp->getConfig();
- foreach ($goods_list as $goods_item) {
- // 需加到库中的商品数据
- $goods_data = [
- 'out_item_id' => $goods_item['goods_id'],
- 'category_id' => $param['cat_id']
- ];
- $groupboy = new \addon\groupbuy\model\Groupbuy();
- $gwhere = [
- ['g.goods_id', '=', $goods_item['goods_id']]
- ];
- $groupboyInfo = $groupboy->getGroupbuyInfo($gwhere)['data'];
- if (empty($groupboyInfo)) return $this->error('', '团购活动不存在');
- //处理图片
- $goods_image_arr = $this->handleImg($goods_item['goods_image'], 'BIG');
- $image_list = [];
- $this->driver = config('upload')['driver'] ?? 'gd';
- $this->image_service = new ImageService($this->driver);
- $chat = urlencode('pages_tool/chat/room');
- foreach ($goods_image_arr as $img_k => $img_y) {
- if (strpos($img_y, 'http://') !== false || strpos($img_y, 'https://') !== false) {
- $image = $this->image_service->open(img($img_y))->thumb(750, 750);
- $file = root_path() . 'runtime/temp/' . $goods_item['goods_id'] . $this->mime[$image->image->mime];
- $image->save($file, 100);
- $image = $miniapp->imageUpload($img_k . $goods_item['goods_name'], $file, true);
- $res = $image['alipay_offline_material_image_upload_response'];
- if ($res['code'] == 10000) {
- if (count($image_list) < 3) {
- $image_list[] = $res['image_id'];
- }
- } else {
- return $this->error('', $res['sub_msg'] . '或图片格式不正确');
- }
- } else {
- if (count($image_list) < 3) {
- $image_list[] = $img_y;
- }
- }
- }
- $groupboy_url = urlencode("pages_promotion/groupbuy/detail?groupbuy_id={$groupboyInfo[ 'groupbuy_id']}");
- // 同步商品所需数据
- $spu_data = [
- 'title' => $goods_item['goods_name'],
- 'path' => "alipays://platformapi/startApp?appId={$miniConfig['appid']}&page={$groupboy_url}",
- 'merchant_name' => $merchant_name,
- 'head_img' => $image_list[0],
- 'image_list' => $image_list,
- 'item_type' => $item_type,
- 'item_details_page_model' => 0,
- 'sold_time' => [
- 'start_time' => $param['start_time'],
- 'end_time' => $param['end_time'],
- ],
- 'customer_service_mobile' => [
- 'phone_type' => isMobileNo($phone_number) ? 1 : 2,
- 'phone_number' => $phone_number,
- 'customer_link' => "alipays://platformapi/startApp?appId={$miniConfig['appid']}&page={$chat}",
- ],
- 'skus' => []
- ];
- $sku_list = model('goods_sku')->getList([['goods_id', '=', $goods_item['goods_id']]], 'sku_id,sku_name,discount_price,market_price,stock,sku_spec_format');
- if (count($sku_list) > 50) {
- return $this->error('', '规格属性不得超过50个');
- }
- $commodity = [
- 'group_name' => '商品组',
- 'total_count' => '',
- 'option_count' => 1,
- 'item_list' => []
- ];
- $unit = $goods_item['unit'] ? $goods_item['unit'] : '人';
- $stock = 0;
- if (count($sku_list) > 1) {
- foreach ($sku_list as $keys => $sku_item) {
- if ($keys >= 50) {
- continue;
- }
- if ($sku_item['market_price'] <= $sku_item['discount_price']) {
- return $this->error('', '销售价格必须小于划线价');
- }
- $stock += numberFormat($sku_item['stock']);
- $sku_spec_format = json_decode($sku_item['sku_spec_format'], true)[0];
- $item_list = [
- 'name' => $sku_spec_format['spec_value_name'],
- 'count' => 1,
- 'count_unit' => $unit,
- 'price' => $sku_item['discount_price'] * 100,
- 'unit' => '元',
- ];
- array_push($commodity['item_list'], $item_list);
- }
- } else {
- $sku_item = $sku_list[0];
- $commodity['item_list'][] = [
- 'name' => $goods_item['goods_name'],
- 'count' => 1,
- 'count_unit' => $unit,
- 'price' => $groupboyInfo['groupbuy_price'] * 100,
- 'unit' => '元',
- ];
- $stock = numberFormat($sku_item['stock']);
- if ($sku_item['market_price'] <= $groupboyInfo['groupbuy_price']) {
- return $this->error('', '销售价格必须小于划线价');
- }
- }
- $skus = [
- 'sale_price' => $groupboyInfo['groupbuy_price'] * 100,
- 'original_price' => $groupboyInfo['price'] * 100,
- 'sale_status' => 'AVAILABLE',
- 'stock_num' => numberFormat($sku_item['stock']),
- ];
- $spu_data['skus'][] = $skus;
- $commodity['total_count'] = count($commodity['item_list']);
- $commodity['option_count'] = 1;
- $commodityArr[] = $commodity;
- $use_url = urlencode("pages/member/index");
- $use_path = "alipays://platformapi/startApp?appId={$miniConfig['appid']}&page={$use_url}";
- $spu_data['attrs'] = [
- [ //库存设置
- 'attr_key' => 'limit_stock_rule',
- 'attr_value' => [
- 'limit' => 1,
- 'num' => $stock,
- 'unit' => $unit,
- ],
- ],
- [
- 'attr_key' => 'original_price_source',//原价配置
- 'attr_value' => 1,
- ],
- [
- 'attr_key' => 'commodity',//套餐
- 'attr_value' => $commodityArr,
- ],
- [
- 'attr_key' => 'notification',//套餐
- 'attr_value' => $param['notification'],
- ],
- [
- 'attr_key' => 'select_all_shop',//蚂蚁门店
- 'attr_value' => 1,
- ],
- [
- 'attr_key' => 'use_date',//可使用日期
- 'attr_value' => [
- 'use_date_type' => 1,
- 'use_start_date' => date('Y-m-d', strtotime($param['start_time'])),
- 'use_end_date' => date('Y-m-d', strtotime($param['end_time'])),
- ],
- ],
- [
- 'attr_key' => 'use_limit',//使用时间限制
- 'attr_value' => [
- 'use_time_type' => 1
- ],
- ],
- [
- 'attr_key' => 'limit_buy_rule',//限购
- 'attr_value' => [
- 'limit' => 0,
- 'num' => ''
- ]
- ],
- [
- 'attr_key' => 'refund_rule',//退费规则
- 'attr_value' => [
- 'refund_policy' => [1, 2]
- ],//使用时间限制
- ],
- [
- 'attr_key' => 'merchant_refund_confirm',//由商家确认退款
- 'attr_value' => 2,//使用时间限制1 商家确认,2无需商家确认
- ],
- [
- 'attr_key' => 'usage_type',//使用方式
- 'attr_value' => [
- 'usage_list' => [
- ['use_type' => 1],
- [
- 'use_type' => 2,
- 'use_path' => $use_path,
- ],
- ]
- ],
- ],
- [
- 'attr_key' => 'verify_type',//核销方式
- 'attr_value' => ['1', '2'],
- ],
- [
- 'attr_key' => 'verify_type',//核销方式
- 'attr_value' => ['1', '2'],
- ],
- [
- 'attr_key' => 'code_source_type',//核销码 1三方核销码 2支付宝核销码
- 'attr_value' => '2',
- ],
- [
- 'attr_key' => 'settle_type',//结算方式
- 'attr_value' => [
- 'settle_type' => '1'
- ]
- ],
- [
- 'attr_key' => 'preorder_rule',//是否预约
- 'attr_value' => [
- 'need_appointment' => false,
- 'appointment_instruction' => '',//预约说明
- ],
- ],
- [
- 'attr_key' => 'contact_info_type',//顾客预留手机信息
- 'attr_value' => '1',
- ],
- [
- 'attr_key' => 'order_settle_rule',//结算规则 1默认核销结算
- 'attr_value' => ['order_settle_rule' => 1],
- ],
-// [
-// 'attr_key' => 'detail_rich_desc',//富文本消息
-// 'attr_value' =>[
-// 'type'=>'1',
-// 'content'=>$goods_item['goods_content'],
-// ]
-// ],
- [
- 'attr_key' => 'coupon_usage_rule',//是否可以使用优惠券 1不可使用 2可使用
- 'attr_value' => '1',
- ],
- [
- 'attr_key' => 'verify_tool',//核销工具
- 'attr_value' => '接口API',
- ]
- ];
- $add_res = $miniapp->requestApi($api, array_merge($goods_data, $spu_data))[$key];
- // 添加商品到小程序
- if ($add_res['code'] != 10000) return $this->error('', $add_res['sub_msg']);
- $goods_data['is_sync'] = 1;
- $goods_data['api_type'] = 'localitem';
- $goods_data['spu_status'] = 'AUDITING';
- $goods_data['goods_id'] = $goods_item['goods_id'];
- $goods_data['item_id'] = $add_res['item_id'];
- $goods_data['skus'] = json_encode($add_res['skus']);
- $goods_data['create_time'] = time();
- $goods_data['site_id'] = $param['site_id'];
- $goods_data['cat_name'] = $category['cat_name'];
- $goods_data['site_name'] = $param['merchant_name'];
- $goods_data['phone_number'] = $param['phone_number'];
- $goods_data['spu_data'] = json_encode($spu_data);
- model('shopalilife_goods')->add($goods_data);
- }
- return $this->success();
- } else {
- return $this->error('', '未获取到要添加的商品');
- }
- }
-
- /***
- * 更新本地生活
- * @param $param
- * @return void
- */
- public function updateGoodslocalitemGoods($goods_id, $param, $item_type)
- {
- //保存本地团购信息获取商品信息
- $goods_model = new GoodsModel();
- $goods_info = $goods_model->getGoodsInfo([['goods_id', '=', $goods_id]], 'site_id,goods_name,goods_image,price,unit')['data'];
- if (!empty($goods_info)) {
- $groupbuy_data = [
- 'goods_id' => $goods_id,
- 'goods_name' => $goods_info['goods_name'],
- 'goods_image' => $goods_info['goods_image'],
- 'goods_price' => $goods_info['price'],
- 'groupbuy_price' => $param['groupbuy_price'],
- 'buy_num' => $param['buy_num'],
- 'start_time' => strtotime($param['start_time']),
- 'end_time' => strtotime($param['end_time']),
- 'rule' => $param['notification'],
- ];
- $groupbuy_id = $param['groupbuy_id'];
- $groupbuy_model = new GroupbuyModel();
- $groupbuy_model->editGroupbuy($groupbuy_id, $param['site_id'], $groupbuy_data);//编辑团购
- $category = (new Category())->getCategoryInfo($param['cat_id'], $goods_info['site_id']);
- $miniapp = new MinCode($goods_info['site_id']);
- $api = 'alipay.open.app.localitem.modify';
- $key = 'alipay_open_app_localitem_modify_response';
- $miniConfig = $miniapp->getConfig();
- // 需加到库中的商品数据
- $goods_data = [
- 'out_item_id' => $goods_id,
- 'category_id' => $param['cat_id']
- ];
- //处理图片
- $goods_image_arr = $this->handleImg($goods_info['goods_image'], 'BIG');
- $image_list = [];
- $this->driver = config('upload')['driver'] ?? 'gd';
- $this->image_service = new ImageService($this->driver);
- $chat = urlencode('pages_tool/chat/room');
- foreach ($goods_image_arr as $img_k => $img_y) {
- if (strpos($img_y, 'http://') !== false || strpos($img_y, 'https://') !== false) {
- $image = $this->image_service->open(img($img_y))->thumb(800, 800);
- $file = root_path() . 'runtime/temp/' . $goods_id . $this->mime[$image->image->mime];
- $image->save($file, 100);
- $image = $miniapp->imageUpload($img_k . $goods_info['goods_name'], $file, true);
- $res = $image['alipay_offline_material_image_upload_response'];
- if ($res['code'] == 10000) {
- if (count($image_list) < 3) {
- $image_list[] = $res['image_id'];
- }
- }
- } else {
- if (count($image_list) < 3) {
- $image_list[] = $img_y;
- }
- }
- }
- $groupboy_url = urlencode("pages_promotion/groupbuy/detail?groupbuy_id={$groupbuy_id}");
- // 同步商品所需数据
- $spu_data = [
- 'title' => $goods_info['goods_name'],
- 'path' => "alipays://platformapi/startApp?appId={$miniConfig['appid']}&page={$groupboy_url}",
- 'merchant_name' => $param['merchant_name'],
- 'head_img' => $image_list[0],
- 'image_list' => $image_list,
- 'item_type' => $item_type,
- 'item_details_page_model' => 0,
- 'sold_time' => [
- 'start_time' => $param['start_time'],
- 'end_time' => $param['end_time'],
- ],
- 'customer_service_mobile' => [
- 'phone_type' => isMobileNo($param['phone_number']) ? 1 : 2,
- 'phone_number' => $param['phone_number'],
- 'customer_link' => "alipays://platformapi/startApp?appId={$miniConfig['appid']}&page={$chat}",
- ],
- 'skus' => []
- ];
- $sku_list = model('goods_sku')->getList([['goods_id', '=', $goods_id]], 'sku_id,sku_name,discount_price,market_price,stock,sku_spec_format');
- if (count($sku_list) > 25) {
- return $this->error('', '规格属性不得超过25个');
- }
- $commodity = [
- 'group_name' => '商品组',
- 'total_count' => '',
- 'option_count' => 1,
- 'item_list' => []
- ];
- $unit = $goods_info['unit'] ? $goods_info['unit'] : '人';
- $stock = 0;
- if (count($sku_list) > 1) {
- foreach ($sku_list as $keys => $sku_item) {
- if ($keys >= 25) {
- continue;
- }
- if ($sku_item['market_price'] <= $sku_item['discount_price']) {
- return $this->error('', '销售价格必须小于划线价');
- }
- $stock += numberFormat($sku_item['stock']);
- $sku_spec_format = json_decode($sku_item['sku_spec_format'], true)[0];
- $item_list = [
- 'name' => $sku_spec_format['spec_value_name'],
- 'count' => 1,
- 'count_unit' => $unit,
- 'price' => $sku_item['discount_price'] * 100,
- 'unit' => '元',
- ];
- array_push($commodity['item_list'], $item_list);
- }
- } else {
- $sku_item = $sku_list[0];
- $commodity['item_list'][] = [
- 'name' => $goods_info['goods_name'],
- 'count' => 1,
- 'count_unit' => $unit,
- 'price' => $param['groupbuy_price'] * 100,
- 'unit' => '元',
- ];
- $stock = numberFormat($sku_item['stock']);
- if ($sku_item['market_price'] <= $param['groupbuy_price']) {
- return $this->error('', '销售价格必须小于划线价');
- }
- }
- $skus = [
- 'sale_price' => $param['groupbuy_price'] * 100,
- 'original_price' => $goods_info['price'] * 100,
- 'sale_status' => 'AVAILABLE',
- 'stock_num' => numberFormat($sku_item['stock']),
- ];
- $spu_data['skus'][] = $skus;
- $commodity['total_count'] = count($commodity['item_list']);
- $commodity['option_count'] = 1;
- $commodityArr[] = $commodity;
- $use_url = urlencode("pages/member/index");
- $use_path = "alipays://platformapi/startApp?appId={$miniConfig['appid']}&page={$use_url}";
- $spu_data['attrs'] = [
- [ //库存设置
- 'attr_key' => 'limit_stock_rule',
- 'attr_value' => [
- 'limit' => 1,
- 'num' => $stock,
- 'unit' => $unit,
- ],
- ],
- [
- 'attr_key' => 'original_price_source',//原价配置
- 'attr_value' => 1,
- ],
- [
- 'attr_key' => 'commodity',//套餐
- 'attr_value' => $commodityArr,
- ],
- [
- 'attr_key' => 'notification',//套餐
- 'attr_value' => $param['notification'],
- ],
- [
- 'attr_key' => 'select_all_shop',//蚂蚁门店
- 'attr_value' => 1,
- ],
- [
- 'attr_key' => 'use_date',//可使用日期
- 'attr_value' => [
- 'use_date_type' => 1,
- 'use_start_date' => date('Y-m-d', strtotime($param['start_time'])),
- 'use_end_date' => date('Y-m-d', strtotime($param['end_time'])),
- ],
- ],
- [
- 'attr_key' => 'use_limit',//使用时间限制
- 'attr_value' => [
- 'use_time_type' => 1
- ],
- ],
- [
- 'attr_key' => 'limit_buy_rule',//限购
- 'attr_value' => [
- 'limit' => 0,
- 'num' => ''
- ]
- ],
- [
- 'attr_key' => 'refund_rule',//退费规则
- 'attr_value' => [
- 'refund_policy' => [1, 2]
- ],//使用时间限制
- ],
- [
- 'attr_key' => 'merchant_refund_confirm',//由商家确认退款
- 'attr_value' => 2,//使用时间限制1 商家确认,2无需商家确认
- ],
- [
- 'attr_key' => 'usage_type',//使用方式
- 'attr_value' => [
- 'usage_list' => [
- ['use_type' => 1],
- [
- 'use_type' => 2,
- 'use_path' => $use_path,
- ],
- ]
- ],
- ],
- [
- 'attr_key' => 'verify_type',//核销方式
- 'attr_value' => ['1', '2'],
- ],
- [
- 'attr_key' => 'verify_type',//核销方式
- 'attr_value' => ['1', '2'],
- ],
- [
- 'attr_key' => 'code_source_type',//核销码 1三方核销码 2支付宝核销码
- 'attr_value' => '2',
- ],
- [
- 'attr_key' => 'settle_type',//结算方式
- 'attr_value' => [
- 'settle_type' => '1'
- ]
- ],
- [
- 'attr_key' => 'preorder_rule',//是否预约
- 'attr_value' => [
- 'need_appointment' => false,
- 'appointment_instruction' => '',//预约说明
- ],
- ],
- [
- 'attr_key' => 'contact_info_type',//顾客预留手机信息
- 'attr_value' => '1',
- ],
- [
- 'attr_key' => 'order_settle_rule',//结算规则 1默认核销结算
- 'attr_value' => ['order_settle_rule' => 1],
- ],
- [
- 'attr_key' => 'coupon_usage_rule',//是否可以使用优惠券 1不可使用 2可使用
- 'attr_value' => '1',
- ],
- [
- 'attr_key' => 'verify_tool',//核销工具
- 'attr_value' => '接口API',
- ]
- ];
- $add_res = $miniapp->requestApi($api, array_merge($goods_data, $spu_data))[$key];
- // 添加商品到小程序
- if ($add_res['code'] != 10000) return $this->error('', $add_res['sub_msg']);
- $goods_data['is_sync'] = 1;
- $goods_data['api_type'] = 'localitem';
- $goods_data['spu_status'] = 'AUDITING';
- $goods_data['goods_id'] = $goods_id;
- $goods_data['item_id'] = $add_res['item_id'];
- $goods_data['skus'] = json_encode($add_res['skus']);
- $goods_data['create_time'] = time();
- $goods_data['site_id'] = $goods_info['site_id'];
- $goods_data['cat_name'] = $category['cat_name'];
- $goods_data['site_name'] = $param['merchant_name'];
- $goods_data['phone_number'] = $param['phone_number'];
- $goods_data['spu_data'] = json_encode($spu_data);
- model('shopalilife_goods')->update($goods_data, ['goods_id' => $goods_id]);
- return $this->success();
- } else {
- return $this->error('', '未获取到要添加的商品');
- }
- }
-
- /**
- * 更新商品
- * @param $param
- * @return array
- */
- public function updateGoods($param, $type = 'allcategory')
- {
- $shopcompoent_goods_info = Db::name('shopalilife_goods')->where([['out_item_id', '=', $param['goods_id']], ['site_id', '=', $param['site_id']]])->find();
- $goods_info = Db::name('goods')->where([['goods_id', '=', $param['goods_id']], ['site_id', '=', $param['site_id']]])->field('goods_id,goods_name,goods_image,sku_id,goods_content')->find();
- $error = '';
- if (!empty($shopcompoent_goods_info) && !empty($goods_info)) {
- $cat_id = $param['cat_id'] ?? $shopcompoent_goods_info['category_id'];
- $category = (new Category())->getCategoryInfo($cat_id, $param['site_id']);
- $miniapp = new MinCode($param['site_id']);
- //处理图片
- $goods_image_arr = $this->handleImg($goods_info['goods_image'], 'BIG');
- $image_list = [];
- $image_urls = [];
- $this->driver = config('upload')['driver'] ?? 'gd';
- $this->image_service = new ImageService($this->driver);
- foreach ($goods_image_arr as $img_k => $img_y) {
- if (strpos($img_y, 'http://') !== false || strpos($img_y, 'https://') !== false) {
- $image = $this->image_service->open(img($img_y))->thumb(750, 750);
- $file = root_path() . 'runtime/temp/' . $goods_info['goods_id'] . '_750' . $this->mime[$image->image->mime];
- $image->save($file, 100);
- $image = $miniapp->imageUpload($goods_info['goods_id'] . '_750', $file, true);
- $res = $image['alipay_offline_material_image_upload_response'];
- if ($res['code'] == 10000) {
- $image_urls[] = $res['image_url'];
- if (count($image_list) < 3) {
- $image_list[] = $res['image_id'];
- }
- }
- } else {
- $image_list[] = $img_y;
- $image_urls[] = 'https://oalipay-dl-django.alicdn.com/rest/1.0/image?fileIds=' . $img_y;
- }
- }
- $url = urlencode("pages_market/goods/detail?goods_id={$goods_info[ 'goods_id' ]}");
- $miniConfig = $miniapp->getConfig();
- // 同步商品所需数据
- $spu_data = [
- 'out_item_id' => $goods_info['goods_id'],
- 'category_id' => $cat_id,
- 'title' => $goods_info['goods_name'],
- 'path' => "alipays://platformapi/startApp?appId={$miniConfig['appid']}&page={$url}",
- 'head_img' => $image_list[0],
- 'desc_info' => [
- 'desc' => $goods_info['goods_name']
- ],
- 'skus' => []
- ];
- $sku_list = Db::name('goods_sku')->where([['goods_id', '=', $goods_info['goods_id']]])->field('sku_id,sku_no,sku_image,discount_price,market_price,stock,sku_spec_format')->select();
- if (count($sku_list) > 1) {
- foreach ($sku_list as $keys => $sku_item) {
- if ($keys > 25) {
- $error = 'SKU大于25个部分属性丢失';
- continue;
- }
- if ($sku_item['market_price'] <= $sku_item['discount_price']) {
- $sku_item['market_price'] = $sku_item['discount_price'] + $sku_item['discount_price'] * 0.5;
- }
- $sku_image = $this->handleImg($sku_item['sku_image'], 'MID')[0];
- if (strpos($sku_image, 'http://') || strpos($sku_image, 'https://')) {
- //图片处理
- $image = $this->image_service->open(img($this->handleImg($sku_item['sku_image'])[0]))->thumb(400, 400);
- $file = root_path() . 'runtime/temp/' . $sku_item['sku_id'] . $this->mime[$image->image->mime];
- $image->save($file, 100);
- $sku_res = $miniapp->imageUpload($sku_item['sku_id'], $file, true)['alipay_offline_material_image_upload_response'];
- $sku_image = "";
- if ($sku_res['code'] == 10000) {
- $sku_image = $sku_res['image_id'];
- }
- }
- $sku_data = [
- 'out_sku_id' => $sku_item['sku_id'],
- 'thumb_img' => $sku_image,
- 'sale_status' => 'AVAILABLE',
- 'stock_num' => numberFormat($sku_item['stock']),
- 'sale_price' => $sku_item['discount_price'] * 100,
- 'original_price' => $sku_item['market_price'] * 100,
- 'item_details_page_model' => 0,
- 'sku_attrs' => [],
- ];
- if (!empty($sku_item['sku_spec_format'])) {
- foreach (json_decode($sku_item['sku_spec_format'], true) as $spec_item) {
- array_push($sku_data['sku_attrs'], [
- 'attr_key' => $spec_item['spec_name'],
- 'attr_value' => $spec_item['spec_value_name']
- ]);
- }
- }
- array_push($spu_data['skus'], $sku_data);
- }
- } else {
- $sku_item = $sku_list[0];
- $spu_data['sale_price'] = $sku_item['discount_price'] * 100;
- $spu_data['original_price'] = $sku_item['market_price'] * 100;
- $spu_data['stock_num'] = numberFormat($sku_item['stock']);
- $spu_data['image_list'] = $image_list;
- $spu_data['sale_status'] = 'AVAILABLE';
- $spu_data['item_details_page_model'] = 0;
- if ($spu_data['original_price'] <= $spu_data['sale_price']) {
- $spu_data['original_price'] = $spu_data['sale_price'] + $spu_data['sale_price'] * 0.5;
- }
- unset($spu_data['skus']);
- }
- $add_res = $miniapp->requestApi('alipay.open.app.item.modify', $spu_data)['alipay_open_app_item_modify_response'];
- if ($add_res['code'] != 10000) {
- $error = $add_res['sub_msg'];
- } else {
- $goods_data['item_id'] = $add_res['item_id'];
- $goods_data['skus'] = json_encode($add_res['skus']);
- $goods_data['spu_status'] = 'AUDITING';
- }
- $goods_data['goods_image'] = implode(',', $image_urls);
- $goods_data['goods_content'] = $this->getGoodsContent($param['site_id'], $goods_info);
- $goods_data['update_time'] = time();
- $goods_data['edit_status'] = 2;
- $goods_data['reject_reason'] = $error;
- $goods_data['cat_name'] = $category['cat_name'];
- $goods_data['spu_data'] = json_encode($spu_data);
- model('shopalilife_goods')->update($goods_data, [['out_item_id', '=', $param['goods_id']], ['site_id', '=', $param['site_id']]]);
- if ($error) return $this->error($error);
- return $this->success();
- } else {
- return $this->error('', '未获取到要更新的商品');
- }
- }
-
- /***
- * 替换支付宝图片富文本
- * @param $site_id
- * @param $goods_info
- * @return string|string[]
- * @throws \think\db\exception\DbException
- */
- public function getGoodsContent($site_id, $goods_info)
- {
- $pattern = '/src=\"(.+?)\".*?/';
- $content = $goods_info['goods_content'];
- preg_match_all($pattern, $content, $match);
- if ($match) {
- //处理图片
- $newArr = [];
- $images = $match[1];
- $album_pic = Db::name('album_pic')->where('pic_path', 'in', $images)->column('pic_id,pic_path,ali_pic_path', 'pic_path');
- $this->driver = config('upload')['driver'] ?? 'gd';
- $this->image_service = new ImageService($this->driver);
- $miniapp = new MinCode($site_id);
- foreach ($images as $img_path) {
- if (strpos($img_path, 'alicdn.com') || (!isset($album_pic[$img_path]) && strpos($img_path, 'https://') || strpos($img_path, 'http://'))) {
- $newArr[] = $img_path;
- continue;
- }
- if (isset($album_pic[$img_path]) && $album_pic[$img_path]['ali_pic_path']) {
- $newArr[] = $album_pic[$img_path]['ali_pic_path'];
- } else {
- $image = $this->image_service->open(img($img_path));
- $file = root_path() . 'runtime/temp/' . $goods_info['goods_id'] . $this->mime[$image->image->mime];
- $image->save($file, 100);
- $image = $miniapp->imageUpload($img_path, $file, true);
- $res = $image['alipay_offline_material_image_upload_response'];
- if ($res['code'] == 10000) {
- $newArr[] = $res['image_url'];
- Db::name('album_pic')->where('pic_path', '=', $img_path)->update(['ali_pic_path' => $res['image_url']]);
- } else {
- $newArr[] = $img_path;
- }
- }
- }
- return str_replace($images, $newArr, $content);
- }
- return '';
- }
-
- /***
- * 编辑商品信息
- * @param $param
- * @return void
- */
- public function GoodsEditupdate($param)
- {
- $where = [
- 'site_id' => $param['site_id'],
- 'goods_id' => $param['goods_id'],
- ];
- $param['cat_id'] = $param['alipay_cat_id'];
- $goodsInfo = model('shopalilife_goods')->getInfo($where);
- if ($goodsInfo) {
- $sku_info = json_decode($goodsInfo['skus'], true);
- $out_sku_ids = array_column($sku_info, 'out_sku_id');
- $sku_list = model('goods_sku')->getColumn([['goods_id', '=', $param['goods_id']]], 'sku_id');
- $result = array_udiff($sku_list, $out_sku_ids, function ($a, $b) {
- return $a == $b ? 0 : 1; //查询是否有更新SKU
- });
- if (empty($result) && $goodsInfo['category_id'] == $param['alipay_cat_id']) {
- $this->syncDtockPrice($param['goods_id'], $param['site_id']);
- } else {
- model('shopalilife_goods')->update(['edit_status' => 1, 'is_sync' => 0, 'reject_reason' => ''], [['out_item_id', '=', $param['goods_id']], ['site_id', '=', $param['site_id']]]);
- }
- } else {
- $this->newAddGoods($param);
- }
- return $this->success();
- }
-
- /**
- * 处理分割图片
- * @param $images
- * @return false|string[]
- */
- private function handleImg($images, $size = '')
- {
- $img_arr = explode(',', $images);
- if ($size) {
- $thumb_value = model('album_pic')->getColumn(['pic_path' => $img_arr], 'thumb_value', 'pic_path');
- $img_arr = array_map(function ($v) use ($thumb_value, $size) {
- if (array_key_exists($v, $thumb_value)) {
- $value = json_decode($thumb_value[$v], true);
- if (array_key_exists($size, $value)) {
- $img_path = $value[$size];
- $thumb_name = $img_path['thumb_name'];
- parse_str($thumb_name, $srt);
- $v = array_values($srt);
- if ($v) {
- return $v[0];
- } else {
- return img($v);
- }
- }
- }
- return img($v);
- }, $img_arr);
- } else {
- $img_arr = array_map('img', $img_arr);
- }
- return $img_arr;
- }
-
- /**
- * 删除商品
- * @param $id
- * @param $site_id
- */
- public function deleteGoods($goods_ids, $site_id)
- {
- if (!empty($goods_ids)) {
- $array_goodsIds = explode(',', $goods_ids);
- }
- $res = (new MinCode($site_id))->requestApi('alipay.open.app.item.delete', ['out_item_id_list' => $array_goodsIds]);
- model('shopalilife_goods')->delete([['site_id', '=', $site_id], ['out_item_id', 'in', $goods_ids]]);
- return $this->success($res);
- }
-
- /**
- * 商品上架
- * @param $goods_ids
- * @param $site_id
- * @return array|mixed
- * @throws \GuzzleHttp\Exception\GuzzleException
- */
- public function goodsListing($goods_ids, $site_id)
- {
- if (!empty($goods_ids)) {
- $array_goodsIds = explode(',', $goods_ids);
- }
- foreach ($array_goodsIds as $k => $goods_id) {
- $api_type = model('shopalilife_goods')->getValue([['out_item_id', '=', $goods_id], ['site_id', '=', $site_id]], 'api_type');
- if ($api_type == 'allcategory') {
- $api = 'alipay.open.app.item.direct.modify';
- } else {
- $api = 'alipay.open.app.localitem.direct.modify';
- }
- $sku_list = model('goods_sku')->getList([['goods_id', '=', $goods_id]], 'sku_id');
- $spu_data = [
- 'out_item_id' => $goods_id,
- 'skus' => []
- ];
- if (count($sku_list) > 1) {
- foreach ($sku_list as $sku_item) {
- $sku_data = [
- 'out_sku_id' => $sku_item['sku_id'],
- 'sale_status' => 'AVAILABLE',
- ];
- array_push($spu_data['skus'], $sku_data);
- }
- } else {
- $spu_data['sale_status'] = 'AVAILABLE';
- }
- $res[$k] = (new MinCode($site_id))->requestApi($api, $spu_data);
- if ($res[$k]['code'] != 0) return $res[$k];
- }
- model('shopcompoent_goods')->update(['spu_status' => 'DELISTING'], [['site_id', '=', $site_id], ['out_item_id', 'in', $goods_ids]]);
- return $this->success();
- }
-
- /**
- * 商品下架
- * @param $goods_ids
- * @param $site_id
- * @return array|mixed
- * @throws \GuzzleHttp\Exception\GuzzleException
- */
- public function goodsDelisting($goods_ids, $site_id)
- {
- if (!empty($goods_ids)) {
- $array_goodsIds = explode(',', $goods_ids);
- }
- foreach ($array_goodsIds as $k => $goods_id) {
- $api_type = model('shopalilife_goods')->getValue([['out_item_id', '=', $goods_id], ['site_id', '=', $site_id]], 'api_type');
- if ($api_type == 'allcategory') {
- $api = 'alipay.open.app.item.direct.modify';
- } else {
- $api = 'alipay.open.app.localitem.direct.modify';
- }
- $sku_list = model('goods_sku')->getList([['goods_id', '=', $goods_id]], 'sku_id');
- $spu_data = [
- 'out_item_id' => $goods_id,
- 'skus' => []
- ];
- if (count($sku_list) > 1) {
- foreach ($sku_list as $sku_item) {
- $sku_data = [
- 'out_sku_id' => $sku_item['sku_id'],
- 'sale_status' => 'DELISTING',
- ];
- array_push($spu_data['skus'], $sku_data);
- }
- } else {
- $spu_data['sale_status'] = 'DELISTING';
- }
- $res[$k] = (new MinCode($site_id))->requestApi($api, $spu_data);
- if ($res[$k]['code'] != 0) return $res[$k];
- }
- model('shopcompoent_goods')->update(['spu_status' => 'DELISTING'], [['site_id', '=', $site_id], ['out_item_id', 'in', $goods_ids]]);
- return $this->success();
- }
-}
\ No newline at end of file
diff --git a/addon/alilife/model/Order.php b/addon/alilife/model/Order.php
deleted file mode 100644
index 4c9cc72..0000000
--- a/addon/alilife/model/Order.php
+++ /dev/null
@@ -1,481 +0,0 @@
- $trade_no
- ];
- $info = $apiApp->requestApi('alipay.trade.query', $data)['alipay_trade_query_response'];
- $buyer_user_id = $info['buyer_user_id'];
- $datas = [
- 'user_id' => $buyer_user_id,
- 'order_id' => $order_id,
- ];
- if ($info['code'] == 10000) {
- $order_mini_query = $apiApp->requestApi('alipay.open.mini.order.query', $datas)['alipay_open_mini_order_query_response'];
- if ($order_mini_query['code'] == 10000) {
- $order_detail = $order_mini_query['order_detail']['item_infos'];
- $pay_info = $order_mini_query['order_detail']['pay_info'];
- foreach ($order_detail as $key => $value) {
- $condition = [
- 'm.site_id' => $site_id,
- 'm.ali_openid' => $buyer_user_id,
- 'og.sku_id' => $value['out_sku_id'],
- 'o.order_status' => -1,
- ];
- $field = 'm.ali_openid,m.member_id,og.*';
- $alias = 'og';
- $join = [
- [
- 'member m', 'm.member_id=og.member_id', 'left'
- ],
- [
- 'order o', 'og.order_id=o.order_id', 'left'
- ]
- ];
- $order_info = model('order_goods')->getInfo($condition, $field, $alias, $join);
- if ($order_info) {
- if (in_array($order_mini_query['status'], ['PAID'])) {
- $updata = [
- 'order_status' => 1,
- 'pay_status' => 1,
- 'is_enable_refund' => 1,
- 'out_trade_no' => $info['out_trade_no'],
- 'is_video_number' => 1,
- 'pay_type' => 'alipay',
- 'pay_type_name' => '支付宝支付',
- 'pay_money' => $info['buyer_pay_amount'],
- 'order_status_name' => '待发货',
- 'order_status_action' => '{"status":1,"name":"待发货","is_allow_refund":0,"icon":"public\/resource\/order\/order-icon-send.png","action":[{"action":"orderDelivery","title":"发货","color":""},{"action":"orderAddressUpdate","title":"修改地址","color":""}],"member_action":[],"color":""}',
- ];
- model('order')->update($updata, ['order_id' => $order_info['order_id']]);
- $data = array(
- 'site_id' => $site_id,
- 'out_trade_no' => $info['out_trade_no'],
- 'pay_type' => 'alipay',
- 'trade_no' => $trade_no,
- 'pay_body' => $order_info['sku_name'],
- 'pay_detail' => $order_info['sku_name'],
- 'pay_money' => $info['buyer_pay_amount'],
- 'pay_no' => '',
- 'event' => 'OrderPayNotify',
- 'return_url' => '',
- 'pay_status' => 2,
- 'create_time' => strtotime($info['send_pay_date']),
- 'pay_time' => strtotime($pay_info['pay_time']),
- );
- if (!model('pay')->getValue(['out_trade_no' => $info['out_trade_no']], 'id')) {
- model('pay')->add($data);
- } else {
- unset($data['out_trade_no']);
- model('pay')->update($data, ['out_trade_no' => $info['out_trade_no']]);
- }
- } else {
- var_dump(555);
- }
- } else {
- $res = $this->createOrder($site_id, $order_detail, $pay_info, $info, $order_mini_query);
- return $res;
- }
- }
- }
- }
- return $this->success('成功');
- }
-
- /****
- * 同步快递信息
- * @param $order_id
- * @param $site_id
- * @param $trade_no
- * @return void
- */
- public function syncDelivery($order_id,$order_status='')
- {
- $res = $this->delivery($order_id, 1);
- if ($res['code'] == 0 && $order_status==10) {
- $this->takeDelivery($order_id, 1);
- }
- return $res;
- }
-
- /***
- * 直接退款
- * @param $trade_no
- * @param $order_id
- * @param $site_id
- * @return void
- */
- public function refund($trade_no, $order_id, $site_id)
- {
- $apiApp = new MinCode($site_id);
- $data = [
- 'trade_no' => $trade_no
- ];
- $info = $apiApp->requestApi('alipay.trade.query', $data)['alipay_trade_query_response'];
- $buyer_user_id = $info['buyer_user_id'];
- $datas = [
- 'user_id' => $buyer_user_id,
- 'order_id' => $order_id,
- ];
- if ($info['code'] == 10000) {
- $order_mini_query = $apiApp->requestApi('alipay.open.mini.order.query', $datas)['alipay_open_mini_order_query_response'];
- $pay_model = new PayModel($site_id);
- $order_detail = $order_mini_query['order_detail']['item_infos'][0];
- $pay_info = $order_mini_query['order_detail']['pay_info'];
- $data = [
- 'pay_info' => [
- 'trade_no' => $info['trade_no'],
- 'pay_type' => 'alipay',
- ],
- 'refund_no' => $info['trade_no'],
- 'trade_no' => $info['trade_no'],
- 'refund_fee' => $info['buyer_pay_amount'],
- 'goods_id' => $order_detail['out_item_id'],
- 'sku_id' => $order_detail['out_sku_id'],
- 'is_video_number' => 1,
- ];
- $rse = $pay_model->refund($data);
- return $rse;
- }
- }
-
- /***
- * 直接创建订单
- * @param $site_id
- * @param $order_detail
- * @param $pay_info
- * @param $info
- * @param $order_mini_query
- * @return array
- */
- public function createOrder($site_id, $order_detail, $pay_info, $info, $order_mini_query)
- {
- $member_info = model('member')->getInfo(['ali_openid' => $info['buyer_user_id']]);
- if (!$member_info) return error(-1, '地址信息不全');
- $member_address = new MemberAddress();
- $type = 1;
- $address = $member_address->getMemberAddressInfo([['member_id', '=', $member_info['member_id']], ['is_default', '=', 1], ['type', '=', $type]]);
- if ($address) {
- $addressInfo = $address['data'];
- $out_trade_no = $info['out_trade_no'];
- $order_item = model('goods_sku')->getInfo(['sku_id' => $order_detail[0]['out_sku_id']]);
- model('order')->startTrans();
- try {
- $data_order = [
- 'order_no' => $out_trade_no,
- 'site_id' => $site_id,
- 'site_name' => '',
- 'order_from' => 'alipay',
- 'order_from_name' => '支付宝小程序',
- 'order_type' => 1,
- 'order_status' => 1,
- 'pay_status' => 1,
- 'is_video_number' => 1,
- 'order_type_name' => '普通订单',
- 'order_status_name' => '待发货',
- 'order_status_action' => '{"status":1,"name":"待发货","is_allow_refund":0,"icon":"public\/resource\/order\/order-icon-send.png","action":[{"action":"orderDelivery","title":"发货","color":""},{"action":"orderAddressUpdate","title":"修改地址","color":""}],"member_action":[],"color":""}',
- 'out_trade_no' => $out_trade_no,
- 'member_id' => $member_info['member_id'],
- 'name' => $addressInfo['name'] ?? '',
- 'mobile' => $addressInfo['mobile'] ?? '',
- 'telephone' => $addressInfo['telephone'] ?? '',
- 'province_id' => $addressInfo['province_id'] ?? '',
- 'city_id' => $addressInfo['city_id'] ?? '',
- 'district_id' => $addressInfo['district_id'] ?? '',
- 'community_id' => $addressInfo['community_id'] ?? '',
- 'address' => $addressInfo['address'] ?? '',
- 'full_address' => $addressInfo['full_address'] ?? '',
- 'longitude' => $addressInfo['longitude'] ?? '',
- 'latitude' => $addressInfo['latitude'] ?? '',
- 'buyer_ip' => request()->ip(),
- 'goods_money' => $info['buyer_pay_amount'],
- 'delivery_money' => 0,
- 'coupon_id' => 0,
- 'coupon_money' => 0,
- 'adjust_money' => 0,
- 'invoice_money' => 0,
- 'promotion_money' => 0,
- 'order_money' => $info['buyer_pay_amount'],
- 'balance_money' => 0,
- 'point_money' => 0,
- 'pay_money' => $info['buyer_pay_amount'],
- 'create_time' => time(),
- 'is_enable_refund' => 0,
- 'order_name' => $order_item['sku_name'],
- 'goods_num' => $order_detail[0]['item_cnt'],
- 'delivery_type' => 'express',
- 'delivery_type_name' => '快递配送',
- 'delivery_store_id' => $order_item['delivery_store_id'] ?? 0,
- 'delivery_store_name' => $order_item['delivery_store_name'] ?? '',
- 'delivery_store_info' => $order_item['delivery_store_info'] ?? '',
- 'buyer_message' => '',
- 'invoice_delivery_money' => $order_item['invoice_delivery_money'] ?? 0,
- 'taxpayer_number' => $order_item['taxpayer_number'] ?? '',
- 'invoice_rate' => $order_item['invoice_rate'] ?? 0,
- 'invoice_content' => $order_item['invoice_content'] ?? '',
- 'invoice_full_address' => $order_item['invoice_full_address'] ?? '',
- 'is_invoice' => $order_item['is_invoice'] ?? 0,
- 'invoice_type' => $order_item['invoice_type'] ?? 0,
- 'invoice_title' => $order_item['invoice_title'] ?? '',
- 'is_tax_invoice' => $order_item['is_tax_invoice'] ?? '',
- 'invoice_email' => $order_item['invoice_email'] ?? '',
- 'invoice_title_type' => $order_item['invoice_title_type'] ?? 0,
- 'buyer_ask_delivery_time' => $order_item['buyer_ask_delivery_time'] ?? '',//定时达
- 'member_card_money' => 0,
- 'store_id' => $order_item['store_id'] ?? ''
- ];
- $order_id = model('order')->add($data_order);
- $data_order_goods = array(
- 'order_id' => $order_id,
- 'site_id' => $order_item['site_id'],
- 'order_no' => $out_trade_no,
- 'member_id' => $member_info['member_id'],
- 'sku_id' => $order_item['sku_id'],
- 'sku_name' => $order_item['sku_name'],
- 'sku_image' => $order_item['sku_image'],
- 'sku_no' => $order_item['sku_no'],
- 'is_virtual' => $order_item['is_virtual'],
- 'goods_class' => $order_item['goods_class'],
- 'goods_class_name' => $order_item['goods_class_name'],
- 'price' => $order_item['price'],
- 'cost_price' => $order_item['cost_price'],
- 'num' => $data_order['goods_num'],
- 'goods_money' => $data_order['goods_money'],
- 'cost_money' => $order_item['cost_price'] * $data_order['goods_num'],
- 'goods_id' => $order_item['goods_id'],
- 'delivery_status' => 0,
- 'delivery_status_name' => '未发货',
- 'real_goods_money' => 0,
- 'coupon_money' => 0,
- 'promotion_money' => 0,
- 'goods_name' => $order_item['goods_name'],
- 'sku_spec_format' => $order_item['sku_spec_format'],
- 'use_point' => $order_item['use_point'] ?? 0,
- 'point_money' => $order_item['point_money'] ?? 0.00,
- 'create_time' => time(),
- 'store_id' => '',
- 'card_item_id' => 0,
- 'card_promotion_money' => 0.00
- );
- $data = array(
- 'site_id' => $site_id,
- 'out_trade_no' => $info['out_trade_no'],
- 'pay_type' => 'alipay',
- 'trade_no' => $info['trade_no'],
- 'pay_body' => $data_order_goods['sku_name'],
- 'pay_detail' => $data_order_goods['sku_name'],
- 'pay_money' => $info['buyer_pay_amount'],
- 'pay_no' => '',
- 'event' => 'OrderPayNotify',
- 'return_url' => '',
- 'pay_status' => 2,
- 'create_time' => strtotime($info['send_pay_date']),
- 'pay_time' => strtotime($pay_info['pay_time']),
- );
- if (!model('pay')->getValue(['out_trade_no' => $info['out_trade_no']], 'id')) {
- model('pay')->add($data);
- } else {
- unset($data['out_trade_no']);
- model('pay')->update($data, ['out_trade_no' => $info['out_trade_no']]);
- }
- model('order_goods')->add($data_order_goods);
- model('order')->commit();
- return $this->success('成功');
- } catch (\Exception $e) {
- model('order')->rollback();
- return error(-1, $e);
- }
- } else {
- return error(-1, '地址信息不全');
- }
- }
-
- /***
- * 发货同步到支付宝
- * @param $order_id
- * @param $is_video_number
- * @return array
- * @throws \GuzzleHttp\Exception\GuzzleException
- */
- public function delivery($order_id,$is_video_number=0)
- {
- try {
- $order = model('order')->getInfo([['order_id', '=', $order_id]], 'site_id,order_no,out_trade_no,is_video_number,pay_type,member_id,order_type,delivery_time');
- if ($is_video_number || ($order['is_video_number'] && in_array($order["pay_type"],['alipay','alipay_stages','zmxxpay','huabie','zmautopay','zmgopay']))) {
- $member = model('member')->getInfo([['member_id', '=', $order['member_id']]], 'ali_openid');
- $apiApp = new MinCode($order['site_id']);
- $data = [
- 'out_order_id' => $order['out_trade_no'],
- 'finish_all_delivery' => 1,
- 'ship_done_time' => date('Y-m-d H:i:s', $order['delivery_time']),
- 'delivery_list' => []
- ];
- if (is_numeric($member['ali_openid'])) {
- $data['user_id'] = $member['ali_openid'];
- } else {
- $data['open_id'] = $member['ali_openid'];
- }
- if ($order['order_type'] == 1) {
- $package_list = model('express_delivery_package')->getList([['order_id', '=', $order_id]], 'delivery_type,express_company_name,delivery_no,order_goods_id_array');
- if (!empty($package_list)) {
- $company_list = $apiApp->getCompanyList();
- foreach ($package_list as $item) {
- $delivery_id = 'OTHERS';
- $index = array_search($item['express_company_name'], array_column($company_list, 'delivery_name'));
- if ($index !== false && isset($company_list[$index])) {
- $delivery_id = $company_list[$index]['delivery_id'];
- }
- $order_goods_model = model('order_goods')->getList([['order_goods_id', "in", $item['order_goods_id_array']]], "goods_id,sku_id,num");
- if ($item['delivery_type'] == 0) {
- $item['delivery_no'] = date('YmdHis');
- }
- $temp = [
- 'delivery_id' => $delivery_id,
- 'waybill_id' => $item['delivery_no'],
- 'item_info_list' => []
- ];
- foreach ($order_goods_model as $order_iem) {
- $temp['item_info_list'][] = [
- 'out_item_id' => $order_iem['goods_id'], //提报服务库外部商品ID
- 'out_sku_id' => $order_iem['sku_id'],//商家SKU
- 'item_cnt' => (int)$order_iem['num'] //商品数量
- ];
- }
- array_push($data['delivery_list'], $temp);
- }
- } else {
- unset($data['delivery_list']);
- }
- }
- $res = $apiApp->sendDelivery($data);
- if ($res['code'] == 10000) {
- return $this->success();
- } else if (isset($res['sub_code']) && !in_array($res['sub_code'], ['STATUS_INVALID', 'SEND_ORDER_IS_REPEAT', 'ORDER_ID_NOT_EXIST', 'OUT_ORDER_ID_INVALIDATE'])) {
- model('order')->update(['is_sync_order' => 2, 'sync_msg' => $res['sub_msg']], [['order_id', '=', $order_id]]);
- return $this->error('', $res['sub_msg']);
- } else { //标记订单已同步
- model('order')->update(['is_sync_order' => 2, 'sync_msg' => $res['sub_msg']], [['order_id', '=', $order_id]]);
- return $this->success();
- }
- return $res;
- }
- } catch (\Exception $e) {
-
- }
- return $this->success();
- }
-
- /**
- * 订单收货
- * @param $order_id
- * @return array
- */
- public function takeDelivery($order_id,$is_video_number=0)
- {
- $order = model('order')->getInfo([['order_id', '=', $order_id]], 'site_id,order_no,out_trade_no,is_video_number,pay_type,member_id,order_type');
- if ($is_video_number || ($order['is_video_number'] && in_array($order["pay_type"],['alipay','alipay_stages','zmxxpay','huabie','zmautopay','zmgopay']))) {
- $member = model('member')->getInfo([['member_id', '=', $order['member_id']]], 'ali_openid');
- $apiApp = new MinCode($order['site_id']);
- $res = $apiApp->recieveDelivery(['out_order_id' => $order['out_trade_no'], 'user_id' => $member['ali_openid']]);
- if ($res['code'] != 10000) {
- return $this->error('', $res['sub_msg']);
- }
- }
- return $this->success();
- }
- /***
- * 订单状态标记
- * @param $json
- * @return void
- */
- public function OrderStatus($json)
- {
- switch ($json['status']) {
- case 'RECEIVED_CONFIRM': //确认收货
- $where = [['out_trade_no', '=', $json['out_order_id']]];
- $field = 'o.order_id,m.nickname,m.member_id';
- $join = [
- ['member m', 'o.member_id=m.member_id', 'inner'],
- ];
- $orderInfo = model('order')->getInfo($where, $field, 'o', $join);
- if ($orderInfo) {
- $log_data = [
- 'uid' => $orderInfo['member_id'],
- 'nick_name' => $orderInfo['nickname'],
- 'action_way' => 2
- ];
- $order_model = new OrderCommonModel();
- $order_model->orderCommonTakeDelivery($orderInfo['order_id'], $log_data);
- }
- break;
- case 'REFUND_CLOSED': //退款
- $where = [['out_trade_no', '=', $json['out_order_id']]];
- $field = 'g.order_goods_id,m.nickname,m.member_id,o.order_id';
- $join = [
- ['order_goods g', 'o.order_id=g.order_id', 'inner'],
- ['member m', 'o.member_id=m.member_id', 'inner'],
- ];
- $orderInfo = model('order')->getList($where, $field, '', 'o', $join);
- $order_refund_model = new OrderRefundModel();
- if ($orderInfo) {
- foreach ($orderInfo as $item) {
- $buyer_name = empty($item['nickname']) ? '' : '【' . $item['nickname'] . '】';
- $log_data = [
- 'uid' => $item['member_id'],
- 'nick_name' => $item['nickname'],
- 'action' => '买家' . $buyer_name . '发起了退款申请',
- 'action_way' => 1
- ];
- $data = array(
- "order_goods_id" => $item['order_goods_id'],
- "refund_type" => 1,
- "refund_reason" => '会员平台申请退款',
- "refund_remark" => '支付宝平台直接申请退款'
- );
- $order_refund_model->orderRefundApply($data, $item, $log_data);
- }
- model('dividemoney_bill')->update(['states' => 5, 'refuse' => '订单已退款'], [['order_id', 'in', array_column($orderInfo, 'order_id')]]);//关闭分账
- }
- break;
- case 'PAID':
- model('order')->update(['is_video_number' => 1], [['out_trade_no', '=', $json['out_order_id']]]);
- break;
- case 'CANCEL_CLOSED'://交易取消
- case 'TIMEOUT_CLOSED': //超时关闭订单
- $order = new OrderCommon();
- $where = [['out_trade_no', '=', $json['out_order_id']]];
- $order_info_result = $order->getOrderInfo($where, "order_id,order_status");
- if (!empty($order_info_result) && $order_info_result["data"]["order_status"] == 0) {
- $order->orderClose($order_info_result['data']["order_id"], [], '长时间未支付,订单自动关闭');//订单自动关闭
- }
- break;
- }
- return success();
- }
-}
\ No newline at end of file
diff --git a/addon/alilife/shop/controller/Category.php b/addon/alilife/shop/controller/Category.php
deleted file mode 100644
index c5ce650..0000000
--- a/addon/alilife/shop/controller/Category.php
+++ /dev/null
@@ -1,111 +0,0 @@
-isAjax()) {
- $category = new CategoryModel();
- $page = input('page', 1);
- $keywords = empty(input('keywords')) ? '' : input('keywords');
- $page_size = input('page_size', PAGE_LIST_ROWS);
- if (!empty($keywords)) {
- $condition [] = ['cat_name', 'like', '%' . $keywords . '%'];
- }
- if (!empty($third_cat_id)) {
- $condition [] = ['cat_id', '=', $third_cat_id];
- }
- $condition [] = ['site_id', '=', $this->site_id];
- $data = $category->getcategoryPageList($condition, '*', '', $page, $page_size);
- return $data;
- } else {
- $this->assign('third_cat_id', $third_cat_id);
- $this->forthMenu();
- return $this->fetch("category/index");
- }
- }
-
- public function template()
- {
- if (request()->isAjax()) {
- $category = new CategoryModel();
- $cat_id = input('cat_id', '');
- $res = $category->getCatTemplate($this->site_id, $cat_id);
- return $res;
- }
- }
-
- /**
- * 同步商品类目
- * @return array
- */
- public function sync()
- {
- if (request()->isAjax()) {
- $category = new CategoryModel();
- $type = input('type', 'allcategory');
- $item_type = input('item_type', 1);
- $res = $category->syncCategory($this->site_id, $item_type, $type);
- return $res;
- }
- }
-
- /**
- * 获取分类通过下级
- * @return array
- */
- public function getCategoryByParent()
- {
- if (request()->isAjax()) {
- $category = new CategoryModel();
- $level = input('level', 1);
- $pid = input('pid', 0);
- $type = input('api_type', 'allcategory');
- $cat_type = '';
- $res = $category->getCategoryByParent($this->site_id, $level, $pid, $cat_type, $type);
- return $res;
- }
- }
-
-
- /***
- * 获取全部分类
- * @return array|void
- */
- public function getCategory()
- {
- if (request()->isAjax()) {
- $category = new CategoryModel();
- $type = input('api_type', 'allcategory');
- $cat_type = input('cat_type', 1);
- $res = $category->getCategory($this->site_id, $type, $cat_type);
- return $res;
- }
- }
-
- /***
- * 获取模版
- * @return void
- */
- public function getTemplate()
- {
- $category = new CategoryModel();
- $category_id = input('category_id');
- $api_type = input('api_type');
- $item_type = input('item_type');
- $res = $category->getCatTemplate($this->site_id, $category_id, $api_type, $item_type);
- return $res;
- }
-}
\ No newline at end of file
diff --git a/addon/alilife/shop/controller/Goods.php b/addon/alilife/shop/controller/Goods.php
deleted file mode 100644
index 83690d5..0000000
--- a/addon/alilife/shop/controller/Goods.php
+++ /dev/null
@@ -1,242 +0,0 @@
-isAjax()) {
- $goods = new GoodsModel();
- $page = input('page', 1);
- $page_size = input('page_size', PAGE_LIST_ROWS);
- $keywords = input('keywords', '');
- $goods_id = input('goods_id', '');
- $condition = [
- ['sg.site_id', '=', $this->site_id],
- ['sg.api_type', '=', 'allcategory'],
- ];
- if ($keywords) {
- $condition[] = [
- 'g.goods_name', 'like', "%{$keywords}%"
- ];
- }
- if ($goods_id) {
- $condition[] = [
- 'g.goods_id', '=', $goods_id
- ];
- }
- $data = $goods->getGoodsPageList($condition, '*', 'id desc', $page, $page_size);
- return $data;
- } else {
- $category = (new Category())->getCategoryByParent($this->site_id, 1, 0, 1);
- $category_two = (new Category())->getCategoryByParent($this->site_id, 1, 0, 2);
- $category_three = (new Category())->getCategoryByParent($this->site_id, 1, 0, 3);
- $this->assign('first_cat_one', $category['data']);
- $this->assign('first_cat_two', $category_two['data']);
- $this->assign('first_cat_three', $category_three['data']);
- $this->assign('Package', $category_three['data']);
- $this->forthMenu();
- return $this->fetch("goods/index");
- }
- }
-
- /***
- * 获取本地生活生商品
- * @return array|mixed
- */
- public function lifelists()
- {
- if (request()->isAjax()) {
- $goods = new GoodsModel();
- $page = input('page', 1);
- $page_size = input('page_size', PAGE_LIST_ROWS);
- $condition = [
- 'sg.site_id' => $this->site_id,
- 'sg.api_type' => 'localitem',
- ];
- $data = $goods->getGoodsPageList($condition, '*', 'id desc', $page, $page_size);
- return $data;
- } else {
- $category = (new Category())->getCategoryByParent($this->site_id, 1, 0, 1, 'localitem');
- $first_cat_two = (new Category())->getCategoryByParent($this->site_id, 1, 0, 2, 'localitem');
- $this->assign('first_cat_one', $category['data']);
- $this->assign('first_cat_two', $first_cat_two['data']);
- $this->assign('shop_info', $this->shop_info);
- $this->forthMenu();
- return $this->fetch("goods/local");
- }
- }
-
- /***
- * 添加商品
- * @return array|void
- */
- public function add()
- {
- if (request()->isAjax()) {
- if ($this->shop_info['site_status'] <= 0) {
- return error('', '您的店铺已到期');
- }
- $param = input();
- if (empty($param)) error('必要参数必填');
- $api_type = input('api_type', 'allcategory');
- $item_type = input('item_type', '');
- $merchant_name = input('merchant_name', '');
- $phone_number = input('phone_number', '');
- $data = [
- 'site_id' => $this->site_id,
- 'goods_ids' => $param['goods_ids'],
- 'cat_id' => $param['cat_id'],
- ];
- $goods_model = new GoodsModel();
- if ($api_type == 'localitem') {
- $data = request()->post();
- $data['site_id'] = $this->site_id;
- return $goods_model->localitemAddGoods($data, $item_type, $merchant_name, $phone_number);
- } else {
- return $goods_model->addGoods($data, $api_type);
- }
- }
- $this->assign('shop_info', $this->shop_info);
- $api_type = input('api_type', 'localitem');
- $this->assign('api_type', $api_type);
- return $this->fetch('goods/add');
- }
-
- /**
- * 修改商品分类
- */
- public function edit()
- {
- $goods_model = new GoodsModel();
- $api_type = input('api_type', 'localitem');
- if (request()->isAjax()) {
- $param = input();
- if (empty($param)) $this->error('必要参数必填');
- $api_type = input('api_type', 'allcategory');
- $data = [
- 'site_id' => $this->site_id,
- 'goods_id' => $param['goods_id'],
- 'cat_id' => $param['cat_id'],
- ];
- if ($api_type == 'localitem') {
- $goods_id = input('goods_id');
- $item_type = input('item_type');
- $data = request()->post();
- return $goods_model->updateGoodslocalitemGoods($goods_id, $data, $item_type);
- } else {
- return $goods_model->updateGoods($data, $api_type);
- }
- }
- if ($api_type == 'localitem') {
- $goods_id = input('goods_id');
- $groupbuy_model = new GroupbuyModel();
- //获取团购信息
- $condition = [
- ['pg.goods_id', '=', $goods_id],
- ['pg.site_id', '=', $this->site_id],
- ['g.goods_state', '=', 1],
- ['g.is_delete', '=', 0]
- ];
- $groupbuy_info = $groupbuy_model->getGroupbuyInfo($condition)['data'];
- $this->assign('groupbuy_info', $groupbuy_info);
- $this->assign('shop_info', $this->shop_info);
- $this->assign('api_type', $api_type);
- $this->assign('category_id', input('category_id'));
- return $this->fetch('goods/edit');
- }
- }
-
- /***
- * 同步商家产品
- * @return array
- */
- public function sync()
- {
- $start = input('start', 0);
- $api_type = input('api_type', 'allcategory');
- $res = (new GoodsModel())->syncGoods($start, 20, $this->site_id, $api_type);
- return $res;
- }
-
-
- public function syncGoods()
- {
- $goods_id = input('goods_id');
- $goods_model = new GoodsModel();
- if (request()->isAjax()) {
- $data = request()->post();
- $api_type = input('api_type');
- if ($api_type != 'allcategory') {
- $res = $goods_model->PushLocaSyncGoodsInfo($goods_id, $data);
- } else {
- $res = $goods_model->PushPTSyncGoodsInfo($goods_id, $data);
- }
- return $res;
- }
- $join = [
- ['goods g', 'g.goods_id=a.goods_id', 'right']
- ];
- $where = [
- ['g.goods_id', '=', $goods_id]
- ];
- $goods_info = $goods_model->getGoodsInfo($where, 'g.*,a.category_id', 'a', $join);
- $this->assign('goods_info', $goods_info);
- $this->assign('goods_id', $goods_id);
- $this->assign('shop_info', $this->shop_info);
- $this->assign('alipaycategory_id', $goods_info['category_id'] ?: '');
- return $this->fetch('goods/syncGoods');
- }
-
- /***
- * 上传库存价格
- * @return array
- */
- public function syncrenew()
- {
- $goods_id = input('goods_id');
- $api_type = input('api_type');
- if ($api_type != 'allcategory') {
- $res = (new GoodsModel())->syncLocalitemPrice($goods_id, $this->site_id);
- } else {
- $res = (new GoodsModel())->syncDtockPrice($goods_id, $this->site_id, $api_type);
- }
- return $res;
- }
-
- /***
- * 下架
- * @return array
- */
- public function goodsDelisting()
- {
- $out_item_id = input('out_item_id', '');
- $res = (new GoodsModel())->goodsDelisting($out_item_id, $this->site_id);
- return $res;
- }
-
- /***
- * 上架
- * @return array
- */
- public function listing()
- {
- $out_item_id = input('out_item_id', '');
- $res = (new GoodsModel())->goodsListing($out_item_id, $this->site_id);
- return $res;
- }
-
- /**
- * 小程序删除商品
- */
- public function delete()
- {
- if (request()->isAjax()) {
- $goods_model = new GoodsModel();
- return $goods_model->deleteGoods(input('out_item_id', ''), $this->site_id);
- }
- }
-}
\ No newline at end of file
diff --git a/addon/alilife/shop/controller/Order.php b/addon/alilife/shop/controller/Order.php
deleted file mode 100644
index 942d992..0000000
--- a/addon/alilife/shop/controller/Order.php
+++ /dev/null
@@ -1,105 +0,0 @@
-syncRepair($trade_no, $order_id, $this->site_id);
- return $res;
- }
-
-
- public function syncDelivery()
- {
- $order_id = input('order_id', '');
- $order_status = input('order_status', '');
- $order = new OrderModel();
- $res = $order->syncDelivery($order_id, $order_status);
- return $res;
- }
-
- /***
- * 直接退款
- * @return null
- */
- public function refund()
- {
- $trade_no = input('trade_no', '');
- $order_id = input('order_id', '');
- $order = new OrderModel();
- $res = $order->refund($trade_no, $order_id, $this->site_id);
- return $res;
- }
-
-
- /***
- * 获取支付宝对账单
- * @return array|mixed
- */
- public function miniOrderItembill()
- {
- if (request()->isAjax()) {
- $goods_model = new GoodsModel();
- $page = input('page', 1);
- $page_size = input('page_size', PAGE_LIST_ROWS);
- $condition = [
- 'page_num' => $page,
- 'page_size' => $page_size,
- ];
- $order_status = input('order_status');
- $settle_status = input('settle_status');
- $create_time = input('create_time');
- $settlement_date = input('settlement_date');
- $service_type_list = input('service_type_list');
- if ($order_status) {
- $condition['order_status'] = $order_status;
- }
- if ($settle_status) {
- $condition['settle_status'] = $settle_status;
- }
- if ($create_time) {
- $condition['create_time'] = $create_time;
- }
- if ($create_time) {
- $condition['settlement_date'] = $settlement_date;
- }
- if ($service_type_list) {
- $condition['service_type_list'] = json_encode([$service_type_list]);
- }
- $res = $goods_model->getBillList($condition, $page, $this->site_id);
- return $res;
- }
- return $this->fetch('bill/lists');
- }
-
-
- /***
- * 确认收货
- * @return array
- */
- public function confirmreceipt()
- {
- if (request()->isAjax()) {
- $order_id = input('order_id', '');
- $order = new OrderModel();
- $res = $order->takeDelivery($order_id, 1);
- return $res;
- }
- }
-
-
- public function detail()
- {
-
-
- }
-}
\ No newline at end of file
diff --git a/addon/alilife/shop/view/bill/lists.html b/addon/alilife/shop/view/bill/lists.html
deleted file mode 100644
index 395e814..0000000
--- a/addon/alilife/shop/view/bill/lists.html
+++ /dev/null
@@ -1,347 +0,0 @@
-{extend name="app/shop/view/base.html"/}
-{block name="resources"}
-
-{/block}
-{block name="main"}
-
-
-
-
-
-
-
-
-{/block}
-{block name="script"}
-
-{/block}
\ No newline at end of file
diff --git a/addon/alilife/shop/view/category/index.html b/addon/alilife/shop/view/category/index.html
deleted file mode 100644
index e51841a..0000000
--- a/addon/alilife/shop/view/category/index.html
+++ /dev/null
@@ -1,357 +0,0 @@
-{extend name="app/shop/view/base.html"/}
-{block name="resources"}
-
-{/block}
-
-{block name="main"}
-
-
-
-
-
-
-
-
-
-
-{/block}
-{block name="script"}
-
-{/block}
\ No newline at end of file
diff --git a/addon/alilife/shop/view/goods/access.html b/addon/alilife/shop/view/goods/access.html
deleted file mode 100644
index d799ea6..0000000
--- a/addon/alilife/shop/view/goods/access.html
+++ /dev/null
@@ -1,288 +0,0 @@
-{extend name="app/shop/view/base.html"/}
-
-{block name="resources"}
-
-{/block}
-
-{block name="main"}
-
-
微信视频号
-
- -
-
-
-
-
-
-
-
创建微信视频号
-
在微信中创建视频号,如已有视频号可越过该步骤。
-
-
接入指南
-
-
-
- -
-
-
-
-
-
-
-
申请开通自定义版交易组件
-
完成自定义版交易组件接入后,小程序即可在视频号中实现商品展示和带货等功能,进一步提升经营能力。若您已开通标准化交易组件,则暂不支持切换
-
- {if $checkres['code'] == 0}
- {if $checkres['data']['status'] != 2 && $checkres['data']['status'] != 3}
-
- {/if}
- {else/}
-
- {/if}
-
-
-
-
-
-
-
-
-
-
-
官方审核团队将对接入资质进行审核,通过后可进行下一步操作。
-
-
- {if $checkres['code'] == 0}
- {if $checkres['data']['status'] == 2}
-
已开通
- {elseif $checkres['data']['status'] == 3}
-
封禁中
- {else/}
-
未开通
- {/if}
- {else/}
-
未开通
- {/if}
-
-
-
-
- -
-
-
-
-
-
-
-
自定义版交易组件申请通过,接口调用场景检测
-
自定义交易组件开通之后,如果当前小程序版本低于4.1.5,则需下载4.1.5或更高版本小程序进行发布,前去发布
-
-
-
-
-
-
-
-
-
-
-
-
请至少将一件商品同步到微信,并等待商品审核通过前去添加
-
-
- {if $checkres['code'] == 0 && $checkres['data']['status'] == 2 && $checkres['data']['access_info']['spu_audit_finished'] eq 1}
-
已完成
- {else/}
-
- {/if}
-
-
-
-
-
-
-
-
-
-
需手动扫码下单,使用微信支付并付款成功
-
-
- {if $checkres['code'] == 0 && $checkres['data']['status'] == 2 && $checkres['data']['access_info']['ec_order_finished'] eq 1}
-
已完成
- {else/}
- {if $checkres['code'] == 0 && $checkres['data']['access_info']['pay_order_success'] eq 1}
-
- {else/}
-
- {/if}
- {/if}
-
-
-
-
-
-
-
-
-
-
订单支付之后,需对该测试订单进行发货操作
-
-
- {if $checkres['code'] == 0 && $checkres['data']['status'] == 2 && $checkres['data']['access_info']['send_delivery_finished'] eq 1}
-
已完成
- {else/}
-
- {/if}
-
-
-
-
-
-
-
-
-
-
订单发货之后,需下单人对该测试订单进行申请维权操作
-
-
- {if $checkres['code'] == 0 && $checkres['data']['status'] == 2 && $checkres['data']['access_info']['ec_after_sale_finished'] eq 1}
-
已完成
- {else/}
-
- {/if}
-
-
-
-
- -
-
-
-
-
-
-
-
自定义版交易组件开通成功
-
开通成功之后可在小程序中“功能>交易组件>场景接入>视频号推广”中关联视频号,关联之后视频号管理员可前往“视频号创作者中心>商品橱窗”中添加商品前去添加。
-
-
-
-
-
-
-{/block}
-
-{block name="script"}
-
-
-{/block}
\ No newline at end of file
diff --git a/addon/alilife/shop/view/goods/add.html b/addon/alilife/shop/view/goods/add.html
deleted file mode 100644
index 3cc05a4..0000000
--- a/addon/alilife/shop/view/goods/add.html
+++ /dev/null
@@ -1,525 +0,0 @@
-{extend name="app/shop/view/base.html"/}
-{block name="resources"}
-
-
-{/block}
-{block name="main"}
-
-{/block}
-{block name="script"}
-
-
-
-
-
-
-
-
-
-
-
-
-{/block}
\ No newline at end of file
diff --git a/addon/alilife/shop/view/goods/edit.html b/addon/alilife/shop/view/goods/edit.html
deleted file mode 100644
index 8216499..0000000
--- a/addon/alilife/shop/view/goods/edit.html
+++ /dev/null
@@ -1,389 +0,0 @@
-{extend name="app/shop/view/base.html"/}
-{block name="resources"}
-
-
-{/block}
-{block name="main"}
-
-{/block}
-{block name="script"}
-
-
-
-
-
-
-
-{/block}
\ No newline at end of file
diff --git a/addon/alilife/shop/view/goods/index.html b/addon/alilife/shop/view/goods/index.html
deleted file mode 100644
index 4f77dc4..0000000
--- a/addon/alilife/shop/view/goods/index.html
+++ /dev/null
@@ -1,779 +0,0 @@
-{extend name="app/shop/view/base.html"/}
-{block name="resources"}
-
-{/block}
-{block name="main"}
-
-
-
操作提示
-
- - 首次添加产品或者新增分类请同步产品分类
- {if $shop_info.is_try==1}
- - 您正在使用{$shop_info.group_name}去升级套餐
- {/if}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-{/block}
-{block name="script"}
-
-
-
-
-
-
-{/block}
diff --git a/addon/alilife/shop/view/goods/local.html b/addon/alilife/shop/view/goods/local.html
deleted file mode 100644
index bd262e2..0000000
--- a/addon/alilife/shop/view/goods/local.html
+++ /dev/null
@@ -1,482 +0,0 @@
-{extend name="app/shop/view/base.html"/}
-{block name="resources"}
-
-{/block}
-{block name="main"}
-
-
-
操作提示
-
- - 首次添加产品或者新增分类请同步产品分类
- {if $shop_info.is_try==1}
- - 您正在使用{$shop_info.group_name}去升级套餐
- {/if}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-{/block}
-{block name="script"}
-
-
-{/block}
diff --git a/addon/alilife/shop/view/goods/syncGoods.html b/addon/alilife/shop/view/goods/syncGoods.html
deleted file mode 100644
index 94db219..0000000
--- a/addon/alilife/shop/view/goods/syncGoods.html
+++ /dev/null
@@ -1,255 +0,0 @@
-{extend name="app/shop/view/base.html"/}
-{block name="resources"}
-
-
-{/block}
-{block name="body"}
-
-{/block}
-{block name="script"}
-
-
-
-
-{/block}
diff --git a/addon/commission/api/controller/Index.php b/addon/commission/api/controller/Index.php
deleted file mode 100644
index 9724b00..0000000
--- a/addon/commission/api/controller/Index.php
+++ /dev/null
@@ -1,126 +0,0 @@
-checkToken();
- if ($token['code'] < 0) return $this->response($token);
- $this->params['member_id'] = $this->member_id;
- $statistics = (new Legumes())->getStatistics($this->params);
-
- $statisticsList = [
- // ['title' => '已获得豆','value' => $statistics['reality_get_legumes']],
- // ['title' => '积分释放上限','value' => $statistics['integral_upper_limit']],
- ['title' => '积分赠送上限','value' => $statistics['not_integral']],
- ['title' => '已赠送积分','value' => $statistics['get_integral']],
- ['title' => '可用积分','value' => $statistics['used_integral']],
- ['title' => '已使用积分','value' => $statistics['use_integral']],
- ['title' => '冻结中积分','value' => $statistics['freeze_integral']],
- ];
-
- return $this->response(success(0,'success',$statisticsList));
- }
- /**
- * Common: 豆豆积分明细 - 变更记录
- * Author: wu-hui
- * Time: 2024/05/11 15:12
- * @return false|string
- */
- public function LegumesChangeList(){
- // 用户登录信息
- $token = $this->checkToken();
- if ($token['code'] < 0) return $this->response($token);
- // 分页及参数信息
- $page = $this->params['page'] ?? 1;
- $this->params['page_size'] = 20;
- $this->params['member_id'] = (new Member())->getAllMemberIds((int)$this->member_id);
- $result = (new Legumes())->getLegumesLogList($page, $this->params);
-
- return $this->response($result);
- }
- /**
- * Common: 豆豆积分明细 - 每条信息是否记录
- * Author: wu-hui
- * Time: 2024/05/15 15:09
- * @return false|string
- */
- public function legumesReleaseLog(){
- $this->params['page_size'] = 20;
- $result = (new Legumes())->legumesReleaseLog($this->params);
-
- return $this->response($result);
- }
- /**
- * Common: 获取流水信息
- * Author: wu-hui
- * Time: 2024/05/13 17:20
- * @return false|string
- */
- public function accountList(){
- // 用户登录信息
- $token = $this->checkToken();
- if ($token['code'] < 0) return $this->response($token);
- // 分页及参数信息
- $page = $this->params['page'] ?? 1;
- $this->params['page_size'] = 20;
- $this->params['member_id'] = $this->member_id;
- $result = (new Account())->accountList($page, $this->params);
-
- return $this->response($result);
- }
- /**
- * Common: 收益统计 - 统计信息
- * Author: wu-hui
- * Time: 2024/05/21 14:08
- * @return false|string
- */
- public function accountStatistics(){
- // 用户登录信息
- $token = $this->checkToken();
- if ($token['code'] < 0) return $this->response($token);
- // 分页及参数信息
- $result = (new Account())->statistics($this->member_id);
-
- return $this->response($result);
- }
- /**
- * Common: 收益统计 - 收益列表
- * Author: wu-hui
- * Time: 2024/05/21 15:08
- * @return false|string
- */
- public function accountListV2(){
- // 用户登录信息
- $token = $this->checkToken();
- if ($token['code'] < 0) return $this->response($token);
- // 分页及参数信息
- $this->params['page'] = $this->params['page'] ?? 1;
- $this->params['page_size'] = 20;
- $this->params['member_id'] = $this->member_id;
- // $result = (new Account())->accountListV2($this->params);
- $result = (new Account())->accountListV3($this->params);
-
- return $this->response($result);
- }
-
-}
\ No newline at end of file
diff --git a/addon/commission/command/Commission.php b/addon/commission/command/Commission.php
deleted file mode 100644
index a550c7e..0000000
--- a/addon/commission/command/Commission.php
+++ /dev/null
@@ -1,47 +0,0 @@
-setName('commission')
- ->addArgument('run_type', Argument::OPTIONAL, "运行类型")
- ->setDescription('平台抽成相关任务');
- }
-
- protected function execute(Input $input,Output $output){
- // 参数获取
- $runType = trim($input->getArgument('run_type'));
- $runType = $runType ?: '';
- // 根据类型执行对应的操作
- switch($runType){
- // 合伙人佣金结算
- case 'partner_settlement':
- trace($runType, '计划任务 - 合伙人佣金周期计算 - 开始处理');
-
- (new Partner())->settlementInit();
- break;
- // 计算昨天产生的豆豆总数
- case 'compute_legumes':
- trace($runType, '计划任务 - 计算昨日产生的豆豆总数 - 开始处理');
-
- (new Legumes())->computeYesterdayLegumes();
- break;
- default:
- trace($runType, '计划任务 - 错误 - 不明确的执行内容');
- break;
- }
- // $output->writeln('接收参数:'. $runType);
- // $output->writeln('success');
- }
-}
diff --git a/addon/commission/config/diy_view.php b/addon/commission/config/diy_view.php
deleted file mode 100644
index bb54e83..0000000
--- a/addon/commission/config/diy_view.php
+++ /dev/null
@@ -1,31 +0,0 @@
- '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
- 'template' => [],
- // 后台自定义组件——装修
- 'util' => [],
- // 自定义页面路径
- 'link' => [],
- // 自定义图标库
- 'icon_library' => [],
- // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
- 'component' => [],
- // uni-app 页面,多个逗号隔开
- 'pages' => [],
- // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
- 'info' => [],
- // 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
- 'theme' => [],
- // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
- 'data' => []
-];
\ No newline at end of file
diff --git a/addon/commission/config/event.php b/addon/commission/config/event.php
deleted file mode 100644
index 02a40de..0000000
--- a/addon/commission/config/event.php
+++ /dev/null
@@ -1,58 +0,0 @@
- [],
- 'listen' => [
- //展示活动
- 'ShowPromotion' => [
- 'addon\commission\event\ShowPromotion',
- ],
- // 下单成功
- 'OrderCreate' => [
- 'addon\commission\event\OrderCreate',
- 'addon\commission\event\checkAccountsDivide',//验证积分释放可抵扣佣金
- ],
- // 支付成功
- 'OrderPay' => [
- 'addon\commission\event\OrderPay',
- ],
- // 在线买单支付成功
- 'CashierOrderPay' => [
- 'addon\commission\event\OrderPay',
- ],
- // 订单完成
- 'OrderComplete' => [
- 'addon\commission\event\OrderComplete',
- ],
- // 收银台订单完成
- 'CashierOrderComplete' => [
- 'addon\commission\event\OrderComplete',
- ],
- // 订单退款
- 'OrderRefundFinish' => [
- 'addon\commission\event\OrderRefundFinish',
- ],
- //订单关闭
- 'OrderClose' => [
- 'addon\commission\event\OrderClose',
- ],
- 'getDivideAccounts' => [//获取分佣账号
- 'addon\commission\event\getDivideAccounts'
- ],
- 'checkAccountsAuth' => [ //验证是否参与在线支付分账
- 'addon\commission\event\checkAccountsAuth',
- ],
- 'DivideMoneyAccounts' => [ //计算托管佣金划扣
- 'addon\commission\event\DivideMoneyAccounts',
- ],
- // 店铺收入统计 这里统计豆豆积分收入
- 'IncomeStatistics' => [
- 'addon\commission\event\IncomeStatistics',
- ],
- // 店铺支出统计 这里统计豆豆积分退款返还
- 'DisburseStatistics' => [
- 'addon\commission\event\DisburseStatistics',
- ],
- ],
- 'subscribe' => [],
-];
diff --git a/addon/commission/config/info.php b/addon/commission/config/info.php
deleted file mode 100644
index 50ebf00..0000000
--- a/addon/commission/config/info.php
+++ /dev/null
@@ -1,20 +0,0 @@
- 'commission',
- 'title' => '平台抽成',
- 'description' => '平台抽取订单部分金额,分配给指定角色!',
- 'type' => 'promotion', //插件类型 system :系统插件(自动安装), promotion:扩展营销插件 tool:工具插件
- 'status' => 1,
- 'author' => '',
- 'version' => '1.0.0',
- 'version_no' => '2024042911',
- 'content' => '',
-];
\ No newline at end of file
diff --git a/addon/commission/config/menu_shop.php b/addon/commission/config/menu_shop.php
deleted file mode 100644
index 0c40233..0000000
--- a/addon/commission/config/menu_shop.php
+++ /dev/null
@@ -1,61 +0,0 @@
- 'COMMISSION',
- 'title' => '平台抽成',
- 'url' => 'commission://shop/index/index',
- 'parent' => 'PROMOTION_CENTER',
- 'is_show' => 1,
- 'sort' => 100,
- 'child_list' => [
- [
- 'name' => 'COMMISSION_INDEX',
- 'title' => '抽成记录',
- 'url' => 'commission://shop/index/index',
- 'is_show' => 1,
- 'sort' => 1,
- ],
- [
- 'name' => 'COMMISSION_WEIGHT_VALUE',
- 'title' => '权重值管理',
- 'url' => 'commission://shop/index/weightValue',
- 'is_show' => 1,
- 'sort' => 1,
- ],
- [
- 'name' => 'COMMISSION_PARTNER',
- 'title' => '合伙人佣金',
- 'url' => 'commission://shop/index/partner',
- 'is_show' => 1,
- 'sort' => 1,
- 'menu_type' => 1
- ],
- [
- 'name' => 'COMMISSION_LEGUMES',
- 'title' => '豆豆积分',
- 'url' => 'commission://shop/index/legumes',
- 'is_show' => 1,
- 'sort' => 1,
- 'menu_type' => 1
- ],
- [
- 'name' => 'COMMISSION_ACCOUNT',
- 'title' => '流水明细',
- 'url' => 'commission://shop/index/accountList',
- 'is_show' => 1,
- 'sort' => 1,
- 'menu_type' => 1
- ],
- [
- 'name' => 'COMMISSION_SET',
- 'title' => '抽成设置',
- 'url' => 'commission://shop/index/set',
- 'is_show' => 1,
- 'sort' => 1,
- ]
- ]
- ]
-];
diff --git a/addon/commission/event/DisburseStatistics.php b/addon/commission/event/DisburseStatistics.php
deleted file mode 100644
index b737496..0000000
--- a/addon/commission/event/DisburseStatistics.php
+++ /dev/null
@@ -1,34 +0,0 @@
-getRefundSum([
- ['site_id', '=', $param['site_id']],
- ['refund_money_type', '=', '1,2'],
- ['refund_time', 'between', [$param['start_time'],$param['end_time']] ]
- ], 'legumes_integral_money')['data'];
-
- return [
- [
- 'title' => '订单退款返还积分抵扣金额',
- 'value' => $money,
- 'desc' => '统计时间内,订单退款返还积分抵扣金额之和',
- 'url' => 'shop/orderrefund/lists?order_scene=legumes_integral'
- ]
- ];
- }
-}
\ No newline at end of file
diff --git a/addon/commission/event/DivideMoneyAccounts.php b/addon/commission/event/DivideMoneyAccounts.php
deleted file mode 100644
index 45939ff..0000000
--- a/addon/commission/event/DivideMoneyAccounts.php
+++ /dev/null
@@ -1,31 +0,0 @@
-getList(['order_id' => $goods_ids], 'goods_id,goods_money');
- $dataArr = [];
- $Account = new Account();
- foreach ($order_goods_ids as $k => $v) {
- $param['goods_money'] = $v['goods_money'];
- $param['goods_id'] = $v['goods_id'];
- $tempArr = $Account->getDivideOrderCalculate($param);
- $dataArr = array_merge($dataArr, $tempArr);
- }
- if (empty($dataArr)) {
- $res = event('OrderPayFinish', $param); //取消订单支状态
- }
- return $dataArr;
- } catch (\Exception $e) {
- return [];
- }
- }
-}
diff --git a/addon/commission/event/IncomeStatistics.php b/addon/commission/event/IncomeStatistics.php
deleted file mode 100644
index 1eb91a8..0000000
--- a/addon/commission/event/IncomeStatistics.php
+++ /dev/null
@@ -1,33 +0,0 @@
-getOrderMoneySum([
- ['site_id','=',$param['site_id']],
- ['pay_time','between',[$param['start_time'],$param['end_time']]],
- ],'legumes_integral_money')['data'];
- return [
- [
- 'title' => '积分抵扣金额',
- 'value' => $money,
- 'desc' => '统计时间内,使用的积分抵扣金额之和',
- 'url' => 'shop/order/lists?order_scene=legumes_integral'
- ]
- ];
- }
-}
\ No newline at end of file
diff --git a/addon/commission/event/Install.php b/addon/commission/event/Install.php
deleted file mode 100644
index 3a6046d..0000000
--- a/addon/commission/event/Install.php
+++ /dev/null
@@ -1,23 +0,0 @@
- 0 && $memberId > 0){
- // 获取退回的记录列表
- $useLegumesLogList = (new Legumes())->getUsedList((int)$memberId,(float)$useLegumesIntegral);
- // 循环处理
- $returnComputeIntegral = $useLegumesIntegral;// 计算用 退回积分
- $updateData = [];
- foreach($useLegumesLogList as $logInfo){
- // 当前分配信息可退回积分 剩余可退回积分
- $reduce = $returnComputeIntegral < $logInfo['use_integral'] ? $returnComputeIntegral : $logInfo['use_integral'];
- $returnComputeIntegral = (float)sprintf("%.2f",$returnComputeIntegral - $reduce);
- $updateData[] = [
- 'id' => $logInfo['id'],
- 'use_integral' => (float)sprintf("%.2f",$logInfo['use_integral'] - $reduce)
- ];
- if($returnComputeIntegral <= 0) break;
- }
- if($updateData){
- // 修改
- $goodsSkuModel = (new NewBaseModel(['table_name' => 'commission_legumes_log', 'pk' => 'id']));
- $goodsSkuModel->saveAll($updateData);
- // 添加用户账单信息变更记录
- $mark = '订单关闭 - 退回使用积分:'.$useLegumesIntegral;
- model('commission_account')->add([
- 'site_id' => $siteId,
- 'member_id' => $memberId,
- 'join_id' => $orderId,
- 'account_type' => 'close_legumes_integral',
- 'account_type_name' => '积分退回',
- 'account_data' => $useLegumesIntegral,
- 'status' => 2,
- 'remark' => $mark,
- ]);
- }
- }
-
- }catch(Exception $e){
- trace($e->getMessage(), '平台抽成 - 订单关闭 - 错误');
- }
- return success();
- }
-
-
-}
\ No newline at end of file
diff --git a/addon/commission/event/OrderComplete.php b/addon/commission/event/OrderComplete.php
deleted file mode 100644
index b64e643..0000000
--- a/addon/commission/event/OrderComplete.php
+++ /dev/null
@@ -1,42 +0,0 @@
-update(['status'=>1],[
- ['order_id', '=', $orderId]
- ]);
- // 结算当前订单的 招商员佣金、推广员佣金
- Queue::push(AccountSettlementJob::class,[
- 'order_id' => (int)$orderId,
- 'account_type' => 'merchants_promoter',
- ]);
-
- }catch(Exception $e){
- trace($e->getMessage(), '平台抽成 - 订单完成 - 错误');
- }
-
- return success();
- }
-
-
-}
\ No newline at end of file
diff --git a/addon/commission/event/OrderCreate.php b/addon/commission/event/OrderCreate.php
deleted file mode 100644
index 0ebe686..0000000
--- a/addon/commission/event/OrderCreate.php
+++ /dev/null
@@ -1,28 +0,0 @@
- (int)$params['order_id'],
- ]);
- }catch(Exception $e){
- trace($e->getMessage(), '平台抽成 - 下单成功 - 错误');
- }
- return success();
- }
-}
diff --git a/addon/commission/event/OrderPay.php b/addon/commission/event/OrderPay.php
deleted file mode 100644
index 80c9759..0000000
--- a/addon/commission/event/OrderPay.php
+++ /dev/null
@@ -1,52 +0,0 @@
- (int)$params['member_id'],
- 'order_id' => (int)$params['order_id']
- ]);
- // 支付成功 - 赠送权重值
- Queue::push(GiveWeightValueJob::class,[
- 'member_id' => (int)$params['member_id'],
- 'order_id' => (int)$params['order_id'],
- 'site_id' => (int)$params['site_id']
- ]);
- // 非普通订单支付成功 减少豆豆积分
- $orderType = model('order')->getValue(['order_id' => (int)$params['order_id']], 'order_type');
- if($orderType != 1){
- Queue::push(UseLegumesIntegralJob::class,[
- 'order_id' => (int)$params['order_id'],
- ]);
- }
- }catch(Exception $e){
- trace($e->getMessage(), '平台抽成 - 支付成功 - 错误');
- }
- return success();
- }
-
-
-}
diff --git a/addon/commission/event/OrderRefundFinish.php b/addon/commission/event/OrderRefundFinish.php
deleted file mode 100644
index 85c940a..0000000
--- a/addon/commission/event/OrderRefundFinish.php
+++ /dev/null
@@ -1,344 +0,0 @@
-handleCommissionRecord($data['order_goods_id'], $refundRate);
- // 退款成功 权重值相关处理
- $this->handleWeightValue($data['order_goods_id'], $refundRate);
- // 招商员佣金 & 推广员佣金处理
- $this->HandleCommissionMoney($data['order_goods_id'], $refundRate);
- // 合伙人佣金处理
- $this->HandlePartnerMoney($data['order_goods_id'], $refundRate);
- // 积分和豆豆处理
- $this->HandleLegumes($data['order_goods_id'], $refundRate);
- // 抵扣积分退回
- $this->HandleIntegral($data['order_goods_id'], $refundRate);
- }
-
- Db::commit();
- }
- catch(Exception $e){
- Db::rollback();
- $error = [
- 'order_goods_id' => $data['order_goods_id'],
- 'msg' => $e->getMessage()
- ];
- trace($error, '平台抽成 - 订单退款 - 错误');
- }
- return success(0,'平台抽成退款操作完成');
- }
-
- // 退款处理 - 平台抽成记录处理
- private function handleCommissionRecord($orderGoodsId, $refundRate){
- $hasRefundRatio = (float)model('commission_record')->getValue(['order_goods_id'=>$orderGoodsId],'refund_ratio');
- $updateData = [
- 'refund_ratio' => (float)sprintf("%.2f", $hasRefundRatio + $refundRate)
- ];
- if($updateData['refund_ratio'] >= 100){
- $updateData['refund_ratio'] = 100;
- $updateData['partner_status'] = 3;
- $updateData['merchants_status'] = 3;
- $updateData['promoter_status'] = 3;
- }
- model('commission_record')->update($updateData,[
- ['order_goods_id', '=', $orderGoodsId]
- ]);
- return true;
- }
- // 退款处理 - 权重值相关处理
- private function handleWeightValue($orderGoodsId, $refundRate){
- $weightValueLogList = model('commission_weight_value_log')->getList([
- ['order_goods_id', '=', $orderGoodsId],
- ['change_type', '=', 1],
- ['source', '=', 0],
- ],'id,member_id,level_id,order_goods_id,change_quantity,goods_id,order_id');
- $insertLogData = [];
- $updateData = [];
- foreach($weightValueLogList as $weightValueLogInfo){
- // 获取用户持有信息
- $holdInfo = model('commission_weight_value')->getInfo([
- ['member_id', '=', $weightValueLogInfo['member_id']],
- ['level_id', '=', $weightValueLogInfo['level_id']],
- ]);
- // 获取已经减少数量
- $reduced = model('commission_weight_value_log')->getSum([
- ['order_goods_id', '=', $weightValueLogInfo['order_goods_id']],
- ['change_type', '=', 0],
- ['source', '=', 1],
- ['member_id', '=', $weightValueLogInfo['member_id']],
- ], 'change_quantity');
- // 计算减少信息,总减少数量不能超过获取数量
- $reduce = (float)sprintf("%.2f",$weightValueLogInfo['change_quantity'] * $refundRate / 100);
- $totalReduce = (float)sprintf("%.2f",$reduced * $reduce);
- if($totalReduce > $weightValueLogInfo['change_quantity']) $reduce = (float)sprintf("%.2f",$weightValueLogInfo['change_quantity'] - $reduced);
- $changeFront = $holdInfo->quantity;
- $surplusQuantity = (float)sprintf("%.2f",$holdInfo['quantity'] - $reduce);
- $updateData[] = [
- 'id' => $holdInfo['id'],
- 'quantity' => $surplusQuantity
- ];
- // 记录变更记录
- $insertLogData[] = [
- 'site_id' => $holdInfo['site_id'],
- 'member_id' => $weightValueLogInfo['member_id'],
- 'level_id' => $weightValueLogInfo['level_id'],
- 'goods_id' => $weightValueLogInfo['goods_id'],
- 'order_id' => $weightValueLogInfo['order_id'],
- 'order_goods_id' => $weightValueLogInfo['order_goods_id'],
- 'change_type' => 0,
- 'change_quantity' => $reduce,
- 'change_front' => $changeFront,
- 'change_after' => (float)$surplusQuantity,
- 'remark' => '商品退款,减少权重值',
- 'source' => 1,
- ];
- }
- if(count($insertLogData) > 0){
- model('commission_weight_value_log')->addList($insertLogData);
- }
- if(count($updateData) > 0){
- $goodsSkuModel = (new NewBaseModel(['table_name' => 'commission_weight_value', 'pk' => 'id']));
- $goodsSkuModel->saveAll($updateData);
- }
- return true;
- }
- // 退款处理 - 招商员佣金 & 推广员佣金处理
- private function HandleCommissionMoney($orderGoodsId, $refundRate){
- $where = [
- ['order_goods_id', '=', $orderGoodsId],
- ['merchants_status', '=', 1],
- ];
- $field = [
- 'a.id',
- 'a.site_id',
- 'a.store_id',
- 'a.order_id',
- 'a.order_goods_id',
- 'a.merchants_money',
- 's.merchants_member_id',
- 's.store_name',
- 'a.member_id',
- 'a.promoter_money',
- 'm.is_fenxiao',
- 'm.nickname',
- 'fx.member_id as fenxiao_member_id',
- 'fx.parent'
- ];
- $join = [
- ['store s', 's.store_id = a.store_id', 'LEFT'], // 关联客服
- ['member m', 'a.member_id = m.member_id', 'LEFT'],
- ['fenxiao fx', 'm.fenxiao_id = fx.fenxiao_id', 'LEFT'],
- ];
- $info = model('commission_record')->getInfo($where,$field,'a',$join);
- if(!$info) return false;
- // 处理招商员佣金
- if((int)$info['merchants_member_id'] > 0){
- // 获取冻结中佣金信息
- $reduce = (float)sprintf("%.3f",$info['merchants_money'] * $refundRate / 100);// 减少数量
- model('commission_account')->add([
- 'site_id' => $info['site_id'],
- 'member_id' => $info['merchants_member_id'],
- 'join_id' => $info['id'],
- 'account_type' => 'merchants_refund',
- 'account_type_name' => '招商员佣金退款',
- 'account_data' => '-' . $reduce,
- 'remark' => '订单退款,减少收入',
- 'status' => 2,
- ]);
- $memberCommissionMoney = model('member')->getValue([['member_id', '=', $info['merchants_member_id']]], 'commission_money');
- model('member')->update(['commission_money' => sprintf("%.2f", $memberCommissionMoney - $reduce)],[
- ['member_id', '=', $info['merchants_member_id']],
- ]);
- }
- // 处理推广员佣金
- if($info['is_fenxiao'] == 1) $parentMemberId = model('fenxiao')->getValue(['fenxiao_id'=>$info['parent']], 'member_id');// 当前用户是分销商 使用parent查询上级用户id
- else $parentMemberId = $info['fenxiao_member_id'];// 当前用户不是分销商 直接为fenxiao_member_id
- if($parentMemberId > 0){
- $reduce = (float)sprintf("%.3f",$info['promoter_money'] * $refundRate / 100);// 减少数量
- model('commission_account')->add([
- 'site_id' => $info['site_id'],
- 'member_id' => $parentMemberId,
- 'join_id' => $info['id'],
- 'account_type' => 'promoter_refund',
- 'account_type_name' => '推广员佣金退款',
- 'account_data' => '-' . $reduce,
- 'remark' => '订单退款,减少收入',
- 'status' => 2,
- ]);
- $memberCommissionMoney = model('member')->getValue([['member_id', '=', $parentMemberId]], 'commission_money');
- model('member')->update(['commission_money' => sprintf("%.2f", $memberCommissionMoney - $reduce)],[
- ['member_id', '=', $parentMemberId],
- ]);
- }
- return true;
- }
- // 退款处理 - 合伙人佣金处理
- private function HandlePartnerMoney($orderGoodsId, $refundRate){
- $commissionRecord = model('commission_record')->getInfo([
- ['order_goods_id', '=', $orderGoodsId]
- ],'partner_status,create_time,partner_money');
- // 待结算-结算时处理,已结算-减少用户已获得佣金,2、3-无处理
- if($commissionRecord['partner_status'] == 1){
- // 获取:获取当前抽成结算的归属周期
- $createTime = strtotime($commissionRecord['create_time']);
- $cycleInfo = model('commission_partner_cycle')->getInfo([
- ['start_time', '<', $createTime],
- ['end_time', '>', $createTime],
- ]);
- if($cycleInfo){
- // 计算总退款的合伙人佣金
- $reduceCommissionMoney = (float)sprintf("%.3f",$commissionRecord['partner_money'] * $refundRate / 100);// 减少数量
- // 获取退款的用户列表
- $userList = model('commission_partner')->getList([
- ['cycle_id', '=', $cycleInfo['cycle_id']],
- ],'id,site_id,member_id,money,proportion,cycle_id');
- $insertData = [];
- foreach($userList as $partnerInfo){
- // 计算当前用户应扣除合伙人佣金
- $reduce = (float)sprintf("%.2f",$reduceCommissionMoney * $partnerInfo['proportion'] / 100);
- // 记录账单
- $insertData = [
- 'site_id' => $partnerInfo['site_id'],
- 'member_id' => $partnerInfo['member_id'],
- 'join_id' => $partnerInfo['id'],
- 'account_type' => 'partner_refund',
- 'account_type_name' => '合伙人佣金退款',
- 'account_data' => '-' . $reduce,
- 'remark' => "订单退款,减少收入",
- 'status' => 2,
- ];
- $memberCommissionMoney = model('member')->getValue([['member_id', '=', $partnerInfo['member_id']]], 'commission_money');
- model('member')->update(['commission_money' => sprintf("%.2f", $memberCommissionMoney - $reduce)],[
- ['member_id', '=', $partnerInfo['member_id']],
- ]);
- }
- // 记录账单变化信息
- if (count($insertData) > 0) model('commission_account')->addList($insertData);
- }
- }
- return true;
- }
- // 退款处理 - 积分和豆豆处理
- private function HandleLegumes($orderGoodsId, $refundRate){
- // 获取当前抽成信息
- $commissionRecord = model('commission_record')->getInfo([
- ['order_goods_id', '=', $orderGoodsId]
- ],'id,create_time');
- // 判断:当前抽成豆豆信息是否已经结算,未结算-无操作处理(结算时处理退款内容);已结算-处理退款相关内容
- $maxEndTime = model('commission_legumes')->getMax([],'end_time');
- $createTime = strtotime($commissionRecord['create_time']);
- if($createTime < $maxEndTime){
- // 已结算 - 处理退款相关内容
- $legumesId = model('commission_legumes')->getValue([
- ['start_time', '<', $createTime],
- ['end_time', '>', $createTime]
- ], 'id');
- if($legumesId > 0){
- // 获取需要修改的信息列表
- $correlationList = model('commission_legumes_log')->getList([
- ['legumes_id', '=', $legumesId]
- ], 'id,member_id,order_money,refund_order_money,get_legumes,refund_get_legumes,get_integral');
- // 循环处理
- $updateData = [];
- foreach($correlationList as $correlationInfo){
- // 计算 退款金额
- $reduceOrderMoney = (float)sprintf("%.2f",$correlationInfo['order_money'] * $refundRate / 100);
- $refundOrderMoney = (float)sprintf("%.3f", $correlationInfo['refund_order_money'] + $reduceOrderMoney);
- if($refundOrderMoney > $correlationInfo['order_money']) $refundOrderMoney = $correlationInfo['order_money'];
- // 计算 退款豆豆
- $reduceGetLegumes = (float)sprintf("%.2f",$correlationInfo['get_legumes'] * $refundRate / 100);
- $refundGetLegumes = (float)sprintf("%.3f", $correlationInfo['refund_get_legumes'] + $reduceGetLegumes);
- if($refundGetLegumes > $correlationInfo['get_legumes']) $refundGetLegumes = $correlationInfo['get_legumes'];
- // 记录修改信息
- $updateData[] = [
- 'id' => $correlationInfo['id'],
- 'refund_order_money' => $refundOrderMoney,
- 'refund_get_legumes' => $refundGetLegumes
- ];
- }
- if(count($updateData) > 0) {
- $goodsSkuModel = (new NewBaseModel(['table_name' => 'commission_legumes_log', 'pk' => 'id']));
- $goodsSkuModel->saveAll($updateData);
- Queue::push(ComputeIntegralJob::class,[
- 'ids' => array_column($correlationList,'id')
- ]);
- }
- }
- }
- return true;
- }
- // 退款处理 - 抵扣积分退回
- private function HandleIntegral($orderGoodsId, $refundRate){
- // 获取订单商品信息
- $orderProductInfo = model('order_goods')->getInfo([
- ['order_goods_id', '=', $orderGoodsId]
- ],'site_id,member_id,order_id,legumes_integral_use');
- $useLegumesIntegral = $orderProductInfo['legumes_integral_use'] ?? 0;
- $memberId = $orderProductInfo['member_id'] ?? 0;
- if($useLegumesIntegral > 0 && $memberId > 0){
- // 计算退回积分
- $returnIntegral = (float)sprintf("%.2f",$useLegumesIntegral * $refundRate / 100);
- // 获取退回的记录列表
- $useLegumesLogList = (new Legumes())->getUsedList((int)$memberId,(float)$returnIntegral);
- // 循环处理
- $returnComputeIntegral = $returnIntegral;// 计算用 退回积分
- $updateData = [];
- foreach($useLegumesLogList as $logInfo){
- // 当前分配信息可退回积分 剩余可退回积分
- $reduce = $returnComputeIntegral < $logInfo['use_integral'] ? $returnComputeIntegral : $logInfo['use_integral'];
- $returnComputeIntegral = (float)sprintf("%.2f",$returnComputeIntegral - $reduce);
- $updateData[] = [
- 'id' => $logInfo['id'],
- 'use_integral' => (float)sprintf("%.2f",$logInfo['use_integral'] - $reduce)
- ];
- if($returnComputeIntegral <= 0) break;
- }
- if($updateData){
- // 修改
- $goodsSkuModel = (new NewBaseModel(['table_name' => 'commission_legumes_log', 'pk' => 'id']));
- $goodsSkuModel->saveAll($updateData);
- // 添加用户账单信息变更记录
- $mark = '订单退款 - 退回抵扣积分:'.$returnIntegral;
- model('commission_account')->add([
- 'site_id' => $orderProductInfo['site_id'],
- 'member_id' => $memberId,
- 'join_id' => $orderProductInfo['order_id'],
- 'account_type' => 'refund_legumes_integral',
- 'account_type_name' => '积分退回',
- 'account_data' => $returnIntegral,
- 'status' => 2,
- 'remark' => $mark,
- ]);
- }
- }
-
- return true;
- }
-
-}
diff --git a/addon/commission/event/ShowPromotion.php b/addon/commission/event/ShowPromotion.php
deleted file mode 100644
index d5fee8a..0000000
--- a/addon/commission/event/ShowPromotion.php
+++ /dev/null
@@ -1,34 +0,0 @@
- [
- [
- //插件名称
- 'name' => 'commission',
- //展示分类(根据平台端设置,admin(平台营销),shop:店铺营销,member:会员营销, tool:应用工具)
- 'show_type' => 'shop',
- //展示主题
- 'title' => '平台抽成',
- //展示介绍
- 'description' => '平台抽取订单部分金额,分配给指定角色!',
- //展示图标
- 'icon' => 'addon/commission/icon.png',
- //跳转链接
- 'url' => 'commission://shop/index/index',
- ]
- ]
- ];
- }
-}
\ No newline at end of file
diff --git a/addon/commission/event/UnInstall.php b/addon/commission/event/UnInstall.php
deleted file mode 100644
index 8758b17..0000000
--- a/addon/commission/event/UnInstall.php
+++ /dev/null
@@ -1,24 +0,0 @@
-checkAccountsAuth($param);
- } catch (\Exception $e) {
- return [];
- }
- }
-}
diff --git a/addon/commission/event/checkAccountsDivide.php b/addon/commission/event/checkAccountsDivide.php
deleted file mode 100644
index d3b929e..0000000
--- a/addon/commission/event/checkAccountsDivide.php
+++ /dev/null
@@ -1,17 +0,0 @@
-setCheckAccountsDivide($param);
- } catch (\Exception $e) {
- return [];
- }
- }
-}
diff --git a/addon/commission/event/getDivideAccounts.php b/addon/commission/event/getDivideAccounts.php
deleted file mode 100644
index 3342e92..0000000
--- a/addon/commission/event/getDivideAccounts.php
+++ /dev/null
@@ -1,17 +0,0 @@
-getDivideAccounts($param);
- } catch (\Exception $e) {
- return [];
- }
- }
-}
diff --git a/addon/commission/icon.png b/addon/commission/icon.png
deleted file mode 100644
index 97f323c..0000000
Binary files a/addon/commission/icon.png and /dev/null differ
diff --git a/addon/commission/job/AccountSettlementJob.php b/addon/commission/job/AccountSettlementJob.php
deleted file mode 100644
index 08864dd..0000000
--- a/addon/commission/job/AccountSettlementJob.php
+++ /dev/null
@@ -1,78 +0,0 @@
-getColumn([
- ['order_id', '=', $data['order_id']]
- ],'id');
- $where[] = ['join_id', 'in', $joinIds];
- }
- // 流水列表
- $list = model('commission_account')->getList($where,'id,sum(account_data) as total_account_data,member_id','','a',[],'member_id');
- // 获取用户已经持有信息
- $memberIds = array_column($list, 'member_id');
- $userList = Db::name('member')
- ->field('commission_money,member_id')
- ->whereIn('member_id', $memberIds)
- ->select()
- ->toArray();
- $userList = array_column($userList, null, 'member_id');
- // 循环流水列表 结算信息
- foreach($list as $singleInfo){
- $userList[$singleInfo['member_id']]['commission_money'] += $singleInfo['total_account_data'];
- }
- // 修改
- $newBaseModel = (new NewBaseModel(['table_name' => 'member', 'pk' => 'member_id']));
- $userList = array_values($userList);
- $newBaseModel->saveAll($userList);
- // 已结算
- model('commission_account')->update(['status'=>1],[
- ['id', 'in', array_column($list, 'id')]
- ]);
-
-
- Db::commit();
- }
- catch(\Exception $e){
- $data['error_msg'] = $e->getMessage();
- trace($data, '平台抽成 - 流水结算到账 - 失败');
- Db::rollback();
- }
- $job->delete();
- }
-
- public function failed($data){
- trace($data, '平台抽成 - 流水结算到账 - 失败(failed)');
- }
-}
diff --git a/addon/commission/job/AllocationLegumesJob.php b/addon/commission/job/AllocationLegumesJob.php
deleted file mode 100644
index 375a767..0000000
--- a/addon/commission/job/AllocationLegumesJob.php
+++ /dev/null
@@ -1,91 +0,0 @@
-getInfo(['id' => $legumesId]);
- if(!$cycleLegumes) throw new Exception('信息不存在');
- if((int)$cycleLegumes['status'] != 0) throw new Exception('当前豆豆已分配!');
- // 获取时间段所有消费用户
- $where = [
- [ 'a.pay_time', 'between', [ $cycleLegumes['start_time'], $cycleLegumes['end_time'] ] ],// 指定时间段内
- [ 'og.refund_status', 'in', [0, 3] ],// 订单商品未退款
- [ 'a.order_status', 'in', [1, 3, 4, 10, 11, 12] ],//待发货、已发货、已收货、已完成、待使用、已使用
- ];
- $join = [
- [ 'order_goods og', 'og.order_id = a.order_id', 'right' ],
- ];
- $field = 'og.order_id,og.order_goods_id,og.member_id,a.order_status,(sum(og.real_goods_money) + sum(og.legumes_integral_money)) as sum_money';
- $orderList = model('order')->getList($where,$field,'','a',$join,'og.order_goods_id');
- $totalMoney = array_sum(array_column($orderList,'sum_money'));
- // 获取平台抽成信息
- $orderGoodsIds = array_column($orderList,'order_goods_id');
- $commissionRecord = model('commission_record')->getList([
- ['order_goods_id','in',$orderGoodsIds],
- ],'order_goods_id,order_id,member_id,integral_money as platform_commission_money');
- $totalPlatformCommission = array_sum(array_column($commissionRecord,'platform_commission_money'));
- $commissionRecord = array_column($commissionRecord,null,'order_goods_id');
- // 循环处理
- $insertData = [];
- foreach($orderList as $orderInfo){
- // 获取平台抽成信息
- $platformCommissionInfo = $commissionRecord[$orderInfo['order_goods_id']] ?? [];
- if($platformCommissionInfo){
- // 计算订单金额占比 必须进行100的偏移计算
- $rate = (float)sprintf("%.3f",$platformCommissionInfo['platform_commission_money'] / $totalPlatformCommission * 100);
- $getLegumes = sprintf("%.4f",$cycleLegumes['legumes_num'] * $rate / 100);
- // 信息记录
- $insertData[] = [
- 'member_id' => $orderInfo['member_id'],
- 'legumes_id' => $legumesId,
- 'order_id' => $orderInfo['order_id'],
- 'order_goods_id' => $orderInfo['order_goods_id'],
- 'cycle_total_legumes' => $cycleLegumes['legumes_num'],
- 'total_sales_money' => $totalMoney,
- 'order_money' => $orderInfo['sum_money'],
- 'order_money_rate' => $rate,
- 'get_legumes' => $getLegumes,
- 'status' => in_array((int)$orderInfo['order_status'],[10,12]) ? 1 : 0,
- ];
- }
- }
- // 添加数据
- if(count($insertData) > 0) model('commission_legumes_log')->addList($insertData);
- // 修改豆豆周期分配状态
- model('commission_legumes')->update(['status' => 1],[
- ['id', '=', $legumesId]
- ]);
- // 触发全平台豆豆转积分操作
- Queue::push(ComputeIntegralJob::class);
- Db::commit();
- }
- catch(\Exception $e){
- Db::rollback();
- $data['error_msg'] = $e->getMessage();
- trace($data, '平台抽成 - 豆豆分配 - 失败');
- }
- $job->delete();
- }
- public function failed($data){
- trace($data, '平台抽成 - 豆豆分配 - 失败(failed)');
- }
-}
diff --git a/addon/commission/job/ComputeIntegralJob.php b/addon/commission/job/ComputeIntegralJob.php
deleted file mode 100644
index 337bdc7..0000000
--- a/addon/commission/job/ComputeIntegralJob.php
+++ /dev/null
@@ -1,92 +0,0 @@
-getLegumesPrice();
- // 获取当前页数据 有效记录、已获取积分低于订单金额
- $where = [
- ['status', 'in', [0,1]]
- ];
- if(count($ids) > 0) $where[] = ['id', 'in', $ids];
- else $where[] = ['', 'exp', Db::raw('get_integral < order_money')];
- $field = 'id,(order_money - refund_order_money) as order_money,(get_legumes - refund_get_legumes) as get_legumes,get_integral,member_id';
- $result = model('commission_legumes_log')->pageList($where,$field,'',$page,$limit);
- $count = $result['count'] ?? 0;
- $list = $result['list'] ?? [];
- if(count($list) <= 0) throw new \Exception('无处理数据!');
- // 循环处理
- $updateData = [];
- $insertData = [];
- foreach($list as $item){
- // 计算最新本订单商品 总释放积分;总释放积分不能超过订单金额
- $getIntegral = (float)sprintf("%.2f",$item['get_legumes'] * $legumesPrice);
- $resultGetIntegral = $getIntegral >= $item['order_money'] ? $item['order_money'] : $getIntegral;
- // 修改信息记录
- $updateData[] = [
- 'id' => $item['id'],
- 'get_integral' => $resultGetIntegral
- ];
- // 增加释放记录 仅存在变更数量时记录
- $changeQuantity = (float)sprintf("%.2f",$resultGetIntegral - $item['get_integral']);
- if($changeQuantity > 0){
- $insertData[] = [
- 'member_id' => $item['member_id'],
- 'legumes_log_id' => $item['id'],
- 'change_front' => $item['get_integral'],
- 'change_quantity' => (float)sprintf("%.2f",$resultGetIntegral - $item['get_integral']),
- 'change_after' => $resultGetIntegral,
- ];
- }
- }
- // 修改
- $newBaseModel = (new NewBaseModel(['table_name' => 'commission_legumes_log', 'pk' => 'id']));
- $newBaseModel->saveAll($updateData);
- // 增加记录
- if(count($insertData) > 0) model('commission_legumes_release_log')->addList($insertData);
- // 判断:是否存在下一页
- $currentLimit = $page * $limit;
- if($currentLimit < $count){
- $data['page'] = $page + 1;
- Queue::push(ComputeIntegralJob::class,$data);
- }
-
- Db::commit();
- }
- catch(\Exception $e){
- Db::rollback();
- trace($e->getMessage(), '平台抽成 - 全平台豆豆转积分 - 失败');
- }
- $job->delete();
- }
-
- public function failed($data){
- trace($data, '平台抽成 - 全平台豆豆转积分 - 失败(failed)');
- }
-}
diff --git a/addon/commission/job/CreateRecordJob.php b/addon/commission/job/CreateRecordJob.php
deleted file mode 100644
index 61a9161..0000000
--- a/addon/commission/job/CreateRecordJob.php
+++ /dev/null
@@ -1,98 +0,0 @@
-getConfig();
- if($adminSet['switch'] != 1) throw new Exception('总平台未开启平台抽成');
- // 当前订单是否已经处理
- $isHas = (int)model('commission_record')->getValue([
- ['order_id', '=', $orderId]
- ],'id');
- if($isHas > 0) throw new Exception('当前订单已经处理');
- // 获取订单商品信息
- $field = 'order_goods_id,order_id,site_id,member_id,goods_id,store_id,num,(real_goods_money + legumes_integral_use) as use_money';
- $orderGoodsList = model('order_goods')->getList(['order_id'=>$orderId],$field);
- // 循环处理
- $insertData = [];
- foreach($orderGoodsList as $orderGoodsInfo){
- $useMoney = $orderGoodsInfo['use_money'] ?? 0;
- if($useMoney <= 0) continue;// 当前订单商品有效金额为0
- // 设置获取
- $set = (new Setting())->getFinalSet((int)$orderGoodsInfo['site_id'],(int)$orderGoodsInfo['goods_id']);
- if($set['switch'] != 1) continue;// 当前商品不参与平台抽成
- $integralRate = (float)$set['integral_rate'] ?? 0;
- $operationsRate = (float)$set['operations_rate'] ?? 0;
- $partnerRate = (float)$set['partner_rate'] ?? 0;
- $merchantsRate = (float)$set['merchants_rate'] ?? 0;
- $promoterRate = (float)$set['promoter_rate'] ?? 0;
- // 根据抽成计算类型生成记录信息
- $commissionType = $set['commission_type'] ?? 0;// 抽成计算类型
- $operationsMoney = (float)sprintf("%.3f",$useMoney * $operationsRate / 100);// 运营抽成总金额
- $operationsTechnologyMoney = (float)sprintf("%.3f",$operationsMoney * 0.2);// 运营抽成 - 技术公司所得(20%)
- $operationsPlatformMoney = (float)sprintf("%.3f",$operationsMoney - $operationsTechnologyMoney);// 运营抽成 - 平台所得(80%)
-
- $insertData[] = [
- 'member_id' => $orderGoodsInfo['member_id'],
- 'site_id' => $orderGoodsInfo['site_id'],
- 'store_id' => $orderGoodsInfo['store_id'],
- 'order_id' => $orderGoodsInfo['order_id'],
- 'order_goods_id' => $orderGoodsInfo['order_goods_id'],
- 'goods_id' => $orderGoodsInfo['goods_id'],
- 'real_goods_money' => $useMoney,
- // 根据计算类型获取值 抽成类型:0=比例,1=固定金额
- 'integral_rate' => $commissionType == 1 ? -1 : $integralRate,
- 'integral_money' => $commissionType == 1 ? sprintf("%.3f",$orderGoodsInfo['num'] * $integralRate) : sprintf("%.3f",$useMoney * $integralRate / 100),
- 'operations_rate' => $operationsRate,
- 'operations_money' => $operationsMoney,
- 'partner_rate' => $commissionType == 1 ? -1 : $partnerRate,
- 'partner_money' => $commissionType == 1 ? sprintf("%.3f",$orderGoodsInfo['num'] * $partnerRate) : sprintf("%.3f",$useMoney * $partnerRate / 100),
- 'merchants_rate' => $commissionType == 1 ? -1 : $merchantsRate,
- 'merchants_money' => $commissionType == 1 ? sprintf("%.3f",$orderGoodsInfo['num'] * $merchantsRate) : sprintf("%.3f",$useMoney * $merchantsRate / 100),
- 'promoter_rate' => $commissionType == 1 ? -1 : $promoterRate,
- 'promoter_money' => $commissionType == 1 ? sprintf("%.3f",$orderGoodsInfo['num'] * $promoterRate) : sprintf("%.3f",$useMoney * $promoterRate / 100),
- 'operations_technology_money' => (float)$operationsTechnologyMoney,
- 'operations_platform_money' => (float)$operationsPlatformMoney,
- ];
- }
-
- if(count($insertData) > 0){
- model('commission_record')->addList($insertData);
- // 支付成功 - 抽成记录生成后 - 招商员佣金结算
- Queue::push(MerchantsSettlementJob::class,[
- 'order_id' => (int)$orderId
- ]);
- // 支付成功 - 抽成记录生成后 - 推广员佣金结算
- Queue::push(PromoterSettlementJob::class,[
- 'order_id' => (int)$orderId,
- ]);
- }
- }
- catch(\Exception $e){
- $data['error_msg'] = $e->getMessage();
- trace($data, '平台抽成 - 支付成功生成抽成记录 - 失败');
- }
-
- $job->delete();
- }
- public function failed($data){
- trace($data, '平台抽成 - 支付成功生成抽成记录 - 失败(failed)');
- }
-}
diff --git a/addon/commission/job/GiveWeightValueJob.php b/addon/commission/job/GiveWeightValueJob.php
deleted file mode 100644
index d3aa051..0000000
--- a/addon/commission/job/GiveWeightValueJob.php
+++ /dev/null
@@ -1,74 +0,0 @@
-getUserHoldList((int)$data['member_id'], (int)$data['site_id']);
- // 获取当前订单中所有商品
- $orderGoodsField = 'order_goods_id,order_id,goods_id,(real_goods_money + legumes_integral_use) as use_money';
- $orderGoodsList = model('order_goods')->getList([['order_id','=', $data['order_id']]], $orderGoodsField);
- $updateData = [];
- $insertLogData = [];
- foreach($userHoldList as $userInfo){
- foreach($orderGoodsList as $goodsInfo){
- // 判断:当前用户是否存在修改记录中 不存在添加修改信息
- if(empty($updateData[$userInfo['id']])){
- $updateData[$userInfo['id']] = [
- 'id' => $userInfo['id'],
- 'quantity' => $userInfo['quantity'],
- ];
- }
- // 持有数量增加
- $changeFront = (float)$updateData[$userInfo['id']]['quantity'];
- $updateData[$userInfo['id']]['quantity'] = (float)sprintf("%.2f",(float)$goodsInfo['use_money'] + $changeFront);
- // 记录变更记录
- $insertLogData[] = [
- 'site_id' => (int)$data['site_id'],
- 'member_id' => $userInfo['member_id'],
- 'level_id' => $userInfo['level_id'],
- 'goods_id' => $goodsInfo['goods_id'],
- 'order_id' => $goodsInfo['order_id'],
- 'order_goods_id' => $goodsInfo['order_goods_id'],
- 'change_type' => 1,
- 'change_quantity' => $goodsInfo['use_money'],
- 'change_front' => $changeFront,
- 'change_after' => (float)$updateData[$userInfo['id']]['quantity'],
- 'remark' => '下线购买商品赠送',
- ];
- }
- }
- // 数据结果处理
- if(count($insertLogData) > 0){
- // 修改
- $updateModel = (new NewBaseModel(['table_name' => 'commission_weight_value', 'pk' => 'id']));
- $updateModel->saveAll($updateData);
- model('commission_weight_value_log')->addList($insertLogData);
- }
- }
- catch(\Exception $e){
- $data['error_msg'] = $e->getMessage();
- trace($data, '下单赠送权重值 - 失败');
- }
- $job->delete();
- }
- public function failed($data){
- trace($data, '下单赠送权重值 - 失败(failed)');
- }
-}
diff --git a/addon/commission/job/MerchantsSettlementJob.php b/addon/commission/job/MerchantsSettlementJob.php
deleted file mode 100644
index 19bd632..0000000
--- a/addon/commission/job/MerchantsSettlementJob.php
+++ /dev/null
@@ -1,82 +0,0 @@
-startTrans();
- try{
- // trace($data, '平台抽成 - 支付成功招商员佣金结算 - 开始处理');
- $orderId = (int)$data['order_id'];
-
- $where = [
- ['order_id', '=', $orderId],
- ['merchants_status', '=', 0],
- ];
- $field = 'a.id,a.site_id,a.store_id,a.order_id,a.merchants_money,s.merchants_member_id,s.store_name';
- $join = [
- ['store s', 's.store_id = a.store_id', 'LEFT'], // 关联客服
- ];
- $list = model('commission_record')->getList($where,$field,'','a',$join);
- // 循环处理
- $updateData = [];
- $insertData = [];
- foreach($list as $recordInfo){
- // 根据是否存在招商员 进行对应的处理
- if((int)$recordInfo['merchants_member_id'] > 0){
- // 存在招商员 招商员佣金结算
- $insertData[] = [
- 'site_id' => $recordInfo['site_id'],
- 'member_id' => $recordInfo['merchants_member_id'],
- 'join_id' => $recordInfo['id'],
- 'account_type' => 'merchants',
- 'account_type_name' => '招商员佣金',
- 'account_data' => $recordInfo['merchants_money'],
- 'remark' => $recordInfo['store_name'] . '的订单收入',
- ];
- // 修改信息
- $updateData[] =[
- 'id' => $recordInfo['id'],
- 'merchants_status' => 1,
- ];
- }
- else{
- // 不存在招商员
- $updateData[] =[
- 'id' => $recordInfo['id'],
- 'merchants_status' => 2,
- ];
- }
- }
- // 数据结果处理
- if(count($insertData) > 0) model('commission_account')->addList($insertData);
- if(count($updateData) > 0){
- $updateModel = (new NewBaseModel(['table_name' => 'commission_record', 'pk' => 'id']));
- $updateModel->saveAll($updateData);
- }
-
-
- model("commission_record")->commit();
- }
- catch(\Exception $e){
- model("commission_record")->rollback();
- $data['error_msg'] = $e->getMessage();
- trace($data, '平台抽成 - 支付成功招商员佣金结算 - 失败');
- }
- $job->delete();
- }
- public function failed($data){
- trace($data, '平台抽成 - 支付成功招商员佣金结算 - 失败(failed)');
- }
-}
diff --git a/addon/commission/job/PartnerSettlementJob.php b/addon/commission/job/PartnerSettlementJob.php
deleted file mode 100644
index af11a71..0000000
--- a/addon/commission/job/PartnerSettlementJob.php
+++ /dev/null
@@ -1,78 +0,0 @@
-getList([
- ['id', 'in', $cycleIds]
- ],'id,start_time,end_time');
- $cycleList = array_column($cycleList, null, 'id');
- // 获取结算记录信息
- $list = model('commission_partner')->getList([
- ['cycle_id', 'in', $cycleIds],
- ['is_settlement', '=', 0],
- ],'id,member_id,cycle_id,money,site_id');
- if(count($list) > 0){
- $insertData = [];
- foreach($list as $singleInfo){
- $cycleInfo = $cycleList[$singleInfo['cycle_id']] ?? [];
- $timePeriod = date("Y-m-d H:i:s",$cycleInfo['start_time']) . ' ~ ' . date("Y-m-d H:i:s",$cycleInfo['end_time']);
- $insertData[] = [
- 'site_id' => $singleInfo['site_id'],
- 'member_id' => $singleInfo['member_id'],
- 'join_id' => $singleInfo['id'],
- 'account_type' => 'partner',
- 'account_type_name' => '合伙人佣金',
- 'account_data' => $singleInfo['money'],
- 'remark' => $timePeriod . "权重值收入",
- ];
- }
- // 记录信息
- if(count($insertData) > 0) model('commission_account')->addList($insertData);
- // 修改结算状态
- $ids = array_column($list,'id');
- model('commission_partner')->update([ 'is_settlement' => 1],[
- ['id', 'in', $ids]
- ]);
-
- // 结算当前订单的 招商员佣金、推广员佣金
- Queue::push(AccountSettlementJob::class,[
- 'account_type' => 'partner',
- ]);
- }
-
- Db::commit();
- }
- catch(\Exception $e){
- Db::rollback();
- $data['error_msg'] = $e->getMessage();
- trace($data, '平台抽成 - 合伙人佣金结算 - 失败');
- }
- $job->delete();
- }
-
- public function failed($data){
- trace($data, '平台抽成 - 合伙人佣金结算 - 失败(failed)');
- }
-}
diff --git a/addon/commission/job/PromoterSettlementJob.php b/addon/commission/job/PromoterSettlementJob.php
deleted file mode 100644
index 4166e43..0000000
--- a/addon/commission/job/PromoterSettlementJob.php
+++ /dev/null
@@ -1,89 +0,0 @@
-startTrans();
- try{
- // trace($data, '平台抽成 - 支付成功推广员佣金结算 - 开始处理');
- $orderId = (int)$data['order_id'];
- // 当前订单
- $where = [
- ['order_id', '=', $orderId],
- ['promoter_status', '=', 0],
- ];
- $join = [
- ['member m', 'a.member_id = m.member_id', 'LEFT'],
- ['fenxiao fx', 'm.fenxiao_id = fx.fenxiao_id', 'LEFT'],
- ];
- $field = 'a.id,a.site_id,a.member_id,a.promoter_money,m.is_fenxiao,m.nickname,fx.member_id as fenxiao_member_id,fx.parent';
- $list = model('commission_record')->getList($where,$field,'','a', $join);
- // 循环处理
- $updateData = [];
- $insertData = [];
- foreach($list as $recordInfo){
- // 判断:当前用户是否为分销 获取对应的上级分销商用户id
- if($recordInfo['is_fenxiao'] == 1){
- // 当前用户是分销商 使用parent查询上级用户id
- $parentMemberId = model('fenxiao')->getValue(['fenxiao_id'=>$recordInfo['parent']], 'member_id');
- }else{
- // 当前用户不是分销商 直接为fenxiao_member_id
- $parentMemberId = $recordInfo['fenxiao_member_id'];
- }
- // 判断:是否存在上级
- if((int)$parentMemberId > 0){
- // 存在上级
- $insertData[] = [
- 'site_id' => $recordInfo['site_id'],
- 'member_id' => $parentMemberId,
- 'join_id' => $recordInfo['id'],
- 'account_type' => 'promoter',
- 'account_type_name' => '推广员佣金',
- 'account_data' => $recordInfo['promoter_money'],
- 'remark' => '推广订单收入',
- ];
- // 修改信息
- $updateData[] =[
- 'id' => $recordInfo['id'],
- 'promoter_status' => 1,
- ];
- }else{
- // 不存在上级
- $updateData[] =[
- 'id' => $recordInfo['id'],
- 'promoter_status' => 2,
- ];
- }
- }
- // 数据结果处理
- if(count($insertData) > 0) model('commission_account')->addList($insertData);
- if(count($updateData) > 0){
- $updateModel = (new NewBaseModel(['table_name' => 'commission_record', 'pk' => 'id']));
- $updateModel->saveAll($updateData);
- }
-
- model("commission_record")->commit();
- }
- catch(\Exception $e){
- model("commission_record")->rollback();
- $data['error_msg'] = $e->getMessage();
- trace($data, '平台抽成 - 支付成功推广员佣金结算 - 失败');
- }
- $job->delete();
- }
- public function failed($data){
- trace($data, '平台抽成 - 支付成功推广员佣金结算 - 失败(failed)');
- }
-}
diff --git a/addon/commission/job/UseLegumesIntegralJob.php b/addon/commission/job/UseLegumesIntegralJob.php
deleted file mode 100644
index 52b3ac2..0000000
--- a/addon/commission/job/UseLegumesIntegralJob.php
+++ /dev/null
@@ -1,74 +0,0 @@
-getInfo([
- ['order_id','=', $data['order_id']],
- ['legumes_integral_use','>', 0]
- ],'order_id,site_id,member_id,legumes_integral_use,legumes_integral_money');
- if(!$orderInfo) throw new \Exception('信息不存在!');
- $useLegumesIntegral = (float)$orderInfo['legumes_integral_use'];
- // 查询需要使用的分配记录
- $useLegumesLogList = (new Legumes())->getUseList((int)$orderInfo['member_id'],(float)$orderInfo['legumes_integral_use']);
- // 循环处理
- $updateData = [];
- foreach($useLegumesLogList as $logInfo){
- $useIntegral = $useLegumesIntegral >= $logInfo['surplus_integral'] ? (float)$logInfo['surplus_integral'] : (float)$useLegumesIntegral;
- $useLegumesIntegral = (float)sprintf("%.2f",$useLegumesIntegral - $useIntegral);
- $updateData[] = [
- 'id' => $logInfo['id'],
- 'use_integral' => (float)sprintf("%.2f",$logInfo['use_integral'] + $useIntegral)
- ];
- if($useLegumesIntegral <= 0) break;
- }
- // 修改成功信息
- if($updateData){
- // 修改豆豆积分使用信息
- $goodsSkuModel = (new NewBaseModel(['table_name' => 'commission_legumes_log', 'pk' => 'id']));
- $goodsSkuModel->saveAll($updateData);
- // 添加用户账单信息变更记录
- $mark = '购买商品使用'.$orderInfo['legumes_integral_use'].'积分抵扣'.floatval($orderInfo['legumes_integral_money']).'元';
- model('commission_account')->add([
- 'site_id' => $orderInfo['site_id'],
- 'member_id' => $orderInfo['member_id'],
- 'join_id' => $orderInfo['order_id'],
- 'account_type' => 'use_legumes_integral',
- 'account_type_name' => '积分使用',
- 'account_data' => '-'.$orderInfo['legumes_integral_use'],
- 'status' => 1,
- 'remark' => $mark,
- ]);
- }
-// Db::commit();
- }
- catch(\Exception $e){
-// Db::rollback();
- $data['error_msg'] = $e->getMessage();
- trace($data, '平台抽成 - 豆豆积分抵扣处理 - 失败');
- }
- $job->delete();
- }
-
- public function failed($data){
- trace($data, '平台抽成 - 豆豆积分抵扣处理 - 失败(failed)');
- }
-}
diff --git a/addon/commission/model/Account.php b/addon/commission/model/Account.php
deleted file mode 100644
index b0bdeb3..0000000
--- a/addon/commission/model/Account.php
+++ /dev/null
@@ -1,813 +0,0 @@
-pageList($where, true, 'id DESC', $page, $pageSize);
-
- return $this->success($result);
- }
-
- /**
- * Common: 获取流水信息
- * Author: wu-hui
- * Time: 2024/05/21 15:08
- * @param $params
- * @return array
- */
- public function accountListV2($params)
- {
- $page = $params['page'] ?? 1;
- $pageSize = $params['page_size'] ?? PAGE_LIST_ROWS;
- // 生成查询条件
- $where = [];
- if (isset($params['member_id']) && $params['member_id'] !== '') $where[] = ['a.member_id', '=', $params['member_id']];
- if (isset($params['account_type']) && $params['account_type'] !== '') {
- // all=全部;promoter=推广员佣金;merchants=招商员佣金;partner=合伙人佣金;
- switch ($params['account_type']) {
- case 'promoter':
- $where[] = ['a.account_type', 'in', ['promoter_refund', 'promoter']];
- break;
- case 'merchants':
- $where[] = ['a.account_type', 'in', ['merchants_refund', 'merchants']];
- break;
- case 'partner':
- $where[] = ['a.account_type', 'in', ['partner_refund', 'partner']];
- break;
- case 'legumes_integral':
- $where[] = ['a.account_type', 'in', ['use_legumes_integral', 'close_legumes_integral']];
- break;
- default :
- $where[] = ['a.account_type', 'in', ['sync', 'partner_refund', 'partner', 'promoter_refund', 'promoter', 'merchants_refund', 'merchants']];
- }
- }
- if (isset($params['time_type']) && $params['time_type'] !== '' && $params['time_type'] !== 'all') {
- // all=全部;day=当日;week=本周;month=本月;
- $startTime = $endTime = 0;
- switch ($params['time_type']) {
- case 'day':
- [$startTime, $endTime] = getTimeStamp('today');
-
- $where[] = ['a.create_time', 'between', [date("Y-m-d H:i:s", $startTime), date("Y-m-d H:i:s", $endTime)]];
- break;
- case 'week':
- [$startTime, $endTime] = getTimeStamp('week');
- $where[] = ['a.create_time', 'between', [date("Y-m-d H:i:s", $startTime), date("Y-m-d H:i:s", $endTime)]];
- break;
- case 'month':
- [$startTime, $endTime] = getTimeStamp('month');
- $where[] = ['a.create_time', 'between', [date("Y-m-d H:i:s", $startTime), date("Y-m-d H:i:s", $endTime)]];
- break;
- }
- }
- if (isset($params['status']) && $params['status'] !== '') $where[] = ['a.status', '=', $params['status']];
- // 流水列表
- $join = [
- ['member m', 'm.member_id = a.member_id', 'left'],
- ['site s', 's.site_id = a.site_id', 'left'],
- ];
- $field = 'a.*,m.username,m.nickname,m.headimg,s.site_name,s.contacts_name,s.contacts_mobile';
-
- $result = model('commission_account')->pageList($where, $field, 'id DESC', $page, $pageSize, 'a', $join);
-
- return $this->success($result);
- }
-
- /**
- * Common: 获取流水信息(平台抽成流水和团队奖励流水合并)
- * Author: wu-hui
- * Time: 2024/08/13 11:51
- * @param $params
- * @return array
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function accountListV3($params)
- {
- $page = $params['page'] ?? 1;
- $pageSize = $params['page_size'] ?? PAGE_LIST_ROWS;
- // 生成查询条件
- $where = [];
- $unionWhere = [];
- if (isset($params['member_id']) && $params['member_id'] !== '') {
- $where[] = ['member_id', '=', $params['member_id']];
- $unionWhere[] = ['member_id', '=', $params['member_id']];
- }
- if (isset($params['account_type']) && $params['account_type'] !== '') {
- // all=全部;promoter=推广员佣金;merchants=招商员佣金;partner=合伙人佣金;
- switch ($params['account_type']) {
- case 'promoter':
- $where[] = ['account_type', 'in', ['promoter_refund', 'promoter']];
- $unionWhere[] = ['id', '=', 0];
- break;
- case 'merchants':
- $where[] = ['account_type', 'in', ['merchants_refund', 'merchants']];
- $unionWhere[] = ['id', '=', 0];
- break;
- case 'partner':
- $where[] = ['account_type', 'in', ['partner_refund', 'partner']];
- $unionWhere[] = ['id', '=', 0];
- break;
- case 'legumes_integral':
- $where[] = ['account_type', 'in', ['use_legumes_integral', 'close_legumes_integral']];
- $unionWhere[] = ['id', '=', 0];
- break;
- case 'team':
- $where[] = ['id', '=', 0];
- break;
- default :
- $where[] = ['account_type', 'in', ['sync', 'partner_refund', 'partner', 'promoter_refund', 'promoter', 'merchants_refund', 'merchants']];
- }
- }
- if (isset($params['time_type']) && $params['time_type'] !== '' && $params['time_type'] !== 'all') {
- // all=全部;day=当日;week=本周;month=本月;
- $startTime = $endTime = 0;
- switch ($params['time_type']) {
- case 'day':
- [$startTime, $endTime] = getTimeStamp('today');
-
- $where[] = ['create_time', 'between', [date("Y-m-d H:i:s", $startTime), date("Y-m-d H:i:s", $endTime)]];
- $unionWhere[] = ['create_time', 'between', [date("Y-m-d H:i:s", $startTime), date("Y-m-d H:i:s", $endTime)]];
- break;
- case 'week':
- [$startTime, $endTime] = getTimeStamp('week');
- $where[] = ['create_time', 'between', [date("Y-m-d H:i:s", $startTime), date("Y-m-d H:i:s", $endTime)]];
- $unionWhere[] = ['create_time', 'between', [date("Y-m-d H:i:s", $startTime), date("Y-m-d H:i:s", $endTime)]];
- break;
- case 'month':
- [$startTime, $endTime] = getTimeStamp('month');
- $where[] = ['create_time', 'between', [date("Y-m-d H:i:s", $startTime), date("Y-m-d H:i:s", $endTime)]];
- $unionWhere[] = ['create_time', 'between', [date("Y-m-d H:i:s", $startTime), date("Y-m-d H:i:s", $endTime)]];
- break;
- }
- }
- if (isset($params['status']) && $params['status'] !== '') {
- $where[] = ['status', '=', $params['status']];
- $unionWhere[] = ['status', '=', $params['status']];
- }
- // 信息查询
- $count = Db::name('commission_account')
- ->field(['id'])
- ->union(function ($query) use ($unionWhere) {
- $query->name('team_account')->field(['id'])->where($unionWhere);
- })->where($where)->count();
-
- $list = Db::name('commission_account')
- ->field(['id', 'create_time', 'account_type', 'status', 'account_data', '"commission" as type'])
- ->union(function ($query) use ($unionWhere) {
- $query->name('team_account')->field(['id', 'create_time', 'account_type', 'status', 'account_data', '"team" as type'])->where($unionWhere);
- })
- ->where($where)
- ->order('create_time', 'DESC')
- ->page($page, $pageSize)
- // ->fetchSql()
- ->select()
- ->toArray();
-
- return $this->success([
- 'count' => $count,
- 'list' => $list,
- 'page_count' => ceil($count / $pageSize),
- ]);
- }
-
-
- /**
- * Common: 统计信息
- * Author: wu-hui
- * Time: 2024/05/21 14:06
- * @param $memberId
- * @return array
- */
- public function statistics($memberId)
- {
- // 总获得佣金
- $all = model('commission_account')->getSum([
- ['account_data', '>', 0],
- ['member_id', '=', $memberId],
- ['account_type', 'in', ['sync', 'promoter', 'merchants', 'partner']],
- ], 'account_data');
- // 可提现收益
- $withdrawal = model('member')->getValue([
- ['member_id', '=', $memberId],
- ], 'commission_money');
- // 总获得 推广收益
- $totalPromoter = model('commission_account')->getSum([
- ['member_id', '=', $memberId],
- ['account_type', '=', 'promoter']
- ], 'account_data');
- // 总获得 招商收益
- $totalMerchants = model('commission_account')->getSum([
- ['member_id', '=', $memberId],
- ['account_type', '=', 'merchants']
- ], 'account_data');
- // 总获得 合伙人分红
- $totalPartner = model('commission_account')->getSum([
- ['member_id', '=', $memberId],
- ['account_type', '=', 'partner']
- ], 'account_data');
- // 推广收益(推广订单数、推广订单总额、推广收益)
- $promoter = Db::name('commission_account')
- ->field([
- 'COUNT(DISTINCT cr.order_id) AS promoter_order',
- 'sum(cr.real_goods_money) as promoter_order_money',
- 'sum(a.account_data) as promoter_account'
- ])
- ->alias('a')
- ->leftjoin("commission_record cr", "a.join_id = cr.id")
- ->where([
- ['a.member_id', '=', $memberId],
- ['a.account_type', '=', 'promoter'],
- ['cr.id', '>', 0]
- ])
- ->findOrEmpty();
- // 招商收益(邀请门店、招商订单总额、招商收益)
- $merchants = Db::name('commission_account')
- ->field([
- 'sum(cr.real_goods_money) as promoter_order_money',
- 'sum(a.account_data) as merchants_account'
- ])
- ->alias('a')
- ->leftjoin("commission_record cr", "a.join_id = cr.id")
- ->where([
- ['a.member_id', '=', $memberId],
- ['a.account_type', '=', 'merchants'],
- ['cr.id', '>', 0]
- ])
- ->findOrEmpty();
- $merchants['total_store'] = model('store')->getCount([
- ['merchants_member_id', '=', $memberId]
- ]);
- // 合伙人(持有权重值、分红收益)
- $partner['hold_weight_value'] = model('commission_weight_value')->getSum([
- ['member_id', '=', $memberId]
- ], 'quantity');
- $partner['partner_account'] = model('commission_account')->getSum([
- ['member_id', '=', $memberId],
- ['account_type', '=', 'partner']
- ], 'account_data');
- // 团队奖励 - 相关统计
- $teamStatistics = (new Commission())->statistics($memberId);
-
-
- return $this->success([
- 'all' => (float)sprintf("%.2f", $all + $teamStatistics['team_total_award']),
- 'withdrawal' => $withdrawal,
- 'total_promoter' => $totalPromoter,
- 'total_merchants' => $totalMerchants,
- 'total_partner' => $totalPartner,
- 'promoter' => $promoter,
- 'merchants' => $merchants,
- 'partner' => $partner,
- 'team_statistics' => $teamStatistics
- ]);
- }
-
-
- /***
- * 检查分账状态
- * @param $params
- * @return void
- */
- public function checkAccountsAuth($params = [])
- {
- $accounts = [];
- if (isset($params['out_trade_no'])) {
- $is_divide = cache($params['out_trade_no']);
- if ($is_divide == 1) {
- $accounts = $this->checkAccountState($params);
- } else if ($is_divide != 'no' || empty($is_divide)) { //预留位置多服务器查询
- $order_model = new OrderCommon();
- $order_info = $order_model->getOrderInfo([['site_id', '=', $params['site_id']], ['out_trade_no', '=', $params['out_trade_no']]])['data'];
- $site_id = $params['site_id'];
- $set = (new Setting())->getFinalSet((int)$site_id, 0);
- if ($set['switch'] == 1) {
- $total_rate = $set['integral_rate'] + $set['operations_rate']; //积分托管,营运抽佣总和
- $goods_money = $order_info['goods_money'];
- $partner_rate_proxy = $getFinalSet['partner_rate_proxy'] ?? 0;
- $merchants_rate_proxy = $getFinalSet['merchants_rate_proxy'] ?? 0;
- $promoter_rate_proxy = $getFinalSet['promoter_rate_proxy'] ?? 0;
- if ($partner_rate_proxy) { //合伙人佣金发放
- $total_rate += $getFinalSet['partner_rate'];
- }
- if ($merchants_rate_proxy) {//招商员分佣比例
- $total_rate += $getFinalSet['merchants_rate'];
- }
- if ($promoter_rate_proxy) { //推广员分佣比例
- $total_rate += $getFinalSet['promoter_rate'];
- }
- $commission = $goods_money * $total_rate / 100;
- if ($commission > $order_info['legumes_integral_money']) {//如果拨出佣金大于抵扣直接使用现金分账
- cache($params['out_trade_no'], 1, 7200); //设置分账状态
- $accounts = $this->checkAccountState($params);
- }
- }
- }
- }
- return $accounts;
- }
-
-
- /***
- * 检查分账状态
- * @param $data
- * @return array|string
- */
- public function checkAccountState($data = [])
- {
- $res = event('getDivideAccounts', $data);
- $divideStatet = true;
- $isDivide = false;
- $is_pay_error = '';
- $Accounts = [];
- if ($res) {
- foreach ($res as $v) {
- foreach ($v as $item) {
- $Accounts[] = $item;
- }
- }
- $is_commission = array_sum(array_column($Accounts, 'is_commission'));
- if ($is_commission <= 0) return '';//剔除免佣账号
- $isDivide = true;
- if ($data['pay_type'] == 'alipay') {//验证支付宝是否开启分账
- $is_pay_error = cache('is_pay_error' . $data['site_id']);
- if (!cache('alipayTradeBatchquery' . $data['site_id']) || $is_pay_error) {
- $micode = new MinCode($data['site_id']);
- $request = $micode->requestApi('alipay.trade.royalty.relation.batchquery', ['out_request_no' => date('YmdHisw')])['alipay_trade_royalty_relation_batchquery_response'];
- if ($request['code'] == 10000) {
- cache('alipayTradeBatchquery' . $data['site_id'], 1, 7200);
- cache('is_pay_error' . $data['site_id'], null);
- } else {
- $divideStatet = false;
- $is_pay_error = '未检开启分账权限';
- }
- }
- }
- $startTime = mktime(0, 0, 0, date('m'), date('d') - 30, date('Y'));
- $where = [
- ['site_id', '=', $data['site_id']],
- ['states', 'in', [0, 2, 3]],
- ['is_order_account_locking', '=', 0],
- ['create_time', '<', $startTime],
- ];
- $countMone = model('dividemoney_bill')->getSum($where, 'amount');
- if ($countMone >= 50) {
- $divideStatet = false;
- $is_pay_error = '服务佣金未结清';
- }
- }
- return [
- 'isDivide' => $isDivide,
- 'divideState' => $divideStatet,
- 'err_msg' => $is_pay_error,
- ];
- }
-
- /***
- * 获取分账账号
- * @param $params
- * @return array
- */
- public function getDivideAccounts($params = [], $proxyFee = 0, $reason = '')
- {
- $site_id = $params['site_id'];
- $pay_type = $params['pay_type'];
- $json = [
- ['website w', 's.agent_id=w.site_id', 'inner'],
- ];
- $field = 's.is_ispfee,s.service_fee,w.site_id,w.web_contacts,w.web_phone,w.settlement_wecaht_mch_id,w.settlement_alipay_account,w.alipay_account_name,w.wecaht_account_name,w.is_divide,w.separate_accounts_value';
- $siteInfo = model('site')->getInfo(['s.site_id' => $site_id], $field, 's', $json);
- $accounts = [];
- if ($siteInfo && $siteInfo['is_divide'] == 1) {
- $getSet = (new Setting())->getFinalSet((int)$site_id, 0);
- $platform = config('accounts');
- $operations_rate = $getSet['operations_rate'];//运营抽佣
- if ($siteInfo['is_ispfee'] == 1) {
- $acc1 = [
- 'is_commission' => 1,
- 'is_platform' => 1,
- 'account_type' => 'technology',
- 'agent_id' => $siteInfo['site_id'],
- 'realname' => $platform['realname'],
- 'mobile' => $platform['mobile'],
- 'alipay_account_name' => $platform['alipay']['realname'],
- 'settlement_alipay_account' => $platform['alipay']['account'],
- 'wecaht_account_name' => $platform['weapp']['realname'],
- 'settlement_wecaht_mch_id' => $platform['weapp']['account'],
- 'fee_commission' => 0.6,
- 'commission_type' => 'sale',
- 'separate_accounts' => $platform,
- 'reason' => '平台技术服务费0.6%'
- ];
- $cisp_fee = $siteInfo['service_fee'] ?? 0;
- if ($cisp_fee > 0) {//如果技术费独立设置
- $acc1['fee_commission'] = $cisp_fee;
- $acc1['reason'] = "平台技术服务费{$cisp_fee}%";
- } else {
- $fee_commission = $platform['default'];
- $service_fee = $operations_rate * $fee_commission / 100;
- $acc1['fee_commission'] = $service_fee;
- $acc1['reason'] = "平台技术服务费{$service_fee}%";
- $operations_rate -= $service_fee;
- }
- $accounts[] = $acc1;
- }
- $integral_rate = $getSet['integral_rate'] ?? 0;
- $acc2 = [
- 'is_commission' => 1,
- 'account_type' => 'integral',
- 'agent_id' => $siteInfo['site_id'],
- 'realname' => $siteInfo['wecaht_account_name'],
- 'mobile' => $siteInfo['web_phone'],
- 'alipay_account_name' => $siteInfo['alipay_account_name'],
- 'settlement_alipay_account' => $siteInfo['settlement_alipay_account'],
- 'wecaht_account_name' => $siteInfo['wecaht_account_name'],
- 'settlement_wecaht_mch_id' => $siteInfo['settlement_wecaht_mch_id'],
- 'fee_commission' => $integral_rate + $proxyFee,
- 'commission_type' => 'sale',
- 'is_platform' => 1,
- 'separate_accounts' => json_decode($siteInfo['separate_accounts_value'], true),
- 'reason' => "消费托管(含:积分托管{$integral_rate}%运营{$operations_rate}%{$reason})"
- ];
- $acc2['fee_commission'] += $operations_rate;
- $accounts[] = $acc2;
- }
- $where = [
- ['site_id', '=', $site_id],
- ];
- switch ($pay_type) {
- case 'wechatpay':
- $account = array_column($accounts, 'settlement_wecaht_mch_id');
- $where[] = ['channel_type', '=', 'wechatpay'];
- $where[] = ['account', 'in', $account];
- break;
- case 'alipay':
- $account = array_column($accounts, 'settlement_alipay_account');
- $where[] = ['channel_type', '=', 'alipay'];
- $where[] = ['account', 'in', $account];
- break;
- case 'cywechatpay':
- case 'cyalipay':
- $separate_accounts = array_column($accounts, 'separate_accounts');
- $cypay = array_column($separate_accounts, 'cypay');
- $account = array_column($cypay, 'account');
- $where[] = ['channel_type', '=', 'cypay'];
- $where[] = ['account', 'in', $account];
- break;
- default:
- return $accounts;
- }
- $res = model('dividemoney_account')->getColumn($where, '*', 'account');
- $model = new DividemoneyAccount();
- foreach ($accounts as $k => &$v) {
- $account = '';
- $data = [
- 'is_system' => 1,
- 'is_platform' => 1,
- ];
- if ($pay_type == 'wechatpay') {
- $account = $res[$v['settlement_wecaht_mch_id']] ?? [];
- $data['account'] = $v['settlement_wecaht_mch_id'];
- $data['account_type'] = 'MERCHANT_ID';
- $data['channel_type'] = 'wechatpay';
- $data['realname'] = $v['wecaht_account_name'];
- $class = 'BingWechatAccount';
- } else if ($pay_type == 'alipay') {
- $account = $res[$v['settlement_alipay_account']] ?? [];
- $data['account'] = $v['settlement_alipay_account'];
- $data['account_type'] = 'userId';
- $data['channel_type'] = 'alipay';
- $data['realname'] = $v['alipay_account_name'];
- $class = 'BingAlipayAccount';
- } else if ($pay_type == 'cywechatpay' || $pay_type == 'cyalipay') {
- $cypay = $v['separate_accounts']['cypay'];
- $account = $res[$cypay['account']] ?? [];
- $data['account'] = $cypay['account'];
- $data['account_type'] = 'PARTNER';
- $data['channel_type'] = 'cypay';
- $data['realname'] = $cypay['realname'];
- $class = 'BingCyPayAccount';
- }
- if (empty($account) || ($account && $account['states'] != 1)) {
- $bing = $model->$class($site_id, $data);
- if ($bing['code'] >= 0) {
- $v['is_auth'] = 1;
- } else {
- $v['is_auth'] = 0;
- }
- } else if ($account && $account['states'] == 1) {
- $v['is_auth'] = 1;
- }
- }
- return $accounts;
- }
-
- public $legumes_integral_community = 0;//积分佣金循环共存
-
- /***
- * 获取账单分佣
- * @param $params
- * @return array
- */
- public function getDivideOrderCalculate($params = [])
- {
- $site_id = $params['site_id'];
- $pay_type = $params['pay_type'];
- $goods_id = $params['goods_id'] ?? 0;
- $getFinalSet = (new Setting())->getFinalSet((int)$site_id, $goods_id);
- if ($getFinalSet['switch'] == 1) {
- $total_rate = $getFinalSet['integral_rate'] + $getFinalSet['operations_rate']; //消费积分托管+营运抽佣总和
- $partner_rate_proxy = $getFinalSet['partner_rate_proxy'] ?? 0;
- $merchants_rate_proxy = $getFinalSet['merchants_rate_proxy'] ?? 0;
- $promoter_rate_proxy = $getFinalSet['promoter_rate_proxy'] ?? 0;
- $reason = '';
- $proxy = 0;
- if ($partner_rate_proxy) { //合伙人佣金发放
- $total_rate += $getFinalSet['partner_rate'];
- $proxy += $getFinalSet['partner_rate'];
- $reason = "合伙人佣金{$getFinalSet['partner_rate']}%";
- }
- if ($merchants_rate_proxy) {//招商员分佣比例
- $total_rate += $getFinalSet['merchants_rate'];
- $proxy += $getFinalSet['merchants_rate'];
- $reason .= "招商佣金{$getFinalSet['merchants_rate']}%";
- }
- if ($promoter_rate_proxy) { //推广员分佣比例
- $total_rate += $getFinalSet['promoter_rate'];
- $proxy += $getFinalSet['promoter_rate'];
- $reason .= "推广佣金{$getFinalSet['promoter_rate']}%";
- }
- $goods_money = $params['goods_money'];
- $commission = $goods_money * $total_rate / 100; //佣金
- $AccInfo = $this->getDivideAccounts($params, $proxy, $reason);
- $accArr = [];
- switch ($pay_type) {
- case 'cyalipay':
- case 'cywechatpay':
- $account_type = 'PARTNER';
- break;
- case 'wechatpay':
- $account_type = 'MERCHANT_ID';
- break;
- case 'alipay':
- $account_type = 'userId';
- break;
- default:
- $account_type = 'Integral';
- break;
- }
- if ($pay_type != 'BALANCE' && $params['legumes_integral_money'] == 0) {
- //如果未使用积分抵扣在线支付
- foreach ($AccInfo as $k => $v) {
- $v['account_type'] = $account_type;
- $arr = $this->getMoneyArr($params, $v, $goods_money, $v['fee_commission'], 1, $v['reason']);
- if ($arr) {
- $accArr[] = $arr;
- }
- }
- } else if ($pay_type == 'BALANCE' || ($params['legumes_integral_money'] && $params['legumes_integral_money'] >= $commission)) {
- //如果抵扣积分大于佣金或使用余额直接使用积分抵扣
- foreach ($AccInfo as $k => $v) {
- $v['account_type'] = 'Integral';
- $arr = $this->getMoneyArr($params, $v, $goods_money, $v['fee_commission'], 1, $v['reason']);
- if ($arr) {
- $accArr[] = $arr;
- }
- }
- $amount = array_sum(array_column($accArr, 'amount'));
- $this->legumes_integral_community += $amount;
-// model('order')->update(['legumes_integral_community' => Db::raw('legumes_integral_community +' . $amount)], ['order_id' => $params['order_id']]);
- } else {//使用积分+支付
- $use_order_money = $params['order_money'] * 0.3;//最大分账率
- $legumes_integral_money = $params['legumes_integral_money'];//使用积分抵扣金额
- $legumes_integral_community = 0; //积分抽佣
- //测试示例
-// $commission = 5;
-// $legumes_integral_money = 0.8;
-// $use_order_money = 2;
- foreach ($AccInfo as $k => $v) {
- $getMoney = $this->getMoneyArr($params, $v, $goods_money, $v['fee_commission'], 1, $v['reason']);
- if (empty($getMoney)) continue;
- if ($pay_type != 'BALANCE' && $commission <= $use_order_money) { //如果佣金大于可抽佣金额直接抽现金
- $getMoney['account_type'] = $account_type;
- $accArr[] = $getMoney;
- } else if ($pay_type == 'BALANCE') { //如果使用余额支付积分抵扣,可能积分是负数,在未结算总额扣除
- $v['account_type'] = 'Integral';
- $accArr[] = $this->getMoneyArr($params, $v, $goods_money, $v['fee_commission'], 1, $v['reason']);
- } else if ($legumes_integral_money) { //如果使用积分抵扣大于佣金
- if ($getMoney['amount'] <= $legumes_integral_money) { //如果积分抵扣大于佣金
- $getMoney['account_type'] = 'Integral';
- $legumes_integral_money -= $getMoney['amount'];
- $legumes_integral_community += $getMoney['amount'];
- $accArr[] = $getMoney;
- } else {
- $amount = $getMoney['amount'];
- if ($amount > $legumes_integral_money) { //抵扣剩余积分
- $amount -= $legumes_integral_money;
- $getMoney['account_type'] = 'Integral';
- $getMoney['amount'] = $legumes_integral_money;
- $legumes_integral_community += $legumes_integral_money;
- $legumes_integral_money = 0;
- $accArr[] = $getMoney;
- }
- if ($amount > 0) { //扣除支付分账
- $getMoney['account_type'] = $account_type;
- $getMoney['amount'] = $amount;
- $use_order_money -= $amount;
- $accArr[] = $getMoney;
- }
- }
- } else if ($pay_type != 'BALANCE' && $use_order_money) {
- $amount = $getMoney['amount'];
- if ($use_order_money >= $amount) {
- $getMoney['account_type'] = $account_type;
- $getMoney['amount'] = $amount;
- $accArr[] = $getMoney;
- } else if ($use_order_money < $amount) {
- if ($use_order_money > 0) {
- $getMoney['account_type'] = $account_type;
- $getMoney['amount'] = $use_order_money;
- $accArr[] = $getMoney;
- $amount -= $use_order_money;
- $use_order_money = 0;
- }
- if ($amount > 0) {
- $getMoney['account_type'] = 'Integral';
- $getMoney['amount'] = $amount;
- $legumes_integral_community += $amount;
- $accArr[] = $getMoney;
- }
- }
- } else { //理论上不会出现
- $getMoney['account_type'] = 'Integral';
- $legumes_integral_community += $getMoney['amount'];
- $accArr[] = $getMoney;
- }
- }
- $this->legumes_integral_community += $legumes_integral_community;//记录循环值防止重复计算
- }
- if ($this->legumes_integral_community > 0) {//防止重复计算
- model('order')->update(['legumes_integral_community' => $this->legumes_integral_community], ['order_id' => $params['order_id']]);
- }
- }
- //如果拨出佣金大于抵扣直接使用现金分账
- return $accArr;
- }
-
-
- /***
- * 整理数据
- * @param $data
- * @param $accIfno
- * @param $price
- * @param $fee_commission
- * @param $platform_type
- * @param $reason
- * @return array
- */
- private function getMoneyArr($data, $accIfno, $price, $fee_commission, $platform_type = 2, $reason = '服务商服务费')
- {
- if (isset($accIfno['commission_type']) && $accIfno['commission_type'] == 'fixfee') {
- $money = $fee_commission;
- } else {
- $money = $price * $fee_commission / 100;
- if ($money < 0.01) {
- $money = 0.01;
- }
- }
- //判断是否按产品抽佣
- $ag_site_id = $data['agent_id'] ?? 0;
- $acc = [
- 'site_id' => $data['site_id'],
- 'ag_site_id' => $ag_site_id,
- 'is_platform' => $platform_type,
- 'order_id' => $data['order_id'],
- 'member_id' => $data['member_id'],
- 'out_trade_no' => $data['out_trade_no'],
- 'trade_no' => $data['trade_no'] ?? '', //订单号
- 'is_video_number' => $data['is_video_number'] ?: 0,
- 'fee_commission' => $fee_commission,
- 'pay_money' => $price,//支付金额,
- 'amount' => $money,
- 'account_type' => $accIfno['account_type'],
- 'channel_type' => $data['pay_type'],
- 'promotion_type' => $data['promotion_type'],
- 'reason' => $reason
- ];
- switch ($data['pay_type']) {
- case 'weapp':
- case 'wechat':
- case 'wechatpay':
- $acc['channel_type'] = 'wechatpay';
- $acc['realname'] = $accIfno['wecaht_account_name'];
- $acc['account'] = $accIfno['settlement_wecaht_mch_id'];
- break;
- case 'alipay':
- case 'aliapp':
- case 'zmxxpay':
- case 'huabie':
- case 'zmgopay':
- $acc['channel_type'] = 'alipay';
- $acc['realname'] = $accIfno['alipay_account_name'];
- $acc['account'] = $accIfno['settlement_alipay_account'];
- break;
- case 'cywechatpay':
- case 'cyalipay':
- $accounts = $accIfno['separate_accounts']['cypay'];
- $acc['realname'] = $accounts['realname'];
- $acc['account'] = $accounts['account'];
- $acc['channel_type'] = 'cypay';
- break;
- case 'hfwechatpay':
- case 'hfalipay':
- $accounts = $accIfno['separate_accounts']['hfpay'];
- $acc['realname'] = $accounts['realname'];
- $acc['account'] = $accounts['account'];
- $acc['channel_type'] = 'hfpay';
- break;
- case 'BALANCE':
- $acc['channel_type'] = 'BALANCE';
- $acc['realname'] = $accIfno['realname'];
- $acc['account'] = $accIfno['settlement_wecaht_mch_id'];
- break;
- default:
- $accounts = $accIfno['separate_accounts']['Integral'];
- $acc['realname'] = $accounts['realname'];
- $acc['account'] = $accounts['account'];
- $acc['channel_type'] = 'Integral';
- }
- $account_type = $acc['account_type'];
- if ($account_type == 'Integral') {
- $accounts = $accIfno['separate_accounts']['Integral'];
- $acc['realname'] = $accounts['realname'];
- $acc['account'] = $accounts['account'];
- $acc['channel_type'] = 'Integral';
- }
- if ($money <= 0 || !$acc['account'] || !$acc['realname']) { //未设置账号不分佣
- $acc = [];
- }
- return $acc;
- }
-
- /***
- * 设置标记是否该订单参与现金分账
- * @param $params
- * @return void
- */
- public function setCheckAccountsDivide($params = [])
- {
- $order_id = $params['order_id'];
- $order_model = new OrderCommon();
- $order_info = $order_model->getOrderInfo([['order_id', '=', $order_id]])['data'];
- $site_id = $params['site_id'];
- $set = (new Setting())->getFinalSet((int)$site_id, 0);
- if ($set['switch'] == 1) {
- $total_rate = $set['integral_rate'] + $set['operations_rate']; //积分托管,营运抽佣总和
- $goods_money = $order_info['goods_money'];
- $commission = $goods_money * $total_rate / 100;
- if ($commission > $order_info['legumes_integral_money']) {//如果拨出佣金大于抵扣直接使用现金分账
- cache($order_info['out_trade_no'], 1, 7200); //设置分账状态
- } else {
- cache($order_info['out_trade_no'], 'no', 7200); //设置分账状态
- }
- }
- return $this->success();
- }
-}
diff --git a/addon/commission/model/CommissionRecord.php b/addon/commission/model/CommissionRecord.php
deleted file mode 100644
index 57b316f..0000000
--- a/addon/commission/model/CommissionRecord.php
+++ /dev/null
@@ -1,118 +0,0 @@
-adminSiteId) $params['site_id'] = $siteId;
- // 生成查询条件
- $where = [];
- if(isset($params['member_id']) && $params['member_id'] !== '') $where[] = ['a.member_id','=',$params['member_id']];
- if(isset($params['site_id']) && $params['site_id'] !== '') $where[] = ['a.site_id','=',$params['site_id']];
- if(isset($params['store_id']) && $params['store_id'] !== '') $where[] = ['a.store_id','=',$params['store_id']];
- if(isset($params['order_id']) && $params['order_id'] !== '') $where[] = ['a.order_id','=',$params['order_id']];
- if(isset($params['order_no']) && $params['order_no'] !== '') $where[] = ['o.order_no','=',$params['order_no']];
- if(isset($params['goods_id']) && $params['goods_id'] !== '') $where[] = ['a.goods_id','=',$params['goods_id']];
- // 关联查询
- $join = [
- [ 'member m', 'm.member_id = a.member_id', 'left' ],
- [ 'order o', 'o.order_id = a.order_id', 'left' ],
- [ 'goods g', 'g.goods_id = a.goods_id', 'left' ],
- [ 'site s', 's.site_id = a.site_id', 'left' ]
- ];
- $field = [
- 'a.id',
- 'a.real_goods_money',
- 'a.integral_rate',
- 'a.integral_money',
- 'a.operations_rate',
- 'a.operations_money',
- 'a.operations_technology_money',
- 'a.operations_platform_money',
- 'a.partner_rate',
- 'a.partner_money',
- 'a.partner_status',
- 'a.merchants_rate',
- 'a.merchants_money',
- 'a.merchants_status',
- 'a.promoter_rate',
- 'a.promoter_money',
- 'a.promoter_status',
- 'a.create_time',
- 'a.refund_ratio',
- 'm.member_id',
- 'm.nickname',
- 'm.username',
- 'm.headimg',
- 'o.order_id',
- 'o.order_no',
- 'o.order_type',
- 'g.goods_id',
- 'g.goods_name',
- 'g.goods_image',
- 's.site_name',
- 's.contacts_name',
- 's.contacts_mobile',
- ];
- $result = model('commission_record')->pageList($where,$field,'a.id DESC',$page,PAGE_LIST_ROWS,'a',$join);
- $result['is_admin'] = $siteId == $this->adminSiteId;
-
- return $this->success($result);
- }
- /**
- * Common: 获取统计信息
- * Author: wu-hui
- * Time: 2024/05/13 9:43
- * @param $params
- * @param $siteId
- * @return array
- */
- public function getStatistics($params, $siteId){
- // 判断:不是总平台 仅显示当前店铺相关抽成记录
- if($siteId != $this->adminSiteId) $params['site_id'] = $siteId;
- // 生成查询条件
- $where = [];
- if(isset($params['member_id']) && $params['member_id'] !== '') $where[] = ['a.member_id','=',$params['member_id']];
- if(isset($params['site_id']) && $params['site_id'] !== '') $where[] = ['a.site_id','=',$params['site_id']];
- if(isset($params['store_id']) && $params['store_id'] !== '') $where[] = ['a.store_id','=',$params['store_id']];
- if(isset($params['order_id']) && $params['order_id'] !== '') $where[] = ['a.order_id','=',$params['order_id']];
- if(isset($params['order_no']) && $params['order_no'] !== '') $where[] = ['o.order_no','=',$params['order_no']];
- if(isset($params['goods_id']) && $params['goods_id'] !== '') $where[] = ['a.goods_id','=',$params['goods_id']];
- // 关联查询
- $join = [
- [ 'order o', 'o.order_id = a.order_id', 'left' ],
- ];
- // 信息统计
- return [
- 'total_real_goods_money' => model('commission_record')->getSum($where,'real_goods_money','a',$join),
- 'total_integral_money' => model('commission_record')->getSum($where,'integral_money','a',$join),
- 'total_operations_money' => model('commission_record')->getSum($where,'operations_money','a',$join),
- 'total_partner_money' => model('commission_record')->getSum($where,'partner_money','a',$join),
- 'total_merchants_money' => model('commission_record')->getSum($where,'merchants_money','a',$join),
- 'total_promoter_money' => model('commission_record')->getSum($where,'promoter_money','a',$join),
- ];
- }
-
-
-}
\ No newline at end of file
diff --git a/addon/commission/model/Legumes.php b/addon/commission/model/Legumes.php
deleted file mode 100644
index dc45cac..0000000
--- a/addon/commission/model/Legumes.php
+++ /dev/null
@@ -1,464 +0,0 @@
- model('commission_legumes_log')->getSum($where, 'get_legumes'),
- 'total_order_money' => model('commission_legumes_log')->getSum($where, 'order_money'),
- 'total_get_integral' => model('commission_legumes_log')->getSum($where, 'get_integral'),
- 'total_use_integral' => model('commission_legumes_log')->getSum($where, 'use_integral'),
- 'total_freeze_integral' => model('commission_legumes_log')->getSum($freezeWhere, 'get_integral'),
- ];
- }
-
- /**
- * Common: 获取豆豆周期结算信息
- * Author: wu-hui
- * Time: 2024/05/09 11:49
- * @param $page
- * @param $params
- * @return array
- */
- public function getCycleList($page, $params)
- {
- // 生成查询条件
- $where = [];
- // 关联查询
- $result = model('commission_legumes')->pageList($where, true, 'id DESC', $page, PAGE_LIST_ROWS);
-
- return $this->success($result);
- }
-
- /**
- * Common: 获取豆豆分配明细
- * Author: wu-hui
- * Time: 2024/05/09 11:58
- * @param $page
- * @param $params
- * @return array
- */
- public function getLegumesLogList($page, $params)
- {
- $pageSize = $params['page_size'] ?? PAGE_LIST_ROWS;
- // 生成查询条件
- $where = [];
- if (isset($params['member_id']) && $params['member_id'] !== '') {
- if (is_array($params['member_id'])) $where[] = ['a.member_id', 'in', $params['member_id']];
- else $where[] = ['a.member_id', '=', $params['member_id']];
- }
- if (isset($params['legumes_id']) && $params['legumes_id'] !== '') $where[] = ['a.legumes_id', '=', $params['legumes_id']];
- if (isset($params['status']) && $params['status'] !== '') $where[] = ['a.status', '=', $params['status']];
- // 关联查询
- $join = [
- ['member m', 'm.member_id = a.member_id', 'left'],
- ];
- $field = [
- 'a.*',
- 'm.nickname',
- 'm.username',
- 'm.headimg',
- ];
- $result = model('commission_legumes_log')->pageList($where, $field, 'id DESC', $page, $pageSize, 'a', $join);
-
- return $this->success($result);
- }
-
- /**
- * Common: 获取积分释放明细
- * Author: wu-hui
- * Time: 2024/05/15 15:06
- * @param $params
- * @return array
- */
- public function legumesReleaseLog($params)
- {
- $pageSize = $params['page_size'] ?? PAGE_LIST_ROWS;
- $page = $params['page'] ?? 1;
- // 生成查询条件
- $where = [];
- if (isset($params['member_id']) && $params['member_id'] !== '') $where[] = ['member_id', '=', $params['member_id']];
- if (isset($params['legumes_log_id']) && $params['legumes_log_id'] !== '') $where[] = ['legumes_log_id', '=', $params['legumes_log_id']];
- // 关联查询
- $result = model('commission_legumes_release_log')->pageList($where, true, 'id DESC', $page, $pageSize);
-
- return $this->success($result);
- }
-
- /**
- * Common: 获取用户持有信息
- * Author: wu-hui
- * Time: 2024/05/09 13:45
- * @param $page
- * @param $params
- * @return array
- */
- public function getHoldList($page, $params)
- {
- $result = $this->getHoldListData($page, $params);
-
- return $this->success($result);
- }
-
- /**
- * Common: 获取用户持有信息(返回信息数组)
- * Author: wu-hui
- * Time: 2024/05/29 11:23
- * @return mixed
- */
- public function getHoldListData($page, $params)
- {
- // 生成查询条件
- $where = [
- ['a.status', 'in', [0, 1]],
- ];
- if (isset($params['member_id']) && $params['member_id'] !== '') {
- if (is_array($params['member_id'])) $where[] = ['a.member_id', 'in', $params['member_id']];
- else $where[] = ['a.member_id', '=', $params['member_id']];
- }
- // 关联查询
- $join = [
- ['member m', 'm.member_id = a.member_id', 'left'],
- ];
- $field = [
- 'a.member_id',
- 'sum(a.order_money) as total_order_money',
- 'sum(a.get_legumes) as total_get_legumes',
- 'sum(a.refund_order_money) as total_refund_order_money',
- 'sum(a.refund_get_legumes) as total_refund_get_legumes',
- 'sum(a.get_integral) as total_get_integral',
- 'sum(a.use_integral) as total_use_integral',
- 'm.nickname',
- 'm.username',
- 'm.headimg',
- ];
- $result = model('commission_legumes_log')->pageList($where, $field, 'id DESC', $page, PAGE_LIST_ROWS, 'a', $join, 'a.member_id');
- // 获取冻结中积分
- $memberIds = array_column($result['list'], 'member_id');
- $freezeWhere = [
- ['member_id', 'in', $memberIds],
- ['status', '=', 0],
- ];
- $freezeField = 'member_id,sum(get_integral) as total_get_integral';
- $freeze = model('commission_legumes_log')->getList($freezeWhere, $freezeField, '', 'a', [], 'member_id');
- $freeze = array_column($freeze, 'total_get_integral', 'member_id');
- foreach ($result['list'] as &$singleInfo) {
- // 总冻结积分
- $singleInfo['total_freeze_integral'] = $freeze[$singleInfo['member_id']] ?? 0;
- // 可使用积分
- $reduce = (float)sprintf("%.2f", $singleInfo['total_freeze_integral'] + $singleInfo['total_use_integral']);// 冻结 + 已使用积分
- $singleInfo['surplus_use_integral'] = (float)sprintf("%.2f", $singleInfo['total_get_integral'] - $reduce);
- }
-
- return $result;
- }
-
- /**
- * Common: 获取单个用户持有信息
- * Author: wu-hui
- * Time: 2024/05/09 16:06
- * @param $memberId
- * @return array|mixed
- */
- public function getMemberHoldInfo($memberId)
- {
- $result = $this->getHoldListData(1, ['member_id' => $memberId]);
- $info = $result['list'] ?? [];
-
- return $info[0] ?? [];
- }
-
-
- /**
- * Common: 获取全平台用户持有总积分信息
- * Author: wu-hui
- * Time: 2024/05/29 11:40
- * @param $memberId
- * @return array
- */
- public function getAllSiteHoldInfo($memberId)
- {
- $memberId = (new Member())->getAllMemberIds($memberId);
- // 根据用户id 获取全部相关持有信息
- $list = $this->getAllSiteHoldAllList(1, $memberId, true);
- return [
- 'total_order_money' => sprintf("%.2f", array_sum(array_column($list, 'total_order_money'))),
- 'total_get_legumes' => sprintf("%.2f", array_sum(array_column($list, 'total_get_legumes'))),
- 'total_refund_order_money' => sprintf("%.2f", array_sum(array_column($list, 'total_refund_order_money'))),
- 'total_refund_get_legumes' => sprintf("%.2f", array_sum(array_column($list, 'total_refund_get_legumes'))),
- 'total_get_integral' => sprintf("%.2f", array_sum(array_column($list, 'total_get_integral'))),
- 'total_use_integral' => sprintf("%.2f", array_sum(array_column($list, 'total_use_integral'))),
- 'total_freeze_integral' => sprintf("%.2f", array_sum(array_column($list, 'total_freeze_integral'))),
- 'surplus_use_integral' => sprintf("%.2f", array_sum(array_column($list, 'surplus_use_integral')))
- ];
- }
-
- /**
- * Common: 获取全平台用户持有积分信息列表(递归获取全部列表)
- * Author: wu-hui
- * Time: 2024/05/29 11:34
- * @param $page
- * @param $memberId
- * @param false $isGetAll
- * @param array $allList
- * @return array
- */
- public function getAllSiteHoldAllList($page, $memberId, $isGetAll = false, $allList = [])
- {
- // 获取信息
- $result = $this->getHoldListData($page, ['member_id' => $memberId]);
- $pageCount = $result['page_count'] ?? 1;
- $allList = array_merge($allList, $result['list']);
- // 判断:是否递归查询全部
- if ($pageCount > $page && $isGetAll) {
- return $this->getAllSiteHoldAllList(++$page, $memberId, true, $allList);
- }
- // 返回列表信息
- return $allList;
- }
-
-
- /**
- * Common: 豆豆计算 - 计算昨天产生的豆豆总数
- * Author: wu-hui
- * Time: 2024/05/08 18:13
- */
- public function computeYesterdayLegumes()
- {
- // 获取总平台配置信息
- $config = (new Setting())->getConfig();
- $legumesPrice = (new Setting())->getLegumesPrice();
- // 获取周期时间
- [$startTime, $endTime] = getTimeStamp('yesterday');// 天
- Db::startTrans();
- try {
- // 判断:当前时间周期是否已经结算
- $maxTime = model('commission_legumes')->getMax([], 'end_time');
- if ($endTime <= $maxTime) throw new Exception('当前周期积分抽成已结算!');
-// [$startTime,$endTime] = getTimeStamp('today');// todo:调试信息
-// $startTime = mktime(0, 0, 0, date('m'), date('d') - 1, date('Y'));
-// $endTime = mktime(0, 0, 0, date('m'), date('d'), date('Y'));
- // 获取周期内积分抽成信息
- $integralInfo = $this->getIntegralInfo($startTime, $endTime);
- if ((float)$integralInfo['reality_money'] <= 0) throw new Exception('周期内无积分抽成信息');
- // 计算豆豆数量 豆豆数量 = 积分抽成金额(昨日总金额) * 0.2 / 豆豆当前价格
- $legumesNum = (float)sprintf("%.4f", (float)$integralInfo['reality_money'] * 0.2 / $legumesPrice); // 今日豆豆数量
- // 计算豆豆价格 下次豆豆价格 = 积分抽成金额(全平台总金额) ➗ 文创豆数量(全平台总数量)
- $allIntegralInfo = $this->getIntegralInfo();
- $allLegumes = model('commission_legumes')->getSum([], 'legumes_num');
- $tomorrowLegumesPrice = sprintf("%.4f", $allIntegralInfo['reality_money'] / ($allLegumes + $legumesNum));
- // 记录
- $recordId = model('commission_legumes')->add([
- 'total_integral_money' => $integralInfo['total_money'],
- 'refund_money' => $integralInfo['refund_money'],
- 'reality_money' => $integralInfo['reality_money'],
- 'legumes_price' => $legumesPrice,
- 'legumes_num' => $legumesNum,
- 'tomorrow_legumes_price' => $tomorrowLegumesPrice,
- 'start_time' => $startTime,
- 'end_time' => $endTime,
- ]);
- // 修改豆豆实时价格
- (new Setting())->setLegumesPrice(0, $tomorrowLegumesPrice);
- // 触发事件 开始给每个消费用户分豆豆
- Queue::push(AllocationLegumesJob::class, [
- 'legumes_id' => $recordId
- ]);
- Db::commit();
- } catch (Exception $e) {
- Db::rollback();
- $data = [
- 'start' => date("Y-m-d H:i:s", $startTime),
- 'end' => date("Y-m-d H:i:s", $endTime),
- 'msg' => $e->getMessage()
- ];
- trace($data, '计算昨天产生的豆豆总数 - 错误');
- }
- }
-
- /**
- * Common: 豆豆计算 - 获取时间段内总积分抽成金额
- * Author: wu-hui
- * Time: 2024/05/08 17:50
- * @param int $startTime
- * @param int $endTime
- * @return array
- */
- public function getIntegralInfo(int $startTime = 0, int $endTime = 0): array
- {
- $where = [];
- if ($startTime > 0 && $endTime > 0) {
- $where[] = ['create_time', 'between', [date("Y-m-d H:i:s", $startTime), date("Y-m-d H:i:s", $endTime)]];
- }
- // 总佣金
- $info['total_money'] = (float)model('commission_record')->getSum($where, 'integral_money');
- // 获取退款金额
- $info['refund_money'] = (float)model('commission_record')->getValue($where, 'sum((integral_money * refund_ratio / 100)) as refund_money');
- // 实际金额
- $info['reality_money'] = (float)sprintf("%.3f", (float)$info['total_money'] - (float)$info['refund_money']);
-
- return $info;
- }
-
-
- /**
- * Common: 查询需要使用的分配信息 尽可能仅查询需要使用的信息
- * Author: wu-hui
- * Time: 2024/05/11 9:45
- * @param int $memberId
- * @param float $useLegumesIntegral
- * @param int $page
- * @return array|mixed
- */
- public function getUseList(int $memberId, float $useLegumesIntegral, int $limit = 10)
- {
- $where = [
- ['status', '=', 1],
- // [ 'member_id', '=', $memberId],
- ['', 'exp', Db::raw('get_integral > use_integral')]
- ];
- // 多平台同用户积分兼容
- $memberId = (new Member())->getAllMemberIds($memberId);
- if (is_array($memberId)) $where[] = ['member_id', 'in', $memberId];
- else $where[] = ['member_id', '=', $memberId];
-
- // 查询
- $field = 'id,member_id,get_integral,use_integral,(get_integral - use_integral) as surplus_integral';
- $result = model('commission_legumes_log')->pageList($where, $field, 'id ASC', 1, $limit);
- $list = $result['list'] ?? [];
- $pageCount = $result['page_count'] ?? 1;
- // 判断:总页数 大于当前页 判断是否需要递归
- if ($pageCount > 1) {
- $totalSurplusIntegral = array_sum(array_column($list, 'surplus_integral'));
- if ($useLegumesIntegral > $totalSurplusIntegral) {
- $limit += 10;
- return $this->getUseList($memberId, $useLegumesIntegral, $limit);
- }
- }
-
- return $list;
- }
-
- /**
- * Common: 查询已使用积分的分配信息 尽可能查询需要的信息
- * Author: wu-hui
- * Time: 2024/05/13 16:19
- * @param int $memberId
- * @param float $maxIntegral
- * @param int $limit
- * @return array|mixed
- */
- public function getUsedList(int $memberId, float $maxIntegral, int $limit = 10)
- {
- $where = [
- ['status', '=', 1],
- // [ 'member_id', '=', $memberId],
- ['use_integral', '>', 0],
- ];
- // 多平台同用户积分兼容
- $memberId = (new Member())->getAllMemberIds($memberId);
- if (is_array($memberId)) $where[] = ['member_id', 'in', $memberId];
- else $where[] = ['member_id', '=', $memberId];
- // 查询
- $result = model('commission_legumes_log')->pageList($where, 'id,get_integral,use_integral', 'id DESC', 1, $limit);
- $list = $result['list'] ?? [];
- $pageCount = $result['page_count'] ?? 1;
- if ($pageCount > 1) {
- $totalSurplusIntegral = array_sum(array_column($list, 'use_integral'));
- if ($maxIntegral > $totalSurplusIntegral) {
- $limit += 10;
- return $this->getUseList($memberId, $maxIntegral, $limit);
- }
- }
-
- return $list;
- }
-
-
- /**
- * Common: 获取统计信息
- * Author: wu-hui
- * Time: 2024/05/11 15:09
- * @param array $params
- * @return array
- */
- public function getStatistics(array $params)
- {
- // 获取当前用户可用豆豆积分
- $legumes = (new Legumes())->getAllSiteHoldInfo((int)$params['member_id']);
- // 获取统计信息
- $data = [
- 'integral_upper_limit' => $this->getModel($params)->sum('order_money'),// 积分释放上限(总)
- 'get_legumes' => $this->getModel($params)->sum('get_legumes'),// 总获得豆豆
- 'refund_get_legumes' => $this->getModel($params)->sum('refund_get_legumes'),// 退款减少豆豆
- 'get_integral' => $this->getModel($params)->sum('get_integral'),// 获得积分
- 'freeze_integral' => $this->getModel($params)->where('status', 0)->sum('get_integral'),// 冻结中积分
- 'used_integral' => $legumes['surplus_use_integral'] ?? 0,// 可用积分
- 'use_integral' => $this->getModel($params)->sum('use_integral'),// 已使用积分
- ];
- // 未释放积分 = 积分释放上限 - 已获得积分
- $data['not_integral'] = (float)sprintf("%.4f", $data['integral_upper_limit'] - $data['get_integral']);
- // 实际获得豆豆
- $data['reality_get_legumes'] = (float)sprintf("%.4f", $data['get_legumes'] - $data['refund_get_legumes']);
-
- return $data;
- }
-
- /**
- * Common: 查询model(统计查询使用)
- * Author: wu-hui
- * Time: 2024/05/11 15:00
- * @param $params
- * @return Db
- */
- public function getModel($params)
- {
- return Db::name('commission_legumes_log')
- ->when((int)$params['member_id'] > 0, function ($query) use ($params) {
- $memberId = (new Member())->getAllMemberIds((int)$params['member_id']);
- if (is_array($memberId)) $query->whereIn('member_id', $memberId);
- else $query->where('member_id', $memberId);
- })
- ->when(isset($params['status']) && $params['status'] !== '', function ($query) use ($params) {
- $query->where('status', $params['status']);
- })
- ->whereIn('status', [0, 1]);
- }
-
-
-}
diff --git a/addon/commission/model/Partner.php b/addon/commission/model/Partner.php
deleted file mode 100644
index 5a2acbd..0000000
--- a/addon/commission/model/Partner.php
+++ /dev/null
@@ -1,286 +0,0 @@
-adminSiteId) $params['site_id'] = $siteId;
- // 生成查询条件
- $where = [];
- if(isset($params['site_id']) && $params['site_id'] !== '') $where[] = ['a.site_id','=',$params['site_id']];
- // 关联查询
- $join = [
- [ 'site s', 's.site_id = a.site_id', 'left' ]
- ];
- $field = [
- 'a.*',
- 's.site_name',
- 's.contacts_name',
- ];
- $result = model('commission_partner_cycle')->pageList($where, $field,'a.id DESC',$page,PAGE_LIST_ROWS,'a',$join);
- $result['is_admin'] = $siteId == $this->adminSiteId;
-
- return $this->success($result);
- }
- /**
- * Common: 获取合伙人佣金分红记录
- * Author: wu-hui
- * Time: 2024/05/09 10:53
- * @param $page
- * @param $params
- * @return array
- */
- public function getLogPageList($page, $params){
- // 生成查询条件
- $where = [];
- if(isset($params['member_id']) && $params['member_id'] !== '') $where[] = ['a.member_id','=',$params['member_id']];
- if(isset($params['site_id']) && $params['site_id'] !== '') $where[] = ['a.site_id','=',$params['site_id']];
- if(isset($params['cycle_id']) && $params['cycle_id'] !== '') $where[] = ['a.cycle_id','=',$params['cycle_id']];
- // 关联查询
- $join = [
- [ 'member m', 'm.member_id = a.member_id', 'left' ],
- ];
- $field = [
- 'a.*',
- 'm.nickname',
- 'm.username',
- 'm.headimg',
- ];
- $result = model('commission_partner')->pageList($where,$field,'id DESC',$page,PAGE_LIST_ROWS, 'a', $join);
-
- return $this->success($result);
- }
-
-
- /**
- * Common: 合伙人佣金结算 - 开始
- * Author: wu-hui
- * Time: 2024/05/08 16:23
- */
- public function settlementInit(){
- Db::startTrans();
- try{
- // 获取总平台配置信息
- $config = (new Setting())->getConfig();
- // 获取周期时间 0=天;1=周;2=月
- if($config['partner_cycle'] == 1) [$startTime,$endTime] = getTimeStamp('last_week');// 周
- else if($config['partner_cycle'] == 2) [$startTime,$endTime] = getTimeStamp('last_month');// 月
- else [$startTime,$endTime] = getTimeStamp('yesterday');// 天
-
-
- // [$startTime,$endTime] = getTimeStamp('today');// TODO:调试使用...
-
-
- // 获取全部子平台 然后循环处理
- $insertData = [];// 明细记录
- $cycleIds = [];// 周期ids
- $siteList = model('site')->getList([],'site_id,site_name');
- foreach($siteList as $siteInfo){
- // 获取子平台配置信息
- $subConfig = (new Setting())->getConfig((int)$siteInfo['site_id']);
- // 判断:是否允许执行
- $isRunResult = $this->settlementIsRun($subConfig, $siteInfo);
- if((int)$isRunResult['code'] != 0){
- // trace([
- // 'msg' => $isRunResult['message'],
- // 'site_id' => (int)$siteInfo['site_id'],
- // ], '子平台循环处理 - 是否允许执行 - 跳出');
- continue;
- }
- // 获取分红金额信息 并且判断是否大于0
- $moneyInfo = $this->getTotalMoney($siteInfo, $startTime, $endTime);
- if((float)$moneyInfo['reality_money'] <= 0){
- // trace([
- // 'site_id' => (int)$siteInfo['site_id'],
- // 'money_info' => $moneyInfo
- // ], '子平台循环处理 - 实际分红金额为0');
- model('commission_record')->update(['partner_status' =>1],[
- [ 'create_time', 'between', [ date("Y-m-d H:i:s",$startTime), date("Y-m-d H:i:s",$endTime) ] ],
- ['partner_status','=', 0],
- ['site_id','=', $siteInfo['site_id']],
- ]);
- continue;
- }
- // 获取用户权重值信息
- $userList = $this->getHoldList($endTime, $siteInfo);
- $totalWeightValue = (float)array_sum($userList);// 总权重值
- if($totalWeightValue <= 0) {
- trace([
- 'site_id' => (int)$siteInfo['site_id'],
- 'totalWeightValue' => $totalWeightValue
- ], '子平台循环处理 - 总权重值为0');
- model('commission_record')->update(['partner_status' =>2],[
- [ 'create_time', 'between', [ date("Y-m-d H:i:s",$startTime), date("Y-m-d H:i:s",$endTime) ] ],
- ['partner_status','=', 0],
- ['site_id','=', $siteInfo['site_id']],
- ]);
- continue;
- }
- // 记录周期分红信息
- $cycleId = model('commission_partner_cycle')->add([
- 'site_id' => (int)$siteInfo['site_id'],
- 'total_commission' => $moneyInfo['total_money'],
- 'refund_money' => $moneyInfo['refund_money'],
- 'reality_money' => $moneyInfo['reality_money'],
- 'total_weight_value' => $totalWeightValue,
- 'total_people' => count($userList),
- 'start_time' => $startTime,
- 'end_time' => $endTime,
- ]);
- $cycleIds[] = $cycleId;
- // 循环处理所有用户
- foreach($userList as $memberId => $weightValue){
- // 添加贡献分享分红信息记录 这里必须进行100的偏移计算
- $radio = (float)sprintf("%.2f",($weightValue / $totalWeightValue) * 100);// 佣金比例
- $money = (float)sprintf("%.2f",($moneyInfo['reality_money'] * $radio) / 100);// 实际获得佣金
- if($money > 0){
- $insertData[] = [
- 'site_id' => (int)$siteInfo['site_id'],
- 'member_id' => $memberId,
- 'cycle_id' => $cycleId,
- 'money' => $money,
- 'hold_contribution' => $totalWeightValue,
- 'total_contribution' => $weightValue,
- 'proportion' => $radio,
- ];
- }
- }
- model('commission_record')->update(['partner_status' =>1],[
- ['create_time', 'between', [ date("Y-m-d H:i:s",$startTime), date("Y-m-d H:i:s",$endTime) ] ],
- ['partner_status','=', 0],
- ['site_id','=', $siteInfo['site_id']],
- ]);
- }
- // 记录分红信息 并且开始结算
- if(count($insertData) > 0){
- model('commission_partner')->addList($insertData);
- // 合伙人佣金结算
- Queue::push(PartnerSettlementJob::class,[
- 'cycle_ids' => $cycleIds
- ]);
- }
-
- Db::commit();
- }catch(Exception $e){
- Db::rollback();
-
- trace($e->getMessage(), '合伙人佣金结算 - 错误');
- }
- }
- /**
- * Common: 合伙人佣金结算 - 判断是否继续允许;获取分佣金额
- * Author: wu-hui
- * Time: 2024/05/08 14:56
- * @param $subConfig
- * @param $siteInfo
- * @return array|void
- */
- private function settlementIsRun($subConfig, $siteInfo){
- // 判断:是否开启
- if($subConfig['switch'] != 1) return $this->error('','未开启平台抽成');
- // 下一个周期结束时间获取
- $upCycleEndTime = model('commission_partner_cycle')->getMax(['site_id'=>$siteInfo['site_id']], 'end_time');
- if($subConfig['partner_cycle'] == 1) {
- // 周 获取下一周开始时间
- $monday = strtotime('Monday this week', $upCycleEndTime);
- $lastRunTime = strtotime(date("Y-m-d 00:00:00",$monday)." +1 week");
- }
- else if($subConfig['partner_cycle'] == 2) {
- // 月 获取下一月开始时间
- $lastRunTime = strtotime(date("Y-m-1 00:00:00",$upCycleEndTime)." +1 month");
- }
- else{
- // 天 获取下一天开始时间
- $lastRunTime = strtotime(date("Y-m-d 00:00:00",$upCycleEndTime)." +1 day");
- }
- // 判断:时间上是否允许继续执行(上一个周期结束时间存在 & 当前时间小于下一个周期结束时间 禁止继续执行)
- if((int)$upCycleEndTime > 0 && time() < $lastRunTime) {
- $msg = "执行时间错误(上一个周期结束时间".date('Y-m-d H:i:s',$upCycleEndTime).",下一个周期结束时间".date('Y-m-d H:i:s',$lastRunTime).")";
- return $this->error('',$msg);
- }
-
- return $this->success('允许执行');
- }
- /**
- * Common: 合伙人佣金结算 - 获取指定平台时间段内的总佣金信息
- * Author: wu-hui
- * Time: 2024/05/08 15:47
- * @param $siteInfo
- * @param $startTime
- * @param $endTime
- * @return array
- */
- public function getTotalMoney($siteInfo, $startTime, $endTime){
- // 总佣金
- $moneyInfo['total_money'] = (float)model('commission_record')->getSum([
- [ 'create_time', 'between', [ date("Y-m-d H:i:s",$startTime), date("Y-m-d H:i:s",$endTime) ] ],
- ['partner_status','=', 0],
- ['site_id','=', $siteInfo['site_id']],
- ], 'partner_money');
- // 获取退款金额
- $refundMoneyInfo = model('commission_record')->getInfo([
- [ 'create_time', 'between', [ date("Y-m-d H:i:s",$startTime), date("Y-m-d H:i:s",$endTime) ] ],
- ['partner_status','=', 0],
- ['site_id','=', $siteInfo['site_id']],
- ],'sum((partner_money * refund_ratio / 100)) as refund_money');
- $moneyInfo['refund_money'] = sprintf("%.2f",$refundMoneyInfo['refund_money'] ?? 0);
- // 实际金额
- $moneyInfo['reality_money'] = (float)sprintf("%.3f",(float)$moneyInfo['total_money'] - (float)$moneyInfo['refund_money']);
-
- return $moneyInfo;
- }
- /**
- * Common: 合伙人佣金结算 - 获取截止结束时用户持有权重值
- * Author: wu-hui
- * Time: 2024/05/08 16:08
- * @param $endTime
- * @param $siteInfo
- * @return array
- */
- private function getHoldList($endTime, $siteInfo){
- $idList = model('commission_weight_value_log')->getList([
- [ 'create_time', '<=', date("Y-m-d H:i:s",$endTime)],
- ['site_id','=', $siteInfo['site_id']],
- ],'max(id) as max_id,CONCAT(member_id,"_", level_id) as group_key','','a',[],'group_key');
- $ids = array_column($idList,'max_id');
- $list = model('commission_weight_value_log')->getList([
- ['id', 'in', $ids],
- ],'member_id,sum(change_after) as change_after','','a',[],'member_id');
-
- return array_column($list,'change_after','member_id');
- }
-
-
-}
\ No newline at end of file
diff --git a/addon/commission/model/Setting.php b/addon/commission/model/Setting.php
deleted file mode 100644
index 374a810..0000000
--- a/addon/commission/model/Setting.php
+++ /dev/null
@@ -1,196 +0,0 @@
- '0',// 是否开启平台抽成
- 'is_alone' => '0',// 是否独立设置 总平台无该设置项
- 'integral_rate' => '0',// 积分抽成比例
- 'operations_rate' => '0',// 运营抽成比例
- 'partner_rate' => '0',// 合伙人分佣比例
- 'partner_cycle' => '0',// 合伙人分佣周期 0=每天,1=每周,2=每月
- 'merchants_rate' => '0',// 招商员分佣比例
- 'promoter_rate' => '0',// 推广员分佣比例
- ];
-
-
- /**
- * Common: 编辑配置 - 总平台、店铺
- * Author: wu-hui
- * Time: 2024/04/29 14:51
- * @param int $siteId
- * @param array $data
- * @param int $is_use
- * @return array
- */
- public function setConfig(int $siteId = 0,array $data = [],int $is_use = 1){
- $setWhere = [
- ['site_id','=', $siteId > 0 ? $siteId : $this->adminSiteId],
- ['app_module','=','shop'],
- ['config_key','=','commission_setting']
- ];
-
- return (new Config())->setConfig($data, '平台抽成设置', $is_use, $setWhere);
- }
- /**
- * Common: 获取配置 - 总平台、店铺
- * Author: wu-hui
- * Time: 2024/04/29 14:51
- * @param int $siteId
- * @return array|string[]
- */
- public function getConfig(int $siteId = 0){
- $setWhere = [
- ['site_id','=', $siteId > 0 ? $siteId : $this->adminSiteId],
- ['app_module','=','shop'],
- ['config_key','=','commission_setting']
- ];
- $res = (new Config())->getConfig($setWhere);
- $value = $res['data'] ? $res['data']['value'] : [];
- $config = array_merge($this->defaultConfig, $value);
- // 判断:当前获取设置 是否为总平台设置
- $config['is_admin'] = $siteId == $this->adminSiteId;
-
- return $config;
- }
-
-
- /**
- * Common: 编辑配置 - 商品
- * Author: wu-hui
- * Time: 2024/05/02 10:15
- * @param int $goodsId
- * @param array $data
- */
- public function setGoodConfig(int $goodsId,array $data){
- // 判断:当前商品是否已经存在设置
- $set = model('goods_commission')->getInfo(['goods_id'=>$goodsId]);
- $set = $set ?? [];
- $updateData = [
- 'switch' => $data['switch'] ?? 0,
- 'is_alone' => $data['is_alone'] ?? 0,
- 'commission_type' => $data['commission_type'] ?? 0,
- 'integral_rate' => $data['integral_rate'] ?? 0,
- 'operations_rate' => $data['operations_rate'] ?? 0,
- 'partner_rate' => $data['partner_rate'] ?? 0,
- 'merchants_rate' => $data['merchants_rate'] ?? 0,
- 'promoter_rate' => $data['promoter_rate'] ?? 0,
- ];
- if($set){
- model('goods_commission')->update($updateData,['goods_id'=>$goodsId]);
- }else{
- $updateData['goods_id'] = $goodsId;
- $updateData['site_id'] = $data['site_id'];
- model('goods_commission')->add($updateData);
- }
- }
- /**
- * Common: 获取配置 - 商品
- * Author: wu-hui
- * Time: 2024/04/30 17:49
- * @param int $goodsId
- * @return array|string[]
- */
- public function getGoodConfig(int $goodsId){
- $set = model('goods_commission')->getInfo(['goods_id'=>$goodsId]);
- $set = $set ?? [];
- $defaultConfig = $this->defaultConfig;
- $defaultConfig['switch'] = $set['switch'] ?? 1;//商品默认开启
- $defaultConfig['commission_type'] = $set['commission_type'] ?? 0;//抽成类型:0=比例,1=固定金额
-
- return array_merge($defaultConfig, $set);
- }
- /**
- * Common: 获取最终设置
- * Author: wu-hui
- * Time: 2024/05/03 11:49
- * @param int $siteId
- * @param int $goodsId
- * @return array|string[]
- */
- public function getFinalSet(int $siteId,int $goodsId = 0){
- // ---获取总平台设置
- $adminSet = $this->getConfig();
- if($siteId == $this->adminSiteId) return $adminSet;
- // ---获取子平台(店铺)设置
- $shopSet = $this->getConfig((int)$siteId);
- // 店铺关闭抽成 || (店铺开启抽成,但是为独立设置)=使用店铺设置;店铺开启抽成 并且不为独立设置=总平台统一设置
- if($shopSet['switch'] == 0 || ($shopSet['switch'] == 1 && $shopSet['is_alone'] == 1)) $shopFinal = $shopSet;
- else $shopFinal = $adminSet;
- // 处理店铺不可修改项
- $shopFinal['partner_cycle'] = $adminSet['partner_cycle'];
- $goodFinal['operations_rate'] = $adminSet['operations_rate'];
- $shopFinal['is_alone'] = $shopSet['is_alone'];
- // 判断:是否仅获取店铺级 最终设置;是则返回店铺级最终设置;否则继续判断商品级
- if($goodsId <= 0) return $shopFinal;
- // ---获取商品设置
- $goodSet = (array)$this->getGoodConfig($goodsId);
- if(empty($goodSet)) return $shopFinal;
- // 商品关闭抽成 || (商品开启抽成,但是为独立设置)=使用商品设置;商品开启抽成 并且不为独立设置=店铺最终设置
- if($goodSet['switch'] == 0 || ($goodSet['switch'] == 1 && $goodSet['is_alone'] == 1)) $goodFinal = $goodSet;
- else $goodFinal = $shopFinal;
- // 设置补齐
- $goodFinal['partner_cycle'] = $adminSet['partner_cycle'];
- $goodFinal['operations_rate'] = $shopFinal['operations_rate'];// todo 运营抽成目前商品不可独立设置
- $goodFinal['is_alone'] = $goodSet['is_alone'];
-
- return $goodFinal;
- }
-
-
- /**
- * Common: 豆豆价格 - 设置
- * Author: wu-hui
- * Time: 2024/05/08 17:39
- * @param int $siteId
- * @param float $legumesPrice
- * @return array
- */
- public function setLegumesPrice(int $siteId = 0,float $legumesPrice = 0.5){
- $setWhere = [
- ['site_id','=', $siteId > 0 ? $siteId : $this->adminSiteId],
- ['app_module','=','shop'],
- ['config_key','=','legumes_price']
- ];
-
- return (new Config())->setConfig(['legumes_price' => $legumesPrice], '豆豆价格', 1, $setWhere);
- }
- /**
- * Common: 豆豆价格 - 获取
- * Author: wu-hui
- * Time: 2024/05/08 17:37
- * @param int $siteId
- * @return float|mixed
- */
- public function getLegumesPrice(int $siteId = 0){
- $setWhere = [
- ['site_id','=', $siteId > 0 ? $siteId : $this->adminSiteId],
- ['app_module','=','shop'],
- ['config_key','=','legumes_price']
- ];
- $res = (new Config())->getConfig($setWhere);
- $value = $res['data'] ? $res['data']['value'] : [];
-
- return $value['legumes_price'] ?? 0.5;
- }
-
-
-
-
-
-
-}
diff --git a/addon/commission/model/WeightValue.php b/addon/commission/model/WeightValue.php
deleted file mode 100644
index a7021a0..0000000
--- a/addon/commission/model/WeightValue.php
+++ /dev/null
@@ -1,145 +0,0 @@
-adminSiteId) $params['site_id'] = $siteId;
- // 生成查询条件
- $where = [];
- if(isset($params['member_id']) && $params['member_id'] !== '') $where[] = ['a.member_id','=',$params['member_id']];
- if(isset($params['site_id']) && $params['site_id'] !== '') $where[] = ['a.site_id','=',$params['site_id']];
- // 关联查询
- $join = [
- [ 'member m', 'm.member_id = a.member_id', 'left' ],
- [ 'site s', 's.site_id = a.site_id', 'left' ],
- [ 'fenxiao_level fl', 'fl.level_id = a.level_id', 'left' ]
- ];
- $field = [
- 'a.*',
- 'm.nickname',
- 'm.username',
- 'm.headimg',
- 's.site_name',
- 's.contacts_name',
- 'fl.level_name',
- 'fl.level_num',
- ];
- $result = model('commission_weight_value')->pageList($where,$field,'a.id DESC',$page,PAGE_LIST_ROWS,'a',$join);
- $result['is_admin'] = $siteId == $this->adminSiteId;
-
- return $this->success($result);
- }
- /**
- * Common: 获取用户权重值变更记录明细
- * Author: wu-hui
- * Time: 2024/05/04 16:07
- * @param $page
- * @param $params
- * @return array
- */
- public function getLogPageList($page, $params){
- // 生成查询条件
- $where = [];
- if(isset($params['member_id']) && $params['member_id'] !== '') $where[] = ['member_id','=',$params['member_id']];
- if(isset($params['site_id']) && $params['site_id'] !== '') $where[] = ['site_id','=',$params['site_id']];
- if(isset($params['level_id']) && $params['level_id'] !== '') $where[] = ['level_id','=',$params['level_id']];
- // 关联查询
- $result = model('commission_weight_value_log')->pageList($where,true,'id DESC',$page,PAGE_LIST_ROWS);
-
- return $this->success($result);
- }
-
-
- /**
- * Common: 根据用户ID 获取所有有效上级持有权重值信息
- * Author: wu-hui
- * Time: 2024/05/04 13:45
- * @param int $memberId
- * @param int $siteId
- * @param array $userHoldList
- * @return array
- */
- public function getUserHoldList(int $memberId,int $siteId,array $userHoldList = []){
- // 获取用户所有上级
- if(count($userHoldList) <= 0){
- // 获取全部上级
- $fenXiaoId = model('fenxiao')->getValue(['member_id'=>$memberId],'fenxiao_id');
- $allSuperiorList = (new Fenxiao())->getAllSuperior($fenXiaoId);
- unset($allSuperiorList[$memberId]);// 删除本人
- if(count($allSuperiorList) <= 0) return [];// 不存在上级
- // 循环处理 仅小区业绩消费才会获得权重值奖励
- $userHoldList = [];// 符合条件的用户
- $currentFenXiaoId = $fenXiaoId;
- foreach($allSuperiorList as $userInfo){
- // 判断:当前用户是否为上级的大区业绩的线
- if(!(new Fenxiao())->isBigAreaPart((int)$currentFenXiaoId,(int)$userInfo['fenxiao_id'])){
- $userHoldList[] = $userInfo;
- }
- $currentFenXiaoId = $userInfo['fenxiao_id'];
- }
- }
- // 获取持有信息
- $where = [
- ['site_id', '=', $siteId],
- ['member_id', 'in', array_column($userHoldList,'member_id')]
- ];
- $field = 'id,site_id,member_id,level_id,quantity,CONCAT(member_id, "_", level_id) AS only_key';
- $holdList = model('commission_weight_value')->getList($where,$field);
- // 判断:是否有不存在的用户持有信息 有则先添加
- $holdList = array_column($holdList,null,'only_key');
- $onlyKeyList = array_column($holdList,'only_key');
- $insertData = [];
- // 判断:是否存在持有信息 不存在添加
- $currentLevelList = [];
- foreach($userHoldList as $userItem){
- $onlyKey = $userItem['member_id'].'_'.$userItem['level_id'];
- if(!in_array($onlyKey,$onlyKeyList)){
- // 不存在 需要添加
- $defaultData = [
- 'site_id' => $siteId,
- 'member_id' => $userItem['member_id'],
- 'level_id' => $userItem['level_id'],
- 'quantity' => 0,
- ];
- $insertData[] = $defaultData;
- }
- else{
- $currentLevelList[] = $holdList[$onlyKey];
- }
- }
- // 存在新增加内容 增加然后再次执行
- if(count($insertData) > 0) {
- model('commission_weight_value')->addList($insertData);
-
- return $this->getUserHoldList($memberId,$siteId,$userHoldList);
- }
-
- return $currentLevelList;
- }
-
-
-
-}
\ No newline at end of file
diff --git a/addon/commission/shop/controller/Index.php b/addon/commission/shop/controller/Index.php
deleted file mode 100644
index 11ae1a6..0000000
--- a/addon/commission/shop/controller/Index.php
+++ /dev/null
@@ -1,245 +0,0 @@
-isAjax()) {
- // 参数获取
- $page = input('page', 1);
- $params = [
- 'member_id' => input('member_id', ''),
- 'site_id' => input('site_id', ''),
- 'order_no' => input('order_no', ''),
- 'goods_id' => input('goods_id', ''),
- ];
- return (new CommissionRecord())->getPageList($page, $params, $this->site_id);
- }
- $this->forthMenu();
- return $this->fetch("index/index");
- }
- /**
- * Common: 获取抽成记录统计信息
- * Author: wu-hui
- * Time: 2024/05/13 9:48
- * @return array
- */
- public function recordStatistics(){
- $params = [
- 'member_id' => input('member_id', ''),
- 'site_id' => input('site_id', ''),
- 'order_no' => input('order_no', ''),
- 'goods_id' => input('goods_id', ''),
- ];
- $data = (new CommissionRecord())->getStatistics($params, $this->site_id);
-
- return success(0, 'success', [
- ['className' => 'el-icon-coin','count' => $data['total_real_goods_money'],'name' => '订单总金额'],
- ['className' => 'el-icon-coin','count' => $data['total_integral_money'],'name' => '积分抽成总金额'],
- ['className' => 'el-icon-coin','count' => $data['total_operations_money'],'name' => '运营抽成总金额'],
- ['className' => 'el-icon-coin','count' => $data['total_partner_money'],'name' => '合伙人抽成总金额'],
- ['className' => 'el-icon-coin','count' => $data['total_merchants_money'],'name' => '招商员抽成总金额'],
- ['className' => 'el-icon-coin','count' => $data['total_promoter_money'],'name' => '推广员抽成总金额'],
- ]);
- }
- /**
- * Common: 权重值 - 持有列表
- * Author: wu-hui
- * Time: 2024/05/04 16:01
- * @return array|mixed
- */
- public function weightValue(){
- if (request()->isAjax()) {
- // 参数获取
- $page = input('page', 1);
- $params = [
- 'member_id' => input('member_id', '')
- ];
- return (new WeightValue())->getPageList($page, $params, $this->site_id);
- }
-
- $this->forthMenu();
- return $this->fetch("index/weight_value");
- }
- /**
- * Common: 权重值 - 变更记录明细
- * Author: wu-hui
- * Time: 2024/05/04 16:07
- * @return array
- */
- public function weightValueLog(){
- $page = input('page', 1);
- $params = [
- 'site_id' => input('site_id',''),
- 'member_id' => input('member_id',''),
- 'level_id' => input('level_id',''),
- ];
-
- return (new WeightValue())->getLogPageList($page, $params);
- }
- /**
- * Common: 合伙人佣金 - 周期记录
- * Author: wu-hui
- * Time: 2024/05/09 10:54
- * @return array|mixed
- */
- public function partner(){
- if (request()->isAjax()) {
- // 参数获取
- $page = input('page', 1);
- $params = [];
- return (new Partner())->getPageList($page, $params, $this->site_id);
- }
-
- $this->forthMenu();
- return $this->fetch("index/partner");
- }
- /**
- * Common: 合伙人佣金 - 分红记录
- * Author: wu-hui
- * Time: 2024/05/09 10:54
- * @return array
- */
- public function partnerLog(){
- $page = input('page', 1);
- $params = [
- 'site_id' => input('site_id',''),
- 'member_id' => input('member_id',''),
- 'cycle_id' => input('cycle_id',''),
- ];
-
- return (new Partner())->getLogPageList($page, $params);
- }
- /**
- * Common: 获取豆豆积分
- * Author: wu-hui
- * Time: 2024/05/13 10:30
- * @return array
- */
- public function getLegumesStatistics(){
- // 获取实时豆豆价格
- $legumesPrice = (new Setting())->getLegumesPrice();
- $params = [
- 'legumes_id' => input('legumes_id',''),
- 'member_id' => input('member_id',''),
- 'status' => input('status',''),
- ];
- $data = (new Legumes())->getTotalStatistics($params);
-
- return success(0, 'success', [
- ['className' => 'el-icon-coin','count' => $legumesPrice,'name' => '当前豆豆价格'],
- ['className' => 'el-icon-coin','count' => $data['total_get_legumes'],'name' => '已分配豆豆'],
- ['className' => 'el-icon-coin','count' => $data['total_order_money'],'name' => '订单总金额(积分上限)'],
- ['className' => 'el-icon-coin','count' => $data['total_get_integral'],'name' => '已产生积分'],
- ['className' => 'el-icon-coin','count' => $data['total_use_integral'],'name' => '已使用积分'],
- ['className' => 'el-icon-coin','count' => $data['total_freeze_integral'],'name' => '冻结中积分'],
- ]);
- }
- /**
- * Common: 豆豆积分 - 周期记录
- * Author: wu-hui
- * Time: 2024/05/09 11:55
- * @return array|mixed
- */
- public function legumes(){
- if (request()->isAjax()) {
- // 参数获取
- $page = input('page', 1);
- $params = [];
- return (new Legumes())->getCycleList($page, $params);
- }
-
- $this->forthMenu();
- return $this->fetch("index/legumes");
- }
- /**
- * Common: 豆豆积分 - 分配记录
- * Author: wu-hui
- * Time: 2024/05/09 11:58
- * @return array
- */
- public function legumesLog(){
- $page = input('page', 1);
- $params = [
- 'legumes_id' => input('legumes_id',''),
- 'member_id' => input('member_id',''),
- 'status' => input('status',''),
- ];
-
- return (new Legumes())->getLegumesLogList($page, $params);
- }
- /**
- * Common: 豆豆积分 - 持有记录
- * Author: wu-hui
- * Time: 2024/05/09 13:46
- * @return array
- */
- public function legumesHoldList(){
- $page = input('page', 1);
- $params = [
- 'member_id' => input('member_id',''),
- ];
-
- return (new Legumes())->getHoldList($page, $params);
- }
- // 佣金流水列表
- public function accountList(){
- if (request()->isAjax()) {
- // 参数获取
- $params = [
- 'member_id' => input('member_id',''),
- 'account_type' => input('account_type',''),
- 'status' => input('status',''),
- 'page' => input('page',1),
- 'page_size' => input('limit',10),
- ];
-
- return (new Account())->accountListV2($params);
- }
- $this->forthMenu();
- return $this->fetch("index/account_list");
- }
-
-
- /**
- * Common: 基本设置
- * Author: wu-hui
- * Time: 2024/04/29 16:36
- * @return array|mixed
- */
- public function set(){
- if (request()->isAjax()) {
- // 参数获取
- $info = input('set',[]);
- (new Setting())->setConfig((int)$this->site_id, (array)$info);
-
- return success(0, '修改成功');
- }
- else {
- $set = (new Setting())->getConfig((int)$this->site_id);
- $adminSet = (new Setting())->getConfig();
- $this->forthMenu();
-
- return $this->fetch("index/set",[
- 'set' => json_encode($set, JSON_UNESCAPED_UNICODE),
- 'admin_set' => json_encode($adminSet, JSON_UNESCAPED_UNICODE),
- ]);
- }
- }
-}
diff --git a/addon/commission/shop/controller/Test.php b/addon/commission/shop/controller/Test.php
deleted file mode 100644
index bf47438..0000000
--- a/addon/commission/shop/controller/Test.php
+++ /dev/null
@@ -1,1609 +0,0 @@
-computeYesterdayLegumes();
-
-//
-// var_dump($res);die;
- // $orderIds = [257,259,262,267,271];
- // foreach($orderIds as $orderId){
- // $this->createRecord($orderId);
- // }
-// $this->createRecord(354);
-// die;
-
- // $this->GiveWeightValueTest();
- // $this->MerchantsSettlement();
- // $this->PromoterSettlement();
- // (new Partner())->settlementInit();
- // $this->PartnerSettlement();
- // (new Legumes())->computeYesterdayLegumes();
- // $this->AllocationLegumes();
- // $this->ComputeIntegral();
- // $this->settlementMoney();
- // $this->useLegumesIntegral();
- // $this->orderRefundFinish();
-
-
- /*$params = array (
- 'order_id' => 280,
- 'order_no' => '20240717100137001',
- 'site_id' => 5,
- 'site_name' => '张先生',
- 'website_id' => 0,
- 'order_name' => '0.1元买单',
- 'order_from' => 'cashier',
- 'order_from_name' => '收银台',
- 'order_type' => 5,
- 'order_type_name' => '收银订单',
- 'order_promotion_type' => 0,
- 'order_promotion_name' => '',
- 'promotion_id' => 0,
- 'out_trade_no' => '17211816855317612629',
- 'out_trade_no_2' => '',
- 'delivery_code' => '',
- 'order_status' => 10,
- 'order_status_name' => '已完成',
- 'order_status_action' => '{"status":10,"name":"已完成","is_allow_refund":1,"icon":"public\\/resource\\/order\\/order-icon-received.png","action":[],"member_action":[],"color":""}',
- 'pay_status' => 1,
- 'delivery_status' => 0,
- 'refund_status' => 0,
- 'pay_type' => 'wechatpay',
- 'pay_type_name' => '微信支付',
- 'delivery_type' => '0',
- 'delivery_type_name' => '',
- 'member_id' => 37,
- 'name' => '',
- 'mobile' => '',
- 'telephone' => '',
- 'province_id' => 0,
- 'city_id' => 0,
- 'district_id' => 0,
- 'community_id' => 0,
- 'address' => '',
- 'full_address' => '',
- 'longitude' => '',
- 'latitude' => '',
- 'buyer_ip' => '',
- 'buyer_ask_delivery_time' => '',
- 'buyer_message' => '',
- 'goods_money' => '0.10',
- 'delivery_money' => '0.00',
- 'promotion_money' => '0.00',
- 'coupon_id' => 0,
- 'coupon_money' => '0.00',
- 'invoice_money' => '0.00',
- 'order_money' => '0.10',
- 'adjust_money' => '0.00',
- 'balance_money' => '0.00',
- 'pay_money' => '0.10',
- 'create_time' => 1721181685,
- 'pay_time' => 1721181693,
- 'delivery_time' => 0,
- 'sign_time' => 0,
- 'finish_time' => 1721181693,
- 'close_time' => 0,
- 'is_lock' => 0,
- 'is_evaluate' => 0,
- 'is_delete' => 0,
- 'is_enable_refund' => 1,
- 'remark' => '',
- 'goods_num' => '1.000',
- 'delivery_store_id' => 0,
- 'delivery_status_name' => '',
- 'is_settlement' => 0,
- 'store_settlement_id' => 0,
- 'delivery_store_name' => '',
- 'promotion_type' => '',
- 'promotion_type_name' => '',
- 'promotion_status_name' => '',
- 'delivery_store_info' => NULL,
- 'virtual_code' => '',
- 'evaluate_status' => 0,
- 'evaluate_status_name' => '',
- 'refund_money' => '0.00',
- 'commission' => '0.00',
- 'is_invoice' => 0,
- 'invoice_type' => 1,
- 'invoice_title' => '',
- 'taxpayer_number' => '',
- 'invoice_rate' => '0.00',
- 'invoice_content' => '',
- 'invoice_delivery_money' => '0.00',
- 'invoice_full_address' => '',
- 'is_tax_invoice' => 0,
- 'invoice_email' => '',
- 'invoice_title_type' => 0,
- 'is_fenxiao' => 1,
- 'point_money' => '0.00',
- 'member_card_money' => '0.00',
- 'member_card_order' => 0,
- 'invoice_status' => 0,
- 'invoice_remark' => NULL,
- 'invoice_code' => '',
- 'invoice_image' => '',
- 'invoice_time' => 0,
- 'predict_delivery_time' => 0,
- 'is_video_number' => 0,
- 'is_sync_order' => 0,
- 'is_deduction' => 0,
- 'sync_msg' => '',
- 'close_cause' => '',
- 'cashier_order_type' => 'goods',
- 'cashier_sell_time' => 0,
- 'cashier_operator_id' => 0,
- 'cashier_operator_name' => '',
- 'balance' => '0.00',
- 'total_balance' => '0.00',
- 'store_id' => 8,
- 'reduction' => '0.00',
- 'round_money' => '0',
- 'order_scene' => 'cashier',
- 'store_commission_rate' => '0.00',
- 'store_commission' => '0.00',
- 'cl_id' => 0,
- 'cl_name' => '',
- 'is_community_settlement' => 0,
- 'arrive_time' => 0,
- 'delivery_id' => 0,
- 'commission_rate' => '0.00',
- 'delivery_commission' => '0.00',
- 'delivery_community_id' => 0,
- 'delivery_community' => '',
- 'delivery_community_info' => NULL,
- 'legumes_integral_use' => '0.00',
- 'legumes_integral_money' => '0.00',
- 'legumes_integral_community' => 0.0,
- );*/
- // (new Weapp($params['site_id']))->getRidInfo();
- // debug("结果");
- // (new Weapp($params['site_id']))->authSendGoods($params);
- // 积分收入结算到店铺 调试
- // (new ShopAccount())->orderIntegralSettlement(336);
- // $this->handleOperations();
-// $this->verificationLegumesPrice();
- // 修改豆豆实时价格
- // (new Setting())->setLegumesPrice(0, 7.3859);
-
-// $this->afreshComputeLegumes();
-// $this->afreshAllocationLegumes();
-
-
-
-// $this->settlementAccount();
-
-
-
- debug("调试中...". date("Y-m-d H:i:s"));
- }
- // 调试 - 支付成功生成抽成记录
- private function createRecord($orderId){
-
-// $orderId = (int)$data['order_id'];
-// $orderId='';
- $adminSet = (new Setting())->getConfig();
- if($adminSet['switch'] != 1) throw new Exception('总平台未开启平台抽成');
- // 当前订单是否已经处理
- $isHas = (int)model('commission_record')->getValue([
- ['order_id', '=', $orderId]
- ],'id');
-// if($isHas > 0) throw new Exception('当前订单已经处理');
- // 获取订单商品信息
- $field = 'order_goods_id,order_id,site_id,member_id,goods_id,store_id,num,(real_goods_money + legumes_integral_use) as use_money';
- $orderGoodsList = model('order_goods')->getList(['order_id'=>$orderId],$field);
- // 循环处理
- $insertData = [];
- foreach($orderGoodsList as $orderGoodsInfo){
- $useMoney = $orderGoodsInfo['use_money'] ?? 0;
- if($useMoney <= 0) continue;// 当前订单商品有效金额为0
- // 设置获取
- $set = (new Setting())->getFinalSet((int)$orderGoodsInfo['site_id'],(int)$orderGoodsInfo['goods_id']);
- if($set['switch'] != 1) continue;// 当前商品不参与平台抽成
- $integralRate = (float)$set['integral_rate'] ?? 0;
- $operationsRate = (float)$set['operations_rate'] ?? 0;
- $partnerRate = (float)$set['partner_rate'] ?? 0;
- $merchantsRate = (float)$set['merchants_rate'] ?? 0;
- $promoterRate = (float)$set['promoter_rate'] ?? 0;
- // 根据抽成计算类型生成记录信息
- $commissionType = $set['commission_type'] ?? 0;
- $insertData[] = [
- 'member_id' => $orderGoodsInfo['member_id'],
- 'site_id' => $orderGoodsInfo['site_id'],
- 'store_id' => $orderGoodsInfo['store_id'],
- 'order_id' => $orderGoodsInfo['order_id'],
- 'order_goods_id' => $orderGoodsInfo['order_goods_id'],
- 'goods_id' => $orderGoodsInfo['goods_id'],
- 'real_goods_money' => $useMoney,
- // 根据计算类型获取值 抽成类型:0=比例,1=固定金额
- 'integral_rate' => $commissionType == 1 ? -1 : $integralRate,
- 'integral_money' => $commissionType == 1 ? sprintf("%.3f",$orderGoodsInfo['num'] * $integralRate) : sprintf("%.3f",$useMoney * $integralRate / 100),
- 'operations_rate' => $operationsRate,
- 'operations_money' => sprintf("%.3f",$useMoney * $operationsRate / 100),
- 'partner_rate' => $commissionType == 1 ? -1 : $partnerRate,
- 'partner_money' => $commissionType == 1 ? sprintf("%.3f",$orderGoodsInfo['num'] * $partnerRate) : sprintf("%.3f",$useMoney * $partnerRate / 100),
- 'merchants_rate' => $commissionType == 1 ? -1 : $merchantsRate,
- 'merchants_money' => $commissionType == 1 ? sprintf("%.3f",$orderGoodsInfo['num'] * $merchantsRate) : sprintf("%.3f",$useMoney * $merchantsRate / 100),
- 'promoter_rate' => $commissionType == 1 ? -1 : $promoterRate,
- 'promoter_money' => $commissionType == 1 ? sprintf("%.3f",$orderGoodsInfo['num'] * $promoterRate) : sprintf("%.3f",$useMoney * $promoterRate / 100),
- ];
- }
- var_dump($insertData);
- //
- //
- //
- //
-// if(count($insertData) > 0){
-//// model('commission_record')->addList($insertData);
-// // 支付成功 - 抽成记录生成后 - 招商员佣金结算
-// Queue::push(MerchantsSettlementJob::class,[
-// 'order_id' => (int)$orderId
-// ]);
-// // 支付成功 - 抽成记录生成后 - 推广员佣金结算
-// Queue::push(PromoterSettlementJob::class,[
-// 'order_id' => (int)$orderId,
-// ]);
-// }
- }
- // 调试 - 支付成功赠送权重值
- private function GiveWeightValueTest(){
- // $data = [
- // 'member_id' => 21,
- // 'order_id' => 224,
- // 'site_id' => 2,
- // ];
- // try{
- // // 获取当前用户 所有有效上级的 权重值持有信息
- // $userHoldList = (new WeightValue())->getUserHoldList((int)$data['member_id'], (int)$data['site_id']);
- //
- // debug($userHoldList);
- // // 获取当前订单中所有商品
- // $orderGoodsField = 'order_goods_id,order_id,goods_id,(real_goods_money + point_money) as use_money';
- // $orderGoodsList = model('order_goods')->getList([['order_id','=', $data['order_id']]], $orderGoodsField);
- // $updateData = [];
- // $insertLogData = [];
- // foreach($userHoldList as $userInfo){
- // foreach($orderGoodsList as $goodsInfo){
- // // 判断:当前用户是否存在修改记录中 不存在添加修改信息
- // if(empty($updateData[$userInfo['id']])){
- // $updateData[$userInfo['id']] = [
- // 'id' => $userInfo['id'],
- // 'quantity' => $userInfo['quantity'],
- // ];
- // }
- // // 持有数量增加
- // $changeFront = (float)$updateData[$userInfo['id']]['quantity'];
- // $updateData[$userInfo['id']]['quantity'] = (float)sprintf("%.2f",(float)$goodsInfo['use_money'] + $changeFront);
- // // 记录变更记录
- // $insertLogData[] = [
- // 'site_id' => (int)$data['site_id'],
- // 'member_id' => $userInfo['member_id'],
- // 'level_id' => $userInfo['level_id'],
- // 'goods_id' => $goodsInfo['goods_id'],
- // 'order_id' => $goodsInfo['order_id'],
- // 'order_goods_id' => $goodsInfo['order_goods_id'],
- // 'change_type' => 1,
- // 'change_quantity' => $goodsInfo['use_money'],
- // 'change_front' => $changeFront,
- // 'change_after' => (float)$updateData[$userInfo['id']]['quantity'],
- // 'remark' => '下线购买商品赠送',
- // ];
- // }
- // }
- //
- //
- // debug($insertLogData);
- // // 数据结果处理
- // if(count($insertLogData) > 0){
- // // 修改
- // // $goodsSkuModel = (new NewBaseModel(['table_name' => 'commission_weight_value', 'pk' => 'id']));
- // // $goodsSkuModel->saveAll($updateData);
- // // model('commission_weight_value_log')->addList($insertLogData);
- // }
- // }
- // catch(\Exception $e){
- // $data['error_msg'] = $e->getMessage();
- // debug(['失败:调试中...'=>$data]);
- // }
- }
- // 调试 - 招商员佣金结算
- private function MerchantsSettlement(){
- $orderId = (int)48;
- // 当前订单
- // $where = [
- // // ['order_id', '=', $orderId],
- // ['merchants_status', '=', 0],
- // ];
- // $field = 'a.id,a.site_id,a.store_id,a.order_id,a.merchants_money,s.merchants_member_id,s.store_name';
- // $join = [
- // ['store s', 's.store_id = a.store_id', 'LEFT'], // 关联客服
- // ];
- // $list = model('commission_record')->getList($where,$field,'','a',$join);
- // // 循环处理
- // $updateData = [];
- // $insertData = [];
- // foreach($list as $recordInfo){
- // // 根据是否存在招商员 进行对应的处理
- // if((int)$recordInfo['merchants_member_id'] > 0){
- // // 存在招商员 招商员佣金结算
- // $insertData[] = [
- // 'site_id' => $recordInfo['site_id'],
- // 'member_id' => $recordInfo['merchants_member_id'],
- // 'join_id' => $recordInfo['id'],
- // 'account_type' => 'merchants',
- // 'account_type_name' => '招商员佣金',
- // 'account_data' => $recordInfo['merchants_money'],
- // 'remark' => $recordInfo['store_name'] . '的订单收入',
- // ];
- // // 修改信息
- // $updateData[] =[
- // 'id' => $recordInfo['id'],
- // 'merchants_status' => 1,
- // ];
- // }
- // else{
- // // 不存在招商员
- // $updateData[] =[
- // 'id' => $recordInfo['id'],
- // 'merchants_status' => 2,
- // ];
- // }
- // }
- // // 数据结果处理
- // if(count($insertData) > 0) model('commission_account')->addList($insertData);
- // if(count($updateData) > 0){
- // $updateModel = (new NewBaseModel(['table_name' => 'commission_record', 'pk' => 'id']));
- // $updateModel->saveAll($updateData);
- // }
-
-
-
- // debug([
- // '修改内容'=> $updateData,
- // '循环列表' => $list,
- // '$insertData' => $insertData,
- // '$updateData' => $updateData,
- //
- // ]);
- }
- // 调试 - 推广员佣金结算
- private function PromoterSettlement(){
- // $orderId = (int)48;
- // // 当前订单
- // $where = [
- // // ['order_id', '=', $orderId],
- // ['promoter_status', '=', 0],
- // ];
- // $join = [
- // ['member m', 'a.member_id = m.member_id', 'LEFT'],
- // ['fenxiao fx', 'm.fenxiao_id = fx.fenxiao_id', 'LEFT'],
- // ];
- // $field = 'a.id,a.site_id,a.member_id,a.promoter_money,m.is_fenxiao,m.nickname,fx.member_id as fenxiao_member_id,fx.parent';
- // $list = model('commission_record')->getList($where,$field,'','a', $join);
- // // 循环处理
- // $updateData = [];
- // $insertData = [];
- // foreach($list as $recordInfo){
- // // 判断:当前用户是否为分销 获取对应的上级分销商用户id
- // if($recordInfo['is_fenxiao'] == 1){
- // // 当前用户是分销商 使用parent查询上级用户id
- // $parentMemberId = model('fenxiao')->getValue(['fenxiao_id'=>$recordInfo['parent']], 'member_id');
- // }else{
- // // 当前用户不是分销商 直接为fenxiao_member_id
- // $parentMemberId = $recordInfo['fenxiao_member_id'];
- // }
- // // 判断:是否存在上级
- // if((int)$parentMemberId > 0){
- // // 存在上级
- // $insertData[] = [
- // 'site_id' => $recordInfo['site_id'],
- // 'member_id' => $parentMemberId,
- // 'join_id' => $recordInfo['id'],
- // 'account_type' => 'promoter',
- // 'account_type_name' => '推广员佣金',
- // 'account_data' => $recordInfo['promoter_money'],
- // 'remark' => $recordInfo['nickname'] . '的推广佣金',
- // ];
- // // 修改信息
- // $updateData[] =[
- // 'id' => $recordInfo['id'],
- // 'promoter_status' => 1,
- // ];
- // }else{
- // // 不存在上级
- // $updateData[] =[
- // 'id' => $recordInfo['id'],
- // 'promoter_status' => 2,
- // ];
- // }
- // }
- // // 数据结果处理
- // if(count($insertData) > 0) model('commission_account')->addList($insertData);
- // if(count($updateData) > 0){
- // $updateModel = (new NewBaseModel(['table_name' => 'commission_record', 'pk' => 'id']));
- // $updateModel->saveAll($updateData);
- // }
- // debug([
- // '修改内容'=> $updateData,
- // '循环列表' => $list,
- // '$insertData' => $insertData,
- // '$updateData' => $updateData,
- //
- // ]);
- }
- // 调试 - 合伙人佣金结算
- private function PartnerSettlement(){
- // $data = [
- // 'cycle_ids' => [
- // 0 => 5,
- // ],
- // ];
- //
- // $cycleIds = $data['cycle_ids'] ?? [];
- // if(count($cycleIds) <= 0) throw new Exception('无周期记录信息!');
- // // 获取周期结算信息
- // $cycleList = model('commission_partner_cycle')->getList([
- // ['id', 'in', $cycleIds]
- // ],'id,start_time,end_time');
- // $cycleList = array_column($cycleList, null, 'id');
- // // 获取结算记录信息
- // $list = model('commission_partner')->getList([
- // ['cycle_id', 'in', $cycleIds],
- // ['is_settlement', '=', 0],
- // ],'id,member_id,cycle_id,money,site_id');
- // if(count($list) > 0){
- // $insertData = [];
- // foreach($list as $singleInfo){
- // $cycleInfo = $cycleList[$singleInfo['cycle_id']] ?? [];
- // $timePeriod = date("Y-m-d H:i:s",$cycleInfo['start_time']) . ' ~ ' . date("Y-m-d H:i:s",$cycleInfo['end_time']);
- // $insertData[] = [
- // 'site_id' => $singleInfo['site_id'],
- // 'member_id' => $singleInfo['member_id'],
- // 'join_id' => $singleInfo['id'],
- // 'account_type' => 'partner',
- // 'account_type_name' => '合伙人佣金',
- // 'account_data' => $singleInfo['money'],
- // 'remark' => $timePeriod . "权重值收入",
- // ];
- // }
- // // 记录信息
- // if(count($insertData) > 0) model('commission_account')->addList($insertData);
- // // 修改结算状态
- // $ids = array_column($list,'id');
- // model('commission_partner')->update([ 'is_settlement' => 1],[
- // ['id', 'in', $ids]
- // ]);
- // }
-
- debug("结束");
- }
- // 调试 - 豆豆分配
- private function AllocationLegumes(){
- $data = [
- 'legumes_id' => 29,
- ];
-
- // 获取周期信息
- $legumesId = $data['legumes_id'];
- $cycleLegumes = model('commission_legumes')->getInfo(['id' => $legumesId]);
- if(!$cycleLegumes) throw new Exception('信息不存在');
- // if((int)$cycleLegumes['status'] != 0) throw new Exception('当前豆豆已分配!');
- // 获取时间段所有消费用户
- $where = [
- [ 'a.pay_time', 'between', [ $cycleLegumes['start_time'], $cycleLegumes['end_time'] ] ],// 指定时间段内
- [ 'og.refund_status', 'in', [0, 3] ],// 订单商品未退款
- [ 'a.order_status', 'in', [1, 3, 4, 10, 11, 12] ],//待发货、已发货、已收货、已完成、待使用、已使用
- ];
- $join = [
- [ 'order_goods og', 'og.order_id = a.order_id', 'right' ],
- ];
- $field = 'og.order_id,og.order_goods_id,og.member_id,a.order_status,(sum(og.real_goods_money) + sum(og.legumes_integral_money)) as sum_money';
- $orderList = model('order')->getList($where,$field,'','a',$join,'og.order_goods_id');
-
- debug($where);
- $totalMoney = array_sum(array_column($orderList,'sum_money'));
- // debug([$totalMoney,implode(',', array_column($orderList,'order_id')),$orderList]);
- // 获取平台抽成信息
- $orderGoodsIds = array_column($orderList,'order_goods_id');
- $commissionRecord = model('commission_record')->getList([
- ['order_goods_id','in',$orderGoodsIds],
- ],'order_goods_id,order_id,member_id,integral_money as platform_commission_money');
- $totalPlatformCommission = array_sum(array_column($commissionRecord,'platform_commission_money'));
- $commissionRecord = array_column($commissionRecord,null,'order_goods_id');
- // 循环处理
- $insertData = [];
- foreach($orderList as $orderInfo){
- // 获取平台抽成信息
- $platformCommissionInfo = $commissionRecord[$orderInfo['order_goods_id']] ?? [];
- if($platformCommissionInfo){
- // 计算订单金额占比 必须进行100的偏移计算
- $rate = (float)sprintf("%.3f",$platformCommissionInfo['platform_commission_money'] / $totalPlatformCommission * 100);
- $getLegumes = sprintf("%.3f",$cycleLegumes['legumes_num'] * $rate / 100);
- // 信息记录
- $insertData[] = [
- 'member_id' => $orderInfo['member_id'],
- 'legumes_id' => $legumesId,
- 'order_id' => $orderInfo['order_id'],
- 'order_goods_id' => $orderInfo['order_goods_id'],
- 'cycle_total_legumes' => $cycleLegumes['legumes_num'],
- 'total_sales_money' => $totalMoney,
- 'order_money' => $orderInfo['sum_money'],
- 'order_money_rate' => $rate,
- 'get_legumes' => $getLegumes,
- 'status' => in_array((int)$orderInfo['order_status'],[10,12]) ? 1 : 0,
- ];
- }
- }
- //
- debug($insertData);
- // // 添加数据
- // if(count($insertData) > 0) model('commission_legumes_log')->addList($insertData);
- // // 修改豆豆周期分配状态
- // model('commission_legumes')->update(['status' => 1],[
- // ['id', '=', $legumesId]
- // ]);
- // // 触发全平台豆豆转积分操作
- // Queue::push(ComputeIntegralJob::class);
- }
- // 调试 - 全平台豆豆转积分
- private function ComputeIntegral($data = []){
- // // 判断:当前data不为数组时 强制为数组
- // if(!is_array($data)) $data = [];
- // // 并且开启处理
- // $page = $data['page'] ?? 1;
- // $ids = $data['ids'] ?? [];
- // $limit = 1000;
- // $legumesPrice = (new Setting())->getLegumesPrice();
- // // 获取当前页数据 有效记录、已获取积分低于订单金额
- // $where = [
- // ['status', 'in', [0,1]]
- // ];
- // if(count($ids) > 0) $where[] = ['id', 'in', $ids];
- // else $where[] = ['', 'exp', Db::raw('get_integral < order_money')];
- // $field = 'id,(order_money - refund_order_money) as order_money,(get_legumes - refund_get_legumes) as get_legumes,get_integral,member_id';
- // $result = model('commission_legumes_log')->pageList($where,$field,'',$page,$limit);
- // $count = $result['count'] ?? 0;
- // $list = $result['list'] ?? [];
- // if(count($list) <= 0) throw new \Exception('无处理数据!');
- // // 循环处理
- // $updateData = [];
- // $insertData = [];
- // foreach($list as $item){
- // // 计算最新本订单商品 总释放积分;总释放积分不能超过订单金额
- // $getIntegral = (float)sprintf("%.2f",$item['get_legumes'] * $legumesPrice);
- // $resultGetIntegral = $getIntegral >= $item['order_money'] ? $item['order_money'] : $getIntegral;
- // // 修改信息记录
- // $updateData[] = [
- // 'id' => $item['id'],
- // 'get_integral' => $resultGetIntegral
- // ];
- // // 增加释放记录
- // $insertData[] = [
- // 'member_id' => $item['member_id'],
- // 'legumes_log_id' => $item['id'],
- // 'change_front' => $item['get_integral'],
- // 'change_quantity' => (float)sprintf("%.2f",$resultGetIntegral - $item['get_integral']),
- // 'change_after' => $resultGetIntegral,
- // ];
- // }
- //
- // // 修改
- // $newBaseModel = (new NewBaseModel(['table_name' => 'commission_legumes_log', 'pk' => 'id']));
- // $newBaseModel->saveAll($updateData);
- // // 增加记录
- // if(count($insertData) > 0) model('commission_legumes_release_log')->addList($insertData);
- // // 判断:是否存在下一页
- // $currentLimit = $page * $limit;
- // if($currentLimit < $count){
- // $data['page'] = $page + 1;
- // Queue::push(ComputeIntegralJob::class,$data);
- // }
- }
- // 调试 - 流水结算到账
- private function settlementMoney(){
-
- $data = [
- // 'account_type' => 'partner',
- //
- 'order_id' => 355,
- 'account_type' => 'merchants_promoter',
- ];
-
-
- Db::startTrans();
- try{
- // trace($data, '平台抽成 - 流水结算到账 - 开始');
-
- // 根据结算流水类型 获取对应条件
- $where = [
- ['status', '=', 0]
- ];
- if($data['account_type'] == 'partner') {
- // 合伙人佣金
- $where[] = ['account_type', '=', 'partner'];
- }
- else if($data['account_type'] == 'merchants_promoter') {
- // 推广员佣金、招商员佣金
- $where[] = ['account_type', 'in', ['promoter', 'merchants']];
- // 仅结算指定订单相关
- $joinIds = model('commission_record')->getColumn([
- ['order_id', '=', $data['order_id']]
- ],'id');
- $where[] = ['join_id', 'in', $joinIds];
- }
- // 流水列表
- // $list = model('commission_account')->getList($where,'id,sum(account_data) as total_account_data,member_id','','a',[],'member_id');
- $list = Db::name('commission_account')
- ->field('id,sum(account_data) as total_account_data,member_id')
- ->where('status', 0)
- ->when($data['account_type'] == 'partner',function($query){
- $query->where('account_type', 'partner');
- },function($query) use ($data){
- // 仅结算指定订单相关
- $joinIds = model('commission_record')->getColumn([
- ['order_id', '=', $data['order_id']]
- ],'id');
- $query->whereIn('account_type', ['promoter', 'merchants'])
- ->whereIn('join_id', $joinIds);
- })
- ->group('member_id')
- ->select()
- ->toArray();
-
-
-
-
- debug($list);
-
- // trace($list, '平台抽成 - 流水结算到账 - 流水列表');
- // 获取用户已经持有信息
- $memberIds = array_column($list, 'member_id');
- $userList = Db::name('member')
- ->field('commission_money,member_id')
- ->whereIn('member_id', $memberIds)
- ->select()
- ->toArray();
- $userList = array_column($userList, null, 'member_id');
- // 循环流水列表 结算信息
- foreach($list as $singleInfo){
- $userList[$singleInfo['member_id']]['commission_money'] += $singleInfo['total_account_data'];
- }
- // 修改
- // $newBaseModel = (new NewBaseModel(['table_name' => 'member', 'pk' => 'member_id']));
- // $userList = array_values($userList);
- // $newBaseModel->saveAll($userList);
- // // 已结算
- // model('commission_account')->update(['status'=>1],[
- // ['id', 'in', array_column($list, 'id')]
- // ]);
-
-
-
- // trace($userList, '平台抽成 - 流水结算到账 - 处理完成');
- Db::commit();
-
- debug([
- '用户信息修改列表' => $userList,
- '处理流水列表' => $list
- ]);
- }
- catch(\Exception $e){
- Db::rollback();
- $data['error_msg'] = $e->getMessage();
-
- debug($data);
- // trace($data, '平台抽成 - 流水结算到账 - 失败');
- }
- }
- // 调试 - 订单支付成功 使用豆豆积分
- private function useLegumesIntegral(){
- // $data = [
- // 'order_id' => 66
- // ];
- //
- //
- //
- // // 获取订单信息
- // $orderInfo = model('order')->getInfo([
- // ['order_id','=', $data['order_id']],
- // ['legumes_integral_use','>', 0]
- // ],'order_id,site_id,member_id,legumes_integral_use,legumes_integral_money');
- // if(!$orderInfo) throw new \Exception('信息不存在!');
- // $useLegumesIntegral = (float)$orderInfo['legumes_integral_use'];
- // // 查询需要使用的分配记录
- // $useLegumesLogList = (new Legumes())->getUseList((int)$orderInfo['member_id'],(float)$orderInfo['legumes_integral_use']);
- // // 循环处理
- // $updateData = [];
- // foreach($useLegumesLogList as $logInfo){
- // $useIntegral = $useLegumesIntegral >= $logInfo['surplus_integral'] ? (float)$logInfo['surplus_integral'] : (float)$useLegumesIntegral;
- // $useLegumesIntegral = (float)sprintf("%.2f",$useLegumesIntegral - $useIntegral);
- // $updateData[] = [
- // 'id' => $logInfo['id'],
- // 'use_integral' => (float)sprintf("%.2f",$logInfo['use_integral'] + $useIntegral)
- // ];
- // if($useLegumesIntegral <= 0) break;
- // }
- // // 修改成功信息
- // if($updateData){
- // // 修改豆豆积分使用信息
- // $goodsSkuModel = (new NewBaseModel(['table_name' => 'commission_legumes_log', 'pk' => 'id']));
- // $goodsSkuModel->saveAll($updateData);
- // // 添加用户账单信息变更记录
- // $mark = '购买商品使用'.$orderInfo['legumes_integral_use'].'积分抵扣'.floatval($orderInfo['legumes_integral_money']).'元';
- // model('commission_account')->add([
- // 'site_id' => $orderInfo['site_id'],
- // 'member_id' => $orderInfo['member_id'],
- // 'join_id' => $orderInfo['order_id'],
- // 'account_type' => 'use_legumes_integral',
- // 'account_type_name' => '积分使用',
- // 'account_data' => '-'.$orderInfo['legumes_integral_use'],
- // 'status' => 1,
- // 'remark' => $mark,
- // ]);
- // }
-
-
-
-
- }
- // 退款处理
- private function orderRefundFinish(){
-/* $data = array (
- 'order_goods_id' => 235,
- 'order_id' => 218,
- 'order_no' => '20240513135030313361',
- 'site_id' => 2,
- 'member_id' => 21,
- 'goods_id' => 3,
- 'sku_id' => 4,
- 'sku_name' => '削笔机削笔器 ',
- 'sku_image' => 'https://aidian-1251027355.cos.ap-chengdu.myqcloud.com/upload/2/common/images/20240425/20240425030636171402879621442.jpg',
- 'sku_no' => '',
- 'is_virtual' => 0,
- 'goods_class' => '1',
- 'goods_class_name' => '实物商品',
- 'price' => '29.90',
- 'cost_price' => '0.00',
- 'num' => '5.000',
- 'goods_money' => '149.50',
- 'cost_money' => '0.00',
- 'delivery_status' => 0,
- 'delivery_status_name' => '未发货',
- 'delivery_no' => '',
- 'gift_flag' => 0,
- 'refund_no' => '202405130151256359',
- 'refund_status' => 3,
- 'refund_status_name' => '维权结束',
- 'refund_status_action' => '{"status":3,"name":"维权结束","action":[],"member_action":[]}',
- 'refund_type' => 1,
- 'refund_apply_money' => '100.00',
- 'refund_reason' => '商家对订单进行了主动退款',
- 'refund_real_money' => '100.00',
- 'refund_delivery_name' => '',
- 'refund_delivery_no' => '',
- 'refund_time' => 1715579490,
- 'refund_refuse_reason' => '',
- 'refund_action_time' => 1715579485,
- 'real_goods_money' => '148.88',
- 'refund_remark' => '商家对订单进行了主动退款',
- 'refund_delivery_remark' => '',
- 'refund_address' => '',
- 'is_refund_stock' => 0,
- 'refund_money_type' => 1,
- 'shop_active_refund' => 0,
- 'shop_refund_remark' => '',
- 'refund_mode' => 1,
- 'promotion_money' => '0.00',
- 'coupon_money' => '0.00',
- 'adjust_money' => '0.00',
- 'goods_name' => '削笔机削笔器',
- 'sku_spec_format' => '',
- 'is_fenxiao' => 1,
- 'use_point' => 0,
- 'point_money' => '0.00',
- 'refund_delivery_money' => '0.00',
- 'create_time' => 1715579430,
- 'out_aftersale_id' => '202405131350303133611715579485235',
- 'refund_address_id' => 0,
- 'refund_pay_money' => '0.00',
- 'store_id' => 2,
- 'card_item_id' => 0,
- 'card_promotion_money' => '0.00',
- 'legumes_integral_use' => '1.10',
- 'legumes_integral_money' => '0.62',
- );
- Db::startTrans();
- try{
- if($data['refund_status_action']){
- // 判断:当前商品是否存在豆豆积分抵扣情况
- if((int)$data['legumes_integral_use'] <= 0) throw new Exception('商品不存在豆豆积分抵扣');
- //计算退款比例 单位:%
- $refundRate = (float)sprintf("%.2f",(float)$data['refund_real_money'] / (float)$data['real_goods_money'] * 100);
- // 退款成功 计算平台抽成相关退款内容
- $this->handleCommissionRecord($data['order_goods_id'], $refundRate);
- // 退款成功 权重值相关处理
- $this->handleWeightValue($data['order_goods_id'], $refundRate);
- // 招商员佣金 & 推广员佣金处理
- $this->HandleCommissionMoney($data['order_goods_id'], $refundRate);
- // 合伙人佣金处理
- $this->HandlePartnerMoney($data['order_goods_id'], $refundRate);
- // 积分和豆豆处理
- $this->HandleLegumes($data['order_goods_id'], $refundRate);
- // 抵扣积分退回
- $this->HandleIntegral($data['order_goods_id'], $refundRate);
- }
-
- Db::commit();
- }catch(Exception $e){
- Db::rollback();
-
- debug('错误:' . $e->getMessage());
- }*/
- }
- // 退款处理 - 平台抽成记录处理
- private function handleCommissionRecord($orderGoodsId, $refundRate){
- $hasRefundRatio = (float)model('commission_record')->getValue(['order_goods_id'=>$orderGoodsId],'refund_ratio');
- $updateData = [
- 'refund_ratio' => (float)sprintf("%.2f", $hasRefundRatio + $refundRate)
- ];
- if($updateData['refund_ratio'] >= 100){
- $updateData['refund_ratio'] = 100;
- $updateData['partner_status'] = 3;
- $updateData['merchants_status'] = 3;
- $updateData['promoter_status'] = 3;
- }
- model('commission_record')->update($updateData,[
- ['order_goods_id', '=', $orderGoodsId]
- ]);
-
-
- return true;
- }
- // 退款处理 - 权重值相关处理
- private function handleWeightValue($orderGoodsId, $refundRate){
- $weightValueLogList = model('commission_weight_value_log')->getList([
- ['order_goods_id', '=', $orderGoodsId],
- ['change_type', '=', 1],
- ['source', '=', 0],
- ],'id,member_id,level_id,order_goods_id,change_quantity,goods_id,order_id');
- $insertLogData = [];
- $updateData = [];
- foreach($weightValueLogList as $weightValueLogInfo){
- // 获取用户持有信息
- $holdInfo = model('commission_weight_value')->getInfo([
- ['member_id', '=', $weightValueLogInfo['member_id']],
- ['level_id', '=', $weightValueLogInfo['level_id']],
- ]);
- // 获取已经减少数量
- $reduced = model('commission_weight_value_log')->getSum([
- ['order_goods_id', '=', $weightValueLogInfo['order_goods_id']],
- ['change_type', '=', 0],
- ['source', '=', 1],
- ['member_id', '=', $weightValueLogInfo['member_id']],
- ], 'change_quantity');
- // 计算减少信息,总减少数量不能超过获取数量
- $reduce = (float)sprintf("%.2f",$weightValueLogInfo['change_quantity'] * $refundRate / 100);
- $totalReduce = (float)sprintf("%.2f",$reduced * $reduce);
- if($totalReduce > $weightValueLogInfo['change_quantity']) $reduce = (float)sprintf("%.2f",$weightValueLogInfo['change_quantity'] - $reduced);
- $changeFront = $holdInfo->quantity;
- $surplusQuantity = (float)sprintf("%.2f",$holdInfo['quantity'] - $reduce);
- $updateData[] = [
- 'id' => $holdInfo['id'],
- 'quantity' => $surplusQuantity
- ];
- // 记录变更记录
- $insertLogData[] = [
- 'site_id' => $holdInfo['site_id'],
- 'member_id' => $weightValueLogInfo['member_id'],
- 'level_id' => $weightValueLogInfo['level_id'],
- 'goods_id' => $weightValueLogInfo['goods_id'],
- 'order_id' => $weightValueLogInfo['order_id'],
- 'order_goods_id' => $weightValueLogInfo['order_goods_id'],
- 'change_type' => 0,
- 'change_quantity' => $reduce,
- 'change_front' => $changeFront,
- 'change_after' => (float)$surplusQuantity,
- 'remark' => '商品退款,减少权重值',
- 'source' => 1,
- ];
- }
-
- if(count($insertLogData) > 0){
- model('commission_weight_value_log')->addList($insertLogData);
- }
- if(count($updateData) > 0){
- $goodsSkuModel = (new NewBaseModel(['table_name' => 'commission_weight_value', 'pk' => 'id']));
- $goodsSkuModel->saveAll($updateData);
- }
-
-
- return true;
- }
- // 退款处理 - 招商员佣金 & 推广员佣金处理
- private function HandleCommissionMoney($orderGoodsId, $refundRate){
- $where = [
- ['order_goods_id', '=', $orderGoodsId],
- ['merchants_status', '=', 1],
- ];
- $field = [
- 'a.id',
- 'a.site_id',
- 'a.store_id',
- 'a.order_id',
- 'a.order_goods_id',
- 'a.merchants_money',
- 's.merchants_member_id',
- 's.store_name',
- 'a.member_id',
- 'a.promoter_money',
- 'm.is_fenxiao',
- 'm.nickname',
- 'fx.member_id as fenxiao_member_id',
- 'fx.parent'
- ];
- $join = [
- ['store s', 's.store_id = a.store_id', 'LEFT'], // 关联客服
- ['member m', 'a.member_id = m.member_id', 'LEFT'],
- ['fenxiao fx', 'm.fenxiao_id = fx.fenxiao_id', 'LEFT'],
- ];
- $info = model('commission_record')->getInfo($where,$field,'a',$join);
- if(!$info) return false;
- // 处理招商员佣金
- if((int)$info['merchants_member_id'] > 0){
- // 获取冻结中佣金信息
- $reduce = (float)sprintf("%.3f",$info['merchants_money'] * $refundRate / 100);// 减少数量
- model('commission_account')->add([
- 'site_id' => $info['site_id'],
- 'member_id' => $info['merchants_member_id'],
- 'join_id' => $info['id'],
- 'account_type' => 'merchants_refund',
- 'account_type_name' => '招商员佣金退款',
- 'account_data' => '-' . $reduce,
- 'remark' => '订单退款,减少收入',
- 'status' => 2,
- ]);
- $memberCommissionMoney = model('member')->getValue([['member_id', '=', $info['merchants_member_id']]], 'commission_money');
- model('member')->update(['commission_money' => sprintf("%.2f", $memberCommissionMoney - $reduce)],[
- ['member_id', '=', $info['merchants_member_id']],
- ]);
- }
- // 处理推广员佣金
- if($info['is_fenxiao'] == 1) $parentMemberId = model('fenxiao')->getValue(['fenxiao_id'=>$info['parent']], 'member_id');// 当前用户是分销商 使用parent查询上级用户id
- else $parentMemberId = $info['fenxiao_member_id'];// 当前用户不是分销商 直接为fenxiao_member_id
- if($parentMemberId > 0){
- $reduce = (float)sprintf("%.3f",$info['promoter_money'] * $refundRate / 100);// 减少数量
- model('commission_account')->add([
- 'site_id' => $info['site_id'],
- 'member_id' => $parentMemberId,
- 'join_id' => $info['id'],
- 'account_type' => 'promoter_refund',
- 'account_type_name' => '推广员佣金退款',
- 'account_data' => '-' . $reduce,
- 'remark' => '订单退款,减少收入',
- 'status' => 2,
- ]);
- $memberCommissionMoney = model('member')->getValue([['member_id', '=', $parentMemberId]], 'commission_money');
- model('member')->update(['commission_money' => sprintf("%.2f", $memberCommissionMoney - $reduce)],[
- ['member_id', '=', $parentMemberId],
- ]);
- }
-
- return true;
- }
- // 退款处理 - 合伙人佣金处理
- private function HandlePartnerMoney($orderGoodsId, $refundRate){
- $commissionRecord = model('commission_record')->getInfo([
- ['order_goods_id', '=', $orderGoodsId]
- ],'partner_status,create_time,partner_money');
- // 待结算-结算时处理,已结算-减少用户已获得佣金,2、3-无处理
- if($commissionRecord['partner_status'] == 1){
- // 获取:获取当前抽成结算的归属周期
- $createTime = strtotime($commissionRecord['create_time']);
- $cycleInfo = model('commission_partner_cycle')->getInfo([
- ['start_time', '<', $createTime],
- ['end_time', '>', $createTime],
- ]);
- if($cycleInfo){
- // 计算总退款的合伙人佣金
- $reduceCommissionMoney = (float)sprintf("%.3f",$commissionRecord['partner_money'] * $refundRate / 100);// 减少数量
- // 获取退款的用户列表
- $userList = model('commission_partner')->getList([
- ['cycle_id', '=', $cycleInfo['cycle_id']],
- ],'id,site_id,member_id,money,proportion,cycle_id');
- $insertData = [];
- foreach($userList as $partnerInfo){
- // 计算当前用户应扣除合伙人佣金
- $reduce = (float)sprintf("%.2f",$reduceCommissionMoney * $partnerInfo['proportion'] / 100);
- // 记录账单
- $insertData = [
- 'site_id' => $partnerInfo['site_id'],
- 'member_id' => $partnerInfo['member_id'],
- 'join_id' => $partnerInfo['id'],
- 'account_type' => 'partner_refund',
- 'account_type_name' => '合伙人佣金退款',
- 'account_data' => '-' . $reduce,
- 'remark' => "订单退款,减少收入",
- 'status' => 2,
- ];
- $memberCommissionMoney = model('member')->getValue([['member_id', '=', $partnerInfo['member_id']]], 'commission_money');
- model('member')->update(['commission_money' => sprintf("%.2f", $memberCommissionMoney - $reduce)],[
- ['member_id', '=', $partnerInfo['member_id']],
- ]);
- }
- // 记录账单变化信息
- if (count($insertData) > 0) model('commission_account')->addList($insertData);
- }
- }
-
- return true;
- }
- // 退款处理 - 积分和豆豆处理
- private function HandleLegumes($orderGoodsId, $refundRate){
- // 获取当前抽成信息
- $commissionRecord = model('commission_record')->getInfo([
- ['order_goods_id', '=', $orderGoodsId]
- ],'id,create_time');
- // 判断:当前抽成豆豆信息是否已经结算,未结算-无操作处理(结算时处理退款内容);已结算-处理退款相关内容
- $maxEndTime = model('commission_legumes')->getMax([],'end_time');
- $createTime = strtotime($commissionRecord['create_time']);
- if($createTime < $maxEndTime){
- // 已结算 - 处理退款相关内容
- $legumesId = model('commission_legumes')->getValue([
- ['start_time', '<', $createTime],
- ['end_time', '>', $createTime]
- ], 'id');
- if($legumesId > 0){
- // 获取需要修改的信息列表
- $correlationList = model('commission_legumes_log')->getList([
- ['legumes_id', '=', $legumesId]
- ], 'id,member_id,order_money,refund_order_money,get_legumes,refund_get_legumes,get_integral');
- // 循环处理
- $updateData = [];
- foreach($correlationList as $correlationInfo){
- // 计算 退款金额
- $reduceOrderMoney = (float)sprintf("%.2f",$correlationInfo['order_money'] * $refundRate / 100);
- $refundOrderMoney = (float)sprintf("%.3f", $correlationInfo['refund_order_money'] + $reduceOrderMoney);
- if($refundOrderMoney > $correlationInfo['order_money']) $refundOrderMoney = $correlationInfo['order_money'];
- // 计算 退款豆豆
- $reduceGetLegumes = (float)sprintf("%.2f",$correlationInfo['get_legumes'] * $refundRate / 100);
- $refundGetLegumes = (float)sprintf("%.3f", $correlationInfo['refund_get_legumes'] + $reduceGetLegumes);
- if($refundGetLegumes > $correlationInfo['get_legumes']) $refundGetLegumes = $correlationInfo['get_legumes'];
- // 记录修改信息
- $updateData[] = [
- 'id' => $correlationInfo['id'],
- 'refund_order_money' => $refundOrderMoney,
- 'refund_get_legumes' => $refundGetLegumes
- ];
- }
-
- if(count($updateData) > 0) {
- $goodsSkuModel = (new NewBaseModel(['table_name' => 'commission_legumes_log', 'pk' => 'id']));
- $goodsSkuModel->saveAll($updateData);
- Queue::push(ComputeIntegralJob::class,[
- 'ids' => array_column($correlationList,'id')
- ]);
- }
- }
- }
-
- return true;
- }
- // 退款处理 - 抵扣积分退回
- private function HandleIntegral($orderGoodsId, $refundRate){
- // 获取订单商品信息
- $orderProductInfo = model('order_goods')->getInfo([
- ['order_goods_id', '=', $orderGoodsId]
- ],'site_id,member_id,order_id,legumes_integral_use');
- $useLegumesIntegral = $orderProductInfo['legumes_integral_use'] ?? 0;
- $memberId = $orderProductInfo['member_id'] ?? 0;
- if($useLegumesIntegral > 0 && $memberId > 0){
- // 计算退回积分
- $returnIntegral = (float)sprintf("%.2f",$useLegumesIntegral * $refundRate / 100);
- // 获取退回的记录列表
- $useLegumesLogList = (new Legumes())->getUsedList((int)$memberId,(float)$returnIntegral);
- // 循环处理
- $returnComputeIntegral = $returnIntegral;// 计算用 退回积分
- $updateData = [];
- foreach($useLegumesLogList as $logInfo){
- // 当前分配信息可退回积分 剩余可退回积分
- $reduce = $returnComputeIntegral < $logInfo['use_integral'] ? $returnComputeIntegral : $logInfo['use_integral'];
- $returnComputeIntegral = (float)sprintf("%.2f",$returnComputeIntegral - $reduce);
- $updateData[] = [
- 'id' => $logInfo['id'],
- 'use_integral' => (float)sprintf("%.2f",$logInfo['use_integral'] - $reduce)
- ];
- if($returnComputeIntegral <= 0) break;
- }
- if($updateData){
- // 修改
- $goodsSkuModel = (new NewBaseModel(['table_name' => 'commission_legumes_log', 'pk' => 'id']));
- $goodsSkuModel->saveAll($updateData);
- // 添加用户账单信息变更记录
- $mark = '订单退款 - 退回抵扣积分:'.$returnIntegral;
- model('commission_account')->add([
- 'site_id' => $orderProductInfo['site_id'],
- 'member_id' => $memberId,
- 'join_id' => $orderProductInfo['order_id'],
- 'account_type' => 'refund_legumes_integral',
- 'account_type_name' => '积分退回',
- 'account_data' => $returnIntegral,
- 'status' => 2,
- 'remark' => $mark,
- ]);
- }
- }
-
- return true;
- }
- // 运营抽成处理 - 区分技术和平台
- private function handleOperations(){
- $list = model('commission_record')->getList([
- ['operations_money', '>', 0]
- ],'id,operations_money');
- $updateData = [];
- foreach($list as $item){
- $operationsMoney = (float)$item['operations_money'];// 运营抽成总金额
- $operationsTechnologyMoney = (float)sprintf("%.3f",$operationsMoney * 0.2);// 运营抽成 - 技术公司所得(20%)
- $operationsPlatformMoney = (float)sprintf("%.3f",$operationsMoney - $operationsTechnologyMoney);// 运营抽成 - 平台所得(80%)
-
- $updateData[] = [
- 'id' => $item['id'],
- 'operations_technology_money' => $operationsTechnologyMoney,
- 'operations_platform_money' => $operationsPlatformMoney,
- ];
- }
- // debug($updateData);
- if($updateData){
- // 修改
- $goodsSkuModel = (new NewBaseModel(['table_name' => 'commission_record', 'pk' => 'id']));
- $goodsSkuModel->saveAll($updateData);
- }
- }
- // 验证 - 每日豆豆价格是否正确
- private function verificationLegumesPrice(){
- $list = model('commission_legumes')->getList('','','id ASC');
- foreach($list as $item){
- echo "
";
- echo "
";
- echo "数据库存储数据
";
- echo "时间段:" . date("Y-m-d H:i:s", $item['start_time']) . ' ~ ' . date("Y-m-d H:i:s", $item['end_time']) . "
";
- echo date("Y-m-d H:i:s", $item['start_time'])."豆豆价格:" . $item['legumes_price'] . "
";
- echo date("Y-m-d H:i:s", $item['start_time'])."产生豆豆数量:" . $item['legumes_num'] . "
";
- echo date("Y-m-d H:i:s", $item['end_time'])."豆豆价格:" . $item['tomorrow_legumes_price'] . "
";
- echo "
";
- // 计算豆豆价格 豆豆价格 = 积分抽成金额(全平台总金额) ➗ 文创豆数量(全平台总数量)
- echo "校验数据 重新根据抽成记录进行计算
";
- $total_money = (float)model('commission_record')->getSum([
- [ 'create_time', '<=', date("Y-m-d H:i:s", $item['start_time']) ]
- ], 'integral_money');// 总佣金
- // 获取退款金额
- $refund_money = (float)model('commission_record')->getValue([
- [ 'create_time', '<=', date("Y-m-d H:i:s", $item['start_time']) ]
- ],'sum((integral_money * refund_ratio / 100)) as refund_money');
- // 实际金额
- $reality_money = (float)sprintf("%.3f",(float)$total_money - (float)$refund_money);
- // 以产生豆豆
- $allLegumes = model('commission_legumes')->getSum([
- [ 'start_time', '<=', $item['start_time'] ]
- ],'legumes_num');
-
- echo "截止".date("Y-m-d H:i:s", $item['start_time'])."
";
- echo date("Y-m-d H:i:s", $item['start_time'])."前全平台总积分抽成佣金:{$total_money}
";
- echo date("Y-m-d H:i:s", $item['start_time'])."前全平台总积分抽成佣金退款金额:{$refund_money}
";
- echo date("Y-m-d H:i:s", $item['start_time'])."前全平台实际有效总积分抽成佣金:{$reality_money}
";
- echo date("Y-m-d H:i:s", $item['start_time'])."前全平台已产生豆豆:{$allLegumes}
";
- if($total_money > 0) echo date("Y-m-d H:i:s", $item['start_time'])."豆豆价格:".sprintf("%.4f",$reality_money / $allLegumes)."
";
- else echo date("Y-m-d H:i:s", $item['start_time'])."豆豆价格:0.5
";
- echo "
";
- }
-
-
- debug("结束");
- }
-
-
- // 重新计算豆豆相关数据
- private function afreshComputeLegumes(){
-
- $legumesModel = new Legumes();
- $list = model('commission_legumes')->getList([
- ['id', '>', 23]
- ]);
- $legumesPrice = 6.31;//0.5;
- $allLegumes = model('commission_legumes')->getSum([
- ['id', '<=', 23]
- ], 'legumes_num');
- $updateData = [];
-
- foreach($list as $legumes){
- // 获取周期内积分抽成信息
- $integralInfo = $legumesModel->getIntegralInfo($legumes['start_time'],$legumes['end_time']);
- // if((float)$integralInfo['reality_money'] <= 0){
- // echo "ID:{$legumes['id']}无积分抽成信息";
- // continue;
- // }
- // 计算豆豆数量 豆豆数量 = 积分抽成金额(昨日总金额) * 0.2 / 豆豆当前价格
- $legumesNum = (float)sprintf("%.4f",(float)$integralInfo['reality_money'] * 0.2 / $legumesPrice);
- // 计算豆豆价格 下次豆豆价格 = 积分抽成金额(全平台总金额) ➗ 文创豆数量(全平台总数量)
- $allIntegralInfo = $legumesModel->getIntegralInfo(1704076126, $legumes['end_time']);
- // $allLegumes = model('commission_legumes')->getSum([
- // [ 'end_time', 'between', [ 1704076126, $legumes['end_time'] ] ]
- // ],'legumes_num');
- $allLegumes += $legumesNum;
- $tomorrowLegumesPrice = sprintf("%.4f",$allIntegralInfo['reality_money'] / $allLegumes);
-
- // 2024-05-26 00:00:00
- // debug(model('commission_record')->getList([
- // [ 'create_time', 'between', [ date("Y-m-d H:i:s",1704076126), '2024-05-26 00:00:00' ] ]
- // ], 'id,integral_money,create_time'));
-
- echo "
";
- print_r([
- 'ID' => $legumes['id'],
- '时间戳' => $legumes['start_time'] . '~' . $legumes['end_time'] ,
- '时间' => date("Y-m-d H:i:s", $legumes['start_time']) . '~' . date("Y-m-d H:i:s", $legumes['end_time']) ,
- date("Y-m-d", $legumes['start_time']) . '价格' => $legumesPrice,
- date("Y-m-d", $legumes['end_time']) . '价格' => $tomorrowLegumesPrice,
- date("Y-m-d", $legumes['start_time']) . '豆豆数量' => $legumesNum,
- date("Y-m-d H:i:s", $legumes['start_time']) . '~' . date("Y-m-d H:i:s", $legumes['end_time']) . '积分抽成信息' => [
- '总金额' => $integralInfo['total_money'],
- '退款减少金额' => $integralInfo['refund_money'],
- '实际有效' => $integralInfo['reality_money'],
- ],
- "截至".date("Y-m-d H:i:s", $legumes['end_time']).'全平台抽成信息' => [
- '总金额' => $allIntegralInfo['total_money'],
- '退款减少金额' => $allIntegralInfo['refund_money'],
- '实际有效' => $allIntegralInfo['reality_money'],
- ],
- "截至".date("Y-m-d H:i:s", $legumes['end_time']).'全平台豆豆数量' => $allLegumes,
- ]);
-
-
-
- $updateData[] = [
- 'id' => $legumes['id'],
- 'total_integral_money' => (float)$integralInfo['total_money'],// 当前周期积分抽成总金额
- 'refund_money' => (float)$integralInfo['refund_money'],// 未结算前 - 已退款金额
- 'reality_money' => (float)$integralInfo['reality_money'],// 实际结算时拥有的基金池总数
- 'legumes_price' => (float)$legumesPrice,// 豆豆价格(当日价格)
- 'legumes_num' => (float)$legumesNum,// 豆豆数量(当日产生数量)
- 'tomorrow_legumes_price' => (float)$tomorrowLegumesPrice,// 豆豆价格(明日价格)
- 'status' => (float)0,// 状态:0=待分配,1=已分配
- ];
-
- echo "
";
- $legumesPrice = $tomorrowLegumesPrice;
- }
- // 修改信息
- // $goodsSkuModel = (new NewBaseModel(['table_name' => 'commission_legumes', 'pk' => 'id']));
- // $goodsSkuModel->saveAll($updateData);
- //
- // (new Setting())->setLegumesPrice(0, $legumesPrice);
-
-
-
- debug("结束");
- }
- // 豆豆重新分配
- private function afreshAllocationLegumes(){
- $list = model('commission_legumes')->getList([
- ['id', '>', 23]
- ]);
-
- $updateData = [];
-
- foreach($list as $item){
- $logList = model('commission_legumes_log')->getList([
- ['legumes_id', '=', $item['id']]
- ]);
- foreach($logList as $log){
- $updateData[] = [
- 'id' => $log['id'],
- 'cycle_total_legumes' => (float)$item['legumes_num'],// 当前周期豆豆总数
- 'get_legumes' => (float)sprintf("%.4f",$item['legumes_num'] * $log['order_money_rate'] / 100),// 当前订单实际获得豆豆
- ];
- }
- }
- // 修改豆豆积分使用信息
- $goodsSkuModel = (new NewBaseModel(['table_name' => 'commission_legumes_log', 'pk' => 'id']));
- $goodsSkuModel->saveAll($updateData);
-
-
- // 修改豆豆周期分配状态
- $ids = array_column($list, 'id');
- model('commission_legumes')->update(['status' => 1],[
- ['id', 'in', $ids]
- ]);
- // 触发全平台豆豆转积分操作
- Queue::push(ComputeIntegralJob::class);
-
-
- debug($updateData);
- }
- // 结算平台抽成相关流水
- private function settlementAccount(){
- $where = [
- ['a.status', '=', 0],
- ['a.account_type', '=', 'promoter']
- ];
- $field = 'a.id,a.account_data,a.member_id,o.order_status,o.order_status_name';
-
- $join = [
- ['commission_record cr','cr.id = a.join_id', 'left'],
- ['order o','o.order_id = cr.order_id', 'left'],
- ];
- $list = model('commission_account')->getList($where,$field,'a.id DESC','a',$join);
- // 获取用户已经持有信息
- $memberIds = array_column($list, 'member_id');
- $userList = Db::name('member')
- ->field('commission_money,member_id')
- ->whereIn('member_id', $memberIds)
- ->select()
- ->toArray();
- $userList = array_column($userList, null, 'member_id');
- debug($userList,false);
- $ids = [];
- foreach($list as $item){
- if($item['order_status'] == 10){
- $userList[$item['member_id']]['commission_money'] += $item['account_data'];
- $ids[] = $item['id'];
- }
- }
- // // 修改
- // $newBaseModel = (new NewBaseModel(['table_name' => 'member', 'pk' => 'member_id']));
- // $userList = array_values($userList);
- // $newBaseModel->saveAll($userList);
- // // 已结算
- // model('commission_account')->update(['status'=>1],[
- // ['id', 'in', $ids]
- // ]);
- debug($userList);
- }
-
-
-
- /******** 数据库批量处理 ***************************************/
- private function sqlInit(){
- // 不清除数据的表
- $notCleanUp = [
- // 'tk_addon
- // 'tk_adv
- // 'tk_album
- // 'tk_album_pic
- // 'tk_area
- // 'tk_attachments
- // 'tk_cashier_auth
- // 'tk_cashier_auth_group
- // 'tk_cloud_order
-
-
- // 开发中 ......
-
-
- // 'tk_config
- // 'tk_cron
- // 'tk_cron_log
- // 'tk_diy_template
- // 'tk_diy_template_goods
- // 'tk_diy_template_goods_item
- // 'tk_diy_theme
- // 'tk_diy_view_util
- // 'tk_document
- // 'tk_express_company
- // 'tk_express_company_template
- // 'tk_express_deliver
- // 'tk_express_delivery_package
- // 'tk_express_template
- // 'tk_express_template_free_shipping
- // 'tk_express_template_item
- // 'tk_fenxiao
- // 'tk_fenxiao_account
- // 'tk_fenxiao_goods_sku
- // 'tk_fenxiao_level
- // 'tk_fenxiao_order
- // 'tk_fenxiao_withdraw
- // 'tk_form
- // 'tk_form_data
- // 'tk_goods
- // 'tk_goods_attr_class
- // 'tk_goods_browse
- // 'tk_goods_category
- // 'tk_goods_commission
- // 'tk_goods_label
- // 'tk_goods_service
- // 'tk_goods_sku
- // 'tk_group
- // 'tk_link
- // 'tk_local
- // 'tk_manage_account
- // 'tk_manage_level
- // 'tk_manage_order
- // 'tk_manage_user
- // 'tk_member
- // 'tk_member_account
- // 'tk_member_address
- // 'tk_member_bank_account
- // 'tk_member_level
- // 'tk_member_level_records
- // 'tk_member_recommend
- // 'tk_menu
- // 'tk_message
- // 'tk_message_template
- // 'tk_message_variable
- // 'tk_order
- // 'tk_order_goods
- // 'tk_order_log
- // 'tk_order_refund_log
- // 'tk_pay
- // 'tk_pay_notify_log
- // 'tk_pay_refund
- // 'tk_pay_shop
- // 'tk_promotion_bundling
- // 'tk_promotion_coupon
- // 'tk_promotion_coupon_type
- // 'tk_promotion_groupbuy
- // 'tk_promotion_jielong
- // 'tk_promotion_pinfan
- // 'tk_promotion_pinfan_group
- // 'tk_promotion_topic
- // 'tk_service_category
- // 'tk_shop
- // 'tk_site
- // 'tk_site_diy_template
- // 'tk_site_diy_view
- // 'tk_site_group
- // 'tk_sms_template
- // 'tk_stat_shop
- // 'tk_stat_shop_hour
- // 'tk_stat_store
- // 'tk_stat_store_hour
- // 'tk_stock_document
- // 'tk_stock_document_goods
- // 'tk_stock_inventory
- // 'tk_stock_inventory_goods
- // 'tk_store
- // 'tk_store_category
- // 'tk_store_goods
- // 'tk_store_goods_sku
- // 'tk_store_label
- // 'tk_store_member
- // 'tk_supply_goods_warehousing
- // 'tk_supply_order
- // 'tk_supply_sub_order
- // 'tk_uni_fans
- // 'tk_user
- // 'tk_user_group
- // 'tk_user_log
- // 'tk_verifier
- // 'tk_verify
- // 'tk_verify_record
- // 'tk_website
- // 'tk_wechat_replay_rule
-
-
-
- ];
- // 获取全部数据库列表
- $tables = $this->getAllTable();
- // 获取存在数据的表
- // $hasTable = $this->getHasSpecifyDataTable($tables,$notCleanUp);
- $hasTable = $this->getHasDataTable($tables,$notCleanUp);
-
- debug($hasTable);
- // 执行清除操作
- // foreach($tables as $name){
- // if(!in_array($name,$notCleanUp)){
- // // 执行清除操作
- // $res = Db::query('TRUNCATE TABLE '.$name.';');
- // }
- // }
-
- debug("处理完成");
- }
- // 数据库处理 - 获取全部数据库
- private function getAllTable(){
- $database = Db::query('SELECT DATABASE() as database_name')[0]['database_name'];
- $tables = Db::query('SHOW TABLES');
- return array_column($tables,'Tables_in_'.$database);
- }
- // 数据库处理 - 获取存在数据的表(任意数据)
- private function getHasDataTable($tables,$notCleanUp){
- $tableList = [];
- foreach($tables as $tableName){
- if(!in_array($tableName,$notCleanUp)){
- // echo "{$tableName}
\n\r";
- // 获取字段信息
- $result = Db::query("select count(*) as count_data from {$tableName}");
- $countData = $result[0]['count_data'] ?? 0;
- if($countData > 0){
- $tableList[] = $tableName;
- }
- }
- }
-
- return $tableList;
- }
- // 数据库处理 - 获取存在指定数据的表
- private function getHasSpecifyDataTable($tables,$notCleanUp){
- $tableList = [];
- foreach($tables as $tableName){
- if(!in_array($tableName,$notCleanUp)){
- echo "{$tableName}\n\r";
- // 获取字段信息
- $allFieldDesc = Db::query("show columns from {$tableName}");
- $allField = array_column($allFieldDesc,'Field');
- // if($this->isHasSpecifyData($allField,$name)) $tableList[] = $name;
-
-
- $res = $this->isHasSpecifyData($allField,$tableName);
- echo $res ? "存在\n\r" : "不存在\n\r";
- if($res){
- // 批量替换
- $query = "UPDATE {$tableName} SET ";
- $handleFieldNum = 0;
- foreach($allFieldDesc as $fieldInfo){
- if(strpos($fieldInfo['Type'], 'int') !== false || $fieldInfo['Key'] == 'PRI') continue;
-
- $fieldName = $fieldInfo['Field'];
- $query .= "`{$fieldName}` = REPLACE(`{$fieldName}`,'bt.test.cdlfjy.com','zc.test.cdlfjy.com'),";
- ++$handleFieldNum;
- }
- $query = trim($query);
- $query = trim($query,',');
- $query = trim($query);
- echo "SQL({$handleFieldNum}):{$query}\n";
- if($handleFieldNum > 0) Db::query($query);
- }
-
- echo "\n\n\n";
- }
- }
-
- return $tableList;
- }
- // 数据库处理 - 判断当前表是否具有指定内容
- private function isHasSpecifyData($allField,$tableName){
- $query = "select * from {$tableName} where (";
- foreach($allField as $fieldName){
- $query .= "`{$fieldName}` like '%bt.test.cdlfjy.com%' OR ";
- }
- $query = trim($query);
- $query = trim($query,'OR');
- $query = trim($query) . ")";
-
- $result = Db::query($query);
- if($result) return true;
-
- return false;
- }
-
-}
diff --git a/addon/commission/shop/view/index/account_list.html b/addon/commission/shop/view/index/account_list.html
deleted file mode 100644
index 48d4474..0000000
--- a/addon/commission/shop/view/index/account_list.html
+++ /dev/null
@@ -1,199 +0,0 @@
-{extend name="app/shop/view/base.html"/}
-{block name="resources"}
-
-
-
-
-{/block}
-
-{block name="main"}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
![]()
-
-
-
{{ scope.row.nickname || scope.row.username }}
-
UID:{{ scope.row.member_id }}
-
-
-
-
-
-
- {{ scope.row.site_name || '' }}
- {{ scope.row.contacts_name || '' }}
- {{ scope.row.contacts_mobile || '' }}
-
-
-
-
-
-
- 待结算
- 已结算
- 已退款
-
-
-
-
-
-
-
-
-
-{/block}
-
-{block name="script"}
-
-{/block}
\ No newline at end of file
diff --git a/addon/commission/shop/view/index/index.html b/addon/commission/shop/view/index/index.html
deleted file mode 100644
index c914bbe..0000000
--- a/addon/commission/shop/view/index/index.html
+++ /dev/null
@@ -1,453 +0,0 @@
-{extend name="app/shop/view/base.html"/}
-{block name="resources"}
-
-
-
-
-{/block}
-
-{block name="main"}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
![]()
-
-
-
{{ scope.row.nickname || scope.row.username }}
-
UID:{{ scope.row.member_id }}
-
-
-
-
-
-
- {{ scope.row.site_name || '' }}
- 联系人:{{ scope.row.contacts_name || '' }}
-
-
-
-
-
-
-
![]()
-
-
-
{{ scope.row.goods_name || '' }}
-
订单号:{{ scope.row.order_no || '' }}
-
商品ID:{{ scope.row.goods_id || '' }}
-
-
-
-
-
在线买单
-
订单号:{{ scope.row.order_no || '' }}
-
-
- -
-
-
-
-
- 抽成和佣金
- 总金额
- 占有比例
- 退款减少金额
- 实际有效金额
-
-
-
- {{ scope.row.real_goods_money || '0.00' }}元
-
-
-
-
- {{ scope.row.integral_money || '0.00' }}元
-
- {{ scope.row.integral_rate || '0' }}%
- 固定金额
-
-
- {{ Number(Number(scope.row.integral_money) * Number(scope.row.refund_ratio) / 100).toFixed(2) }}元
-
-
-
- {{ Number(Number(scope.row.integral_money) - (Number(scope.row.integral_money) * Number(scope.row.refund_ratio) / 100)).toFixed(2) }}元
-
-
-
-
-
-
- {{ scope.row.operations_money || '0.00' }}元
-
- {{ scope.row.operations_rate || '0' }}%
- 固定金额
-
-
- {{ Number(Number(scope.row.operations_money) * Number(scope.row.refund_ratio) / 100).toFixed(2) }}元
-
-
-
- {{ Number(Number(scope.row.operations_money) - (Number(scope.row.operations_money) * Number(scope.row.refund_ratio) / 100)).toFixed(2) }}元
-
-
-
-
-
- {{ scope.row.operations_technology_money || '0.00' }}元
-
- 20%
-
-
- {{ Number(Number(scope.row.operations_technology_money) * Number(scope.row.refund_ratio) / 100).toFixed(2) }}元
-
-
-
- {{ Number(Number(scope.row.operations_technology_money) - (Number(scope.row.operations_technology_money) * Number(scope.row.refund_ratio) / 100)).toFixed(2)}}元
-
-
-
-
-
- {{ scope.row.operations_platform_money || '0.00' }}元
-
- 80%
-
-
- {{ Number(Number(scope.row.operations_technology_money) * Number(scope.row.refund_ratio) / 100).toFixed(2) }}元
-
-
-
- {{ Number(Number(scope.row.operations_technology_money) - (Number(scope.row.operations_technology_money) * Number(scope.row.refund_ratio) / 100)).toFixed(2)}}元
-
-
-
-
-
-
- {{ scope.row.partner_money || '0.00' }}元
-
- {{ scope.row.partner_rate || '0' }}%
- 固定金额
-
-
- {{ Number(Number(scope.row.partner_money) * Number(scope.row.refund_ratio) / 100).toFixed(2) }}元
-
-
-
- {{ Number(Number(scope.row.partner_money) - (Number(scope.row.partner_money) * Number(scope.row.refund_ratio) / 100)).toFixed(2)}}元
-
-
- 待结算
- 已结算
- 无合伙人
-
-
-
-
- {{ scope.row.merchants_money || '0.00' }}元
-
- {{ scope.row.merchants_rate || '0' }}%
- 固定金额
-
-
- {{ Number(Number(scope.row.merchants_money) * Number(scope.row.refund_ratio) / 100).toFixed(2) }}元
-
-
-
- {{ Number(Number(scope.row.merchants_money) - (Number(scope.row.merchants_money) * Number(scope.row.refund_ratio) / 100)).toFixed(2)}}元
-
-
- 待结算
- 已结算
- 无招商员
-
-
-
-
- {{ scope.row.promoter_money || '0.00' }}元
-
- {{ scope.row.promoter_rate || '0' }}%
- 固定金额
-
-
- {{ Number(Number(scope.row.promoter_money) * Number(scope.row.refund_ratio) / 100).toFixed(2) }}元
-
-
-
- {{ Number(Number(scope.row.promoter_money) - (Number(scope.row.promoter_money) * Number(scope.row.refund_ratio) / 100)).toFixed(2)}}元
-
-
- 待结算
- 已结算
- 无推广员
-
-
-
-
-
-
-
-
-
-{/block}
-
-{block name="script"}
-
-{/block}
\ No newline at end of file
diff --git a/addon/commission/shop/view/index/legumes.html b/addon/commission/shop/view/index/legumes.html
deleted file mode 100644
index 6889f6d..0000000
--- a/addon/commission/shop/view/index/legumes.html
+++ /dev/null
@@ -1,456 +0,0 @@
-{extend name="app/shop/view/base.html"/}
-{block name="resources"}
-
-
-
-
-{/block}
-
-{block name="main"}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- {{ scope.row.start_time | formatDate }} ~ {{ scope.row.end_time | formatDate }}
-
-
-
-
-
- 已分配
- 待分配
-
-
-
-
- 分配明细
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
![]()
-
-
-
{{ scope.row.nickname || '' }}
-
ID:{{ scope.row.member_id }}
-
-
-
-
-
-
-
-
-
- {{ (scope.row.order_money - scope.row.refund_order_money).toFixed(2) }}
-
-
-
-
-
-
-
-
-
- {{ (scope.row.get_legumes - scope.row.refund_get_legumes).toFixed(4) }}
-
-
-
-
-
-
- {{ (scope.row.order_money - scope.row.refund_order_money).toFixed(2) }}
-
-
-
-
-
-
- {{ (scope.row.get_integral - scope.row.use_integral).toFixed(2) }}
-
-
-
-
-
- 冻结中
- 可使用
- 已失效
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
![]()
-
-
-
{{ scope.row.nickname || '' }}
-
ID:{{ scope.row.member_id }}
-
-
-
-
-
-
-
-
-
- {{ (scope.row.total_get_legumes - scope.row.total_refund_get_legumes).toFixed(2) }}
-
-
-
-
-
-
- {{ scope.row.total_get_integral }} / {{ (scope.row.total_order_money - scope.row.total_refund_order_money).toFixed(2) }}
-
-
-
-
-
-
-
-
-
-
-
-
-
-{/block}
-
-{block name="script"}
-
-{/block}
\ No newline at end of file
diff --git a/addon/commission/shop/view/index/partner.html b/addon/commission/shop/view/index/partner.html
deleted file mode 100644
index 6d9eb0b..0000000
--- a/addon/commission/shop/view/index/partner.html
+++ /dev/null
@@ -1,262 +0,0 @@
-{extend name="app/shop/view/base.html"/}
-{block name="resources"}
-
-
-
-
-{/block}
-
-{block name="main"}
-
-
-
-
-
-
-
- 店铺名称:{{ scope.row.site_name || '' }}
- 联系人:{{ scope.row.contacts_name || '' }}
-
-
-
-
-
-
-
-
-
- {{ scope.row.start_time | formatDate }} ~ {{ scope.row.end_time | formatDate }}
-
-
-
-
-
- 查看明细
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
![]()
-
-
-
{{ scope.row.nickname || scope.row.username }}
-
UID:{{ scope.row.member_id }}
-
-
-
-
-
-
-
-
-
- 已结算
- 待结算
-
-
-
-
-
-
-
-
-
-{/block}
-
-{block name="script"}
-
-{/block}
\ No newline at end of file
diff --git a/addon/commission/shop/view/index/set.html b/addon/commission/shop/view/index/set.html
deleted file mode 100644
index ba5882a..0000000
--- a/addon/commission/shop/view/index/set.html
+++ /dev/null
@@ -1,121 +0,0 @@
-{extend name="app/shop/view/base.html"/}
-{block name="resources"}
-
-
-
-
-{/block}
-
-{block name="main"}
-
-
-
-
- 关闭
- 开启
-
-
-
-
-
- 统一默认设置
- 独立设置
-
-
-
-
- {{admin_set.integral_rate}}%
- {{admin_set.operations_rate}}%
- {{admin_set.partner_rate}}%
-
- {{admin_set.partner_cycle == 0 ? '每天' : (admin_set.partner_cycle == 1 ? '每周' : '每月') }}
-
- {{admin_set.merchants_rate}}%
- {{admin_set.promoter_rate}}%
-
-
-
-
-
- %
-
-
-
- {{set.operations_rate}}%
-
-
- %
-
-
-
-
-
- %
-
-
-
-
- {{admin_set.partner_cycle == 0 ? '每天' : (admin_set.partner_cycle == 1 ? '每周' : '每月') }}
-
-
-
- 每天
- 每周
- 每月
-
-
-
-
-
- %
-
-
-
-
- %
-
-
-
-
-
- 提交
-
-
-
-{/block}
-
-{block name="script"}
-
-
-{/block}
\ No newline at end of file
diff --git a/addon/commission/shop/view/index/weight_value.html b/addon/commission/shop/view/index/weight_value.html
deleted file mode 100644
index 7f8e90a..0000000
--- a/addon/commission/shop/view/index/weight_value.html
+++ /dev/null
@@ -1,261 +0,0 @@
-{extend name="app/shop/view/base.html"/}
-{block name="resources"}
-
-
-
-
-{/block}
-
-{block name="main"}
-
-
-
-
-
-
-
-
-
-
-
-
![]()
-
-
-
{{ scope.row.nickname || scope.row.username }}
-
UID:{{ scope.row.member_id }}
-
-
-
-
-
-
- 店铺名称:{{ scope.row.site_name || '' }}
- 联系人:{{ scope.row.contacts_name || '' }}
-
-
-
-
-
-
- 查看明细
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 增加
- 减少
-
-
-
-
-
-
-
-
-
-
-
-
-
-{/block}
-
-{block name="script"}
-
-{/block}
\ No newline at end of file
diff --git a/addon/fenxiao/event/OrderPay.php b/addon/fenxiao/event/OrderPay.php
index fbb6f1f..f65b9ce 100644
--- a/addon/fenxiao/event/OrderPay.php
+++ b/addon/fenxiao/event/OrderPay.php
@@ -35,7 +35,7 @@ class OrderPay
'member_id' => $order['member_id'],
'action' => 'order_pay',
]);
- // 自动成为分销商
+ // // 自动成为分销商
$fenxiao_model->autoBecomeFenxiao($order['member_id'], $order['site_id']);
$fenxiao_order = new FenxiaoOrder();
$res = $fenxiao_order->calculate($order);
diff --git a/addon/fenxiao/model/Config.php b/addon/fenxiao/model/Config.php
index 8c1caa6..2c96f26 100644
--- a/addon/fenxiao/model/Config.php
+++ b/addon/fenxiao/model/Config.php
@@ -38,6 +38,8 @@ class Config extends BaseModel
'is_apply' => $data[ 'is_apply' ],//是否开启分销申请
'is_commission_money' => $data[ 'is_commission_money' ],//是否开启商品详情一级佣金
'is_support_cashier' => $data[ 'is_support_cashier' ],//是否开启商品详情一级佣金
+ 'direct_rate' => $data[ 'direct_rate' ],//默认直推
+ 'indirect_rate' => $data[ 'indirect_rate' ],//默认间推
];
$config->setConfig($basics_data, '分销基本配置', $is_use, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'FENXIAO_BASICS_CONFIG' ] ]);
//分销商设置
@@ -80,7 +82,8 @@ class Config extends BaseModel
'internal_buy' => 0,//分销内购
'is_examine' => 0,//是否需要审核
'is_apply' => 0,//分销商申请方式
- 'is_commission_money' => 1,//是否开启商品详情一级佣金
+ 'direct_rate' => 0,//是否开启商品详情一级佣金
+ 'indirect_rate' => 0,//是否开启商品详情一级佣金
];
}
$res[ 'data' ][ 'value' ][ 'is_commission_money' ] = $res[ 'data' ][ 'value' ][ 'is_commission_money' ] ?? 1;
@@ -88,6 +91,8 @@ class Config extends BaseModel
$res[ 'data' ][ 'value' ][ 'is_apply' ] = $res[ 'data' ][ 'value' ][ 'is_apply' ] ?? 1;
$res[ 'data' ][ 'value' ][ 'level' ] = $res[ 'data' ][ 'value' ][ 'level' ] == 3 ? 2 : $res[ 'data' ][ 'value' ][ 'level' ];
$res[ 'data' ][ 'value' ][ 'is_support_cashier' ] = $res[ 'data' ][ 'value' ][ 'is_support_cashier' ] ?? 0;
+ $res[ 'data' ][ 'value' ][ 'direct_rate' ] = $res[ 'data' ][ 'value' ][ 'direct_rate' ] ?? 0;
+ $res[ 'data' ][ 'value' ][ 'indirect_rate' ] = $res[ 'data' ][ 'value' ][ 'indirect_rate' ] ?? 0;
return $res;
}
@@ -317,4 +322,4 @@ class Config extends BaseModel
}
/******************************************************************** 分销文字配置 end ****************************************************************************/
-}
\ No newline at end of file
+}
diff --git a/addon/fenxiao/model/Fenxiao.php b/addon/fenxiao/model/Fenxiao.php
index 95adac0..587bd12 100644
--- a/addon/fenxiao/model/Fenxiao.php
+++ b/addon/fenxiao/model/Fenxiao.php
@@ -370,8 +370,10 @@ class Fenxiao extends BaseModel
if (!$basics_config[ 'level' ]) return $this->error('', '未开启分销');
if ($basics_config[ 'is_apply' ] != 0) return $this->error('', '成为分销商需进行申请');
// 成为分销商的资格
+
$fenxiao_config = $config->getFenxiaoConfig($site_id);
$fenxiao_config = $fenxiao_config[ 'data' ][ 'value' ];
+
switch ( $fenxiao_config[ 'fenxiao_condition' ] ) {
case 2:
// 消费次数
@@ -428,7 +430,9 @@ class Fenxiao extends BaseModel
'level_id' => $level_info[ 'data' ][ 'level_id' ],
'level_name' => $level_info[ 'data' ][ 'level_name' ]
];
+
$res = $this->addFenxiao($data);
+
return $res;
}
}
diff --git a/addon/fenxiao/model/FenxiaoOrder.php b/addon/fenxiao/model/FenxiaoOrder.php
index 4371c18..9830f26 100644
--- a/addon/fenxiao/model/FenxiaoOrder.php
+++ b/addon/fenxiao/model/FenxiaoOrder.php
@@ -11,6 +11,8 @@ namespace addon\fenxiao\model;
use app\model\BaseModel;
use app\model\message\Message;
use app\model\system\Stat;
+use think\facade\Db;
+
/**
* 分销商品
*/
@@ -38,11 +40,12 @@ class FenxiaoOrder extends BaseModel
]);
$member_info = model("member")->getInfo([ [ 'member_id', '=', $order[ 'member_id' ] ] ], 'fenxiao_id,is_fenxiao,nickname,mobile');
}
+
// //如果没有分销商直接返回不计算,没有考虑首次付款上下级绑定
if (empty($member_info)) return $this->success();
if ($member_info[ 'fenxiao_id' ] == 0) return $this->success();
$fenxiao_id = $member_info[ 'fenxiao_id' ];
- $field = 'f.fenxiao_id,f.fenxiao_name,f.member_id,f.level_id,f.parent,f.grand_parent,l.level_num';
+ $field = 'f.fenxiao_id,f.fenxiao_name,f.member_id,f.level_id,f.site_id,f.status,f.parent,f.grand_parent,f.chain,l.level_num,l.one_rate,l.two_rate';
$join = [
['fenxiao_level l', 'f.level_id = l.level_id', 'right']
];
@@ -56,165 +59,170 @@ class FenxiaoOrder extends BaseModel
}
// //判断几级分销
- dump($fenxiao_basic_config);
- dump($fenxiao_info);
// $parent_fenxiao_info = $level_config >= 2 ? model('fenxiao')->getInfo([ [ 'fenxiao_id', '=', $fenxiao_info[ 'parent' ] ], [ 'is_delete', '=', 0 ] ], 'fenxiao_id, fenxiao_name, status, parent') : [];
// $grand_parent_fenxiao_info = $level_config >= 3 && !empty($parent_fenxiao_info[ 'parent' ]) ? model('fenxiao')->getInfo([ [ 'fenxiao_id', '=', $parent_fenxiao_info[ 'parent' ] ], [ 'is_delete', '=', 0 ] ], 'fenxiao_id, fenxiao_name, status') : [];
$order_goods = model('order_goods')->getList([ [ 'order_id', '=', $order[ 'order_id' ] ], [ 'is_fenxiao', '=', 1 ] ], 'order_goods_id, goods_id, sku_id, sku_name, sku_image, sku_no, is_virtual, price, cost_price, num, goods_money, cost_money, delivery_no, delivery_status, real_goods_money');
if (empty($order_goods)) return $this->success();
model('fenxiao_order')->delete([ [ 'order_id', '=', $order[ 'order_id' ] ] ]);
+
foreach($order_goods as $k => $v){
- $goods_info = model('goods')->getInfo([['goods_id','=',$v['goods_id']]],'is_fenxiao, fenxiao_type');
$order_fenxiao_data = [
+ 'commission' => 0,
+ 'commission_rate' => 0,
'one_rate' => 0,
'one_commission' => 0,
+ 'one_fenxiao_id' => 0,
+ 'one_fenxiao_name' => '',
'two_rate' => 0,
'two_commission' => 0,
+ 'two_fenxiao_id' => 0,
+ 'two_fenxiao_name' => '',
+ 'wholesale_fenxiao_id' => [],
+ 'wholesale_rate' => 0,
+ 'wholesale_commission' => 0,
+ 'wholesale_fenxiao_detail' => [],
];
+ $goods_info = model('goods')->getInfo([['goods_id','=',$v['goods_id']]],'is_fenxiao, fenxiao_type');
//参与了分销商品,有直推间推奖励
if($goods_info['is_fenxiao']){
- $order_fenxiao_data = $this->getPushFenXiaoCommission($fenxiao_info,);
- }else{
-
+ $order_fenxiao_data = $this->getPushFenXiaoCommission($fenxiao_info,$v,$order_fenxiao_data,$goods_info['fenxiao_type'],$fenxiao_basic_config);
}
+
+ $order_fenxiao_data = $this->getWholesaleFenXiaoCommission($fenxiao_info,$v,$order_fenxiao_data);
+
+ $data = [
+ 'order_id' => $order['order_id'],
+ 'order_no' => $order['order_no'],
+ 'order_goods_id' => $v['order_goods_id'],
+ 'site_id' => $order['site_id'],
+ 'site_name' => $order['site_name'],
+ 'goods_id' => $v['goods_id'],
+ 'sku_id' => $v['sku_id'],
+ 'sku_name' => $v['sku_name'],
+ 'sku_image' => $v['sku_image'],
+ 'price' => $v['price'],
+ 'num' => $v['num'],
+ 'real_goods_money' => $v['real_goods_money'],
+ 'member_id' => $order['member_id'],
+ 'member_name' => !empty($order['name']) ? $order['name'] : $member_info['nickname'],
+ 'member_mobile' => !empty($order['mobile']) ? $order['mobile'] : $member_info['mobile'],
+ 'full_address' => $order['full_address'].$order['address'],
+ 'commission' => $order_fenxiao_data['commission'],
+ 'commission_rate' => $order_fenxiao_data['commission_rate'],
+ 'one_fenxiao_id' => $order_fenxiao_data['one_fenxiao_id'],
+ 'one_rate' => $order_fenxiao_data['one_rate'],
+ 'one_commission' => $order_fenxiao_data['one_commission'],
+ 'one_fenxiao_name' => $order_fenxiao_data['one_fenxiao_name'],
+ 'two_fenxiao_id' => $order_fenxiao_data['two_fenxiao_id'],
+ 'two_rate' => $order_fenxiao_data['two_rate'],
+ 'two_commission' => $order_fenxiao_data['two_commission'],
+ 'two_fenxiao_name' => $order_fenxiao_data['two_fenxiao_name'],
+ 'wholesale_fenxiao_id' => json_encode($order_fenxiao_data['wholesale_fenxiao_id']),
+ 'wholesale_rate' => $order_fenxiao_data['wholesale_rate'],
+ 'wholesale_commission' => $order_fenxiao_data['wholesale_commission'],
+ 'wholesale_fenxiao_detail' => json_encode($order_fenxiao_data['wholesale_fenxiao_detail']),
+ 'create_time' => time()
+ ];
+ model("fenxiao_order")->add($data);
}
- // //获取分销等级
- // foreach ($order_goods as $k => $v) {
- // $v[ 'num' ] = numberFormat($v[ 'num' ]);
- // // 判断:是否开启分销
- // if($order['order_from'] == 'cashier'){
- // // 收银台订单
- // $isOpenFenXiao = $fenxiao_basic_config['is_support_cashier'] ?? 0;
- // $fenXiaoType = 1;
- // }else{
- // // 其他订单
- // $goods_info = model('goods')->getInfo([['goods_id','=',$v['goods_id']]],'is_fenxiao, fenxiao_type');
- // $isOpenFenXiao = $goods_info['is_fenxiao'] ?? 0;
- // $fenXiaoType = $goods_info[ 'fenxiao_type' ] ?? 1;
- // }
- // if($isOpenFenXiao != 1) continue;
- // // 配送规格
- // $sku_info = model('goods_sku')->getInfo([ [ 'sku_id', '=', $v[ 'sku_id' ] ] ], 'fenxiao_price');
- // if (!empty($sku_info) && $sku_info[ 'fenxiao_price' ] > 0) $v[ 'real_goods_money' ] = $sku_info[ 'fenxiao_price' ] * $v[ 'num' ];
- // $commission = 0;
- // $commission_rate = 0;
- // $order_fenxiao_data = [
- // 'one_rate' => 0,
- // 'one_commission' => 0,
- // 'two_rate' => 0,
- // 'two_commission' => 0,
- // 'three_rate' => 0,
- // ];
- // if ($fenXiaoType == 2) {
- // // 自定义分销规则
- // $fenxiao_level = model('fenxiao_goods_sku')->getInfo([ [ 'goods_id', '=', $v[ 'goods_id' ] ], [ 'sku_id', '=', $v[ 'sku_id' ] ], [ 'level_id', '=', $fenxiao_info[ 'level_id' ] ] ]);
- // if (empty($fenxiao_level)) continue;
- // if ($fenxiao_info[ 'status' ] == 1) {
- // if ($fenxiao_level[ 'one_rate' ] > 0) {
- // $commission_rate += $order_fenxiao_data[ 'one_rate' ] = $fenxiao_level[ 'one_rate' ];
- // $commission += $order_fenxiao_data[ 'one_commission' ] = $fenxiao_level[ 'one_rate' ] * $v[ 'real_goods_money' ] / 100;
- // } else {
- // $commission_rate += $order_fenxiao_data[ 'one_rate' ] = round($fenxiao_level[ 'one_money' ] * $v[ 'num' ] / $v[ 'real_goods_money' ], 2);
- // $commission += $order_fenxiao_data[ 'one_commission' ] = $fenxiao_level[ 'one_money' ] * $v[ 'num' ];
- // }
- // }
- // if (!empty($parent_fenxiao_info) && $parent_fenxiao_info[ 'status' ] == 1) {
- // if ($fenxiao_level[ 'two_rate' ] > 0) {
- // $commission_rate += $order_fenxiao_data[ 'two_rate' ] = $fenxiao_level[ 'two_rate' ];
- // $commission += $order_fenxiao_data[ 'two_commission' ] = $fenxiao_level[ 'two_rate' ] * $v[ 'real_goods_money' ] / 100;
- // } else {
- // $commission_rate += $order_fenxiao_data[ 'two_rate' ] = round($fenxiao_level[ 'two_money' ] * $v[ 'num' ] / $v[ 'real_goods_money' ], 2);
- // $commission += $order_fenxiao_data[ 'two_commission' ] = $fenxiao_level[ 'two_money' ] * $v[ 'num' ];
- // }
- // }
- // if (!empty($grand_parent_fenxiao_info) && $grand_parent_fenxiao_info[ 'status' ] == 1) {
- // if ($fenxiao_level[ 'three_rate' ] > 0) {
- // $commission_rate += $order_fenxiao_data[ 'three_rate' ] = $fenxiao_level[ 'three_rate' ];
- // $commission += $order_fenxiao_data[ 'three_commission' ] = $fenxiao_level[ 'three_rate' ] * $v[ 'real_goods_money' ] / 100;
- // } else {
- // $commission_rate += $order_fenxiao_data[ 'three_rate' ] = round($fenxiao_level[ 'three_money' ] * $v[ 'num' ] / $v[ 'real_goods_money' ], 2);
- // $commission += $order_fenxiao_data[ 'three_commission' ] = $fenxiao_level[ 'three_money' ] * $v[ 'num' ];
- // }
- // }
- // } else {
- // // 默认规则
- // $fenxiao_level = model('fenxiao_level')->getInfo([ [ 'level_id', '=', $fenxiao_info[ 'level_id' ] ] ]);
- // if ($fenxiao_info[ 'status' ] == 1) {
- // if ($fenxiao_level[ 'one_rate' ] > 0) {
- // $commission_rate += $order_fenxiao_data[ 'one_rate' ] = $fenxiao_level[ 'one_rate' ];
- // $commission += $order_fenxiao_data[ 'one_commission' ] = $fenxiao_level[ 'one_rate' ] * $v[ 'real_goods_money' ] / 100;
- // } else {
- // $order_fenxiao_data[ 'one_rate' ] = 0;
- // $order_fenxiao_data[ 'one_commission' ] = 0;
- // }
- // }
- // if (!empty($parent_fenxiao_info) && $parent_fenxiao_info[ 'status' ] == 1) {
- // if ($fenxiao_level[ 'two_rate' ] > 0) {
- // $commission_rate += $order_fenxiao_data[ 'two_rate' ] = $fenxiao_level[ 'two_rate' ];
- // $commission += $order_fenxiao_data[ 'two_commission' ] = $fenxiao_level[ 'two_rate' ] * $v[ 'real_goods_money' ] / 100;
- // } else {
- // $order_fenxiao_data[ 'two_rate' ] = 0;
- // $order_fenxiao_data[ 'two_commission' ] = 0;
- // }
- // }
- // if (!empty($grand_parent_fenxiao_info) && $grand_parent_fenxiao_info[ 'status' ] == 1) {
- // if ($fenxiao_level[ 'three_rate' ] > 0) {
- // $commission_rate += $order_fenxiao_data[ 'three_rate' ] = $fenxiao_level[ 'three_rate' ];
- // $commission += $order_fenxiao_data[ 'three_commission' ] = $fenxiao_level[ 'three_rate' ] * $v[ 'real_goods_money' ] / 100;
- // } else {
- // $order_fenxiao_data[ 'three_rate' ] = 0;
- // $order_fenxiao_data[ 'three_commission' ] = 0;
- // }
- // }
- // }
- // //启动分销
- // $siteName = model('site')->getValue([
- // ['site_id', '=', $order['site_id']]
- // ], 'site_name');
- // $data = [
- // 'order_id' => $order['order_id'],
- // 'order_no' => $order['order_no'],
- // 'order_goods_id' => $v['order_goods_id'],
- // 'site_id' => $order['site_id'],
- // 'site_name' => $siteName,
- // 'goods_id' => $v['goods_id'],
- // 'sku_id' => $v['sku_id'],
- // 'sku_name' => $v['sku_name'],
- // 'sku_image' => $v['sku_image'],
- // 'price' => $v['price'],
- // 'num' => $v['num'],
- // 'real_goods_money' => $order_goods[$k]['real_goods_money'],
- // 'member_id' => $order['member_id'],
- // 'member_name' => !empty($order['name']) ? $order['name'] : $member_info['nickname'],
- // 'member_mobile' => !empty($order['mobile']) ? $order['mobile'] : $member_info['mobile'],
- // 'full_address' => $order['full_address'].$order['address'],
- // 'commission' => $commission,
- // 'commission_rate' => $commission_rate,
- // 'one_fenxiao_id' => empty($fenxiao_info) ? 0 : $fenxiao_info['fenxiao_id'],
- // 'one_rate' => empty($order_fenxiao_data['one_rate']) ? 0 : $order_fenxiao_data['one_rate'],
- // 'one_commission' => empty($order_fenxiao_data['one_commission']) ? 0 : $order_fenxiao_data['one_commission'],
- // 'one_fenxiao_name' => empty($fenxiao_info) ? '' : $fenxiao_info['fenxiao_name'],
- // 'two_fenxiao_id' => empty($parent_fenxiao_info) ? 0 : $parent_fenxiao_info['fenxiao_id'],
- // 'two_rate' => empty($order_fenxiao_data['two_rate']) ? 0 : $order_fenxiao_data['two_rate'],
- // 'two_commission' => empty($order_fenxiao_data['two_commission']) ? 0 : $order_fenxiao_data['two_commission'],
- // 'two_fenxiao_name' => empty($parent_fenxiao_info) ? '' : $parent_fenxiao_info['fenxiao_name'],
- // 'three_fenxiao_id' => empty($grand_parent_fenxiao_info) ? '' : $grand_parent_fenxiao_info['fenxiao_id'],
- // 'three_rate' => empty($order_fenxiao_data['three_rate']) ? 0 : $order_fenxiao_data['three_rate'],
- // 'three_commission' => empty($order_fenxiao_data['three_commission']) ? 0 : $order_fenxiao_data['three_commission'],
- // 'three_fenxiao_name' => empty($grand_parent_fenxiao_info) ? '' : $grand_parent_fenxiao_info['fenxiao_name'],
- // 'create_time' => time()
- // ];
- //
- // model("fenxiao_order")->add($data);
- // }
+
// // 分销商检测升级
- // event('FenxiaoUpgrade', [
- // 'fenxiao_id' => $member_info[ 'fenxiao_id' ]
- // ]);
+ event('FenxiaoUpgrade', [
+ 'fenxiao_id' => $member_info[ 'fenxiao_id' ]
+ ]);
return $this->success();
}
+ private function getPushFenXiaoCommission($fenxiao_info,$v,&$order_fenxiao_data,$type,$config){
+ if($type == 2){
+ $fenxiao_level = model('fenxiao_goods_sku')->getInfo([ [ 'goods_id', '=', $v[ 'goods_id' ] ], [ 'sku_id', '=', $v[ 'sku_id' ] ], [ 'level_id', '=', $fenxiao_info[ 'level_id' ] ] ]);
+ if (empty($fenxiao_level)) return false;
+ $one_rate = $fenxiao_level['direct_rate'];
+ $one_money = $fenxiao_level['direct_money'];
+ $two_rate = $fenxiao_level['indirect_rate'];
+ $two_money = $fenxiao_level['indirect_money'];
+ }else{
+ $one_rate = $config['direct_rate'];
+ $two_rate = $config['indirect_rate'];
+ $one_money = $two_money = 0;
+ }
+
+ $parent_fenxiao_info = $fenxiao_info['parent'] > 0 ? model('fenxiao')->getInfo([ [ 'fenxiao_id', '=', $fenxiao_info[ 'parent' ] ], [ 'is_delete', '=', 0 ] ], 'fenxiao_id, fenxiao_name, status, parent') : [];
+ if ($fenxiao_info[ 'status' ] == 1) {
+ if ($one_rate > 0) {
+ $order_fenxiao_data['commission_rate'] += $order_fenxiao_data[ 'one_rate' ] = $one_rate;
+ $order_fenxiao_data['commission'] += $order_fenxiao_data[ 'one_commission' ] = $one_rate * $v[ 'real_goods_money' ] / 100;
+ } else {
+ $order_fenxiao_data['commission_rate'] += $order_fenxiao_data[ 'one_rate' ] = round($one_money * $v[ 'num' ] / $v[ 'real_goods_money' ], 2);
+ $order_fenxiao_data['commission'] += $order_fenxiao_data[ 'one_commission' ] = $one_money * $v[ 'num' ];
+ }
+ $order_fenxiao_data['one_fenxiao_id'] = $fenxiao_info['fenxiao_id'];
+ $order_fenxiao_data['one_fenxiao_name'] = $fenxiao_info['fenxiao_name'];
+ }
+ if (!empty($parent_fenxiao_info) && $parent_fenxiao_info[ 'status' ] == 1) {
+ if ($two_rate > 0) {
+ $order_fenxiao_data['commission_rate'] += $order_fenxiao_data[ 'two_rate' ] = $two_rate;
+ $order_fenxiao_data['commission'] += $order_fenxiao_data[ 'two_commission' ] = $two_rate * $v[ 'real_goods_money' ] / 100;
+ } else {
+ $order_fenxiao_data['commission_rate'] += $order_fenxiao_data[ 'two_rate' ] = round($two_money * $v[ 'num' ] / $v[ 'real_goods_money' ], 2);
+ $order_fenxiao_data['commission'] += $order_fenxiao_data[ 'two_commission' ] = $two_money * $v[ 'num' ];
+ }
+ $order_fenxiao_data['two_fenxiao_id'] = $parent_fenxiao_info['fenxiao_id'];
+ $order_fenxiao_data['two_fenxiao_name'] = $fenxiao_info['fenxiao_name'];
+ }
+ return $order_fenxiao_data;
+ }
+
+ private function getWholesaleFenXiaoCommission($fenxiao_info,$v,&$order_fenxiao_data){
+ $order_fenxiao_data['wholesale_fenxiao_id'][] = $fenxiao_info['fenxiao_id'];
+ $order_fenxiao_data['commission_rate'] += $order_fenxiao_data[ 'wholesale_rate' ] = $fenxiao_info[ 'one_rate' ];
+ $commission = $fenxiao_info[ 'one_rate' ] * $v[ 'real_goods_money' ] / 100;
+ $order_fenxiao_data['commission'] += $order_fenxiao_data[ 'wholesale_commission' ] = $commission;
+ $order_fenxiao_data['wholesale_fenxiao_detail'][] = ['name' => $fenxiao_info['fenxiao_name'], 'commission' => $commission];
+ $level_List = model('fenxiao_level')->getList([['site_id', '=' ,$fenxiao_info['site_id']],['level_num' , '>' ,$fenxiao_info['level_num']]],'*','level_num asc');
+ if($fenxiao_info['chain'] && $level_List){
+ $data = explode(',', $fenxiao_info['chain']);
+ $chain = array_filter($data, function ($value) {
+ return !empty($value);
+ });
+ // $count = count($chain);
+ // //要删除最后一个数据,最后一个数据是自己的分销商ID
+ // //因为逗号分割去除空白后最后一个key会被去掉,所以count不需要 - 1;
+ // unset($chain[$count]);
+ $chain = array_values($chain);
+ $nodeUser = Db::name('fenxiao')
+ ->where('f.is_delete', '=', 0)
+ ->alias('f')
+ ->join('fenxiao_level l', 'f.level_id = l.level_id', 'right')
+ ->where('f.fenxiao_id', '<>', $fenxiao_info['fenxiao_id'])
+ ->whereIn('f.fenxiao_id', $chain)
+ ->field('f.fenxiao_id,f.fenxiao_name,f.member_id,f.level_id,f.site_id,f.fenxiao_name,f.status,l.level_num,l.one_rate,l.two_rate')
+ ->select(); //获取上级用户
+ $nodeUser = $nodeUser ? $nodeUser->toArray() : [];
+ if(count($nodeUser) > 0){
+ $order_fenxiao_data = $this->getWholesaleCommission($nodeUser,$v,$order_fenxiao_data,$level_List);
+ }
+ }
+ return $order_fenxiao_data;
+ }
+
+ protected function getWholesaleCommission($nodeUser,$v,&$order_fenxiao_data,$level_List){
+ //不考虑商品单独规则
+ $fenxiao_user_level_num = array_column($nodeUser,'level_num');
+ foreach($level_List as $key => $val){
+ $search = array_search($val['level_num'],$fenxiao_user_level_num);
+ if($search){
+ $order_fenxiao_data['wholesale_fenxiao_id'][] = $nodeUser[$search]['fenxiao_id'];
+ $order_fenxiao_data['commission_rate'] += $order_fenxiao_data[ 'wholesale_rate' ] += $val[ 'two_rate' ];
+ $commission = $val[ 'two_rate' ] * $v[ 'real_goods_money' ] / 100;
+ $order_fenxiao_data['commission'] += $order_fenxiao_data[ 'wholesale_commission' ] += $commission;
+ $order_fenxiao_data['wholesale_fenxiao_detail'][] = ['name' => $nodeUser[$search]['fenxiao_name'], 'commission' => $commission];
+ }
+ }
+ return $order_fenxiao_data;
+ }
+
/**
* 订单退款
* @param $order_goods_id
diff --git a/addon/fenxiao/shop/controller/Config.php b/addon/fenxiao/shop/controller/Config.php
index 4f595db..aa94272 100644
--- a/addon/fenxiao/shop/controller/Config.php
+++ b/addon/fenxiao/shop/controller/Config.php
@@ -49,6 +49,8 @@ class Config extends BaseShop
'one_rate' => input('one_rate', 0.00),
'two_rate' => input('two_rate', 0.00),
'three_rate' => input('three_rate', 0.00),
+ 'direct_rate' => input('direct_rate', 0.00),
+ 'indirect_rate' => input('indirect_rate', 0.00),
'is_support_cashier' => input('is_support_cashier', 0)
];
diff --git a/addon/fenxiao/shop/controller/Goods.php b/addon/fenxiao/shop/controller/Goods.php
index e938e2f..0cd0baa 100644
--- a/addon/fenxiao/shop/controller/Goods.php
+++ b/addon/fenxiao/shop/controller/Goods.php
@@ -8,6 +8,7 @@
* =========================================================
*/
namespace addon\fenxiao\shop\controller;
+use addon\fenxiao\model\Config;
use addon\fenxiao\model\FenxiaoGoodsSku as FenxiaoGoodsSkuModel;
use addon\fenxiao\model\FenxiaoLevel as FenxiaoLevelModel;
use app\model\goods\Goods as GoodsModel;
@@ -120,14 +121,14 @@ class Goods extends BaseShop
$fenxiao_skus = input('fenxiao', []);
$is_fenxiao = input('is_fenxiao', 0);
$fenxiao_price = input('fenxiao_price', []);
-
+ $default_level_id = model('fenxiao_level')->getValue([['site_id', '=' , $this->site_id],['level_num' ,'=' ,0]],'level_id');
$goods_data = [ 'is_fenxiao' => $is_fenxiao, 'fenxiao_type' => $fenxiao_type ];
if ($fenxiao_type == 2) {
$fenxiao_goods_sku_data = [];
foreach ($fenxiao_skus as $level_id => $level_data) {
foreach ($level_data[ 'sku_id' ] as $key => $sku_id) {
$fenxiao_total = 0;
- $fenxiao_level = [ 'one', 'two', 'three' ];
+ $fenxiao_level = [ 'one', 'two', 'three', 'direct', 'indirect' ];
foreach ($fenxiao_level as $level) {
$item_rate_array = $level_data[ $level . '_rate' ] ?? [];
$item_rate = $item_rate_array[ $key ] ?? 0;
@@ -143,7 +144,7 @@ class Goods extends BaseShop
$fenxiao_total += $item_money;
}
}
- if (empty($fenxiao_total)) {
+ if (empty($fenxiao_total) && $level_id != $default_level_id) {
return error(-1, '分销金额不可以为零');
}
if ($level_data[ 'sku_price' ][ $key ] < $fenxiao_total) {
@@ -169,6 +170,10 @@ class Goods extends BaseShop
'two_money' => $two_money ?? 0,
'three_rate' => $three_rate ?? 0,
'three_money' => $three_money ?? 0,
+ 'direct_rate' => $direct_rate ?? 0,
+ 'direct_money' => $direct_money ?? 0,
+ 'indirect_rate' => $indirect_rate ?? 0,
+ 'indirect_money' => $indirect_money ?? 0,
];
$fenxiao_goods_sku_data[] = $fenxiao_sku;
}
@@ -178,6 +183,10 @@ class Goods extends BaseShop
}
if ($fenxiao_type == 1) {
$fenxiao_goods_sku_data = [];
+ $config_model = new Config();
+ $fenxiao_basic_config = $config_model->getFenxiaoBasicsConfig($this->site_id)[ 'data' ][ 'value' ];
+ $direct_rate = $fenxiao_basic_config['direct_rate'];
+ $indirect_rate = $fenxiao_basic_config['indirect_rate'];
foreach ($fenxiao_level[ 'data' ] as $level) {
foreach ($goods_info[ 'data' ][ 'sku_data' ] as $sku) {
$item_one_rate = $level[ 'one_rate' ] ?? 0;
@@ -200,6 +209,10 @@ class Goods extends BaseShop
'two_money' => 0,
'three_rate' => $item_three_rate,
'three_money' => 0,
+ 'direct_rate' => $direct_rate,
+ 'direct_money' => 0,
+ 'indirect_rate' => $indirect_rate,
+ 'indirect_money' => 0,
];
$fenxiao_goods_sku_data[] = $fenxiao_sku;
}
@@ -265,4 +278,4 @@ class Goods extends BaseShop
return $fenxiao_goods_model->modifyGoodsIsFenxiao($goods_ids, $is_fenxiao, $this->site_id);
}
}
-}
\ No newline at end of file
+}
diff --git a/addon/fenxiao/shop/view/config/basics.html b/addon/fenxiao/shop/view/config/basics.html
index b9a76b7..2161d28 100644
--- a/addon/fenxiao/shop/view/config/basics.html
+++ b/addon/fenxiao/shop/view/config/basics.html
@@ -217,24 +217,24 @@
-
会员购买后给对应分销商的返佣比例
+
会员购买后给对应分销商的默认直推返佣比例