PosterController.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. <?php
  2. namespace api\modules\v1\controllers;
  3. use api\controllers\OnAuthController;
  4. use api\modules\v1\forms\user\AlipayMiniForm;
  5. use common\components\export\CsvTool;
  6. use common\enums\DiyEnum;
  7. use common\enums\RabbitMqEnum;
  8. use common\enums\RedisKeyEnum;
  9. use common\enums\StatusEnum;
  10. use common\events\census\ShareEvent;
  11. use common\globals\GlobalInvoke;
  12. use common\helpers\ApiCode;
  13. use common\models\common\Attachment;
  14. use common\models\common\PosterCode;
  15. use common\models\goods\Goods;
  16. use common\models\mall\MallAddons;
  17. use common\models\mall\Poster;
  18. use common\models\user\User;
  19. use common\models\user\UserSignAgreement;
  20. use Grafika\Grafika;
  21. use Grafika\Color;
  22. use Yii;
  23. use yii\helpers\Json;
  24. /**
  25. * 海报控制器
  26. *
  27. *
  28. * Class PosterController
  29. * @package frontend\controllers
  30. */
  31. class PosterController extends OnAuthController
  32. {
  33. public $enableCsrfValidation = false;
  34. public $modelClass = '';
  35. /**
  36. * 不用进行登录验证的方法
  37. *
  38. * 例如: ['index', 'update', 'create', 'view', 'delete']
  39. * 默认全部需要验证
  40. *
  41. * @var array
  42. */
  43. protected $authOptional = ['poster-code-detail','get-share-content', 'upload-poster'];
  44. /**
  45. * 获取海报
  46. * @return mixed|void
  47. */
  48. public function actionIndex()
  49. {
  50. $retuest = Yii::$app->request;
  51. if ($retuest->isGet) {
  52. $params = \Yii::$app->request->get();
  53. $res = \Yii::$app->services->validate->validate($params, [
  54. [['source'], 'required'],
  55. [['goods_id','source','open_group_id','bargain_order_id','active_id','activity_id','lucky_group_activity_id'], 'integer'],
  56. [['extra'],'safe']
  57. ]);
  58. if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  59. $mallId = $this->mall_id;
  60. $sign = $this->mall['mall_sign'];
  61. // 获取个人信息
  62. $data['user_id'] = $this->user->id ?? '';
  63. $data['nickname'] = $this->user->nickname ?? '';
  64. $data['avatar_url'] = $this->user->avatar_url ?? '';
  65. $save_content = ['pid' => $data['user_id'],'invite_mobile'=>$this->user->mobile, 'mall_id' => $mallId, 'source' => $params['source']];// 分享码保存的基本信息
  66. // 根据来源获取不同分享内容
  67. $params['data'] = $data;
  68. if($params['source']==User::SOURCE_SHARE_GOODS){
  69. $goods = Goods::getOne([['id' => $params['goods_id'], 'mall_id' => $mallId]],true,[],false,'id as item_id,goods_name as share_title,price,original_price,cover_pic as share_img');
  70. $data = array_merge($data, $goods);
  71. $save_content['item_id'] = $goods['item_id'];
  72. $save_content['activity_id'] = $params['activity_id']??0;
  73. $page = DiyEnum::GOODS_DETAIL_PATH;
  74. }else{
  75. //['page' => $page, 'data' => $data]
  76. $params['mall_id'] = $this->mall_id;
  77. $params['level'] = $this->user['level'];
  78. $return = GlobalInvoke::exec(GlobalInvoke::INVOKE_GET_POSTER,$this->mall_id,$params);
  79. if(!empty($return['page'])) $page = $return['page'];
  80. if(!empty($return['data'])) $data = $return['data'];
  81. if(!empty($return['save_content'])) $save_content = array_merge($save_content,$return['save_content']);
  82. }
  83. if(!empty($params['extra'])){
  84. $extra = json_decode($params['extra'],true);
  85. if(is_array($extra)){
  86. $save_content = array_merge($save_content,$extra);
  87. }
  88. }
  89. // 查询获取数据
  90. $poster = PosterCode::setData($this->mall_id, $this->user->id, $params['source'], $save_content);
  91. if ($poster == false) return $this->error(PosterCode::getStaticError());
  92. $data['qrcode_url'] = $page . "?sign={$sign}&scene=" . $poster['code'];
  93. // 判断平台是否需要后端生成分享海报
  94. if (in_array($this->platform, [User::PLATFORM_WECHAT,User::PLATFORM_MP_WX,User::PLATFORM_H5,User::PLATFORM_APP,User::PLATFORM_MP_ALI])) {
  95. // 小程序生成二维码
  96. if ($this->platform == User::PLATFORM_MP_WX) {
  97. $applet_url = $this->getAppletQrCode($page, $poster['code']);// 获取小程序二维码
  98. if ($applet_url == false) return $this->error('获取小程序二维码失败');
  99. $data['applet_url'] = $applet_url;
  100. }
  101. if($this->platform == User::PLATFORM_MP_ALI){
  102. // 获取支付宝小程序二维码
  103. $applet_url = $this->getMpAliAppletQrCode($page, "sign={$sign}&scene=" . $poster['code'],$data['share_title'] ?? '');
  104. if ($applet_url == false) return $this->error('获取支付宝小程序二维码失败');
  105. $data['applet_url'] = $applet_url;
  106. }
  107. // TODO 其他平台海报由后台生成
  108. }
  109. //浏览
  110. $event = new ShareEvent($this->mall_id);
  111. \Yii::$app->services->events->dispatch($event, ['mall_id'=>$this->mall_id,'user_id'=>$this->user_id], $event->listeners);
  112. $this->success('获取成功1', $data);
  113. }
  114. }
  115. function base64_image_content($base64_image_content,$path, $fileName = ''){
  116. try {
  117. //匹配出图片的格式
  118. if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $base64_image_content, $result)){
  119. $type = $result[2];
  120. if(!file_exists($path)){
  121. //检查是否有该文件夹,如果没有就创建,并给予最高权限
  122. mkdir($path, 0777, true);
  123. }
  124. $fileName = !empty($fileName) ? $fileName : md5(microtime(true));
  125. if (file_put_contents($path . '/' . $fileName. ".{$type}", base64_decode(str_replace($result[1],'', $base64_image_content)))){
  126. return $fileName . ".{$type}";
  127. }else{
  128. return false;
  129. }
  130. }else{
  131. return false;
  132. }
  133. } catch (\Exception $e) {
  134. // echo $e->getMessage();
  135. return false;
  136. }
  137. }
  138. /**
  139. * 海报分享
  140. * @Author: lun
  141. * @DateTime: 2021/12/24 0024 15:19
  142. * @Copyright: copyright (c) 2021 广东七件事集团
  143. * @return mixed|void
  144. */
  145. public function actionShareList()
  146. {
  147. $retuest = Yii::$app->request;
  148. if ($retuest->isPost) {
  149. $mall_id = $this->mall_id;
  150. $sign = $this->mall['mall_sign'];
  151. $where[] = ['=', 'status', StatusEnum::ENABLED];
  152. $where[] = ['=', 'mall_id', $mall_id];
  153. $select = "id,name,key_word,poster_content";
  154. $params = ['where' => $where, 'order' => 'sort desc, id desc', 'select' => $select];
  155. $list = Poster::lists($params);
  156. if (empty($list)) return $this->success('获取成功', $list);
  157. $setting = Yii::$app->services->setting->mall->get($this->mall_id, 'user');
  158. $is_scan_code_to_app = 0;
  159. if($is_scan_code_to_app == User::PLATFORM_H5){
  160. $is_scan_code_to_app = $setting['is_scan_code_to_app'] ?? $is_scan_code_to_app;
  161. } elseif ($is_scan_code_to_app == User::PLATFORM_APP){
  162. $is_scan_code_to_app = $setting['is_scan_code_to_h5'] ?? $is_scan_code_to_app;
  163. }
  164. foreach ($list as $key => $item) {
  165. $data = [
  166. 'user_id' => $this->user->id,
  167. 'pid' => $this->user->id,
  168. 'nickname' => $this->user->nickname,
  169. // 'avatar_url' => $this->user->avatar_url,
  170. 'item_id' => $item['id'],
  171. ];
  172. // 生成海报对应码
  173. $select_code = "id,mall_id,user_id,source,code,content,applet_code";
  174. if ($key == 0) $select_code.= ",applet_code";
  175. $poster = PosterCode::setData($this->mall_id, $this->user->id, User::SOURCE_SHARE_POSTER, $data, $select_code);
  176. if ($poster == false) return $this->error(PosterCode::getStaticError());
  177. $list[$key]['poster_code_id'] = $poster['id'];
  178. // 检查商城是否安装了门店管家插件,如果已安装则使用门店管家模板路径
  179. $storeStewardSystem = Yii::$app->services->setting->addons->get($this->mall_id, 'StoreSteward', 'basic');
  180. if (MallAddons::isInstall($mall_id, 'StoreSteward') && !empty($storeStewardSystem['index_type'])) {
  181. $prefix_path = DiyEnum::STORE_GUARDIAN_TEMPLATE;
  182. } else {
  183. $prefix_path = $is_scan_code_to_app == 0 ? DiyEnum::HOME_PAGE_PATH : DiyEnum::APP_DOWNLOAD_GUIDE;
  184. }
  185. $list[$key]['qrcode_url'] = $prefix_path . "?sign={$sign}&scene=" . $poster['code'];
  186. // 第一张图片请求获取小程序二维码
  187. if ($this->platform == User::PLATFORM_MP_WX && $key == 0 && empty($poster['applet_code'])) {
  188. $applet_url = $this->getAppletQrCode(DiyEnum::HOME_PAGE_PATH , $poster['code']);// 获取小程序二维码base64数据
  189. if ($applet_url == false) return $this->error('获取小程序二维码失败');
  190. $list[$key]['applet_code'] = $applet_url;
  191. PosterCode::setData($this->mall_id, $this->user->id, User::SOURCE_SHARE_POSTER, array_merge($data,['id' => $poster['id'], 'applet_code' => $applet_url]), $select_code);
  192. }
  193. if ($key == 0) {
  194. // 统计浏览次数
  195. Poster::updateAllCounters(['look_num' => 1],"id=" . $item['id']);
  196. }
  197. $list[$key]['is_scan_code_to_app'] = $is_scan_code_to_app;
  198. }
  199. //浏览
  200. $event = new ShareEvent($this->mall_id);
  201. $data['mall_id'] =$this->mall_id;
  202. \Yii::$app->services->events->dispatch($event, ['mall_id'=>$this->mall_id,'user_id'=>$this->user_id], $event->listeners);
  203. $this->success('获取成功', $list);
  204. }
  205. }
  206. /**
  207. * 根据分享码获取分享内容
  208. * @Author: lun
  209. * @DateTime: 2022/1/14 0014 17:28
  210. * @Copyright: copyright (c) 2021 广东七件事集团
  211. * @return mixed|void
  212. */
  213. public function actionGetShareContent()
  214. {
  215. $retuest = Yii::$app->request;
  216. if ($retuest->isPost) {
  217. $params = Yii::$app->request->post();
  218. $res = Yii::$app->services->validate->validate($params, [
  219. [['scene'], 'string'],
  220. ]);
  221. if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  222. $cache = Yii::$app->cache;
  223. $cache_key = RedisKeyEnum::suffix(RedisKeyEnum::POSTER_CODE , "M{$this->mall_id}" . $params['scene'],true);
  224. $content = $cache->get($cache_key);
  225. $data = empty($content) ? [] : Json::decode($content, true);
  226. // 缓存无法读取小程序码内容,则直接读取数据库
  227. if (empty($data)) $data = PosterCode::getShareByScene($this->mall_id, $params['scene']);
  228. if(isset($data['user_id'])) $data['share_user_id'] = $data['pid'] = $data['user_id'];
  229. if($data && $data['pid'] > 0 && $this->user_id && $data['pid'] != $this->user_id){
  230. //查询用户是否有上级
  231. $where[] = ['mall_id' => $this->mall_id];
  232. $where[] = ['id' => $this->user_id];
  233. $user = User::getUser($where);
  234. if($user && $user->temp_parent_id >= 0 && empty($user->parent_id) && $user->temp_parent_id != $data['pid']){
  235. $user->temp_parent_id = $data['pid'];
  236. $user->save();
  237. }
  238. }
  239. if (!empty($data['store_id'])) $data['marketing_type'] = 'Store';
  240. $this->success('获取成功', $data, ApiCode::CODE_SUCCESS, JSON_BIGINT_AS_STRING);
  241. }
  242. }
  243. /**
  244. * 获取海报码详情
  245. * @Author: lun
  246. * @DateTime: 2021/12/30 0030 14:07
  247. * @Copyright: copyright (c) 2021 广东七件事集团
  248. * @return mixed|void
  249. */
  250. public function actionPosterCodeDetail()
  251. {
  252. $retuest = Yii::$app->request;
  253. if ($retuest->isPost) {
  254. $params = \Yii::$app->request->post();
  255. $res = \Yii::$app->services->validate->validate($params, [
  256. [['scene'], 'string'],
  257. [['poster_code_id'], 'integer'],
  258. ]);
  259. if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  260. $mall_id = $this->mall_id;
  261. $is_save = false;
  262. !empty($params['poster_code_id']) && $where['id'] = $params['poster_code_id'];
  263. $where['mall_id'] = $mall_id;
  264. !empty($params['scene']) && $where['code'] = $params['scene'];
  265. $where['status'] = StatusEnum::ENABLED;
  266. $select = "id,applet_code,source,item_id,source,content,code,store_id";
  267. $detail = PosterCode::find()->select($select)->where($where)->one();
  268. if (empty($detail)) return $this->error('暂无内容');
  269. // 检查客户是否拥有推广资格
  270. $allow_inviter = 1;// 是否允许推广【0=不允许,1=允许】
  271. $inviter_msg = [];// 邀请条件
  272. if (!empty($this->user) && empty($this->user['is_inviter'])) {
  273. list($allow_inviter, $inviter_msg) = User::getInviterMsg($this->mall_id, $allow_inviter);
  274. }
  275. if (!empty($params['poster_code_id']) && empty($detail['applet_code']) && $allow_inviter == 1) {
  276. // 小程序二维码为空则去获取小程序二维码
  277. if ($this->platform == User::PLATFORM_MP_WX) {
  278. // 检查商城是否安装了门店管家插件,如果已安装则使用门店管家模板路径
  279. $storeStewardSystem = Yii::$app->services->setting->addons->get($this->mall_id, 'StoreSteward', 'basic');
  280. if (MallAddons::isInstall($mall_id, 'StoreSteward') && !empty($storeStewardSystem['index_type'])) {
  281. $prefix_path = DiyEnum::STORE_GUARDIAN_TEMPLATE;
  282. } else {
  283. $prefix_path = DiyEnum::HOME_PAGE_PATH;
  284. }
  285. $applet_url = $this->getAppletQrCode($prefix_path, $detail['code']);// 获取小程序二维码base64数据
  286. if ($applet_url == false) $this->error('获取小程序二维码失败');
  287. // 获取到base64将其临时存服务器
  288. $detail->applet_code = $applet_url;
  289. $is_save = true;
  290. }
  291. if($this->platform == User::PLATFORM_MP_ALI){
  292. // 获取支付宝小程序二维码
  293. $sign = $this->mall['mall_sign'];
  294. $applet_url = $this->getMpAliAppletQrCode(DiyEnum::HOME_PAGE_PATH, "sign={$sign}&scene=" . $detail['code'],'海报分享');
  295. if ($applet_url == false) return $this->error('获取支付宝小程序二维码失败');
  296. $detail->applet_code = $applet_url;
  297. $is_save = true;
  298. }
  299. }
  300. // 统计浏览次数
  301. if (!empty($params['poster_code_id'])) {
  302. Poster::updateAllCounters(['look_num' => 1],"id=" . $detail->item_id);
  303. }
  304. // 统计海报扫码次数
  305. if (!empty($params['scene']) && $detail['source'] == User::SOURCE_SHARE_POSTER) {
  306. Poster::updateAllCounters(['scan_code_num' => 1],"id=" . $detail->item_id);
  307. }
  308. // 保存数据
  309. if ($is_save && !$detail->save()) return $this->error("获取错误:" . PosterCode::getStaticError());
  310. // 解析json
  311. $content = Json::decode($detail['content'], true);
  312. if (!empty($content['user_id'])) {
  313. $content = array_merge(['share_user_id' => $content['user_id']], $content);
  314. $user = User::findOne(['id'=>$content['user_id']]);
  315. $content['invite_mobile'] = $user['mobile']??'';
  316. $detail['content'] = Json::encode($content);
  317. }
  318. $detail = $detail->toArray();
  319. $detail['allow_inviter'] = $allow_inviter;
  320. $detail['inviter_msg'] = $inviter_msg;
  321. $this->success('获取成功', $detail);
  322. }
  323. }
  324. /**
  325. * 获取小程序二维码
  326. * @Author: lun
  327. * @DateTime: 2021/12/27 0027 17:25
  328. * @Copyright: copyright (c) 2021 广东七件事集团
  329. * @param $page
  330. * @param $scene
  331. * @return mixed|void
  332. */
  333. public function getAppletQrCode($page, $scene)
  334. {
  335. $page = ltrim($page, '/');
  336. $url = '';
  337. /** @var Wechat $wechat */
  338. Yii::$app->params['wechatMiniProgramConfig'] = Yii::$app->services->setting->mall->get($this->mall_id, 'mini_program');
  339. $miniProgram = Yii::$app->wechat->miniProgram;
  340. $response = $miniProgram->app_code->getUnlimit($scene, ['width' => 200, 'page' => $page]);
  341. if ($response instanceof \EasyWeChat\Kernel\Http\StreamResponse) {
  342. if (in_array('image/jpeg', $response->getHeader('Content-Type'))) {
  343. //返回base64图片
  344. $content = 'data:image/jpg;base64,'. base64_encode($response->getBody()->getContents());
  345. $path = Yii::getAlias('@attachment') . '/download/qrcode';
  346. if (!file_exists($path)) {// 异步生成小程序图片文件夹
  347. Yii::$app->services->rabbitMq->push(RabbitMqEnum::EXCHANGE_TASK, RabbitMqEnum::TASK_QUEUE, ['path' => $path], PosterCode::class, 'mkdirQrcode');
  348. }
  349. $fileName = $this->base64_image_content($content, $path);
  350. if ($fileName == false) return false;
  351. // 图片上传到云存储
  352. $csv = new CsvTool();
  353. $url = $csv->upload($this->mall_id, 'download/qrcode/' . $fileName);
  354. $config = Yii::$app->services->attachment->getStorageConfig($this->mall_id);
  355. if ($config['drive'] != Attachment::DRIVE_LOCAL) unlink($path .'/'. $fileName);// 删除临时存储的文件
  356. } else {
  357. //返回文字
  358. // $res = Json::decode($response->getBody()->getContents(), true);
  359. return $this->error('获取失败:' . $response->getBody()->getContents());
  360. // return false;
  361. }
  362. }else{
  363. return $this->error($response['errmsg']);
  364. // return false;
  365. }
  366. return $url;
  367. }
  368. /**
  369. * todo 画海报-暂写在控制器,后面需要移除
  370. * @Author: lun
  371. * @DateTime: 2021/11/15 0015 15:12
  372. * @Copyright: copyright (c) 2021 广东七件事集团
  373. * @throws \Exception
  374. */
  375. public function actionDraw()
  376. {
  377. $editor = Grafika::createEditor();
  378. $font = Yii::$app->basePath.'/web/resources/img/poster/st-heiti-light.ttc';
  379. $data = [];
  380. $canvas = '';
  381. $list = self::getDefaultParams();
  382. foreach ($list as $key => $item) {
  383. switch ($item['type']) {
  384. case 'background':// 背景
  385. $canvas = Grafika::createBlankImage($item['w'],$item['h']);
  386. $editor->fill($canvas, new Color($item['color']));
  387. break;
  388. case 'image':// 图片
  389. $editor->open($data[$key], $item['content']);
  390. $editor->resizeFill($data[$key], $item['w'], $item['h']);
  391. $editor->blend($canvas, $data[$key], 'normal', 1, 'top-left', $item['x'], $item['y']);
  392. break;
  393. case 'text':// 文字
  394. $editor->text($canvas ,$item['content'], $item['size'], $item['x'], $item['y'], new Color($item['color']),$font);
  395. break;
  396. case 'scribe':// 划线
  397. $editor->draw($canvas, Grafika::createDrawingObject('Line',[$item['s_x'],$item['s_y']],[$item['e_x'] + 20 * mb_strlen($item['content'],'UTF8'),$item['e_y']],1,new Color($item['color'])));
  398. break;
  399. }
  400. }
  401. $editor->save($canvas,"edited.jpg");
  402. }
  403. private static function getDefaultParams()
  404. {
  405. $data = [
  406. [
  407. 'type' => 'background',
  408. 'content' => '',
  409. 'color' => '#ffffff',
  410. 'w' => '590',
  411. 'h' => '942',
  412. ],
  413. [
  414. 'type' => 'image',
  415. 'content' => 'resources/img/poster/goods.png',
  416. 'w' => '510',
  417. 'h' => '510',
  418. 'x' => '40',
  419. 'y' => '40',
  420. ],
  421. [
  422. 'type' => 'text',
  423. 'content' => '摇滚便携式榨汁机',
  424. 'size' => '24',
  425. 'color' => '#000000',
  426. 'x' => '40',
  427. 'y' => '582',
  428. ],
  429. [
  430. 'type' => 'text',
  431. 'content' => '¥',
  432. 'size' => '24',
  433. 'color' => '#DB0505',
  434. 'x' => '40',
  435. 'y' => '637',
  436. ],
  437. [
  438. 'type' => 'text',
  439. 'content' => '128.06',
  440. 'size' => '30',
  441. 'color' => '#DB0505',
  442. 'x' => '65',
  443. 'y' => '630',
  444. ],
  445. [
  446. 'type' => 'text',
  447. 'content' => '¥169',
  448. 'size' => '18',
  449. 'color' => '#9C9C9C',
  450. 'x' => '40',
  451. 'y' => '695',
  452. ],
  453. [
  454. 'type' => 'scribe',
  455. 'content' => '¥169',
  456. 'size' => '22',
  457. 'color' => '#9C9C9C',
  458. 's_x' => 40,
  459. 's_y' => 707,
  460. 'e_x' => 40,
  461. 'e_y' => 707,
  462. ],
  463. [
  464. 'type' => 'image',
  465. 'content' => 'resources/img/poster/avatar.jpg',
  466. 'w' => '64',
  467. 'h' => '64',
  468. 'x' => '40',
  469. 'y' => '754',
  470. ],
  471. [
  472. 'type' => 'text',
  473. 'content' => '娜可露露',
  474. 'size' => '18',
  475. 'color' => '#2C2D2E',
  476. 'x' => '116',
  477. 'y' => '775',
  478. ],
  479. [
  480. 'type' => 'text',
  481. 'content' => '长按识别小程序码进入',
  482. 'size' => '14',
  483. 'color' => '#B5B9BC',
  484. 'x' => '40',
  485. 'y' => '842',
  486. ],
  487. ];
  488. return $data;
  489. }
  490. /**
  491. * 获取支付宝小程序二维码
  492. * @param $page
  493. * @param $params
  494. * @param $desc
  495. * @return mixed|void
  496. * @throws
  497. */
  498. public function getMpAliAppletQrCode($page, $params,$desc = '')
  499. {
  500. $page = ltrim($page, '/');
  501. $form = new AlipayMiniForm($this->mall_id);
  502. $res = $form->qrcode($page,$params,$desc);
  503. if(!$res){
  504. return $this->error($form->getError());
  505. }
  506. return $res;
  507. }
  508. public function actionUploadPoster()
  509. {
  510. $retuest = Yii::$app->request;
  511. if ($retuest->isPost) {
  512. $params = \Yii::$app->request->post();
  513. $res = \Yii::$app->services->validate->validate($params, [
  514. [['file'], 'string'],
  515. ]);
  516. if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  517. $content = $params['file'];
  518. $path = Yii::getAlias('@attachment') . '/poster/'. date('Ymd');
  519. $fileName = $this->base64_image_content($content, $path);
  520. $url = '';
  521. if ($fileName != false) {
  522. $url = Yii::getAlias('@attachurl') . '/poster/'. date('Ymd') . '/'.$fileName;
  523. }
  524. return $this->success('success',compact('url'));
  525. }
  526. }
  527. public function actionGetAgreement()
  528. {
  529. $user_id = $this->user_id;
  530. $mall_id = $this->mall_id;
  531. $config = Yii::$app->services->setting->mall->get($mall_id, 'user_agree');
  532. $promote_code_agree = '';
  533. $is_sign = 0;
  534. $enable_promote_code = $config['enable_promote_code'];
  535. $title = '产品推广中介服务合同';
  536. if($config['enable_promote_code']){
  537. $promote_code_agree = $config['promote_code_agree'] ?? '';
  538. $count = UserSignAgreement::find()->where(['and', ['mall_id' => $mall_id], ['user_id' => $user_id], ['status' => StatusEnum::ENABLED], ['source' => UserSignAgreement::SOURCE_POSTER]])
  539. ->limit(1)->count();
  540. $is_sign = $count ? 1 : 0;
  541. }
  542. $data = compact('enable_promote_code', 'promote_code_agree', 'is_sign', 'title');
  543. return $this->success('数据请求成功', $data);
  544. }
  545. public function actionSignAgreement()
  546. {
  547. try{
  548. $user_id = $this->user_id;
  549. $mall_id = $this->mall_id;
  550. $params = \Yii::$app->request->post();
  551. $is_agree = $params['is_agree'];
  552. if(UserSignAgreement::setData([
  553. 'user_id' => $user_id,
  554. 'mall_id' => $mall_id,
  555. 'source' => UserSignAgreement::SOURCE_POSTER,
  556. ]) == false){
  557. throw new \Exception(UserSignAgreement::getStaticError());
  558. }
  559. return $this->success('签署成功');
  560. }catch(\Exception $e){
  561. return $this->error($e->getMessage());
  562. }
  563. }
  564. }