$params['cid'], 'title' => $params['title'], 'image' => $params['image'] ? FileService::setFileUrl($params['image']) : '', 'contract_y_logo' => $params['contract_y_logo'] ? FileService::setFileUrl($params['contract_y_logo']) : '', 'contract_b_logo' => $params['contract_b_logo'] ? FileService::setFileUrl($params['contract_b_logo']) : '', 'text' => $params['text'], 'content' => $params['content'] ?? '', 'is_show' => $params['is_show'], 'sort' => $params['sort'], 'langs' => json_encode($langs, JSON_UNESCAPED_UNICODE), ]); // //系统消息则创建用户消息记录 // if($params['cid'] == 5){ // $users = User::select()->toArray(); // foreach ($users as &$user) { // UserNotice::create([ // 'user_id' => $user['id'], // 'hint_id' => $hint['id'], // 'title' => $params['text'], // 'content' => $params['content'] ?? '', // 'notice_type' => 3, // 'langs' => json_encode($langs, JSON_UNESCAPED_UNICODE), // ]); // } // } Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); self::setError($e->getMessage()); return false; } } /** * @notes 编辑提示内容 * @param array $params * @return bool * @author BD * @date 2024/03/17 17:01 */ public static function edit(array $params): bool { Db::startTrans(); try { $langs = $params['langs']; foreach ($langs as &$content_lang) { if(!empty($content_lang['image'])){ $content_lang['image'] = FileService::setFileUrl($content_lang['image']); } if(!empty($content_lang['content'])){ $content_lang['content'] = clear_file_domain($content_lang['content']); } } DecorateHint::update([ 'id' => $params['id'], 'title' => $params['title'], 'image' => $params['image'] ? FileService::setFileUrl($params['image']) : '', 'contract_y_logo' => $params['contract_y_logo'] ? FileService::setFileUrl($params['contract_y_logo']) : '', 'contract_b_logo' => $params['contract_b_logo'] ? FileService::setFileUrl($params['contract_b_logo']) : '', 'text' => $params['text'], 'content' => $params['content'] ?? '', 'is_show' => $params['is_show'], 'sort' => $params['sort'], 'langs' => json_encode($langs, JSON_UNESCAPED_UNICODE), ]); // $hint = DecorateHint::where(['id' => $params['id']])->findOrEmpty(); // //系统消息则创建用户消息记录 // $cidArr = array(5,6,7); // if(in_array($hint['cid'], $cidArr)){ // $notices = UserNotice::where(['hint_id' => $params['id']])->select()->toArray(); // foreach ($notices as &$notice) { // UserNotice::update([ // 'id' => $notice['id'], // 'title' => $params['text'], // 'content' => $params['content'] ?? '', // 'langs' => json_encode($langs, JSON_UNESCAPED_UNICODE), // ]); // } // } Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); self::setError($e->getMessage()); return false; } } /** * @notes 删除提示内容 * @param array $params * @return bool * @author BD * @date 2024/03/17 17:01 */ public static function delete(array $params): bool { return DecorateHint::destroy($params['id']); } /** * @notes 获取提示内容详情 * @param $params * @return array * @author BD * @date 2024/03/17 17:01 */ public static function detail($params): array { return DecorateHint::findOrEmpty($params['id'])->toArray(); } /** * @notes 消息列表 * @param $params * @return array * @author BD * @date 2024/03/17 17:01 */ public static function allByType($params) : array { $field = ['id', 'text']; $notices = DecorateHint::field($field) ->where(['cid' => $params['cid'],'is_show' => 1]) ->order(['sort' => 'desc','id' => 'desc']) ->select()->toArray(); return $notices; } }