|
|
@@ -18,6 +18,7 @@ use LinFly\Annotation\Attributes\Route\PostMapping;
|
|
|
use support\Request;
|
|
|
use support\Response;
|
|
|
use function DI\get;
|
|
|
+use function Laravel\Prompts\number;
|
|
|
|
|
|
|
|
|
#[Controller("/api/merchant/plan"),Middleware(AuthMiddleware::class)]
|
|
|
@@ -71,7 +72,7 @@ class Plan extends Base
|
|
|
$liveDyStar = $liveDyGoods = [];
|
|
|
foreach ($goodsData as $k => $v) {
|
|
|
$liveDyGoods[$k] = [
|
|
|
- "commission_rate" => $v['rate'] * 100,
|
|
|
+ "commission_rate" => round($v['rate'] * 100),
|
|
|
"product_id" => $v['goods_id'],
|
|
|
];
|
|
|
}
|
|
|
@@ -170,28 +171,106 @@ class Plan extends Base
|
|
|
$plan = $this->model->where("id",$param['id'])->findOrEmpty();
|
|
|
if ($plan->isEmpty()) return errorTrans("empty.data");
|
|
|
if ($plan['poi_id'] <> $request->user['store_id']) return error("非法操作"); // return errorTrans("empty.data");
|
|
|
- print_r($param);
|
|
|
- return errorTrans("error.data");
|
|
|
-// $goods = (new SaasLivePlanGoods)->where(['plan_id' => $plan['plan_id'],'goods_id' => $param['goods_id']])->findOrEmpty();
|
|
|
-// if ($goods->isEmpty()) return error("商品不存在"); // return errorTrans("empty.data");
|
|
|
-// $resp = (new PlanLive)->config([
|
|
|
-// "appid" => sConf("wechat.mini_appid"),
|
|
|
-// "secret" => sConf("wechat.mini_secret"),
|
|
|
-// ])->token()->planData($plan['plan_id'],[
|
|
|
-// 'name' => $plan['plan_name'],
|
|
|
-// 'mobile' => $plan['merchant_phone'],
|
|
|
-// 'goods' => [
|
|
|
-// [
|
|
|
-// "commission_rate" => $param['commission_rate'] * 100,
|
|
|
-// "product_id" => $param['goods_id']
|
|
|
-// ]
|
|
|
-// ],
|
|
|
-// ]);
|
|
|
-// print_r($resp);
|
|
|
-// if (isset($resp['msg'])) return error($resp['msg']);
|
|
|
-// $state = $goods->save(['commission_rate' => $param['commission_rate']]);
|
|
|
-// if (!$state) return errorTrans("error.data");
|
|
|
-// return successTrans("success.data");
|
|
|
+ $planData = is_string($param['data']) ? json_decode($param['data'],true) : $param['data'];
|
|
|
+ $editData = [];
|
|
|
+ $editPlanData = [
|
|
|
+ 'name' => $plan['plan_name'],
|
|
|
+ 'mobile' => $plan['merchant_phone'],
|
|
|
+ ];
|
|
|
+ if ($param['type'] == 'goods') {
|
|
|
+ foreach ($planData as $k => $v) {
|
|
|
+ $commission_rate = $v['commission_rate'] * 100;
|
|
|
+ echo $commission_rate."\n";
|
|
|
+ $editData[$k] = [
|
|
|
+ "commission_rate" => round($commission_rate),
|
|
|
+ "product_id" => $v['goods_id'],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ $editPlanData['goods'] = $editData;
|
|
|
+ }
|
|
|
+ if ($param['type'] == 'star') {
|
|
|
+ foreach ($planData as $k => $v) {
|
|
|
+ $editData[$k] = $v['unique_id'];
|
|
|
+ }
|
|
|
+ $editPlanData['star'] = $editData;
|
|
|
+ }
|
|
|
+ $resp = (new PlanLive)->config([
|
|
|
+ "appid" => sConf("wechat.mini_appid"),
|
|
|
+ "secret" => sConf("wechat.mini_secret"),
|
|
|
+ ])->token()->planData($plan['plan_id'],$editPlanData);
|
|
|
+ if (isset($resp['msg'])) return error($resp['msg']);
|
|
|
+ $goodsAll = $starAll = [];
|
|
|
+ $state = false;
|
|
|
+ if ($param['type'] == 'goods') {
|
|
|
+ (new SaasLivePlanGoods)->where("plan_id",$plan['plan_id'])->delete();
|
|
|
+ foreach ($planData as $k => $v) {
|
|
|
+ $goodsAll[$k] = [
|
|
|
+ "plan_id" => $resp['plan_id'],
|
|
|
+ "goods_id" => $v['goods_id'],
|
|
|
+ "commission_rate" => $v['commission_rate'],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ $state = (new SaasLivePlanGoods)->insertAll($goodsAll);
|
|
|
+ }
|
|
|
+ if ($param['type'] == 'star') {
|
|
|
+ (new SaasLivePlanStar)->where("plan_id",$plan['plan_id'])->delete();
|
|
|
+ foreach ($planData as $k => $v) {
|
|
|
+ $starAll[$k] = [
|
|
|
+ "plan_id" => $resp['plan_id'],
|
|
|
+ "unique_id" => $v
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ $state = (new SaasLivePlanStar)->insertAll($starAll);
|
|
|
+ }
|
|
|
+ if (!$state) return errorTrans("error.data");
|
|
|
+ return successTrans("success.data");
|
|
|
+ } catch (\Throwable $throwable) {
|
|
|
+ return error($throwable->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ #[PostMapping('close')]
|
|
|
+ public function closePlan(Request $request): Response
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ $param = $this->_valid([
|
|
|
+ "id.require" => trans("empty.require"),
|
|
|
+ ],$request->method());
|
|
|
+ if (!is_array($param)) return error($param);
|
|
|
+ $plan = $this->model->where("id",$param['id'])->findOrEmpty();
|
|
|
+ if ($plan->isEmpty()) return errorTrans("empty.data");
|
|
|
+ if ($plan['poi_id'] <> $request->user['store_id']) return error("非法操作");
|
|
|
+ $resp = (new PlanLive)->config([
|
|
|
+ "appid" => sConf("wechat.mini_appid"),
|
|
|
+ "secret" => sConf("wechat.mini_secret"),
|
|
|
+ ])->token()->planClose($plan['plan_id']);
|
|
|
+ if (isset($resp['msg'])) return error($resp['msg']);
|
|
|
+ $plan->status = 2;
|
|
|
+ $state = $plan->save();
|
|
|
+ if (!$state) return errorTrans("error.data");
|
|
|
+ return successTrans("success.data");
|
|
|
+ } catch (\Throwable $throwable) {
|
|
|
+ return error($throwable->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ #[PostMapping('del')]
|
|
|
+ public function delPlan(Request $request): Response
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ $param = $this->_valid([
|
|
|
+ "id.require" => trans("empty.require"),
|
|
|
+ ],$request->method());
|
|
|
+ if (!is_array($param)) return error($param);
|
|
|
+ $plan = $this->model->where("id",$param['id'])->findOrEmpty();
|
|
|
+ if ($plan->isEmpty()) return errorTrans("empty.data");
|
|
|
+ if ($plan['poi_id'] <> $request->user['store_id']) return error("非法操作");
|
|
|
+ if ($plan['status'] <> 2) return error("该计划暂不支持删除");
|
|
|
+ $state = $plan->delete();
|
|
|
+ if (!$state) return errorTrans("error.data");
|
|
|
+ return successTrans("success.data");
|
|
|
} catch (\Throwable $throwable) {
|
|
|
return error($throwable->getMessage());
|
|
|
}
|