Poster.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. <?php
  2. namespace common\models\mall;
  3. use common\enums\StatusEnum;
  4. use common\enums\WhetherEnum;
  5. use Yii;
  6. use yii\helpers\Json;
  7. /**
  8. * This is the model class for table "{{%poster}}".
  9. *
  10. *
  11. * @property int $mall_id 商城id
  12. * @property string $name 名称
  13. * @property string|null $key_word 关键词
  14. * @property int|null $look_num 浏览次数
  15. * @property int $scan_code_num 扫码次数
  16. * @property string $poster_content 海报内容
  17. * @property int $status 状态【1启用 0禁用 -1删除】
  18. * @property string|null $share_url 分享图片
  19. * @property int $created_at
  20. * @property int $updated_at
  21. */
  22. class Poster extends \common\models\base\BaseActiveRecord
  23. {
  24. /**
  25. * {@inheritdoc}
  26. */
  27. public static function tableName()
  28. {
  29. return '{{%poster}}';
  30. }
  31. /**
  32. * {@inheritdoc}
  33. */
  34. public function rules()
  35. {
  36. return [
  37. [['mall_id', 'name', 'poster_content'], 'required'],
  38. [['mall_id', 'look_num', 'scan_code_num', 'status', 'created_at', 'updated_at','sort'], 'integer'],
  39. [['poster_content'], 'string'],
  40. [['name', 'key_word'], 'string', 'max' => 10],
  41. [['share_url'], 'string', 'max' => 255],
  42. ];
  43. }
  44. /**
  45. * {@inheritdoc}
  46. */
  47. public function attributeLabels()
  48. {
  49. return [
  50. 'id' => 'ID',
  51. 'mall_id' => '商城id',
  52. 'name' => '名称',
  53. 'key_word' => '关键词',
  54. 'look_num' => '浏览次数',
  55. 'scan_code_num' => '扫码次数',
  56. 'poster_content' => '海报内容',
  57. 'sort' => '海报排序',
  58. 'status' => '状态【1启用 0禁用 -1删除】',
  59. 'share_url' => '分享图片',
  60. 'created_at' => 'Created At',
  61. 'updated_at' => 'Updated At',
  62. ];
  63. }
  64. /**
  65. * 保存数据
  66. * @Author lun
  67. * @DateTime 2021-09-16 14:16:24
  68. * @copyright: Copyright (c) 2020 广东七件事集团
  69. * @param array $params
  70. * @return object|boolean
  71. */
  72. public static function setData($mall_id, array $params){
  73. try{
  74. if(!empty($params['id'])){
  75. $model = self::findOne(['and',['id' => $params['id'],'mall_id' => $mall_id],['<>','status',StatusEnum::DELETE]]);
  76. if(empty($model)) throw new \Exception('海报不存在或已删除');
  77. }else{
  78. $model = new self();
  79. $model->loadDefaultValues();
  80. $model->mall_id = $mall_id;
  81. }
  82. // 将内容转为json字符串
  83. $params['poster_content'] = Json::encode($params['poster_content']);
  84. if(!$model->load($params,'') || !$model->save()) throw new \Exception($model->getErrorMessage());
  85. return $model;
  86. }catch(\Exception $e){
  87. self::$static_error = $e->getMessage();
  88. return false;
  89. }
  90. }
  91. /**
  92. * 海报默认参数
  93. * @return array[]
  94. */
  95. public static function getDefaultPoster()
  96. {
  97. $urlPrefix = \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl .
  98. '/resources/img/mall/poster/';
  99. return [
  100. 'share' => [
  101. 'bg_pic' => [
  102. 'url' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/resources/img/mall/poster_bg.png',
  103. 'is_show' => '1',
  104. ],
  105. 'head' => [
  106. 'is_show' => '1',
  107. 'size' => 60 * 2,
  108. 'top' => 10 * 2,
  109. 'left' => 10 * 2,
  110. 'file_type' => 'image',
  111. ],
  112. 'qr_code' => [
  113. 'is_show' => '1',
  114. 'size' => 120 * 2,
  115. 'top' => 150 * 2,
  116. 'left' => 127 * 2,
  117. 'type' => '1',
  118. 'file_type' => 'image',
  119. ],
  120. 'name' => [
  121. 'is_show' => '1',
  122. 'font' => 20,
  123. 'top' => 30 * 2,
  124. 'left' => 80 * 2,
  125. 'color' => '#000',
  126. 'file_type' => 'text',
  127. ],
  128. ],
  129. 'goods' => [
  130. 'bg_pic' => [
  131. 'url' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/resources/img/mall/poster_bg.png',
  132. 'is_show' => '1',
  133. ],
  134. 'pic' => [
  135. 'url' => $urlPrefix . 'default_goods.jpg',
  136. 'is_show' => '1',
  137. 'width' => 375 * 2,
  138. 'height' => 375 * 2,
  139. 'top' => 0,
  140. 'left' => 0,
  141. 'file_type' => 'image',
  142. ],
  143. 'head' => [
  144. 'is_show' => '1',
  145. 'size' => 30 * 2,
  146. 'top' => 550 * 2,
  147. 'left' => 20 * 2,
  148. 'file_type' => 'image',
  149. ],
  150. 'nickname' => [
  151. 'is_show' => '1',
  152. 'font' => 18,
  153. 'top' => 557 * 2,
  154. 'left' => 59 * 2,
  155. 'color' => '#000',
  156. 'file_type' => 'text',
  157. ],
  158. 'name' => [
  159. 'is_show' => '1',
  160. 'font' => 20,
  161. 'top' => 390 * 2,
  162. 'left' => 20 * 2,
  163. 'color' => '#000',
  164. 'file_type' => 'text',
  165. ],
  166. 'price' => [
  167. 'is_show' => '1',
  168. 'font' => 20,
  169. 'top' => 420 * 2,
  170. 'left' => 20 * 2,
  171. 'color' => 'rgb(255, 69, 68)',
  172. 'file_type' => 'text',
  173. ],
  174. 'qr_code' => [
  175. 'is_show' => '1',
  176. 'size' => 120 * 2,
  177. 'top' => 515 * 2,
  178. 'left' => 230 * 2,
  179. 'type' => '1',
  180. 'file_type' => 'image',
  181. ],
  182. 'desc' => [
  183. 'is_show' => '1',
  184. 'width' => 200 * 2,
  185. 'font' => 16,
  186. 'top' => 595,
  187. 'left' => 20 * 2,
  188. 'color' => 'rgb(169, 169, 169)',
  189. 'text' => '长按识别小程序码进入',
  190. 'file_type' => 'text',
  191. ],
  192. ],
  193. 'topic' => [
  194. 'bg_pic' => [
  195. 'url' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/resources/img/mall/poster_bg.png',
  196. 'is_show' => '1',
  197. ],
  198. 'pic' => [
  199. 'url' => $urlPrefix . 'default_goods.jpg',
  200. 'is_show' => '1',
  201. 'width' => 335 * 2,
  202. 'height' => 167 * 2,
  203. 'top' => 90 * 2,
  204. 'left' => 20 * 2,
  205. 'file_type' => 'image',
  206. ],
  207. 'title' => [
  208. 'is_show' => '1',
  209. 'font' => 26,
  210. 'top' => 40 * 2,
  211. 'left' => 20 * 2,
  212. 'color' => '#000',
  213. 'file_type' => 'text',
  214. ],
  215. 'look' => [
  216. 'is_show' => '1',
  217. 'font' => 16,
  218. 'top' => 280 * 2,
  219. 'left' => 20 * 2,
  220. 'color' => '#999',
  221. 'file_type' => 'text',
  222. ],
  223. 'content' => [
  224. 'is_show' => '1',
  225. 'font' => 18,
  226. 'top' => 320 * 2,
  227. 'left' => 20 * 2,
  228. 'color' => '#666666',
  229. 'file_type' => 'text',
  230. ],
  231. 'open_desc' => [
  232. 'is_show' => '1',
  233. 'font' => 20,
  234. 'top' => 410 * 2,
  235. 'left' => 85 * 2,
  236. 'color' => '#D68543',
  237. 'text' => '打开小程序阅读全文',
  238. 'file_type' => 'text',
  239. ],
  240. 'desc' => [
  241. 'is_show' => '1',
  242. 'width' => 205 * 2,
  243. 'font' => 18,
  244. 'top' => 550 * 2,
  245. 'left' => 20 * 2,
  246. 'color' => '#000',
  247. 'text' => '长按识别小程序码进入',
  248. 'file_type' => 'text',
  249. ],
  250. 'qr_code' => [
  251. 'is_show' => '1',
  252. 'size' => 114 * 2,
  253. 'top' => 510 * 2,
  254. 'left' => 234 * 2,
  255. 'type' => '1',
  256. 'file_type' => 'image',
  257. ],
  258. 'line' => [
  259. 'is_show' => '1',
  260. 'width' => 335 * 2,
  261. 'height' => 1,
  262. 'top' => 480 * 2,
  263. 'left' => 20 * 2,
  264. 'color' => '#e2e2e2',
  265. 'file_type' => 'line',
  266. ]
  267. ],
  268. 'footprint' => [
  269. 'bg_pic' => [
  270. 'url' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/resources/img/app/footprint/footprint_poster_bg.png',
  271. 'is_show' => '1',
  272. ],
  273. 'qr_code' => [
  274. 'is_show' => '1',
  275. 'size' => 160 * 2,
  276. 'top' => 1140 * 2,
  277. 'left' => 540 * 2,
  278. 'type' => '1',
  279. 'file_type' => 'image',
  280. ],
  281. 'text_one' => [
  282. 'is_show' => '1',
  283. 'font' => 24,
  284. 'top' => 380 * 2,
  285. 'left' => 124 * 2,
  286. 'color' => '#252525',
  287. 'file_type' => 'text',
  288. 'text' => '1',
  289. 'font_path' => \Yii::$app->basePath . '/web/resources/font/DIN-Medium.otf',
  290. ],
  291. 'text_1' => [
  292. 'is_show' => '1',
  293. 'font' => 24,
  294. 'top' => 380 * 2,
  295. 'left' => 148 * 2,
  296. 'color' => '#252525',
  297. 'file_type' => 'text',
  298. 'text' => '.您在本店共购买',
  299. 'font_path' => \Yii::$app->basePath . '/web/resources/font/hanyicuyuanti.ttf',
  300. ],
  301. 'text_2' => [
  302. 'is_show' => '1',
  303. 'font' => 36,
  304. 'top' => 443 * 2,
  305. 'left' => 124 * 2,
  306. 'color' => '#FF4544',
  307. 'file_type' => 'text',
  308. 'text' => '590',
  309. 'font_path' => \Yii::$app->basePath . '/web/resources/font/DIN-Medium.otf',
  310. ],
  311. 'text_3' => [
  312. 'is_show' => '1',
  313. 'font' => 24,
  314. 'top' => 455 * 2,
  315. 'left' => 295 * 2,
  316. 'color' => '#252525',
  317. 'file_type' => 'text',
  318. 'text' => '件商品',
  319. 'font_path' => \Yii::$app->basePath . '/web/resources/font/hanyicuyuanti.ttf',
  320. ],
  321. 'text_two' => [
  322. 'is_show' => '1',
  323. 'font' => 24,
  324. 'top' => 535 * 2,
  325. 'left' => 124 * 2,
  326. 'color' => '#252525',
  327. 'file_type' => 'text',
  328. 'text' => '2',
  329. 'font_path' => \Yii::$app->basePath . '/web/resources/font/DIN-Medium.otf',
  330. ],
  331. 'text_4' => [
  332. 'is_show' => '1',
  333. 'font' => 24,
  334. 'top' => 535 * 2,
  335. 'left' => 148 * 2,
  336. 'color' => '#252525',
  337. 'file_type' => 'text',
  338. 'text' => '.您在本店共消费',
  339. 'font_path' => \Yii::$app->basePath . '/web/resources/font/hanyicuyuanti.ttf',
  340. ],
  341. 'text_5' => [
  342. 'is_show' => '1',
  343. 'font' => 24,
  344. 'top' => 600 * 2,
  345. 'left' => 124 * 2,
  346. 'color' => '#FF4544',
  347. 'file_type' => 'text',
  348. 'text' => '¥',
  349. // 'font_path' => \Yii::$app->basePath . '/web/resources/font/hanyicuyuanti.ttf',
  350. ],
  351. 'text_6' => [
  352. 'is_show' => '1',
  353. 'font' => 36,
  354. 'top' => 588 * 2,
  355. 'left' => 157 * 2,
  356. 'color' => '#FF4544',
  357. 'file_type' => 'text',
  358. 'text' => '888888',
  359. 'font_path' => \Yii::$app->basePath . '/web/resources/font/DIN-Medium.otf',
  360. ],
  361. 'text_three' => [
  362. 'is_show' => '1',
  363. 'font' => 24,
  364. 'top' => 677 * 2,
  365. 'left' => 124 * 2,
  366. 'color' => '#252525',
  367. 'file_type' => 'text',
  368. 'text' => '3',
  369. 'font_path' => \Yii::$app->basePath . '/web/resources/font/DIN-Medium.otf',
  370. ],
  371. 'text_7' => [
  372. 'is_show' => '1',
  373. 'font' => 24,
  374. 'top' => 677 * 2,
  375. 'left' => 148 * 2,
  376. 'color' => '#252525',
  377. 'file_type' => 'text',
  378. 'text' => '.您在本店最高一次消费达',
  379. 'font_path' => \Yii::$app->basePath . '/web/resources/font/hanyicuyuanti.ttf',
  380. ],
  381. 'text_8' => [
  382. 'is_show' => '1',
  383. 'font' => 24,
  384. 'top' => 742 * 2,
  385. 'left' => 124 * 2,
  386. 'color' => '#FF4544',
  387. 'file_type' => 'text',
  388. 'text' => '¥',
  389. // 'font_path' => \Yii::$app->basePath . '/web/resources/font/hanyicuyuanti.ttf',
  390. ],
  391. 'text_9' => [
  392. 'is_show' => '1',
  393. 'font' => 36,
  394. 'top' => 730 * 2,
  395. 'left' => 157 * 2,
  396. 'color' => '#FF4544',
  397. 'file_type' => 'text',
  398. 'text' => '168888',
  399. 'font_path' => \Yii::$app->basePath . '/web/resources/font/DIN-Medium.otf',
  400. ],
  401. ],
  402. ];
  403. }
  404. /**
  405. * 修改状态
  406. *
  407. * @return boolean
  408. */
  409. public function changeStatus()
  410. {
  411. $this->status = (int)!$this->status;
  412. return $this->save();
  413. }
  414. }