|
|
@@ -3,8 +3,11 @@
|
|
|
namespace app\controller\merchant;
|
|
|
|
|
|
use app\extra\basic\Base;
|
|
|
+use app\extra\dyMini\PlanLive;
|
|
|
use app\middleware\AuthMiddleware;
|
|
|
use app\model\saas\SaasLivePlan;
|
|
|
+use app\model\saas\SaasLivePlanGoods;
|
|
|
+use app\model\saas\SaasLivePlanStar;
|
|
|
use app\service\saas\PlanService;
|
|
|
use DI\Attribute\Inject;
|
|
|
use LinFly\Annotation\Attributes\Route\Controller;
|
|
|
@@ -51,21 +54,71 @@ class Plan extends Base
|
|
|
$param = $this->_valid([
|
|
|
"plan_name.require" => trans("empty.require"),
|
|
|
"merchant_phone.require" => trans("empty.require"),
|
|
|
+ "merchant_phone.mobile" => trans("error.mobile"),
|
|
|
"status.require" => trans("empty.require"),
|
|
|
"goods.require" => trans("empty.require"),
|
|
|
"star.require" => trans("empty.require"),
|
|
|
"plan_id.default" => 0,
|
|
|
],$request->method());
|
|
|
if (!is_array($param)) return error($param);
|
|
|
+ $goodsData = is_string($param['goods']) ? json_decode($param['goods'],true) : $param['goods'];
|
|
|
+ $starData = is_string($param['star']) ? json_decode($param['star'],true) : $param['star'];
|
|
|
$plan = $this->model->where("plan_id",$param['plan_id'])->findOrEmpty();
|
|
|
+ $liveDyStar = $liveDyGoods = [];
|
|
|
+ foreach ($goodsData as $k => $v) {
|
|
|
+ $liveDyGoods[$k] = [
|
|
|
+ "commission_rate" => $v['rate'] * 100,
|
|
|
+ "product_id" => $v['goods_id'],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ foreach ($starData as $k => $v) {
|
|
|
+ $liveDyStar[$k] = $v['unique_id'];
|
|
|
+ }
|
|
|
+ $resp = (new PlanLive)->config([
|
|
|
+ "appid" => sConf("wechat.mini_appid"),
|
|
|
+ "secret" => sConf("wechat.mini_secret"),
|
|
|
+ ])->token()->planData($param['plan_id'],['name' => $param['plan_name'],'mobile' => $param['merchant_phone'],'goods' => $liveDyGoods,'star' => $liveDyStar]);
|
|
|
+ if (isset($resp['msg'])) return error($resp['msg']);
|
|
|
+ if (!isset($resp['plan_id'])) return error("发布直播计划失败");
|
|
|
if ($plan->isEmpty()) { // 新增
|
|
|
-
|
|
|
+ $state = $plan->insertGetId([
|
|
|
+ "plan_id" => $resp['plan_id'],
|
|
|
+ "poi_id" => $request->user['store_id'],
|
|
|
+ "plan_name" => $param['plan_name'],
|
|
|
+ "merchant_phone" => $param['merchant_phone'],
|
|
|
+ "status" => $param['status'],
|
|
|
+ ]);
|
|
|
} else { // 编辑
|
|
|
-
|
|
|
+ (new SaasLivePlanGoods)->where("plan_id",$resp['plan_id'])->delete();
|
|
|
+ (new SaasLivePlanStar)->where("plan_id",$resp['plan_id'])->delete();
|
|
|
+ $state = $plan->save([
|
|
|
+ "plan_name" => $param['plan_name'],
|
|
|
+ "merchant_phone" => $param['merchant_phone'],
|
|
|
+ "status" => $param['status'],
|
|
|
+ ]);
|
|
|
}
|
|
|
+ $goodsAll = $starAll = [];
|
|
|
+ foreach ($liveDyGoods as $k => $v) {
|
|
|
+ $goodsAll[$k] = [
|
|
|
+ "plan_id" => $resp['plan_id'],
|
|
|
+ "goods_id" => $v['product_id'],
|
|
|
+ "commission_rate" => $v['commission_rate'] / 100,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ (new SaasLivePlanGoods)->insertAll($goodsAll);
|
|
|
+ foreach ($liveDyStar as $k => $v) {
|
|
|
+ $starAll[$k] = [
|
|
|
+ "plan_id" => $resp['plan_id'],
|
|
|
+ "unique_id" => $v
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ (new SaasLivePlanStar)->insertAll($starAll);
|
|
|
+ if (!$state) return errorTrans("error.data");
|
|
|
+ return successTrans("success.data");
|
|
|
} catch (\Throwable $throwable) {
|
|
|
return error($throwable->getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
}
|