No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Field.php 28KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  1. <?php
  2. /**
  3. * 易优CMS
  4. * ============================================================================
  5. * 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
  6. * 网站地址: http://www.eyoucms.com
  7. * ----------------------------------------------------------------------------
  8. * 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
  9. * ============================================================================
  10. * Author: 小虎哥 <1105415366@qq.com>
  11. * Date: 2018-4-3
  12. */
  13. namespace app\admin\model;
  14. use think\Db;
  15. use think\Model;
  16. /**
  17. * 字段
  18. */
  19. class Field extends Model
  20. {
  21. //初始化
  22. protected function initialize()
  23. {
  24. // 需要调用`Model`的`initialize`方法
  25. parent::initialize();
  26. }
  27. /**
  28. * 获取全部字段类型
  29. * @author 小虎哥 by 2018-7-25
  30. */
  31. public function getFieldTypeAll($field = '*', $index_key = '')
  32. {
  33. $cacheKey = md5("admin-Field-getFieldTypeAll-{$field}-{$index_key}");
  34. $result = cache($cacheKey);
  35. if (!empty($result)) {
  36. return $result;
  37. }
  38. $result = Db::name('FieldType')->field($field)->order('sort_order asc')->select();
  39. if (!empty($index_key)) {
  40. $result = convert_arr_key($result, $index_key);
  41. }
  42. cache($cacheKey, $result, null, 'field_type');
  43. return $result;
  44. }
  45. /**
  46. * 查询解析模型数据用以构造from表单
  47. * @param intval $channel_id 模型ID
  48. * @param intval $ifmain 是否主表、附加表
  49. * @param intval $aid 表主键ID
  50. * @param array $archivesInfo 主表数据
  51. * @author 小虎哥 by 2018-7-25
  52. */
  53. public function getChannelFieldList($channel_id, $ifmain = false, $aid = '', $archivesInfo = [], $where = [])
  54. {
  55. $hideField = array('id','aid','add_time','update_time'); // 不显示在发布表单的字段
  56. $channel_id = intval($channel_id);
  57. $map = array(
  58. 'channel_id' => array('eq', $channel_id),
  59. 'name' => array('notin', $hideField),
  60. 'ifmain' => 0,
  61. 'ifeditable' => 1,
  62. );
  63. if (false !== $ifmain) {
  64. $map['ifmain'] = $ifmain;
  65. }
  66. $map = array_merge($map, $where);
  67. $row = model('Channelfield')->getListByWhere($map, '*');
  68. /*编辑时显示的数据*/
  69. $addonRow = array();
  70. if (0 < intval($aid)) {
  71. if (1 == $channel_id) {
  72. $tableExt = 'article';
  73. } else if (2 == $channel_id) {
  74. $tableExt = 'product';
  75. } else if (3 == $channel_id) {
  76. $tableExt = 'images';
  77. } else if (4 == $channel_id) {
  78. $tableExt = 'download';
  79. } else if (5 == $channel_id) {
  80. $tableExt = 'media';
  81. } else if (6 == $channel_id) {
  82. $tableExt = 'single';
  83. $aid = Db::name('archives')->where(array('typeid'=>$aid, 'channel'=>$channel_id))->getField('aid');
  84. } else if (7 == $channel_id) {
  85. $tableExt = 'special';
  86. } else {
  87. $tableExt = Db::name('channeltype')->where('id', $channel_id)->getField('table');
  88. }
  89. $tableExt .= '_content';
  90. $addonRow = Db::name($tableExt)->field('*')->where('aid', $aid)->find();
  91. }
  92. /*--end*/
  93. $list = $this->showViewFormData($row, 'addonFieldExt', $addonRow, $archivesInfo);
  94. return $list;
  95. }
  96. /**
  97. * 查询解析数据表的数据用以构造from表单
  98. * @param intval $channel_id 模型ID
  99. * @param intval $id 表主键ID
  100. * @author 小虎哥 by 2018-7-25
  101. */
  102. public function getTabelFieldList($channel_id, $id = '')
  103. {
  104. $hideField = array('id','aid','add_time','update_time'); // 不显示在发布表单的字段
  105. $channel_id = intval($channel_id);
  106. $map = array(
  107. 'channel_id' => array('eq', $channel_id),
  108. 'name' => array('notin', $hideField),
  109. 'ifsystem' => 0,
  110. );
  111. $row = model('Channelfield')->getListByWhere($map, '*');
  112. /*编辑时显示的数据*/
  113. $addonRow = array();
  114. if (0 < intval($id)) {
  115. if (config('global.arctype_channel_id') == $channel_id) {
  116. $addonRow = Db::name('arctype')->field('*')->where('id', $id)->find();
  117. }
  118. }
  119. /*--end*/
  120. $list = $this->showViewFormData($row, 'addonField', $addonRow);
  121. return $list;
  122. }
  123. /**
  124. * 处理页面显示自定义字段的表单数据
  125. * @param array $list 自定义字段列表
  126. * @param array $formFieldStr 表单元素名称的统一数组前缀
  127. * @param array $addonRow 自定义字段的数据
  128. * @param array $archivesInfo 主表数据
  129. * @author 小虎哥 by 2018-7-25
  130. */
  131. public function showViewFormData($list, $formFieldStr, $addonRow = array(), $archivesInfo = [])
  132. {
  133. if (!empty($list)) {
  134. foreach ($list as $key => $val) {
  135. $val['fieldArr'] = $formFieldStr;
  136. switch ($val['dtype']) {
  137. case 'int':
  138. {
  139. if (array_key_exists($val['name'], $addonRow)) {
  140. $val['dfvalue'] = $addonRow[$val['name']];
  141. } else {
  142. if(preg_match("#[^0-9]#", $val['dfvalue']))
  143. {
  144. $val['dfvalue'] = "";
  145. }
  146. }
  147. break;
  148. }
  149. case 'float':
  150. case 'decimal':
  151. {
  152. if (array_key_exists($val['name'], $addonRow)) {
  153. $val['dfvalue'] = $addonRow[$val['name']];
  154. } else {
  155. if(preg_match("#[^0-9\.]#", $val['dfvalue']))
  156. {
  157. $val['dfvalue'] = "";
  158. }
  159. }
  160. break;
  161. }
  162. case 'select':
  163. case 'radio':
  164. {
  165. $dfvalue = $val['dfvalue'];
  166. $dfvalueArr = explode(',', $dfvalue);
  167. $val['dfvalue'] = $dfvalueArr;
  168. if (array_key_exists($val['name'], $addonRow)) {
  169. $val['trueValue'] = explode(',', $addonRow[$val['name']]);
  170. } else {
  171. $dfTrueValue = !empty($dfvalueArr[0]) ? $dfvalueArr[0] : '';
  172. $val['trueValue'] = array($dfTrueValue);
  173. }
  174. break;
  175. }
  176. case 'region':
  177. {
  178. $dfvalue = unserialize($val['dfvalue']);
  179. $RegionData = [];
  180. $region_ids = explode(',', $dfvalue['region_ids']);
  181. foreach ($region_ids as $id_key => $id_value) {
  182. $RegionData[$id_key]['id'] = $id_value;
  183. }
  184. $region_names = explode(',', $dfvalue['region_names']);
  185. foreach ($region_names as $name_key => $name_value) {
  186. $RegionData[$name_key]['name'] = $name_value;
  187. }
  188. $val['dfvalue'] = $RegionData;
  189. if (array_key_exists($val['name'], $addonRow)) {
  190. $val['trueValue'] = explode(',', $addonRow[$val['name']]);
  191. } else {
  192. if ( !empty($val['set_type']) && 1 == $val['set_type']){
  193. $val['trueValue'] = [];
  194. }else{
  195. $dfTrueValue = !empty($RegionData[0]) ? $RegionData[0]['id'] : '';
  196. $val['trueValue'] = array($dfTrueValue);
  197. }
  198. }
  199. if ( !empty($val['set_type']) && 1 == $val['set_type']){
  200. //三级联动的需要处理
  201. $rid = $val['dfvalue'][0]['id'];
  202. $region_data = Db::name('region')->where('id',$rid)->find();//这里查出来可能是省级1或者市级2,区域3
  203. $val['region_level'] = $region_data['level'];
  204. $region_arr = [['id'=>-1,'name'=>'请选择']];
  205. if (2 == $region_data['level']){
  206. $province_list = get_province_list();
  207. $val['city_list'] = array_merge($region_arr,$val['dfvalue']);
  208. $val['trueValue'][0] = $region_data['parent_id'];
  209. $val['dfvalue'] = $province_list;
  210. }elseif (3 == $region_data['level']){
  211. $province_list = get_province_list();
  212. $province_id = Db::name('region')->where('id',$region_data['parent_id'])->value('parent_id');
  213. $val['area_list'] = array_merge($region_arr,$val['dfvalue']);
  214. $val['dfvalue'] = $province_list;
  215. $val['trueValue'][0] = $province_id;
  216. $val['trueValue'][1] = $region_data['parent_id'];
  217. if (empty($val['trueValue'][2])) $val['trueValue'][2] = -1;
  218. }
  219. if (!empty($val['trueValue'][1])){
  220. $field_region_type = config('global.field_region_type');
  221. //如果是4个特殊的直辖市,市的数据直接显示到区
  222. if (in_array($val['trueValue'][0],$field_region_type)){
  223. $city_ids = Db::name('region')->where(['level'=>2,'parent_id'=>$val['trueValue'][0]])->column('id');
  224. $city_list = Db::name('region')->where(['level'=>3])->where('parent_id','in',$city_ids)->select();
  225. }else{
  226. $city_list = Db::name('region')->where(['level'=>2,'parent_id'=>$val['trueValue'][0]])->select();
  227. }
  228. $val['city_list'] = array_merge($region_arr,$city_list);
  229. }
  230. if (!empty($val['trueValue'][2]) && $val['trueValue'][2] > 0){
  231. $area_list = Db::name('region')->where(['level'=>3,'parent_id'=>$val['trueValue'][1]])->select();
  232. $val['area_list'] = array_merge($region_arr,$area_list);
  233. }
  234. }
  235. break;
  236. }
  237. case 'checkbox':
  238. {
  239. $dfvalue = $val['dfvalue'];
  240. $dfvalueArr = explode(',', $dfvalue);
  241. $val['dfvalue'] = $dfvalueArr;
  242. if (array_key_exists($val['name'], $addonRow)) {
  243. $val['trueValue'] = explode(',', $addonRow[$val['name']]);
  244. } else {
  245. $val['trueValue'] = array();
  246. }
  247. break;
  248. }
  249. case 'img':
  250. {
  251. $val[$val['name'].'_eyou_is_remote'] = 0;
  252. $val[$val['name'].'_eyou_remote'] = '';
  253. $val[$val['name'].'_eyou_local'] = '';
  254. if (array_key_exists($val['name'], $addonRow)) {
  255. if (is_http_url($addonRow[$val['name']])) {
  256. $val[$val['name'].'_eyou_is_remote'] = 1;
  257. $val[$val['name'].'_eyou_remote'] = handle_subdir_pic($addonRow[$val['name']]);
  258. } else {
  259. $val[$val['name'].'_eyou_is_remote'] = 0;
  260. $val[$val['name'].'_eyou_local'] = handle_subdir_pic($addonRow[$val['name']]);
  261. }
  262. }
  263. break;
  264. }
  265. case 'imgs':
  266. {
  267. /*将多图字段类型varchar改为text*/
  268. try {
  269. $channelfieldRow = Db::name('channelfield')->field('id,title,maxlength')
  270. ->where([
  271. 'name' => $val['name'],
  272. 'channel_id' => $val['channel_id'],
  273. ])->find();
  274. if (!empty($channelfieldRow) && 1001 == $channelfieldRow['maxlength']) {
  275. $tableExt = Db::name('channeltype')->where('id', $val['channel_id'])->getField('table');
  276. $tableExt = PREFIX.$tableExt.'_content';
  277. $fieldComment = $channelfieldRow['title'];
  278. empty($fieldComment) && $fieldComment = '图集';
  279. $sql = " ALTER TABLE `{$tableExt}` MODIFY COLUMN `{$val['name']}` varchar(10001) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '{$fieldComment}|10001' ";
  280. if (@Db::execute($sql)) {
  281. Db::name('channelfield')->where([
  282. 'id' => $channelfieldRow['id'],
  283. ])->update([
  284. 'define' => 'varchar(10001)',
  285. 'maxlength' => 10001,
  286. 'update_time' => getTime(),
  287. ]);
  288. }
  289. }
  290. } catch (\Exception $e) {}
  291. /*end*/
  292. $val[$val['name'].'_eyou_imgupload_list'] = array();
  293. if (array_key_exists($val['name'], $addonRow) && !empty($addonRow[$val['name']])) {
  294. $eyou_imgupload_list = @unserialize($addonRow[$val['name']]);
  295. if (false === $eyou_imgupload_list) {
  296. $eyou_imgupload_list = [];
  297. $eyou_imgupload_data = explode(',', $addonRow[$val['name']]);
  298. foreach ($eyou_imgupload_data as $k1 => $v1) {
  299. $eyou_imgupload_list[$k1] = [
  300. 'image_url' => handle_subdir_pic($v1),
  301. 'intro' => '',
  302. ];
  303. }
  304. }
  305. $val[$val['name'].'_eyou_imgupload_list'] = $eyou_imgupload_list;
  306. }
  307. break;
  308. }
  309. case 'datetime':
  310. {
  311. $val['dfvalue'] = !empty($addonRow[$val['name']]) ? date('Y-m-d H:i:s', $addonRow[$val['name']]) : '';
  312. break;
  313. }
  314. case 'file':
  315. {
  316. $val[$val['name'].'_eyou_is_remote'] = 0;
  317. $val[$val['name'].'_eyou_remote'] = '';
  318. $val[$val['name'].'_eyou_local'] = '';
  319. if (array_key_exists($val['name'], $addonRow)) {
  320. if (is_http_url($addonRow[$val['name']])) {
  321. $val[$val['name'].'_eyou_is_remote'] = 1;
  322. $val[$val['name'].'_eyou_remote'] = handle_subdir_pic($addonRow[$val['name']]);
  323. } else {
  324. $val[$val['name'].'_eyou_is_remote'] = 0;
  325. $val[$val['name'].'_eyou_local'] = handle_subdir_pic($addonRow[$val['name']]);
  326. }
  327. }
  328. $val['dfvalue'] = handle_subdir_pic($addonRow[$val['name']]);
  329. $val['upload_flag'] = 'local';
  330. $WeappConfig = Db::name('weapp')->field('code, status')->where('code', 'IN', ['Qiniuyun', 'AliyunOss', 'Cos'])->where('status',1)->select();
  331. foreach ($WeappConfig as $value) {
  332. if ('Qiniuyun' == $value['code']) {
  333. $val['upload_flag'] = 'qny';
  334. } else if ('AliyunOss' == $value['code']) {
  335. $val['upload_flag'] = 'oss';
  336. } else if ('Cos' == $value['code']) {
  337. $val['upload_flag'] = 'cos';
  338. }
  339. }
  340. $val['ext'] = tpCache('basic.file_type');
  341. $val['filesize'] = upload_max_filesize();
  342. break;
  343. }
  344. case 'media':
  345. {
  346. $val['dfvalue'] = $addonRow[$val['name']];
  347. $val['upload_flag'] = 'local';
  348. $WeappConfig = Db::name('weapp')->field('code, status')->where('code', 'IN', ['Qiniuyun', 'AliyunOss', 'Cos'])->where('status',1)->select();
  349. foreach ($WeappConfig as $value) {
  350. if ('Qiniuyun' == $value['code']) {
  351. $val['upload_flag'] = 'qny';
  352. } else if ('AliyunOss' == $value['code']) {
  353. $val['upload_flag'] = 'oss';
  354. } else if ('Cos' == $value['code']) {
  355. $val['upload_flag'] = 'cos';
  356. }
  357. }
  358. $ext = tpCache('basic.media_type');
  359. $val['ext'] = !empty($ext) ? $ext : config('global.media_ext');
  360. $val['filesize'] = upload_max_filesize();
  361. break;
  362. }
  363. case 'htmltext':
  364. {
  365. $val['dfvalue'] = isset($addonRow[$val['name']]) ? $addonRow[$val['name']] : $val['dfvalue'];
  366. /*追加指定内嵌样式到编辑器内容的img标签,兼容图片自动适应页面*/
  367. $title = '';
  368. if (!empty($archivesInfo['title'])) {
  369. $title = $archivesInfo['title'];
  370. } else {
  371. $title = !empty($archivesInfo['typename']) ? $archivesInfo['typename'] : '';
  372. }
  373. $content = htmlspecialchars_decode($val['dfvalue']);
  374. $val['dfvalue'] = htmlspecialchars(img_style_wh($content, $title));
  375. /*--end*/
  376. /*支持子目录*/
  377. $val['dfvalue'] = handle_subdir_pic($val['dfvalue'], 'html');
  378. /*--end*/
  379. break;
  380. }
  381. default:
  382. {
  383. $val['dfvalue'] = array_key_exists($val['name'], $addonRow) ? $addonRow[$val['name']] : $val['dfvalue'];
  384. /*支持子目录*/
  385. if (is_string($val['dfvalue'])) {
  386. $val['dfvalue'] = handle_subdir_pic($val['dfvalue'], 'html');
  387. $val['dfvalue'] = handle_subdir_pic($val['dfvalue']);
  388. }
  389. /*--end*/
  390. break;
  391. }
  392. }
  393. $list[$key] = $val;
  394. }
  395. }
  396. return $list;
  397. }
  398. /**
  399. * 查询解析模型数据用以构造from表单
  400. * @author 小虎哥 by 2018-7-25
  401. */
  402. public function dealChannelPostData($channel_id, $data = array(), $dataExt = array())
  403. {
  404. if (!empty($channel_id)) {
  405. $nowDataExt = array();
  406. $fieldTypeList = model('Channelfield')->getListByWhere(array('channel_id'=>$channel_id), 'name,dtype', 'name');
  407. foreach ($dataExt as $key => $val) {
  408. /*处理复选框取消选中的情况下*/
  409. if (preg_match('/^(.*)(_eyempty)$/', $key) && empty($val)) {
  410. $key = preg_replace('/^(.*)(_eyempty)$/', '$1', $key);
  411. $nowDataExt[$key] = '';
  412. continue;
  413. }
  414. /*end*/
  415. $key = preg_replace('/^(.*)(_eyou_is_remote|_eyou_remote|_eyou_local)$/', '$1', $key);
  416. $dtype = !empty($fieldTypeList[$key]) ? $fieldTypeList[$key]['dtype'] : '';
  417. switch ($dtype) {
  418. case 'checkbox':
  419. {
  420. $val = implode(',', $val);
  421. break;
  422. }
  423. case 'region':
  424. {
  425. if (!is_numeric($val)) { // 三级联动
  426. //选择全国的时候干掉城市区域的值
  427. if ($val[0] == 0){
  428. if (isset($val[1])) unset($val[1]);
  429. if (isset($val[2])) unset($val[2]);
  430. }else{
  431. $parent_data = Db::name('region')->where('id',$val[0])->find();
  432. if (!empty($parent_data) && !empty($parent_data['parent_id'])){
  433. //只有市级和区域能选择
  434. array_unshift($val,$parent_data['parent_id']);
  435. //只有区域能选择
  436. if (3 == $parent_data['level']){
  437. $parent_id = Db::name('region')->where('id',$val[0])->value('parent_id');
  438. array_unshift($val,$parent_id);
  439. }
  440. }
  441. }
  442. //三级联动的需要选择
  443. $val = implode(',', $val);
  444. } else {
  445. if (is_array($val)) {
  446. $new_val = [];
  447. foreach ($val as $_k => $_v) {
  448. $_v = trim($_v);
  449. if (!empty($_v)) {
  450. $new_val[] = $_v;
  451. }
  452. }
  453. $val = $new_val;
  454. } else {
  455. $val = trim($val);
  456. }
  457. }
  458. break;
  459. }
  460. case 'switch':
  461. case 'int':
  462. {
  463. $val = intval($val);
  464. break;
  465. }
  466. case 'img':
  467. {
  468. $is_remote = !empty($dataExt[$key.'_eyou_is_remote']) ? $dataExt[$key.'_eyou_is_remote'] : 0;
  469. if (1 == $is_remote) {
  470. $val = $dataExt[$key.'_eyou_remote'];
  471. } else {
  472. $val = $dataExt[$key.'_eyou_local'];
  473. }
  474. break;
  475. }
  476. case 'imgs':
  477. {
  478. $imgData = [];
  479. $imgsIntroArr = !empty($dataExt[$key.'_eyou_intro']) ? $dataExt[$key.'_eyou_intro'] : [];
  480. foreach ($val as $k2 => $v2) {
  481. $v2 = trim($v2);
  482. if (!empty($v2)) {
  483. $intro = !empty($imgsIntroArr[$k2]) ? $imgsIntroArr[$k2] : '';
  484. $imgData[] = [
  485. 'image_url' => $v2,
  486. 'intro' => $intro,
  487. ];
  488. }
  489. }
  490. $val = !empty($imgData) ? serialize($imgData) : '';
  491. break;
  492. }
  493. case 'file':
  494. {
  495. $is_remote = !empty($dataExt[$key.'_eyou_is_remote']) ? $dataExt[$key.'_eyou_is_remote'] : 0;
  496. if (1 == $is_remote) {
  497. $val = $dataExt[$key.'_eyou_remote'];
  498. } else {
  499. $val = $dataExt[$key.'_eyou_local'];
  500. }
  501. break;
  502. }
  503. // case 'files':
  504. // {
  505. // foreach ($val as $k2 => $v2) {
  506. // if (empty($v2)) {
  507. // unset($val[$k2]);
  508. // continue;
  509. // }
  510. // $val[$k2] = trim($v2);
  511. // }
  512. // $val = implode(',', $val);
  513. // break;
  514. // }
  515. case 'datetime':
  516. {
  517. $val = !empty($val) ? strtotime($val) : getTime();
  518. break;
  519. }
  520. case 'decimal':
  521. {
  522. $moneyArr = explode('.', $val);
  523. $money1 = !empty($moneyArr[0]) ? intval($moneyArr[0]) : '0';
  524. $money2 = !empty($moneyArr[1]) ? intval(msubstr($moneyArr[1], 0, 2)) : '00';
  525. $val = $money1.'.'.$money2;
  526. break;
  527. }
  528. case 'htmltext':
  529. {
  530. if (!empty($val)) {
  531. $val = preg_replace("/^&amp;nbsp;/i", "", $val);
  532. }
  533. $val = preg_replace("/&lt;script[\s\S]*?script&gt;/i", "", $val);
  534. $val = trim($val);
  535. // /*追加指定内嵌样式到编辑器内容的img标签,兼容图片自动适应页面*/
  536. // $title = '';
  537. // if (!empty($data['title'])) {
  538. // $title = $data['title'];
  539. // } else {
  540. // $title = !empty($data['typename']) ? $data['typename'] : '';
  541. // }
  542. // $content = htmlspecialchars_decode($val);
  543. // $val = htmlspecialchars(img_style_wh($content, $title));
  544. // /*--end*/
  545. // break;
  546. }
  547. default:
  548. {
  549. if (is_array($val)) {
  550. $new_val = [];
  551. foreach ($val as $_k => $_v) {
  552. $_v = trim($_v);
  553. if (!empty($_v)) {
  554. $new_val[] = $_v;
  555. }
  556. }
  557. $val = $new_val;
  558. } else {
  559. $val = trim($val);
  560. }
  561. break;
  562. }
  563. }
  564. $nowDataExt[$key] = $val;
  565. }
  566. $nowData = array(
  567. 'aid' => $data['aid'],
  568. 'add_time' => getTime(),
  569. 'update_time' => getTime(),
  570. );
  571. !empty($nowDataExt) && $nowData = array_merge($nowDataExt, $nowData);
  572. $tableExt = Db::name('channeltype')->where('id', $channel_id)->getField('table');
  573. $tableExt .= '_content';
  574. $count = Db::name($tableExt)->where('aid', $data['aid'])->count();
  575. if (empty($count)) {
  576. Db::name($tableExt)->insert($nowData);
  577. } else {
  578. Db::name($tableExt)->where('aid', $data['aid'])->save($nowData);
  579. }
  580. }
  581. }
  582. }